Hello all,
It seems my FSF paperwork finally went through, so here is a
re-submission of the changes I've made. Due to formatting differences
the patch was difficult to read, so I put the whole files here:
http://www.qc.physto.se/~sven/Geom
This is the missing contains/intersects code for Cubic- and
QuadCurve2D, as well as an implementation of GeneralPath,
including the changes suggested by Sacha.
(the png file explaining winding rules is intended for
java/awt/geom/doc-files )
There is also (included with this post) a new patch for
RoundRectangle2D, which had the following errors:
contains() - the corner arc was off by a factor 2
intersects() - didn't handle the round corners at all, when it should
This fixes bug #6067, by the way.
getPathIterator() - The arcs were not being defined correctly and
one point was in the wrong place. Fixed it and changed the iteration
direction to counterclockwise, which I find a bit more logical
since Arc2D's are defined with that direction as positive.
So if it's all OK, now there's one bug and one task less out there.
And between vacations and paid work, I'm still working on Area.
/Sven
--- original/RoundRectangle2D.java 2004-07-11 02:49:30.000000000 +0200
+++ RoundRectangle2D.java 2004-07-12 18:03:08.000000000 +0200
@@ -1,5 +1,5 @@
/* RoundRectangle2D.java -- represents a rectangle with rounded corners
- Copyright (C) 2000, 2002, 2003 Free Software Foundation
+ Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -87,8 +87,10 @@
// Now check to see if the point is in range of an arc.
double dy = Math.min(Math.abs(my - y), Math.abs(my + mh - y));
double dx = Math.min(Math.abs(mx - x), Math.abs(mx + mw - x));
- double aw = getArcWidth();
- double ah = getArcHeight();
+ // The arc dimensions are that of the corresponding ellipse
+ // thus a 90 degree segment is half of that.
+ double aw = getArcWidth()/2.0;
+ double ah = getArcHeight()/2.0;
if (dx > aw || dy > ah)
return true;
@@ -112,8 +114,8 @@
{
// We have to check all four points here (for ordinary rectangles
// we can just check opposing corners).
- return (contains(x, y) && contains(x + w, h)
- && contains(x, y + h) && contains(x + w, y + h));
+ return(contains(x, y) && contains(x, y + h)
+ && contains(x + w, y + h) && contains(x + w, y));
}
/** Return a new path iterator which iterates over this rectangle.
@@ -129,8 +131,8 @@
final double archeight = getArcHeight();
return new PathIterator()
{
- /** We iterate clockwise around the rectangle, starting in the
- * upper left. This variable tracks our current point, which
+ /** We iterate counterclockwise around the rectangle, starting in the
+ * upper right. This variable tracks our current point, which
* can be on either side of a given corner. */
private int current = 0;
@@ -160,37 +162,37 @@
{
case 0:
case 8:
- temp[0] = minx;
- temp[1] = miny + archeight;
- break;
- case 1:
- temp[0] = minx + arcwidth;
- temp[1] = miny;
- break;
- case 2:
- temp[0] = maxx - arcwidth;
- temp[1] = maxy;
- break;
- case 3:
temp[0] = maxx;
temp[1] = miny + archeight;
break;
- case 4:
+ case 7:
temp[0] = maxx;
temp[1] = maxy - archeight;
break;
- case 5:
+ case 6:
temp[0] = maxx - arcwidth;
temp[1] = maxy;
break;
- case 6:
+ case 5:
temp[0] = minx + arcwidth;
temp[1] = maxy;
break;
- case 7:
+ case 4:
temp[0] = minx;
temp[1] = maxy - archeight;
break;
+ case 3:
+ temp[0] = minx;
+ temp[1] = miny + archeight;
+ break;
+ case 2:
+ temp[0] = minx + arcwidth;
+ temp[1] = miny;
+ break;
+ case 1:
+ temp[0] = maxx - arcwidth;
+ temp[1] = miny;
+ break;
}
}
@@ -218,8 +220,11 @@
double x1 = temp[0];
double y1 = temp[1];
getPoint(current + 1);
- arc.setFrameFromDiagonal(x1, y1, temp[0], temp[1]);
- arc.setAngles(x1, y1, temp[0], temp[1]);
+ Rectangle2D.Double r = new Rectangle2D.Double(Math.min(x1,temp[0]),
+ Math.min(y1,temp[1]),
+ Math.abs(x1-temp[0]),
+ Math.abs(y1-temp[1]));
+ arc.setArc(r,(current >> 1)*90.0, 90.0, Arc2D.OPEN);
corner = arc.getPathIterator(at);
}
}
@@ -286,14 +291,9 @@
*/
public boolean intersects(double x, double y, double w, double h)
{
- // Here we can use the same code we use for an ordinary rectangle.
- double mx = getX();
- double mw = getWidth();
- if (x < mx || x >= mx + mw || x + w < mx || x + w >= mx + mw)
- return false;
- double my = getY();
- double mh = getHeight();
- return y >= my && y < my + mh && y + h >= my && y + h < my + mh;
+ // Check if any corner is within the rectangle
+ return(contains(x, y) || contains(x, y + h)
+ || contains(x + w, y + h) || contains(x + w, y));
}
/** Set the boundary of this round rectangle.
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://lists.gnu.org/mailman/listinfo/classpath