Skip to content

Commit

Permalink
Fixed recently introduced InflatePaths bug (#405)
Browse files Browse the repository at this point in the history
Fixed Delphi 7 and FPC compatibility (#402)
  • Loading branch information
AngusJohnson committed Feb 10, 2023
1 parent 7bad95c commit 9e8734a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 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 : 9 February 2023 *
* Date : 10 February 2023 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2023 *
* Purpose : Path Offset (Inflate/Shrink) *
Expand Down Expand Up @@ -288,7 +288,7 @@ void ClipperOffset::OffsetPoint(Group& group,
if (!almostNoAngle)
{
// create a simple self-intersection that will be cleaned up later
//group.path_.push_back(path[j]);
group.path_.push_back(path[j]); // definitely needed (#405)
group.path_.push_back(GetPerpendic(path[j], norms[j], group_delta_));
}
}
Expand Down
16 changes: 12 additions & 4 deletions CPP/Tests/TestOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ TEST(Clipper2Tests, TestOffsets) {
co.AddPaths(subject, Clipper2Lib::JoinType::Round, Clipper2Lib::EndType::Polygon);
const auto outputs = co.Execute(1);

// is the sum total area of the solution is positive
const auto outer_is_positive = Clipper2Lib::Area(outputs) > 0;

// there should be exactly one exterior path
const auto is_hole = Clipper2Lib::IsPositive<int64_t>;
const auto hole_count = std::count_if(outputs.begin(), outputs.end(), is_hole);
const auto exterior_count = outputs.size() - hole_count;
EXPECT_EQ(exterior_count, 1);
const auto is_positive_func = Clipper2Lib::IsPositive<int64_t>;
const auto is_positive_count = std::count_if(
outputs.begin(), outputs.end(), is_positive_func);
const auto is_negative_count =
outputs.size() - is_positive_count;
if (outer_is_positive)
EXPECT_EQ(is_positive_count, 1);
else
EXPECT_EQ(is_negative_count, 1);
}
}
12 changes: 6 additions & 6 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 : 9 February 2023 *
* Date : 10 February 2023 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2023 *
* Purpose : Core Clipper Library module *
Expand Down Expand Up @@ -102,6 +102,11 @@ TPointD = record
property MidPoint: TPointD read GetMidPoint;
end;

{$IF CompilerVersion <= 15}
TPointerList = array of Pointer;
TListSortCompareFunc = function (Item1, Item2: Pointer): Integer;
{$IFEND}

TListEx = class
private
fCount : integer;
Expand All @@ -128,11 +133,6 @@ TListEx = class

EClipper2LibException = class(Exception);

{$IF CompilerVersion <= 15}
TPointerList = array of Pointer;
TListSortCompareFunc = function (Item1, Item2: Pointer): Integer;
{$IFEND}

function Area(const path: TPath64): Double; overload;
function Area(const paths: TPaths64): Double; overload;
{$IFDEF INLINING} inline; {$ENDIF}
Expand Down
10 changes: 4 additions & 6 deletions Delphi/Clipper2Lib/Clipper.Offset.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(*******************************************************************************
* Author : Angus Johnson *
* Date : 9 February 2023 *
* Date : 10 February 2023 *
* Website : http://www.angusj.com *
* Copyright : Angus Johnson 2010-2023 *
* Purpose : Path Offset (Inflate/Shrink) *
Expand Down Expand Up @@ -299,14 +299,12 @@ procedure TClipperOffset.DoGroupOffset(group: TGroup);
group.reversed := (area < 0);
if group.reversed then fGroupDelta := -fDelta
else fGroupDelta := fDelta;
fAbsGrpDelta := Abs(fGroupDelta);
end else
begin
group.reversed := false;
fGroupDelta := Abs(fDelta) * 0.5;
fAbsGrpDelta := fGroupDelta;
end;

fAbsGrpDelta := Abs(fGroupDelta);
fJoinType := group.joinType;
if fArcTolerance > 0 then
arcTol := Min(fAbsGrpDelta, fArcTolerance) else
Expand Down Expand Up @@ -697,8 +695,8 @@ procedure TClipperOffset.OffsetPoint(j: Integer;
AddPoint(GetPerpendic(fInPath[j], fNorms[k], fGroupDelta));
if not almostNoAngle then
begin
// create a simple self-intersection that will be cleaned up later
//AddPoint(fInPath[j]); // todo: check, as may not be needed
// ensure a clean self-intersection ...
AddPoint(fInPath[j]); // definitely needed (#405)
AddPoint(GetPerpendic(fInPath[j], fNorms[j], fGroupDelta));
end;
end
Expand Down

0 comments on commit 9e8734a

Please sign in to comment.