From 75d12d6a5a2cb0a360ec4376a74ff50ad474c3bc Mon Sep 17 00:00:00 2001 From: borovec zdenek Date: Wed, 4 Sep 2024 14:36:34 +0200 Subject: [PATCH] Implement Region.GetContourCopies --- Commands.cs | 7 ++++++- Contour.cs | 13 ++++++------- Region.cs | 23 +++++++++-------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Commands.cs b/Commands.cs index 2519f9d..e804ccb 100644 --- a/Commands.cs +++ b/Commands.cs @@ -111,7 +111,12 @@ namespace Boprs BooleanOperation bopr = new BooleanOperation(subject, clip, type); - bopr.Result.Draw(); + List contours = bopr.Result.GetContourCopies(); + + foreach (Contour contour in contours) + { + contour.Draw(); + } } } } diff --git a/Contour.cs b/Contour.cs index 8d781e4..d310f5a 100644 --- a/Contour.cs +++ b/Contour.cs @@ -20,17 +20,17 @@ namespace Boprs /// /// Simple closed polygon. /// - public class Contour + public class Contour : ICloneable { - /// - /// Depth of the contour within the region. - /// - internal int ContourDepth { get; set; } + public object Clone() + { + return new Contour() { Vertices = new List(Vertices) }; + } /// /// Vertices of the contour. /// - public List Vertices { get; } + public List Vertices { get; private set; } /// /// Are the vertices of the contour arranged in clockwise manner? @@ -70,7 +70,6 @@ namespace Boprs /// public Contour() { - ContourDepth = 0; Vertices = new List(); } diff --git a/Region.cs b/Region.cs index c2c486e..e678376 100644 --- a/Region.cs +++ b/Region.cs @@ -173,13 +173,11 @@ namespace Boprs SweepVertex acVx = vertices[i]; bool shouldBeCW = !acVx.Edge.TransitionInside; - Point2d target = acVx.Point; - - // Traverse connected edges, and mark taversed vertices as processed, // until we loop back to the first discovered vertex on the contour. int pos = i; processed[i] = true; + Point2d target = acVx.Point; contour.Vertices.Add(vertices[pos].Point); acVx.Edge.ParentContour = contour; while (!Utils.DoubleEquals(vertices[pos].OtherVertex().Point.GetDistanceTo(target), 0)) @@ -226,7 +224,14 @@ namespace Boprs /// List of copies of the regions contours. public List GetContourCopies() { - throw new NotImplementedException(); + List copies = new List(); + + foreach (Contour contour in Contours) + { + copies.Add((Contour)contour.Clone()); + } + + return copies; } /// @@ -253,15 +258,5 @@ namespace Boprs return region; } - -#if DEBUG - internal void Draw() - { - foreach (Contour contour in Contours) - { - contour.Draw(); - } - } -#endif } }