3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-12 22:20:08 +01:00

Took polygon-in-point algorithm from WorldGuard.

Dieser Commit ist enthalten in:
sk89q 2011-04-02 19:56:05 -07:00
Ursprung 87f172b4ed
Commit ac920fd5b6

Datei anzeigen

@ -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;
@ -286,36 +285,34 @@ public class Polygonal2DRegion implements Region {
xOld = points.get(npoints - 1).getBlockX(); xOld = points.get(npoints - 1).getBlockX();
zOld = points.get(npoints - 1).getBlockZ(); zOld = points.get(npoints - 1).getBlockZ();
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;
} }
return inside; return inside;
} }