Bug 297569 - The "containsPoint" method in class "org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg" will cause an integer overflow error
Summary: The "containsPoint" method in class "org.eclipse.gmf.runtime.draw2d.ui.geomet...
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 major
Target Milestone: 2.2.2   Edit
Assignee: Alex Boyko CLA
QA Contact:
URL:
Whiteboard: 2.1.4 Patch
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-11 04:49 EST by ztwang CLA
Modified: 2010-01-14 13:39 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ztwang CLA 2009-12-11 04:49:28 EST
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Build Identifier: 20090619-0625

I use the method "intersect" method of class "org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg" to get the intersection points of connections, in this method the "containsPoint" method will be invoked, if the connection is verg long, the "containsPoint" method will cause a integer overflow error, this is because the connection length is treated as integer. The integer overflow statements are :

double lengthOfSegment = Math.sqrt((origin.x - terminus.x)*(origin.x - terminus.x) + (origin.y - terminus.y)*(origin.y - terminus.y));
double lengthFromOriginToPoint = Math.sqrt((origin.x - aPoint.x)*(origin.x - aPoint.x) + (origin.y - aPoint.y)*(origin.y - aPoint.y));
double lengthFromTerminusToPoint = Math.sqrt((terminus.x - aPoint.x)*(terminus.x - aPoint.x) + (terminus.y - aPoint.y)*(terminus.y - aPoint.y));


Reproducible: Always
Comment 1 ztwang CLA 2009-12-11 04:52:24 EST
My suggestion is to use the "getDistance" method from class "Point" to calculation the length of a connection, updated code will be like this:

public final boolean containsPoint(final Point aPoint, final int tolerance) {
         double lengthOfSegment = origin.getDistance(terminus);
	double lengthFromOriginToPoint = origin.getDistance(aPoint);
	double lengthFromTerminusToPoint = terminus.getDistance(aPoint);
			
	return lengthFromTerminusToPoint + lengthFromOriginToPoint - lengthOfSegment <= tolerance;
}
Comment 2 Anthony Hunter CLA 2010-01-13 15:54:22 EST
Hi Alex, cab you check this one out?

Not sure if this team has the patch / fix we made in Bug 246288
Comment 3 Alex Boyko CLA 2010-01-13 16:43:59 EST
The fix proposed in the comment looks good to me. I'll commit it today/tomorrrow.
Do we want to commit this for 2.2.2 or just 2.3 as it stands?
Comment 4 Anthony Hunter CLA 2010-01-13 17:38:06 EST
The team requested it go into CVS for Ganymede/3.4.2.

So that would be R2_1_maintance, R2_2_maintance and HEAD.
Comment 5 Alex Boyko CLA 2010-01-14 10:31:00 EST
Done, committed for all 3 streams
Comment 6 Eclipse Webmaster CLA 2010-07-19 12:30:27 EDT
[GMF Restructure] Bug 319140 : product GMF and component Runtime Diagram was the original product and component for this bug