Skip to content

Commit

Permalink
Clipper.RectClip.cs - fixed a bug in C# RectClipLines (#828)
Browse files Browse the repository at this point in the history
Clipper.Core.pas - added overflow management for IsCollinear function.
  • Loading branch information
AngusJohnson committed May 6, 2024
1 parent 3963bae commit bf56169
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CSharp/Clipper2Lib/Clipper.RectClip.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 27 April 2024 *
* Date : 7 May 2024 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : FAST rectangular clipping *
Expand Down Expand Up @@ -1014,6 +1014,7 @@ private void ExecuteInternal(Path64 path)
if (i > highI)
{
foreach (Point64 pt in path) Add(pt);
return;
}
if (prev == Location.inside) loc = Location.inside;
i = 1;
Expand Down Expand Up @@ -1050,7 +1051,7 @@ private void ExecuteInternal(Path64 path)
// intersect pt but we'll also need the first intersect pt (ip2)
crossingLoc = prev;
GetIntersection(rectPath_, prevPt, path[i], ref crossingLoc, out Point64 ip2);
Add(ip2);
Add(ip2, true);
Add(ip);
}
else // path must be exiting rect
Expand Down
14 changes: 7 additions & 7 deletions Delphi/Clipper2Lib/Clipper.Core.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(*******************************************************************************
* Author : Angus Johnson *
* Date : 27 April 2024 *
* Date : 3 May 2024 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : Core Clipper Library module *
Expand Down Expand Up @@ -1864,16 +1864,16 @@ function IsPositive(const path: TPathD): Boolean;
end;
//------------------------------------------------------------------------------

{$OVERFLOWCHECKS OFF}
function IsCollinear(const pt1, pt2, pt3: TPoint64): Boolean;
var
a,b,c,d: Int64;
a,b: Int64;
begin
a := (pt2.X - pt1.X);
b := (pt2.Y - pt1.Y);
c := (pt3.X - pt2.X);
d := (pt3.Y - pt2.Y);
result := a * d = b * c;
a := (pt2.X - pt1.X) * (pt3.Y - pt2.Y);
b := (pt2.Y - pt1.Y) * (pt3.X - pt2.X);
result := a = b;
end;
{$OVERFLOWCHECKS ON}
//------------------------------------------------------------------------------

function CrossProduct(const pt1, pt2, pt3: TPoint64): double;
Expand Down
3 changes: 2 additions & 1 deletion Delphi/Clipper2Lib/Clipper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(*******************************************************************************
* Author : Angus Johnson *
* Date : 27 April 2024 *
* Date : 7 May 2024 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Purpose : This module provides a simple interface to the Clipper Library *
Expand Down Expand Up @@ -42,6 +42,7 @@ interface
frNonZero = Clipper.Core.frNonZero;
frPositive = Clipper.Core.frPositive;
frNegative = Clipper.Core.frNegative;
jtBevel = Clipper.Offset.jtBevel;
jtSquare = Clipper.Offset.jtSquare;
jtRound = Clipper.Offset.jtRound;
jtMiter = Clipper.Offset.jtMiter;
Expand Down

0 comments on commit bf56169

Please sign in to comment.