mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 10:17:39 +00:00
Took polygon-in-point algorithm from WorldGuard.
This commit is contained in:
parent
87f172b4ed
commit
ac920fd5b6
@ -267,10 +267,9 @@ public class Polygonal2DRegion implements Region {
|
|||||||
if (points.size() < 3) {
|
if (points.size() < 3) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
int targetX = pt.getBlockX(); //wide
|
||||||
int targetX = pt.getBlockX();
|
int targetY = pt.getBlockY(); //height
|
||||||
int targetY = pt.getBlockY();
|
int targetZ = pt.getBlockZ(); //depth
|
||||||
int targetZ = pt.getBlockZ();
|
|
||||||
|
|
||||||
if (targetY < minY || targetY > maxY) {
|
if (targetY < minY || targetY > maxY) {
|
||||||
return false;
|
return false;
|
||||||
@ -290,28 +289,26 @@ public class Polygonal2DRegion implements Region {
|
|||||||
for (i = 0; i < npoints; i++) {
|
for (i = 0; i < npoints; i++) {
|
||||||
xNew = points.get(i).getBlockX();
|
xNew = points.get(i).getBlockX();
|
||||||
zNew = points.get(i).getBlockZ();
|
zNew = points.get(i).getBlockZ();
|
||||||
|
//Check for corner
|
||||||
|
if (xNew == targetX && zNew == targetZ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (xNew > xOld) {
|
if (xNew > xOld) {
|
||||||
x1 = xOld - 1;
|
x1 = xOld;
|
||||||
x2 = xNew;
|
x2 = xNew;
|
||||||
z1 = zOld;
|
z1 = zOld;
|
||||||
z2 = zNew + 1;
|
z2 = zNew;
|
||||||
} else {
|
} else {
|
||||||
x1 = xNew - 1;
|
x1 = xNew;
|
||||||
x2 = xOld;
|
x2 = xOld;
|
||||||
z1 = zNew;
|
z1 = zNew;
|
||||||
z2 = zOld + 1;
|
z2 = zOld;
|
||||||
}
|
}
|
||||||
|
if ((xNew < targetX) == (targetX <= xOld)
|
||||||
if (xNew < targetX == targetX <= xOld) {
|
&& ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1)
|
||||||
long v1 = ((long) targetZ - (long) z1) * (long) (x2 - x1);
|
* (long) (targetX - x1)) {
|
||||||
long v2 = ((long) z2 - (long) z1) * (long) (targetX - x1);
|
inside = !inside;
|
||||||
|
|
||||||
if (v1 < v2) {
|
|
||||||
inside = !inside;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xOld = xNew;
|
xOld = xNew;
|
||||||
zOld = zNew;
|
zOld = zNew;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user