Skip to content

Commit

Permalink
Merge pull request #9 from bertt/add_multilines_support
Browse files Browse the repository at this point in the history
add multilines support + 1.4.2
  • Loading branch information
bertt authored Feb 20, 2024
2 parents 23fc7a8 + c1d0744 commit c8e0d23
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/triangulator.tests/TriangulateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WktSerializer>(wkt);

var triangles = Triangulator.Triangulate(line, 1, 60);

Assert.That(triangles.Geometries.Count == 948);

GltfCreator.CreateGltf(triangles, @"multilines.gltf");

}
[Test]
public void TriangulateLine()
{
Expand All @@ -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");
}

Expand Down
19 changes: 19 additions & 0 deletions src/triangulator/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Polygon>();

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<Polygon>();
Expand Down
6 changes: 3 additions & 3 deletions src/triangulator/triangulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<PackageTags>wkb triangulate earcut</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>Bert Temme</Copyright>
<Version>1.4.1</Version>
<Version>1.4.2</Version>
<PackageReleaseNotes>Add lines support</PackageReleaseNotes>
<RootNamespace>Triangulate</RootNamespace>
<AssemblyVersion>1.4.1</AssemblyVersion>
<FileVersion>1.4.1</FileVersion>
<AssemblyVersion>1.4.2</AssemblyVersion>
<FileVersion>1.4.2</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit c8e0d23

Please sign in to comment.