Merge boy0001/FastAsyncWorldEdit

This commit is contained in:
Jesse Boyd
2018-09-14 02:42:55 +10:00
parent e3172e08b8
commit 8ed67f66ad
9 changed files with 109 additions and 47 deletions

View File

@ -293,6 +293,54 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
recalculate();
}
@Override
public boolean contains(int targetX, int targetZ) {
boolean inside = false;
int npoints = points.size();
int xNew, zNew;
int xOld, zOld;
int x1, z1;
int x2, z2;
long crossproduct;
int i;
xOld = points.get(npoints - 1).getBlockX();
zOld = points.get(npoints - 1).getBlockZ();
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;
x2 = xNew;
z1 = zOld;
z2 = zNew;
} else {
x1 = xNew;
x2 = xOld;
z1 = zNew;
z2 = zOld;
}
if (x1 <= targetX && targetX <= x2) {
crossproduct = ((long) targetZ - (long) z1) * (long) (x2 - x1)
- ((long) z2 - (long) z1) * (long) (targetX - x1);
if (crossproduct == 0) {
if ((z1 <= targetZ) == (targetZ <= z2)) return true; //on edge
} else if (crossproduct < 0 && (x1 != targetX)) {
inside = !inside;
}
}
xOld = xNew;
zOld = zNew;
}
return inside;
}
@Override
public boolean contains(Vector position) {
return contains(points, minY, maxY, position);

View File

@ -64,7 +64,7 @@ public class FlatRegionIterator implements Iterator<Vector2D> {
}
private void forward() {
while (hasNext() && !region.contains(new Vector(nextX, y, nextZ))) {
while (hasNext() && !region.contains(nextX, y, nextZ)) {
forwardOne();
}
}