diff --git a/CPP/Clipper2Lib/src/clipper.offset.cpp b/CPP/Clipper2Lib/src/clipper.offset.cpp index 36182c08..d2b319be 100644 --- a/CPP/Clipper2Lib/src/clipper.offset.cpp +++ b/CPP/Clipper2Lib/src/clipper.offset.cpp @@ -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) * @@ -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_)); } } diff --git a/CPP/Tests/TestOffsets.cpp b/CPP/Tests/TestOffsets.cpp index a760be73..fd28ffd5 100644 --- a/CPP/Tests/TestOffsets.cpp +++ b/CPP/Tests/TestOffsets.cpp @@ -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; - 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; + 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); } } \ No newline at end of file diff --git a/Delphi/Clipper2Lib/Clipper.Core.pas b/Delphi/Clipper2Lib/Clipper.Core.pas index 07c97ce9..94b3006b 100644 --- a/Delphi/Clipper2Lib/Clipper.Core.pas +++ b/Delphi/Clipper2Lib/Clipper.Core.pas @@ -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 * @@ -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; @@ -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} diff --git a/Delphi/Clipper2Lib/Clipper.Offset.pas b/Delphi/Clipper2Lib/Clipper.Offset.pas index c9adfae8..2894df9d 100644 --- a/Delphi/Clipper2Lib/Clipper.Offset.pas +++ b/Delphi/Clipper2Lib/Clipper.Offset.pas @@ -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) * @@ -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 @@ -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