From 26d07b4ca472845881b8d07668ca81fd6d53d516 Mon Sep 17 00:00:00 2001 From: Droolio Date: Tue, 23 Aug 2011 16:01:16 +0100 Subject: [PATCH] Fixed polygonal edges with explicit test for point-on-line segment Closes pull #136 --- .../sk89q/worldedit/regions/Polygonal2DRegion.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 03305efc8..ab1b0527a 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -302,6 +302,7 @@ public class Polygonal2DRegion implements Region { int xOld, zOld; int x1, z1; int x2, z2; + long crossproduct; int i; xOld = points.get(npoints - 1).getBlockX(); @@ -325,10 +326,14 @@ public class Polygonal2DRegion implements Region { z1 = zNew; z2 = zOld; } - if ((xNew < targetX) == (targetX <= xOld) - && ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1) - * (long) (targetX - x1)) { - inside = !inside; + 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;