From 38a9dfcd14c4e142cc9e94d4770512280a6919c7 Mon Sep 17 00:00:00 2001 From: Prokhorov Kirill Date: Wed, 28 Aug 2024 20:07:32 +0300 Subject: [PATCH] Fix subtract --- DesktopEditor/graphics/BooleanOperations.cpp | 23 +++++++++++++++----- DesktopEditor/graphics/BooleanOperations.h | 2 +- DesktopEditor/graphics/GraphicsPath.h | 5 ++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/DesktopEditor/graphics/BooleanOperations.cpp b/DesktopEditor/graphics/BooleanOperations.cpp index d0aa00f091..69613a23d8 100644 --- a/DesktopEditor/graphics/BooleanOperations.cpp +++ b/DesktopEditor/graphics/BooleanOperations.cpp @@ -677,7 +677,6 @@ CBooleanOperations::CBooleanOperations(CGraphicsPath* path1, Path1(path1), Path2(path2), Result(new CGraphicsPath), - AllOverlap(true), IsDeleted(false) { TraceBoolean(); @@ -735,13 +734,17 @@ void CBooleanOperations::TraceBoolean() GetIntersection(); - if (AllOverlap && Op == Subtraction) + if (AllOverlap()) + { + if (Op != Subtraction) + Result = Path1; return; + } - if (Locations.empty() || AllOverlap) + if (Locations.empty()) { int count = 0; - PointD minPt = GetMinPoint(Segments1); + PointD minPt = GetMinPoint(Segments2); for (const auto& c : Curves2) count += CheckInters(minPt, Segments1[0], c); @@ -1459,7 +1462,6 @@ void CBooleanOperations::DivideLocations() void CBooleanOperations::InsertLocation(std::shared_ptr loc, bool overlap) { - if (!overlap) AllOverlap = false; if (Locations.empty()) { Locations.push_back(loc); @@ -1515,6 +1517,17 @@ void CBooleanOperations::InsertLocation(std::shared_ptr loc, bool over Locations.insert(Locations.begin() + l, loc); } +bool CBooleanOperations::AllOverlap() const +{ + if (Locations.empty()) return false; + + bool overlap = true; + for (const auto& l : Locations) + overlap = l->Overlap; + + return overlap; +} + void CBooleanOperations::AddLocation(Curve curve1, Curve curve2, double t1, double t2, bool overlap) { diff --git a/DesktopEditor/graphics/BooleanOperations.h b/DesktopEditor/graphics/BooleanOperations.h index 5fcb97312c..f0eb78e929 100644 --- a/DesktopEditor/graphics/BooleanOperations.h +++ b/DesktopEditor/graphics/BooleanOperations.h @@ -136,6 +136,7 @@ namespace Aggplus void DivideLocations(); void AddLocation(Curve curve1, Curve curve2, double t1, double t2, bool overlap = false); void InsertLocation(std::shared_ptr loc, bool overlap); + bool AllOverlap() const; // Util void SetVisited(const Segment& segment); @@ -157,7 +158,6 @@ namespace Aggplus std::vector> Locations; - bool AllOverlap; bool IsDeleted; }; } // namespace Aggplus diff --git a/DesktopEditor/graphics/GraphicsPath.h b/DesktopEditor/graphics/GraphicsPath.h index ac4650e14d..965e8593ae 100644 --- a/DesktopEditor/graphics/GraphicsPath.h +++ b/DesktopEditor/graphics/GraphicsPath.h @@ -173,9 +173,8 @@ namespace Aggplus { Intersection = 1, Union = 0, - Subtraction = 3, - Exclusion = 3, - Division = 4 + Subtraction = 2, + Exclusion = 3 }; GRAPHICS_DECL CGraphicsPath* CalcBooleanOperation(CGraphicsPath* path1, CGraphicsPath* path2, BooleanOpType op);