OK, so I know that this question has already been asked a million times, but I have a slightly different problem. I have Polygon objects, which are made from 1 unit "blocks", and I need to determine if the blocks touch each other. Other answers have had code like this:
Area area1 = new Area(poly1);
Area area2 = new Area(poly2);
area1.instersect(poly2);
if(!area1.isEmpty()) {
// Do collision stuff here
}
This has a problem though, which is that if the shapes are next to each other (they are touching), this would not report a collision.
My original idea was to have one Polygon have a 1 unit border around it, so if they were next to each other, the border would intersect with the second Polygon and I would get a collision. I can't seem to find a way to add a border though.
Help is greatly appreciated!
EDIT:
If this matters, all blocks are 1x1 unit in size, and are stored in "chunks" (With an ArrayList). My Polygon objects represent a whole chunk of objects. If there is a better way to do this, please let me know!
My code needs to be as efficent as possible, as I potentially have hundreds of chunks/thousands of blocks, and the physics loop runs every 1 second