Skip to content

Commit 8f6844b

Browse files
authored
Add constrainedDelaunayTriangulation (#114)
Add constrainedDelaunayTriangulation
1 parent b0f9c42 commit 8f6844b

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1414
[compat]
1515
julia = "1.6"
1616
CEnum = "0.2, 0.3, 0.4"
17-
GEOS_jll = "3.9"
17+
GEOS_jll = "3.10"
1818
GeoInterface = "0.4, 0.5"
1919

2020
[targets]

src/LibGEOS.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export Point,
4343
snap,
4444
delaunayTriangulation,
4545
delaunayTriangulationEdges,
46+
constrainedDelaunayTriangulation,
4647
disjoint,
4748
touches,
4849
intersects,

src/geos_functions.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,17 @@ function delaunayTriangulation(
642642
result
643643
end
644644

645+
function constrainedDelaunayTriangulation(
646+
ptr::GEOSGeom,
647+
context::GEOSContext = _context,
648+
)
649+
result = GEOSConstrainedDelaunayTriangulation_r(context.ptr, ptr)
650+
if result == C_NULL
651+
error("LibGEOS: Error in GEOSConstrainedDelaunayTriangulation")
652+
end
653+
result
654+
end
655+
645656
# -----
646657
# Binary predicates - return 2 on exception, 1 on true, 0 on false
647658
# -----

src/geos_operations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ for geom in (
182182
MultiLineString(delaunayTriangulation(obj.ptr, tol, true))
183183
@eval delaunayTriangulation(obj::$geom, tol::Real = 0.0) =
184184
GeometryCollection(delaunayTriangulation(obj.ptr, tol, false))
185+
@eval constrainedDelaunayTriangulation(obj::$geom) =
186+
GeometryCollection(constrainedDelaunayTriangulation(obj.ptr))
185187
end
186188

187189
sharedPaths(obj1::LineString, obj2::LineString) =

test/test_geos_operations.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ end
7070
g2 = delaunayTriangulationEdges(g1, 2.0)
7171
equivalent_to_wkt(g2, "MULTILINESTRING ((0 0, 10 10), (0 0, 10 0), (10 0, 10 10))")
7272

73+
# LibGEOS.constrainedDelaunayTriangulationTest
74+
g1 = readgeom("POLYGON EMPTY")
75+
g2 = constrainedDelaunayTriangulation(g1)
76+
@test isEmpty(g1)
77+
@test isEmpty(g2)
78+
@test GeoInterface.geotype(g2) == :GeometryCollection
79+
80+
g1 = readgeom("POINT(0 0)")
81+
g2 = constrainedDelaunayTriangulation(g1)
82+
@test isEmpty(g2)
83+
@test GeoInterface.geotype(g2) == :GeometryCollection
84+
85+
g1 = readgeom("POLYGON ((10 10, 20 40, 90 90, 90 10, 10 10))")
86+
g2 = constrainedDelaunayTriangulation(g1)
87+
equivalent_to_wkt(g2, "GEOMETRYCOLLECTION (POLYGON ((10 10, 20 40, 90 10, 10 10)), POLYGON ((90 90, 20 40, 90 10, 90 90)))")
88+
7389
# GEOSDistanceTest
7490
g1 = readgeom("POINT(10 10)")
7591
g2 = readgeom("POINT(3 6)")

0 commit comments

Comments
 (0)