Bug 212460 - Request for extra methods on PrecisionRectangle and a fix on PrecisionPoint
Summary: Request for extra methods on PrecisionRectangle and a fix on PrecisionPoint
Status: RESOLVED FIXED
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4.0 (Ganymede) M5   Edit
Assignee: Alex Boyko CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks: 194482
  Show dependency tree
 
Reported: 2007-12-10 16:16 EST by Alex Boyko CLA
Modified: 2008-09-18 13:32 EDT (History)
3 users (show)

See Also:


Attachments
Patch for PrecisionPoint and PrecisionRecatngle (5.66 KB, application/octet-stream)
2007-12-10 16:19 EST, Alex Boyko CLA
no flags Details
patch (5.66 KB, patch)
2007-12-11 17:49 EST, Alex Boyko CLA
no flags Details | Diff
Corrected patch (5.66 KB, patch)
2007-12-12 17:14 EST, Alex Boyko CLA
no flags Details | Diff
Added methods to Point, Dimension and Rectangle to make cleaner API on precise geomteric objects (14.86 KB, patch)
2007-12-14 14:21 EST, Alex Boyko CLA
no flags Details | Diff
Corrected patch (14.85 KB, patch)
2007-12-18 11:00 EST, Alex Boyko CLA
no flags Details | Diff
Corrected patch (16.58 KB, patch)
2008-01-02 13:04 EST, Alex Boyko CLA
ahunter.eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Boyko CLA 2007-12-10 16:16:59 EST
1. PrecisionPoint.
Constructors PrecisionPoint(Point copy) and PrecisionPoint(double x, double y)
may result in diffent x and y values for PrecisionPoint
Suppose preciseX = N.999999... preciseY = M.99999.... Hence x = N + 1 and y = M + 1.
If this is copied using PrecisionPoint(Point copy) then everything is correct.
If PrecisionPoint(double x, double y) is used then copied x and y would be N and M instead of N + 1, M + 1.

2. Would like to have methods supporting PrecisionPoint(s):
shrink(double, double)
expand (double, double)
union(double, double)
getPreciseCenter()
setLocation(Point)
transpose()
contains(Point)

Patch will be uploaded.
Comment 1 Alex Boyko CLA 2007-12-10 16:19:43 EST
Created attachment 84900 [details]
Patch for PrecisionPoint and PrecisionRecatngle

Hi Randy and Pratik.

Could you please take a look at the patch and tell if it's ok to commit it?
Thanks in advance.
Comment 2 Alex Boyko CLA 2007-12-11 17:49:03 EST
Created attachment 85011 [details]
patch

Previous patch was not uploaded correctly. Here is the correctly uploaded patch. Sorry for any inconvenience.
Comment 3 Alex Boyko CLA 2007-12-12 17:14:42 EST
Created attachment 85133 [details]
Corrected patch

Corrected the patch:
1. Added the correct @since #
2. In PrecisionRectangle#transpose() after double precise values are transposed it's better to call super to transpose the int values intsead of updateInts().
Comment 4 Randy Hudson CLA 2007-12-13 21:38:20 EST
We have one non-standard signature on PrecisionRectangle already:
union(PrecisionRectangle).

But maybe we could avoid further confusion if we make some changes to Point, Dimension, and/or Rectangle first. What if we add:

float preciseX()
float preciseY()

to the standard Point class? It could be package visibility, but I don't see any problem in their being public too. Then this new union(point) method would not behave differently based on which method gets called (i.e. union(Point) vs. union(PrecisePoint)), or we could avoid instance of checks, as with:

public Rectangle setLocation(Point loc) {
+	if (loc instanceof PrecisionPoint) {
+		PrecisionPoint preciseLoc = (PrecisionPoint) loc;
+		this.preciseX = preciseLoc.preciseX;
+		this.preciseY = preciseLoc.preciseY;
+		updateInts();
+		return this;
+	} else {
+		return super.setLocation(loc);
+	}
+}

But with new methods on Point, etc.:

public Rectangle setLocation(Point loc) {
+	this.preciseX = loc.preciseX();
+	this.preciseY = loc.preciseY();
+	updateInts();
+	return this;
+}

If the client could call union(Point) instead of union(double, double), that could minimize the number of new signatures.
Comment 5 Alex Boyko CLA 2007-12-14 14:21:25 EST
Created attachment 85304 [details]
Added methods to Point, Dimension and Rectangle to make cleaner API on precise geomteric objects

I've added double preciseX() type of methods on Point, Dimension and Rectangle and reworked PrecisionPoint, PrecisionDimension and PrecisionRectangle accordingly.
Also I removed "final" for Rectangle#union(Rectangle) and Rectangle#union(Point) methods such that they can be overriden on PrecisionRectangle. PrecisionRectangle#union(PrecisionRectangle) is deprecated therefore.

Please let me know if this looks as you'd expect it.
Thnanks in advance.
Comment 6 Randy Hudson CLA 2007-12-17 17:32:14 EST
is getPreciseCenter still needed, or could PrecisionRectangle just override getCenter() now that x & y are polymorphic, or whatever it's called.
Comment 7 Alex Boyko CLA 2007-12-18 11:00:24 EST
Created attachment 85466 [details]
Corrected patch

Indeed, it's not needed at all - Point#getCenter() must be overriden in this case.
The corrected patch is uploaded.
Comment 8 Alex Boyko CLA 2007-12-18 11:02:53 EST
So, if everything else looks ok, perhaps, Anthony could commit that last corrected patch?
Comment 9 Alex Boyko CLA 2007-12-19 11:15:45 EST
Hi Anthony,

Could you commit the last corrected patch please?
Thanks in advance.
Comment 10 Anthony Hunter CLA 2008-01-02 12:00:13 EST
I am getting a single compile error in 

public PrecisionPoint getCenter() {
	return new PrecisionPoint(preciseX + preciseWidth / 2.0, preciseY + preciseHeight / 2.0);
}

PrecisionRectangle.java: line 300: The return type is incompatible with Rectangle.getCenter()
Comment 11 Randy Hudson CLA 2008-01-02 12:36:57 EST
It looks like Pratik added *.prefs to the .cvsignore a while back, which can allow the code to be compiled with the wrong compatibility settings (1.5 instead of 1.4).  It makes sense to me to force anyone creating patches to also check-out the proper project-specific compiler settings to avoid this in the future.
Comment 12 Alex Boyko CLA 2008-01-02 13:04:06 EST
Created attachment 86005 [details]
Corrected patch

Corrected the compiler error
Comment 13 Anthony Hunter CLA 2008-01-02 13:45:46 EST
(In reply to comment #11)
> It looks like Pratik added *.prefs to the .cvsignore a while back, which can
> allow the code to be compiled with the wrong compatibility settings (1.5
> instead of 1.4).  It makes sense to me to force anyone creating patches to also
> check-out the proper project-specific compiler settings to avoid this in the
> future.
> 

Hmm, This is a problem since the line
org.eclipse.jdt.core.compiler.compliance=1.4
is in the GEF plug-in but not Draw2d.

I will fix when doing Bug 204605
	

Comment 14 Anthony Hunter CLA 2008-01-02 13:51:12 EST
Committed to HEAD.