summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven de Marothy <sven@physto.se>2004-09-07 16:01:50 +0000
committerSven de Marothy <sven@physto.se>2004-09-07 16:01:50 +0000
commitaab60a3ef7e9f5a3ba9f1dd363d731dc76c24fc5 (patch)
treee872f10cbf12fd0240cc39a0fcd35ac27e3b4bd3
parent3305158444f949244f1a34253fd9c188a32b117f (diff)
downloadclasspath-aab60a3ef7e9f5a3ba9f1dd363d731dc76c24fc5.tar.gz
2004-09-07 Sven de Marothy <sven@physto.se>
* java/awt/geom/doc-files/Area-1.png: Graphics for Area documentation. New file. * java/awt/geom/doc-files/Ellipse-1.png: Graphics for Ellipse2D documentation. New file. * java/awt/geom/doc-files/GeneralPath-1.png: Graphics for GeneralPath documentation. New file. * java/awt/geom/Arc2D.java: (intersects): Fix: Now checks the arc segment. (contains): Cleaned up. * java/awt/geom/Area.java: (isRectangular): Should return true on an empty path. (equals): Check for null. (rayIntersects): Fix insideness-test * java/awt/geom/CubicCurve2D.java: Fix insideness-test to comply with the correct behavior on edges * java/awt/geom/GeneralPath.java: Likewise * java/awt/geom/QuadCurve2D.java: Likewise
-rw-r--r--ChangeLog26
-rw-r--r--java/awt/geom/Arc2D.java133
-rw-r--r--java/awt/geom/Area.java23
-rw-r--r--java/awt/geom/CubicCurve2D.java11
-rw-r--r--java/awt/geom/GeneralPath.java31
-rw-r--r--java/awt/geom/QuadCurve2D.java11
-rw-r--r--java/awt/geom/doc-files/Area-1.pngbin0 -> 21447 bytes
-rw-r--r--java/awt/geom/doc-files/Ellipse-1.pngbin0 -> 19426 bytes
-rw-r--r--java/awt/geom/doc-files/GeneralPath-1.pngbin0 -> 13111 bytes
9 files changed, 153 insertions, 82 deletions
diff --git a/ChangeLog b/ChangeLog
index ce93e33f8..70e001a5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2004-09-07 Sven de Marothy <sven@physto.se>
+ * java/awt/geom/doc-files/Area-1.png:
+ Graphics for Area documentation. New file.
+
+ * java/awt/geom/doc-files/Ellipse-1.png:
+ Graphics for Ellipse2D documentation. New file.
+
+ * java/awt/geom/doc-files/GeneralPath-1.png:
+ Graphics for GeneralPath documentation. New file.
+
+ * java/awt/geom/Arc2D.java:
+ (intersects): Fix: Now checks the arc segment.
+ (contains): Cleaned up.
+
+ * java/awt/geom/Area.java:
+ (isRectangular): Should return true on an empty path.
+ (equals): Check for null.
+ (rayIntersects): Fix insideness-test
+
+ * java/awt/geom/CubicCurve2D.java:
+ Fix insideness-test to comply with the correct behavior on edges
+ * java/awt/geom/GeneralPath.java:
+ Likewise
+ * java/awt/geom/QuadCurve2D.java:
+ Likewise
+
2004-09-07 Jeroen Frijters <jeroen@frijters.net>
* java/util/TimeZone.java
diff --git a/java/awt/geom/Arc2D.java b/java/awt/geom/Arc2D.java
index 8d8e9dead..5e6d191f0 100644
--- a/java/awt/geom/Arc2D.java
+++ b/java/awt/geom/Arc2D.java
@@ -569,40 +569,83 @@ public abstract class Arc2D extends RectangularShape
|| 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 @@ public abstract class Arc2D extends RectangularShape
&& 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;
}
diff --git a/java/awt/geom/Area.java b/java/awt/geom/Area.java
index 1297a0e01..0b971048a 100644
--- a/java/awt/geom/Area.java
+++ b/java/awt/geom/Area.java
@@ -584,6 +584,9 @@ public class Area implements Shape, Cloneable
*/
public boolean isRectangular()
{
+ if (isEmpty())
+ return true;
+
if (holes.size() != 0 || solids.size() != 1)
return false;
@@ -700,6 +703,9 @@ public class Area implements Shape, Cloneable
*/
public boolean equals(Area area)
{
+ if (area == null)
+ return false;
+
if (! getBounds2D().equals(area.getBounds2D()))
return false;
@@ -919,7 +925,7 @@ public class Area implements Shape, Cloneable
}
// Non-intersecting, Is any point inside?
- if (contains(x, y))
+ if (contains(x + w * 0.5, y + h * 0.5))
return true;
// What if the rectangle encloses the whole shape?
@@ -2515,12 +2521,13 @@ public class Area implements Shape, Cloneable
return 0;
if (y0 == 0.0)
- y0 += EPSILON;
+ y0 -= EPSILON;
if (y1 == 0.0)
- y1 += EPSILON;
+ y1 -= EPSILON;
- if (Line2D.linesIntersect(x0, y0, x1, y1, 0.0, 0.0, Double.MAX_VALUE, 0.0))
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ EPSILON, 0.0, Double.MAX_VALUE, 0.0))
return 1;
return 0;
}
@@ -2727,9 +2734,9 @@ public class Area implements Shape, Cloneable
if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0) && (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);
@@ -3139,9 +3146,9 @@ public class Area implements Shape, Cloneable
&& (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);
diff --git a/java/awt/geom/CubicCurve2D.java b/java/awt/geom/CubicCurve2D.java
index 56b90e998..20373061d 100644
--- a/java/awt/geom/CubicCurve2D.java
+++ b/java/awt/geom/CubicCurve2D.java
@@ -59,6 +59,7 @@ import java.util.NoSuchElementException;
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 @@ public abstract class CubicCurve2D implements Shape, Cloneable
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++;
}
diff --git a/java/awt/geom/GeneralPath.java b/java/awt/geom/GeneralPath.java
index 40182eabf..2131c2443 100644
--- a/java/awt/geom/GeneralPath.java
+++ b/java/awt/geom/GeneralPath.java
@@ -793,11 +793,11 @@ public final class GeneralPath implements Shape, Cloneable
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 @@ public final class GeneralPath implements Shape, Cloneable
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 @@ public final class GeneralPath implements Shape, Cloneable
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 @@ public final class GeneralPath implements Shape, Cloneable
&& (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 @@ public final class GeneralPath implements Shape, Cloneable
&& (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 @@ public final class GeneralPath implements Shape, Cloneable
return (windingNumber);
}
} // class GeneralPath
+
diff --git a/java/awt/geom/QuadCurve2D.java b/java/awt/geom/QuadCurve2D.java
index 0cc9eb46e..0376d5a01 100644
--- a/java/awt/geom/QuadCurve2D.java
+++ b/java/awt/geom/QuadCurve2D.java
@@ -59,6 +59,7 @@ import java.util.NoSuchElementException;
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 @@ public abstract class QuadCurve2D implements Shape, Cloneable
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 @@ public abstract class QuadCurve2D implements Shape, Cloneable
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++;
}
diff --git a/java/awt/geom/doc-files/Area-1.png b/java/awt/geom/doc-files/Area-1.png
new file mode 100644
index 000000000..44650f2d8
--- /dev/null
+++ b/java/awt/geom/doc-files/Area-1.png
Binary files differ
diff --git a/java/awt/geom/doc-files/Ellipse-1.png b/java/awt/geom/doc-files/Ellipse-1.png
new file mode 100644
index 000000000..8317db661
--- /dev/null
+++ b/java/awt/geom/doc-files/Ellipse-1.png
Binary files differ
diff --git a/java/awt/geom/doc-files/GeneralPath-1.png b/java/awt/geom/doc-files/GeneralPath-1.png
new file mode 100644
index 000000000..d1d75d575
--- /dev/null
+++ b/java/awt/geom/doc-files/GeneralPath-1.png
Binary files differ