[Patch] java.awt.geom.* merged
Michael Koch
konqueror@gmx.de
Thu Sep 23 22:34:00 GMT 2004
Hi list,
I just commited that attached patch to merge java.awt.gemo.* with GNU
classpath again.
Michael
2004-09-23 Sven de Marothy <sven@physto.se>
* java/awt/geom/Arc2D.java: Reformatted.
(setArc): Correct documentation to say 'upper left corner'.
(setArcByTangent,contains,intersects): Implemented.
(containsAngle): Corrected to handle negative extents.
(ArcIterator): Set to private.
(ArcIterator): Corrected for CHORD-type arcs, negative extents.
(intersects): Fix: Now checks the arc segment.
(contains): Cleaned up.
* java/awt/geom/CubicCurve2a.javaD: Fix insideness-test. Reindent.
(contains): Implemented.
(intersects): Implemented.
* java/awt/geom/QuadCurve2D.java: Fix insideness-test. Reindent.
* java/awt/geom/GeneralPath: Fix insideness-test. Reindent and
document. Fully (re)implemented using separate xpoints and ypoints
float[] coords.
-------------- next part --------------
Index: java/awt/geom/Arc2D.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/geom/Arc2D.java,v
retrieving revision 1.3.14.2
diff -u -r1.3.14.2 Arc2D.java
--- java/awt/geom/Arc2D.java 4 Sep 2004 00:52:17 -0000 1.3.14.2
+++ java/awt/geom/Arc2D.java 23 Sep 2004 08:50:33 -0000
@@ -569,40 +569,83 @@
|| contains(x + w, y + h))
return true;
- double mx = getX() + getWidth() / 2;
- double my = getY() + getHeight() / 2;
- double x1 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart())) / 2;
- double y1 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart())) / 2;
- double x2 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart()
- + extent)) / 2;
- double y2 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart()
- + extent)) / 2;
+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
+
+ double a = getWidth() / 2.0;
+ double b = getHeight() / 2.0;
+
+ double mx = getX() + a;
+ double my = getY() + b;
+ double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart()));
+ double y1 = my - b * Math.sin(Math.toRadians(getAngleStart()));
+ double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent));
+ double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent));
+
if (getArcType() != CHORD)
{
// check intersections against the pie radii
- if (Line2D.linesIntersect(mx, my, x1, y1, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x1, y1, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x1, y1))
return true;
-
- if (Line2D.linesIntersect(mx, my, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x2, y2))
return true;
}
- else if (Line2D.linesIntersect(x1, y1, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(x1, y1, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y + h, x + w, y + h))
+ else// check the chord
+ if (rect.intersectsLine(x1, y1, x2, y2))
return true;
- if ((new Rectangle2D.Double(x, y, w, h)).contains(x1, y1))
+ // Check the Arc segment against the four edges
+ double dx;
+
+ // Check the Arc segment against the four edges
+ double dy;
+ dy = y - my;
+ dx = a * Math.sqrt(1 - ((dy * dy) / (b * b)));
+ if (! java.lang.Double.isNaN(dx))
+ {
+ if (mx + dx >= x && mx + dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (mx - dx >= x && mx - dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx))))
+ return true;
+ }
+ dy = (y + h) - my;
+ dx = a * Math.sqrt(1 - ((dy * dy) / (b * b)));
+ if (! java.lang.Double.isNaN(dx))
+ {
+ if (mx + dx >= x && mx + dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (mx - dx >= x && mx - dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx))))
+ return true;
+ }
+ dx = x - mx;
+ dy = b * Math.sqrt(1 - ((dx * dx) / (a * a)));
+ if (! java.lang.Double.isNaN(dy))
+ {
+ if (my + dy >= y && my + dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (my - dy >= y && my - dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(dy, dx))))
+ return true;
+ }
+
+ dx = (x + w) - mx;
+ dy = b * Math.sqrt(1 - ((dx * dx) / (a * a)));
+ if (! java.lang.Double.isNaN(dy))
+ {
+ if (my + dy >= y && my + dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (my - dy >= y && my - dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(dy, dx))))
+ return true;
+ }
+
+ // Check whether the arc is contained within the box
+ if (rect.contains(mx, my))
return true;
return false;
@@ -627,37 +670,27 @@
&& contains(x + w, y + h)))
return false;
- double mx = getX() + getWidth() / 2;
- double my = getY() + getHeight() / 2;
- double x1 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart())) / 2;
- double y1 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart())) / 2;
- double x2 = mx
- + getWidth() * Math.cos(Math.toRadians(getAngleStart()
- + extent)) / 2;
- double y2 = my
- - getHeight() * Math.sin(Math.toRadians(getAngleStart()
- + extent)) / 2;
+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
+
+ double a = getWidth() / 2.0;
+ double b = getHeight() / 2.0;
+
+ double mx = getX() + a;
+ double my = getY() + b;
+ double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart()));
+ double y1 = my - b * Math.sin(Math.toRadians(getAngleStart()));
+ double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent));
+ double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent));
if (getArcType() != CHORD)
{
// check intersections against the pie radii
- if (Line2D.linesIntersect(mx, my, x1, y1, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x1, y1, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x1, y1, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x1, y1))
return false;
- if (Line2D.linesIntersect(mx, my, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(mx, my, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(mx, my, x2, y2, x, y + h, x + w, y + h))
+ if (rect.intersectsLine(mx, my, x2, y2))
return false;
}
- else if (Line2D.linesIntersect(x1, y1, x2, y2, x, y, x + w, y)
- || Line2D.linesIntersect(x1, y1, x2, y2, x + w, y, x + w, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y, x, y + h)
- || Line2D.linesIntersect(x1, y1, x2, y2, x, y + h, x + w, y + h))
+ else if (rect.intersectsLine(x1, y1, x2, y2))
return false;
return true;
}
Index: java/awt/geom/CubicCurve2D.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/geom/CubicCurve2D.java,v
retrieving revision 1.4.8.1
diff -u -r1.4.8.1 CubicCurve2D.java
--- java/awt/geom/CubicCurve2D.java 8 Aug 2004 19:43:36 -0000 1.4.8.1
+++ java/awt/geom/CubicCurve2D.java 23 Sep 2004 08:50:33 -0000
@@ -59,6 +59,7 @@
public abstract class CubicCurve2D implements Shape, Cloneable
{
private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+ private static final double EPSILON = 1E-10;
/**
* Constructs a new CubicCurve2D. Typical users will want to
@@ -1089,21 +1090,21 @@
If this is not done, bad behaviour may result for points on that axis.*/
if (a0 == 0.0 || a3 == 0.0)
{
- double small = getFlatness() * (1E-10);
+ double small = getFlatness() * EPSILON;
if (a0 == 0.0)
- a0 += small;
+ a0 -= small;
if (a3 == 0.0)
- a3 += small;
+ a3 -= small;
}
if (useYaxis)
{
- if (Line2D.linesIntersect(b0, a0, b3, a3, 0.0, 0.0, distance, 0.0))
+ if (Line2D.linesIntersect(b0, a0, b3, a3, EPSILON, 0.0, distance, 0.0))
nCrossings++;
}
else
{
- if (Line2D.linesIntersect(a0, b0, a3, b3, 0.0, 0.0, 0.0, distance))
+ if (Line2D.linesIntersect(a0, b0, a3, b3, 0.0, EPSILON, 0.0, distance))
nCrossings++;
}
Index: java/awt/geom/GeneralPath.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/geom/GeneralPath.java,v
retrieving revision 1.3.14.1
diff -u -r1.3.14.1 GeneralPath.java
--- java/awt/geom/GeneralPath.java 8 Aug 2004 19:43:36 -0000 1.3.14.1
+++ java/awt/geom/GeneralPath.java 23 Sep 2004 08:50:33 -0000
@@ -793,11 +793,11 @@
y1 = firsty;
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y1 == 0.0)
- y1 += epsilon;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, distance,
- 0.0))
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
windingNumber += (y1 < y0) ? 1 : negative;
cx = firstx;
@@ -814,10 +814,11 @@
y1 = firsty;
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y1 == 0.0)
- y1 += epsilon;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, distance, 0.0))
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
windingNumber += (y1 < y0) ? 1 : negative;
cx = firstx;
@@ -832,10 +833,11 @@
y1 = ypoints[pos++] - (float) y;
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y1 == 0.0)
- y1 += epsilon;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, distance, 0.0))
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
windingNumber += (y1 < y0) ? 1 : negative;
cx = xpoints[pos - 1] - (float) x;
@@ -854,9 +856,9 @@
&& (y0 * y1 <= 0 || y1 * y2 <= 0))
{
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y2 == 0.0)
- y2 += epsilon;
+ y2 -= epsilon;
r[0] = y0;
r[1] = 2 * (y1 - y0);
@@ -897,9 +899,9 @@
&& (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0))
{
if (y0 == 0.0)
- y0 += epsilon;
+ y0 -= epsilon;
if (y3 == 0.0)
- y3 += epsilon;
+ y3 -= epsilon;
r[0] = y0;
r[1] = 3 * (y1 - y0);
@@ -942,3 +944,4 @@
return (windingNumber);
}
} // class GeneralPath
+
Index: java/awt/geom/QuadCurve2D.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/geom/QuadCurve2D.java,v
retrieving revision 1.6.8.1
diff -u -r1.6.8.1 QuadCurve2D.java
--- java/awt/geom/QuadCurve2D.java 8 Aug 2004 19:43:36 -0000 1.6.8.1
+++ java/awt/geom/QuadCurve2D.java 23 Sep 2004 08:50:33 -0000
@@ -59,6 +59,7 @@
public abstract class QuadCurve2D implements Shape, Cloneable
{
private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+ private static final double EPSILON = 1E-10;
/**
* Constructs a new QuadCurve2D. Typical users will want to
@@ -962,12 +963,12 @@
If this is not done,bad behaviour may result for points on that axis. */
if (a0 == 0.0 || a2 == 0.0)
{
- double small = getFlatness() * (1E-10);
+ double small = getFlatness() * EPSILON;
if (a0 == 0.0)
- a0 += small;
+ a0 -= small;
if (a2 == 0.0)
- a2 += small;
+ a2 -= small;
}
r[0] = a0;
@@ -990,12 +991,12 @@
if (useYaxis)
{
- if (Line2D.linesIntersect(b0, a0, b2, a2, 0.0, 0.0, distance, 0.0))
+ if (Line2D.linesIntersect(b0, a0, b2, a2, EPSILON, 0.0, distance, 0.0))
nCrossings++;
}
else
{
- if (Line2D.linesIntersect(a0, b0, a2, b2, 0.0, 0.0, 0.0, distance))
+ if (Line2D.linesIntersect(a0, b0, a2, b2, 0.0, EPSILON, 0.0, distance))
nCrossings++;
}
More information about the Java-patches
mailing list