diff --git a/README.md b/README.md index a669535..3071037 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,9 @@ inverted. ## lines Method -Triangles of lines can be calculate using the Triangulate method using the following parameters: +Triangles of (multi)lines can be calculate using the Triangulate method using the following parameters: - - LineString lineString: line geometry + - (Multi)LineString lineString: line geometry - float radius = 1 @@ -113,6 +113,8 @@ wkx-sharp - https://github.com/cschwarz/wkx-sharp for handling geometries ## History +2024-02-20: release 1.4.2: add multi-line support + 2024-02-14: release 1.4.1: make tubularSegments and radialSegments optional 2024-02-14: release 1.4.0: add support for lines diff --git a/src/triangulator.tests/TriangulateTests.cs b/src/triangulator.tests/TriangulateTests.cs index 22e6cf6..8506bc1 100644 --- a/src/triangulator.tests/TriangulateTests.cs +++ b/src/triangulator.tests/TriangulateTests.cs @@ -8,6 +8,20 @@ namespace Triangulate.Tests { public class Tests { + [Test] + public void TriangulateMultiLineString() + { + var wkt = "MULTILINESTRING Z ((3763315.799271699 286413.6056370016 5124311.671963081,3763266.342667458 286473.67236574384 5124344.414418806,3763210.3960400973 286548.5078986015 5124381.765858143,3763152.978906794 286621.42283605755 5124419.449608338,3763101.929717718 286694.671551758 5124452.616537503))"; + + var line = (MultiLineString)Geometry.Deserialize(wkt); + + var triangles = Triangulator.Triangulate(line, 1, 60); + + Assert.That(triangles.Geometries.Count == 948); + + GltfCreator.CreateGltf(triangles, @"multilines.gltf"); + + } [Test] public void TriangulateLine() { @@ -16,6 +30,8 @@ public void TriangulateLine() var triangles = Triangulator.Triangulate(line,2, 60); + Assert.That(triangles.Geometries.Count == 960); + GltfCreator.CreateGltf(triangles, @"lines.gltf"); } diff --git a/src/triangulator/Triangulator.cs b/src/triangulator/Triangulator.cs index 006fac3..6584d96 100644 --- a/src/triangulator/Triangulator.cs +++ b/src/triangulator/Triangulator.cs @@ -34,6 +34,25 @@ public static byte[] Triangulate(byte[] wkb) return result.AsBinary(); } + public static MultiPolygon Triangulate(MultiLineString lineString, float radius = 1, int? tubularSegments = 64, int? radialSegments = 8, bool closed = false) + { + var polygons = new List(); + + foreach(var geom in lineString.Geometries) + { + var triangles = Triangulate((LineString)geom, radius, tubularSegments, radialSegments, closed); + polygons.AddRange(triangles.Geometries); + } + + var result = new MultiPolygon + { + Dimension = Dimension.Xyz + }; + result.Geometries.AddRange(polygons); + return result; + } + + public static MultiPolygon Triangulate(LineString lineString, float radius = 1, int? tubularSegments = 64, int? radialSegments = 8, bool closed = false) { var polygons = new List(); diff --git a/src/triangulator/triangulator.csproj b/src/triangulator/triangulator.csproj index 0c22331..f8e6742 100644 --- a/src/triangulator/triangulator.csproj +++ b/src/triangulator/triangulator.csproj @@ -13,11 +13,11 @@ wkb triangulate earcut MIT Bert Temme - 1.4.1 + 1.4.2 Add lines support Triangulate - 1.4.1 - 1.4.1 + 1.4.2 + 1.4.2