I've made some tests with different epsilon values and the bug still there.
But I've found the reason of the persistence of the bug. For the curious
I'll explain it below (I hadn't time yesterday to test the solution).

This is the current code of the find_duck function:

https://github.com/synfig/synfig/blob/master/synfig-studio/src/gui/duckmatic.cpp#L1041

The interesting part is the one where the current ducks are iterated to see
which is the one closest to the current mouse position:

DuckMap::const_iterator iter;
for(iter=duck_map.begin();iter!=duck_map.end();++iter)
{
        const Duck::Handle& duck(iter->second);
        if(duck->get_ignore() ||
           (duck->get_type() && !(type & duck->get_type())))
                continue;

        Real dist((duck->get_trans_point()-point).mag_squared());

        if(dist<=closest)
        {
                // if there are two ducks at the "same" position, keep track of 
them
                bool equal;
                equal=fabs(dist-closest)<0.0000001?true:false;
                if(equal)
                {
                        // if we haven't any duck stored keep track of last 
found
                        if(!ret_vector.size())
                                ret_vector.push_back(ret);
                        // and also keep track of the one on the same place
                        ret_vector.push_back(duck);
                }
                // we have another closer duck then discard the stored
                else if (!equal && ret_vector.size())
                        ret_vector.clear();
                closest=dist;
                ret=duck;
        }
}


The code considers that two dusks (the closest and one we are comparing to)
are at the "same" place if their relative distance is small enough.

        bool equal;
        equal=fabs(dist-closest)<0.0000001?true:false;
        if(equal) ...


But that's biased, because that portion of code is only executed when dist
is less or equal than closest. But what if dist is slightly greater than
closest? It can be considered that they are at the "same" position but that
conclusion is never reached because there is a previous "<=" comparison
that avoid that situation. So the code inside the if(dist<=closest) is
never reached because dist>closest but in fact (dist-closest) ≈ 0

So the solution for that bug should be move the "equal" lines before the
comparison and use it in replacement of the '=' part:

        bool equal;
        equal=fabs(dist-closest)<0.0000001?true:false;
        if(dist<closest || equal)
        {
                // if there are two ducks at the "same" position, keep track of 
them
                if(equal)
                {
                        // if we haven't any duck stored keep track of last 
found
                        if(!ret_vector.size())
                                ret_vector.push_back(ret);
                        // and also keep track of the one on the same place
                        ret_vector.push_back(duck);
                }
                // we have another closer duck then discard the stored
                else if (!equal && ret_vector.size())
                        ret_vector.clear();
                closest=dist;
                ret=duck;
        }

That is :)
Cheers!


2013/8/8 Konstantin Dmitriev <[email protected]>

> 2013/8/8 Carlos López González <[email protected]>:
> > I think it still has solution just increasing the "epsilon" value. I'll
> take
> > a look as soon as possible.
>
> Thanks! But I'm afraid the "correct" epsilon value would depend on the
> zoom value of parent group. Maybe I'm wrong.
> K.
>
>
> ------------------------------------------------------------------------------
> Get 100% visibility into Java/.NET code with AppDynamics Lite!
> It's a free troubleshooting tool designed for production.
> Get down to code-level detail for bottlenecks, with <2% overhead.
> Download for free and get started troubleshooting in minutes.
> http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
> _______________________________________________
> Synfig-devl mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/synfig-devl
>



-- 
Carlos
http://synfig.org
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to