Hi,

Under certain conditions I find the following:

[code]
Area a, b;
(a.equals(b) && b.equals(a)) != (a.isRectangular && b.isRectangular())
[/code]
Is this a bug? Or am I missing something?

The following code demonstrates the problem:
[code]
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;

public class TestArea {

    public static void main(String[] args) {
        Area horizontal = new Area();
        for (int x = 0; x < 2; x++) {
            horizontal.add(new Area(new Rectangle2D.Double(x, 0, 1, 1)));
        }
        print("Horiz.", horizontal);

        Area vertical = new Area();
        for (int y = 0; y < 2; y++) {
            vertical.add(new Area(new Rectangle2D.Double(0, y, 1, 1)));
        }
        print("Vert.", vertical);

        Area square = new Area();
        for (int x = 0; x < 2; x++) {
            for (int y = 0; y < 2; y++) {
                square.add(new Area(new Rectangle2D.Double(x, y, 1, 1)));
            }
        }
        print("Square", square);

        /*
         * Now is there a difference between a rotated square and a
         * polygon that, in effect, represents a rotated square.
         */
        System.out.println();

        Area rotated = new Area(new Rectangle(1, 1, 1, 1));
        rotated.transform(AffineTransform
                .getQuadrantRotateInstance(1, 1.5, 1.5));
        print("Rotated", rotated);

        Area polygon = new Area(new Polygon(new int[] { 1, 2, 1, 0 },
                new int[] { 0, 1, 2, 1 }, 4));
        print("Polygon", polygon);
    }

    public static void print(String name, Area a) {
        Area b = new Area(a.getBounds2D());
        System.out.println(name

        + "\t a.equals(b): " + a.equals(b)

        + "\t b(equals(a): " + b.equals(a)

        + "\t b.isRectangular(): " + b.isRectangular()

        + "\t a.isRectangular(): " + a.isRectangular()

        );
    }

}
[/code]
This is the output I get:

[pre]
Horiz.   a.equals(b): true       b(equals(a): true       b.isRectangular(): 
true         a.isRectangular(): true
Vert.    a.equals(b): true       b(equals(a): true       b.isRectangular(): 
true         a.isRectangular(): false
Square   a.equals(b): true       b(equals(a): true       b.isRectangular(): 
true         a.isRectangular(): false

Rotated  a.equals(b): true       b(equals(a): true       b.isRectangular(): 
true         a.isRectangular(): true
Polygon  a.equals(b): false      b(equals(a): false      b.isRectangular(): 
true         a.isRectangular(): false

[/pre]
(An additional test examens the behaviour of a rotated Area and an Area that is 
filled with a polygon that, in effect, represents a rotated square)

Thanks for any insights

Piet
[Message sent by forum member 'pietblok' (pietblok)]

http://forums.java.net/jive/thread.jspa?messageID=253539

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to