From 1b92678877af802eb36ad44253c395b10954e0c4 Mon Sep 17 00:00:00 2001 From: Michael Carleton Date: Mon, 22 Jan 2024 22:30:40 +0000 Subject: [PATCH] 6d69b97 rename rectclip... to rectclip...64. fix minor offsetting bugs --- src/main/java/clipper2/Clipper.java | 12 ++++++------ src/main/java/clipper2/offset/ClipperOffset.java | 6 +++--- .../rectclip/{RectClip.java => RectClip64.java} | 10 +++++----- .../{RectClipLines.java => RectClipLines64.java} | 13 ++++++------- src/main/java/clipper2/rectclip/package-info.java | 2 +- 5 files changed, 21 insertions(+), 22 deletions(-) rename src/main/java/clipper2/rectclip/{RectClip.java => RectClip64.java} (98%) rename src/main/java/clipper2/rectclip/{RectClipLines.java => RectClipLines64.java} (91%) diff --git a/src/main/java/clipper2/Clipper.java b/src/main/java/clipper2/Clipper.java index 6e9982b..3324297 100644 --- a/src/main/java/clipper2/Clipper.java +++ b/src/main/java/clipper2/Clipper.java @@ -28,8 +28,8 @@ import clipper2.offset.ClipperOffset; import clipper2.offset.EndType; import clipper2.offset.JoinType; -import clipper2.rectclip.RectClip; -import clipper2.rectclip.RectClipLines; +import clipper2.rectclip.RectClip64; +import clipper2.rectclip.RectClipLines64; public final class Clipper { @@ -234,7 +234,7 @@ public static Paths64 ExecuteRectClip(Rect64 rect, Paths64 paths, boolean convex if (rect.IsEmpty() || paths.size() == 0) { return new Paths64(); } - RectClip rc = new RectClip(rect); + RectClip64 rc = new RectClip64(rect); return rc.Execute(paths, convexOnly); } @@ -263,7 +263,7 @@ public static PathsD ExecuteRectClip(RectD rect, PathsD paths, int precision, bo double scale = Math.pow(10, precision); Rect64 r = ScaleRect(rect, scale); Paths64 tmpPath = ScalePaths64(paths, scale); - RectClip rc = new RectClip(r); + RectClip64 rc = new RectClip64(r); tmpPath = rc.Execute(tmpPath, convexOnly); return ScalePathsD(tmpPath, 1 / scale); } @@ -285,7 +285,7 @@ public static Paths64 ExecuteRectClipLines(Rect64 rect, Paths64 paths) { if (rect.IsEmpty() || paths.size() == 0) { return new Paths64(); } - RectClipLines rc = new RectClipLines(rect); + RectClipLines64 rc = new RectClipLines64(rect); return rc.Execute(paths); } @@ -310,7 +310,7 @@ public static PathsD ExecuteRectClipLines(RectD rect, PathsD paths, int precisio double scale = Math.pow(10, precision); Rect64 r = ScaleRect(rect, scale); Paths64 tmpPath = ScalePaths64(paths, scale); - RectClipLines rc = new RectClipLines(r); + RectClipLines64 rc = new RectClipLines64(r); tmpPath = rc.Execute(tmpPath); return ScalePathsD(tmpPath, 1 / scale); } diff --git a/src/main/java/clipper2/offset/ClipperOffset.java b/src/main/java/clipper2/offset/ClipperOffset.java index ebf8b2f..72c9ba4 100644 --- a/src/main/java/clipper2/offset/ClipperOffset.java +++ b/src/main/java/clipper2/offset/ClipperOffset.java @@ -385,7 +385,7 @@ private PointD GetPerpendicD(Point64 pt, PointD norm) { private void DoSquare(Group group, Path64 path, int j, int k) { PointD vec; if (j == k) { - vec = new PointD(normals.get(0).y, -normals.get(0).x); + vec = new PointD(normals.get(j).y, -normals.get(j).x); } else { vec = GetAvgUnitVector(new PointD(-normals.get(k).y, normals.get(k).x), new PointD(normals.get(j).y, -normals.get(j).x)); } @@ -486,7 +486,7 @@ private void OffsetPoint(Group group, Path64 path, int j, RefObject k) return; } - if (cosA > 0.99) { + if (cosA > 0.999) { DoMiter(group, path, j, k.argValue, cosA); } else if (cosA > -0.99 && (sinA * groupDelta < 0)) { // is concave @@ -502,7 +502,7 @@ private void OffsetPoint(Group group, Path64 path, int j, RefObject k) } else { DoSquare(group, path, j, k.argValue); } - } else if (joinType == JoinType.Square) { + } else if (cosA > 0.99 || joinType == JoinType.Square) { // angle less than 8 degrees or a squared join DoSquare(group, path, j, k.argValue); } else { diff --git a/src/main/java/clipper2/rectclip/RectClip.java b/src/main/java/clipper2/rectclip/RectClip64.java similarity index 98% rename from src/main/java/clipper2/rectclip/RectClip.java rename to src/main/java/clipper2/rectclip/RectClip64.java index 1b3d7b1..6af0f10 100644 --- a/src/main/java/clipper2/rectclip/RectClip.java +++ b/src/main/java/clipper2/rectclip/RectClip64.java @@ -15,16 +15,16 @@ import tangible.RefObject; /** - * RectClip intersects subject polygons with the specified rectangular clipping - * region. Polygons may be simple or complex (self-intersecting). + * RectClip64 intersects subject polygons with the specified rectangular + * clipping region. Polygons may be simple or complex (self-intersecting). *

* This function is extremely fast when compared to the Library's general * purpose Intersect clipper. Where Intersect has roughly O(n³) performance, - * RectClip has O(n) performance. + * RectClip64 has O(n) performance. * * @since 1.0.6 */ -public class RectClip { +public class RectClip64 { protected static class OutPt2 { @Nullable @@ -55,7 +55,7 @@ protected enum Location { protected int currIdx = -1; @SuppressWarnings("unchecked") - public RectClip(Rect64 rect) { + public RectClip64(Rect64 rect) { currIdx = -1; this.rect = rect; mp = rect.MidPoint(); diff --git a/src/main/java/clipper2/rectclip/RectClipLines.java b/src/main/java/clipper2/rectclip/RectClipLines64.java similarity index 91% rename from src/main/java/clipper2/rectclip/RectClipLines.java rename to src/main/java/clipper2/rectclip/RectClipLines64.java index a8040bd..0f9b915 100644 --- a/src/main/java/clipper2/rectclip/RectClipLines.java +++ b/src/main/java/clipper2/rectclip/RectClipLines64.java @@ -9,18 +9,18 @@ import tangible.RefObject; /** - * RectClipLines intersects subject open paths (polylines) with the specified + * RectClipLines64 intersects subject open paths (polylines) with the specified * rectangular clipping region. *

* This function is extremely fast when compared to the Library's general * purpose Intersect clipper. Where Intersect has roughly O(n³) performance, - * RectClipLines has O(n) performance. + * RectClipLines64 has O(n) performance. * * @since 1.0.6 */ -public class RectClipLines extends RectClip { +public class RectClipLines64 extends RectClip64 { - public RectClipLines(Rect64 rect) { + public RectClipLines64(Rect64 rect) { super(rect); } @@ -123,9 +123,8 @@ private void ExecuteInternal(Path64 path) { // we must be crossing the rect boundary to get here //////////////////////////////////////////////////// - if (loc.argValue == Location.INSIDE) // path must be entering rect - { - Add(ip); + if (loc.argValue == Location.INSIDE) { // path must be entering rect + Add(ip, true); } else if (prev.argValue != Location.INSIDE) { // passing right through rect. 'ip' here will be the second // intersect pt but we'll also need the first intersect pt (ip2) diff --git a/src/main/java/clipper2/rectclip/package-info.java b/src/main/java/clipper2/rectclip/package-info.java index 021dae3..ec7f2f2 100644 --- a/src/main/java/clipper2/rectclip/package-info.java +++ b/src/main/java/clipper2/rectclip/package-info.java @@ -1,5 +1,5 @@ /** - * This unit contains the code that implements the RectClip functions found in + * This unit contains the code that implements the RectClip64 functions found in * the Clipper Unit. * * @since 1.0.6