Skip to content

Commit

Permalink
InflatePaths - fixed issue with no ArcTolerance scaling (AngusJohnson…
Browse files Browse the repository at this point in the history
…#949)

clipper.offset.cpp - fixed missing PreserveCollinear assignment (AngusJohnson#951)
  • Loading branch information
AngusJohnson committed Mar 5, 2025
1 parent c86619c commit ca6e8fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions CPP/Clipper2Lib/include/clipper2/clipper.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 27 April 2024 *
* Date : 5 March 2025 *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Copyright : Angus Johnson 2010-2025 *
* Purpose : This module provides a simple interface to the Clipper Library *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************/
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace Clipper2Lib {
if (!delta) return paths;
if (error_code) return PathsD();
const double scale = std::pow(10, precision);
ClipperOffset clip_offset(miter_limit, arc_tolerance);
ClipperOffset clip_offset(miter_limit, arc_tolerance * scale);
clip_offset.AddPaths(ScalePaths<int64_t,double>(paths, scale, error_code), jt, et);
if (error_code) return PathsD();
Paths64 solution;
Expand Down
6 changes: 3 additions & 3 deletions CPP/Clipper2Lib/src/clipper.offset.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 22 January 2025 *
* Date : 5 March 2025 *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2025 *
* Purpose : Path Offset (Inflate/Shrink) *
Expand Down Expand Up @@ -597,10 +597,10 @@ void ClipperOffset::ExecuteInternal(double delta)

if (!solution->size()) return;

bool paths_reversed = CheckReverseOrientation();
bool paths_reversed = CheckReverseOrientation();
//clean up self-intersections ...
Clipper64 c;
c.PreserveCollinear(false);
c.PreserveCollinear(preserve_collinear_);
//the solution should retain the orientation of the input
c.ReverseSolution(reverse_solution_ != paths_reversed);
#ifdef USINGZ
Expand Down
4 changes: 2 additions & 2 deletions CSharp/Clipper2Lib/Clipper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Author : Angus Johnson *
* Date : 22 January 2025 *
* Date : 5 March 2025 *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2025 *
* Purpose : This module contains simple functions that will likely cover *
Expand Down Expand Up @@ -153,7 +153,7 @@ public static PathsD InflatePaths(PathsD paths, double delta, JoinType joinType,
InternalClipper.CheckPrecision(precision);
double scale = Math.Pow(10, precision);
Paths64 tmp = ScalePaths64(paths, scale);
ClipperOffset co = new ClipperOffset(miterLimit, arcTolerance);
ClipperOffset co = new ClipperOffset(miterLimit, scale * arcTolerance);
co.AddPaths(tmp, joinType, endType);
co.Execute(delta * scale, tmp); // reuse 'tmp' to receive (scaled) solution
return ScalePathsD(tmp, 1 / scale);
Expand Down
18 changes: 10 additions & 8 deletions Delphi/Clipper2Lib/Clipper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

(*******************************************************************************
* Author : Angus Johnson *
* Date : 7 May 2024 *
* Date : 5 March 2025 *
* Website : https://www.angusj.com *
* Copyright : Angus Johnson 2010-2024 *
* Copyright : Angus Johnson 2010-2025 *
* Purpose : This module provides a simple interface to the Clipper Library *
* License : https://www.boost.org/LICENSE_1_0.txt *
*******************************************************************************)
Expand Down Expand Up @@ -408,7 +408,7 @@ function InflatePaths(const paths: TPathsD; delta: Double;
invScale := 1/scale;
pp := ScalePaths(paths, scale, scale);

with TClipperOffset.Create(miterLimit, ArcTolerance) do
with TClipperOffset.Create(miterLimit, scale * ArcTolerance) do
try
AddPaths(pp, jt, et);
Execute(delta * scale, pp); // reuse pp to receive the solution.
Expand Down Expand Up @@ -683,7 +683,7 @@ function PathsToString(const p: TPathsD; decimals: integer;
end;
//------------------------------------------------------------------------------

procedure ShowPolyPathStructure64(pp: TPolyPath64; level: integer;
procedure ShowPolyPathStructure64(pp: TPolyPath64; ppIdx, level: integer;
strings: TStrings);
var
i: integer;
Expand All @@ -692,12 +692,14 @@ procedure ShowPolyPathStructure64(pp: TPolyPath64; level: integer;
spaces := StringOfChar(' ', level * 2);
if pp.Count = 1 then plural := '' else plural := 's';
if pp.IsHole then
strings.Add(Format('%sA hole containing %d polygon%s', [spaces, pp.Count, plural]))
strings.Add(Format('%sHole (%d) containing %d polygon%s',
[spaces, ppIdx, pp.Count, plural]))
else
strings.Add(Format('%sA polygon containing %d hole%s', [spaces, pp.Count, plural]));
strings.Add(Format('%sPolygon (%d) containing %d hole%s',
[spaces, ppIdx, pp.Count, plural]));
for i := 0 to pp.Count -1 do
if pp.child[i].Count> 0 then
ShowPolyPathStructure64(pp.child[i], level + 1, strings);
ShowPolyPathStructure64(pp.child[i], i, level + 1, strings);
end;
//------------------------------------------------------------------------------

Expand All @@ -710,7 +712,7 @@ procedure ShowPolyTreeStructure(polytree: TPolyTree64; strings: TStrings);
strings.Add(Format('Polytree with just %d polygons.', [polytree.Count]));
for i := 0 to polytree.Count -1 do
if polytree[i].Count > 0 then
ShowPolyPathStructure64(polytree[i], 1, strings);
ShowPolyPathStructure64(polytree[i], i, 1, strings);
end;
//------------------------------------------------------------------------------

Expand Down

0 comments on commit ca6e8fd

Please sign in to comment.