Skip to content

Commit

Permalink
6d69b97 rename rectclip... to rectclip...64. fix minor offsetting bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
micycle1 committed Jan 22, 2024
1 parent ee017db commit 1b92678
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/main/java/clipper2/Clipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/clipper2/offset/ClipperOffset.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -486,7 +486,7 @@ private void OffsetPoint(Group group, Path64 path, int j, RefObject<Integer> 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
Expand All @@ -502,7 +502,7 @@ private void OffsetPoint(Group group, Path64 path, int j, RefObject<Integer> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
* <p>
* 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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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);
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/clipper2/rectclip/package-info.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1b92678

Please sign in to comment.