From f70be6a937c4c447b4cee05505d7ee2b75d68e62 Mon Sep 17 00:00:00 2001 From: a5rGithub Date: Thu, 8 Sep 2022 23:50:13 +0200 Subject: [PATCH] Provide easier way to recognize contours in the mesh (#28) --- src/Triangle/Geometry/IPolygon.cs | 7 +++++++ src/Triangle/Geometry/Polygon.cs | 24 +++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Triangle/Geometry/IPolygon.cs b/src/Triangle/Geometry/IPolygon.cs index 0a4c834..e07daf5 100644 --- a/src/Triangle/Geometry/IPolygon.cs +++ b/src/Triangle/Geometry/IPolygon.cs @@ -69,6 +69,13 @@ namespace TriangleNet.Geometry /// The index of the segment endpoint to add to the points list (must be 0 or 1). void Add(ISegment segment, int index); + /// + /// Add a contour to the polygon. + /// + /// The contour to insert. + /// label to ease finding contours in the created mesh. + void Add(Contour contour, int regionlabel ); + /// /// Add a contour to the polygon. /// diff --git a/src/Triangle/Geometry/Polygon.cs b/src/Triangle/Geometry/Polygon.cs index 99a6c97..87d5fd9 100644 --- a/src/Triangle/Geometry/Polygon.cs +++ b/src/Triangle/Geometry/Polygon.cs @@ -111,6 +111,23 @@ namespace TriangleNet.Geometry points.Add(segment.GetVertex(index)); } + private void AddContourPointsAndSegments(Contour contour) + { + points.AddRange(contour.Points); + segments.AddRange(contour.GetSegments()); + } + + /// + public void Add(Contour contour, int regionlabel ) + { + if (regionlabel != 0) + { + var interiorPoint = contour.FindInteriorPoint(); + Regions.Add(new RegionPointer(interiorPoint.X, interiorPoint.Y, regionlabel)); + } + AddContourPointsAndSegments(contour); + } + /// public void Add(Contour contour, bool hole = false) { @@ -120,17 +137,14 @@ namespace TriangleNet.Geometry } else { - points.AddRange(contour.Points); - segments.AddRange(contour.GetSegments()); + AddContourPointsAndSegments(contour); } } /// public void Add(Contour contour, Point hole) { - points.AddRange(contour.Points); - segments.AddRange(contour.GetSegments()); - + AddContourPointsAndSegments(contour); holes.Add(hole); } }