Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Starange problem with selection
Starange problem with selection [message #516844] Thu, 25 February 2010 10:47 Go to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Below image is screen of GEF viewer in which all the connections are going from above the figures(no SPC router)..
http://lh6.ggpht.com/_3SpBG8kdCvs/S4ZSvcV2MuI/AAAAAAAADIs/nUIUf0pDrmU/s800/selection%20problem.GIF

In this configration the red connection is the problematic one(its a very long connection)..
when ever i try to select the blue arrow marked figures the red connection gets selected!!!!

This does not happen if i apply ShortestPathConnestionRouter....

Any idea whats happening???
The problem is i can not reproduce it in GEF examples since this is specific figure and connection scanario...

PLS HELP.


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Starange problem with selection [message #534807 is a reply to message #516844] Thu, 20 May 2010 12:09 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Any body else who has the same issue???

---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Starange problem with selection [message #534862 is a reply to message #534807] Thu, 20 May 2010 14:09 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Ok its a bug in draw2d pls conferm...

There is a class in draw2d called Geometry which is being used in polyline.containsPoint(int x, int y)

This has a method called segmentContainsPoint which uses Dot product of two vectors formula to calculate the distance between the point and the line segment...

 /**
     * @return true if the least distance between point (px,py) and segment (x1,y1) - (x2,y2) is
     *         less then specified tolerance
     */
    private static boolean segmentContainsPoint(int x1, int y1, int x2, int y2, int px, int py,
            int tolerance)
    {
        /*
         * Point should be located inside Rectangle(x1 -+ tolerance, y1 -+ tolerance, x2 +-
         * tolerance, y2 +- tolerance)
         */
        Rectangle lineBounds = Rectangle.SINGLETON;
        lineBounds.setSize(0, 0);
        lineBounds.setLocation(x1, y1);
        lineBounds.union(x2, y2);
        lineBounds.expand(tolerance, tolerance);
        if (!lineBounds.contains(px, py))
        {
            return false;
        }

        /*
         * If this is horizontal, vertical line or dot then the distance between specified point
         * and segment is not more then tolerance (due to the lineBounds check above)
         */
        if (x1 == x2 || y1 == y2)
        {
            return true;
        }

        /*
         * Calculating square distance from specified point to this segment using formula for Dot
         * product of two vectors.
         */
        int v1x = x2 - x1;
        int v1y = y2 - y1;
        int v2x = px - x1;
        int v2y = py - y1;
        int numerator = v2x * v1y - v1x * v2y;
        int denominator = v1x * v1x + v1y * v1y;
        int squareDistance = (int) ((long) numerator * numerator / denominator);
        return squareDistance <= tolerance * tolerance;
    }



Here at the end ,the dot product formula is wrong the denominater should be modded,since it can be negative
and the distance can come out to be negative, which will be always less tolerance^2...

In certain scanarious the segmentcontainspoint returns true hence the selection.


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Starange problem with selection [message #534864 is a reply to message #534862] Thu, 20 May 2010 14:17 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=313731

At the time of logging i did not notice this but now
from bug comments
Quote:
> Are you talking about:
> int denominator = v1x * v1x + v1y * v1y
> ?
>
> It's the sum of squares... How could this be negative?

int squareDistance = (int) ((long) numerator * numerator /
denominator);

If the value of v1x * v1x + v1y * v1y becomes more then integer max,
then after casting it will become negative Smile


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Thu, 20 May 2010 15:05]

Report message to a moderator

Previous Topic:How to define custom PolylineConnection graphics?
Next Topic:Creating only Figure Without UI.
Goto Forum:
  


Current Time: Thu Apr 25 06:34:26 GMT 2024

Powered by FUDForum. Page generated in 0.03262 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top