Took polygon-in-point algorithm from WorldGuard.

This commit is contained in:
sk89q 2011-04-02 19:56:05 -07:00
parent 87f172b4ed
commit ac920fd5b6

View File

@ -267,10 +267,9 @@ public static boolean contains(List<BlockVector2D> points, int minY,
if (points.size() < 3) {
return false;
}
int targetX = pt.getBlockX();
int targetY = pt.getBlockY();
int targetZ = pt.getBlockZ();
int targetX = pt.getBlockX(); //wide
int targetY = pt.getBlockY(); //height
int targetZ = pt.getBlockZ(); //depth
if (targetY < minY || targetY > maxY) {
return false;
@ -290,28 +289,26 @@ public static boolean contains(List<BlockVector2D> points, int minY,
for (i = 0; i < npoints; i++) {
xNew = points.get(i).getBlockX();
zNew = points.get(i).getBlockZ();
//Check for corner
if (xNew == targetX && zNew == targetZ) {
return true;
}
if (xNew > xOld) {
x1 = xOld - 1;
x1 = xOld;
x2 = xNew;
z1 = zOld;
z2 = zNew + 1;
z2 = zNew;
} else {
x1 = xNew - 1;
x1 = xNew;
x2 = xOld;
z1 = zNew;
z2 = zOld + 1;
z2 = zOld;
}
if (xNew < targetX == targetX <= xOld) {
long v1 = ((long) targetZ - (long) z1) * (long) (x2 - x1);
long v2 = ((long) z2 - (long) z1) * (long) (targetX - x1);
if (v1 < v2) {
if ((xNew < targetX) == (targetX <= xOld)
&& ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1)
* (long) (targetX - x1)) {
inside = !inside;
}
}
xOld = xNew;
zOld = zNew;
}