Hi,
I’m having a problem when I check for collision detection with 2 GeneralPath objects. The following test class prints true while from my understanding it prints false. The code constructs 2 shapes that are composed of blocks and look like this:
oo
o
and
o
oo
So when translated the 2 shapes are set like this:
oo
oo
oo
public class GeneralPathTest {
public static void main(String[] args) {
int blockSize = 32;
Polygon bounds = new Polygon();
bounds.addPoint(0, 0);
bounds.addPoint(blockSize * 2 - 1, 0);
bounds.addPoint(blockSize * 2 - 1, blockSize - 1);
bounds.addPoint(blockSize - 1, blockSize - 1);
bounds.addPoint(blockSize - 1, blockSize * 2 - 1);
bounds.addPoint(0, blockSize * 2 - 1);
Polygon bounds2 = new Polygon();
bounds2.addPoint(blockSize - 1, 0);
bounds2.addPoint(blockSize * 2 - 1, 0);
bounds2.addPoint(blockSize * 2 - 1, blockSize * 2 - 1);
bounds2.addPoint(0, blockSize * 2 - 1);
bounds2.addPoint(0, blockSize - 1);
bounds2.addPoint(blockSize - 1, blockSize - 1);
GeneralPath poly1 = new GeneralPath(bounds);
poly1.transform(AffineTransform.getTranslateInstance(100, 100));
GeneralPath poly2 = new GeneralPath(bounds2);
poly2.transform(AffineTransform.getTranslateInstance(100, 132));
System.out.println(poly1.intersects(poly2.getBounds()));
System.out.println(poly2.intersects(poly1.getBounds()));
}
}
What’s wrong here???