-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.0
-
generic
-
generic
Name: boT120536 Date: 03/20/2001
java version "1.2.2"
Solaris VM (build Solaris_JDK_1.2.2_05a, native threads, sunwjit)
/*
There appears to be a bug in the way that Polygon.contains() works. This
bug only surfaces if you manually change (by poking around in the
xpoints/ypoints arrays) the vertices of the polygon.
This program prints:
true
true
false
thereby illustrating that contains does not work properly if the
array data in the polygon is changed manually!
*/
import java.awt.*;
public class Translate {
public static void main(String[] args) {
int dist = 2;
Point center = new Point(10, 20);
// make a triangle centered at center of height 2 * dist
Polygon triangle = new Polygon();
triangle.addPoint(center.x - dist, center.y - dist);
triangle.addPoint(center.x + dist, center.y - dist);
triangle.addPoint(center.x, center.y + dist);
// test contains
System.out.println(triangle.contains(center));
// translate the triangle and the center and test contains again
triangle.translate(dist, dist);
center.translate(dist, dist);
System.out.println(triangle.contains(center));
// same thing, only this time do the translation manually
for (int i = 0; i < triangle.npoints; i++) {
triangle.xpoints[i] += dist;
triangle.ypoints[i] += dist;
}
center.translate(dist, dist);
System.out.println(triangle.contains(center));
}
}
(Review ID: 119031)
======================================================================
- duplicates
-
JDK-4212883 Polygon object should expose methods for updating bounds after modifications
-
- Resolved
-