Skip to content

Commit 6222af4

Browse files
committed
Fixed a minor bug in RectClip (#597)
Fixed a minor bug in merging solution polygons (#606)
1 parent 3867aab commit 6222af4

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

CPP/Clipper2Lib/src/clipper.engine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,6 @@ namespace Clipper2Lib {
24992499
#endif
25002500
AddTrialHorzJoin(op);
25012501
}
2502-
OutRec* currHorzOutrec = horz.outrec;
25032502

25042503
while (true) // loop through consec. horizontal edges
25052504
{
@@ -2579,9 +2578,8 @@ namespace Clipper2Lib {
25792578
e = horz.prev_in_ael;
25802579
}
25812580

2582-
if (horz.outrec && horz.outrec != currHorzOutrec)
2581+
if (horz.outrec)
25832582
{
2584-
currHorzOutrec = horz.outrec;
25852583
//nb: The outrec containining the op returned by IntersectEdges
25862584
//above may no longer be associated with horzEdge.
25872585
AddTrialHorzJoin(GetLastOp(horz));

CPP/Clipper2Lib/src/clipper.rectclip.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
3-
* Date : 16 July 2023 *
3+
* Date : 6 August 2023 *
44
* Website : http://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2023 *
66
* Purpose : FAST rectangular clipping *
@@ -474,7 +474,7 @@ namespace Clipper2Lib {
474474
// intersect pt but we'll also need the first intersect pt (ip2)
475475
loc = prev;
476476
GetIntersection(rect_as_path_, prev_pt, path[i], loc, ip2);
477-
if (crossing_prev != Location::Inside)
477+
if (crossing_prev != Location::Inside && crossing_prev != loc) //579
478478
AddCorner(crossing_prev, loc);
479479

480480
if (first_cross_ == Location::Inside)

CPP/Tests/TestRectClip.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ TEST(Clipper2Tests, TestRectClip)
5555
EXPECT_EQ(solBounds.Width(), rect.Width());
5656
EXPECT_EQ(solBounds.Height(), rect.Height());
5757

58+
}
59+
60+
TEST(Clipper2Tests, TestRectClip2) //#597
61+
{
62+
Clipper2Lib::Rect64 rect(54690, 0, 65628, 6000);
63+
Clipper2Lib::Paths64 subject {{{700000, 6000}, { 0, 6000 }, { 0, 5925 }, { 700000, 5925 }}};
64+
65+
Clipper2Lib::Paths64 solution = Clipper2Lib::RectClip(rect, subject);
66+
67+
//std::cout << solution << std::endl;
68+
EXPECT_TRUE(solution.size() == 1 && solution[0].size() == 4);
5869
}

CSharp/Clipper2Lib/Clipper.Engine.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
3-
* Date : 26 July 2023 *
3+
* Date : 6 August 2023 *
44
* Website : http://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2023 *
66
* Purpose : This is the main polygon clipping module *
@@ -2173,7 +2173,6 @@ private void DoHorizontal(Active horz)
21732173
#endif
21742174
AddToHorzSegList(op);
21752175
}
2176-
OutRec? currOutrec = horz.outrec!;
21772176

21782177
for (; ; )
21792178
{
@@ -2248,11 +2247,8 @@ private void DoHorizontal(Active horz)
22482247
ae = horz.prevInAEL;
22492248
}
22502249

2251-
if (IsHotEdge(horz) && (horz.outrec != currOutrec))
2252-
{
2253-
currOutrec = horz.outrec;
2250+
if (IsHotEdge(horz))
22542251
AddToHorzSegList(GetLastOp(horz));
2255-
}
22562252

22572253
} // we've reached the end of this horizontal
22582254

CSharp/Clipper2Lib/Clipper.RectClip.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
3-
* Date : 30 May 2023 *
3+
* Date : 6 August 2023 *
44
* Website : http://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2023 *
66
* Purpose : FAST rectangular clipping *
@@ -544,7 +544,7 @@ private void ExecuteInternal(Path64 path)
544544
loc = prev;
545545
GetIntersection(rectPath_,
546546
prevPt, path[i], ref loc, out Point64 ip2);
547-
if (prevCrossLoc != Location.inside)
547+
if (prevCrossLoc != Location.inside && prevCrossLoc != loc) //#597
548548
AddCorner(prevCrossLoc, loc);
549549

550550
if (firstCross == Location.inside)

Delphi/Clipper2Lib/Clipper.Engine.pas

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
(*******************************************************************************
44
* Author : Angus Johnson *
5-
* Date : 26 July 2023 *
5+
* Date : 6 August 2023 *
66
* Website : http://www.angusj.com *
77
* Copyright : Angus Johnson 2010-2023 *
88
* Purpose : This is the main polygon clipping module *
@@ -3401,7 +3401,6 @@ procedure TClipperBase.DoHorizontal(horzEdge: PActive);
34013401
e: PActive;
34023402
pt: TPoint64;
34033403
op: POutPt;
3404-
currOr: POutRec;
34053404
isLeftToRight, horzIsOpen: Boolean;
34063405
begin
34073406
(*******************************************************************************
@@ -3443,7 +3442,6 @@ procedure TClipperBase.DoHorizontal(horzEdge: PActive);
34433442
{$ENDIF}
34443443
FHorzSegList.Add(op);
34453444
end;
3446-
currOr := horzEdge.outrec;
34473445

34483446
while true do // loop through consec. horizontal edges
34493447
begin
@@ -3520,9 +3518,8 @@ procedure TClipperBase.DoHorizontal(horzEdge: PActive);
35203518
horzEdge.currX := e.currX;
35213519
e := horzEdge.prevInAEL;
35223520
end;
3523-
if IsHotEdge(horzEdge) and (horzEdge.outrec <> currOr) then
3521+
if IsHotEdge(horzEdge) then
35243522
begin
3525-
currOr := horzEdge.outrec;
35263523
//nb: The outrec containining the op returned by IntersectEdges
35273524
//above may no longer be associated with horzEdge.
35283525
FHorzSegList.Add(GetLastOp(horzEdge));

Delphi/Clipper2Lib/Clipper.RectClip.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
(*******************************************************************************
44
* Author : Angus Johnson *
5-
* Date : 30 May 2023 *
5+
* Date : 6 August 2023 *
66
* Website : http://www.angusj.com *
77
* Copyright : Angus Johnson 2010-2023 *
88
* Purpose : FAST rectangular clipping *
@@ -700,7 +700,7 @@ procedure TRectClip64.ExecuteInternal(const path: TPath64);
700700
// intersect pt but we'll also need the first intersect pt (ip2)
701701
loc := prevLoc;
702702
GetIntersection(fRectPath, prevPt, path[i], loc, ip2);
703-
if (prevCrossLoc <> locInside) then
703+
if (prevCrossLoc <> locInside) and (prevCrossLoc <> loc) then //#579
704704
AddCorner(prevCrossLoc, loc);
705705

706706
if (firstCrossLoc = locInside) then

0 commit comments

Comments
 (0)