Skip to content

Commit 67cfcbb

Browse files
committed
Clear empty features
1 parent a093f7c commit 67cfcbb

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DelaunayTriangulation"
22
uuid = "927a84f5-c5f4-47a5-9785-b46e178433df"
33
authors = ["Daniel VandenHeuvel <[email protected]>"]
4-
version = "0.1.2"
4+
version = "0.2.0"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/bowyerwatson.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function triangulate_bowyer(pts;
8989
randomise=true,
9090
trim=true,
9191
try_last_inserted_point=true,
92+
trim_empty_features = true,
9293
skip_pts=Set{Int64}()) where {I,E,V,Es,Ts}
9394
!all_points_are_unique(pts) && throw("The points must all be unique.")
9495
pt_order = randomise ? shuffle(_eachindex(pts)) : collect(_eachindex(pts))
@@ -120,6 +121,8 @@ function triangulate_bowyer(pts;
120121
pt_idx, m, initial_search_point)
121122
update_centroid_after_new_point!(pts, new_point)
122123
end
124+
trim_empty_features && clear_empty_keys!(adj)
125+
trim_empty_features && clear_empty_points!(DG)
123126
trim && remove_ghost_triangles!(T, adj, adj2v, DG)
124127
return T, adj, adj2v, DG
125128
end

src/deberg.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function triangulate_berg(pts;
3131
TrianglesType::Type{Ts}=Set{TriangleType},
3232
randomise=true,
3333
trim=true,
34+
trim_empty_features=true,
3435
skip_pts=Set{Int64}()) where {I,E,V,Es,Ts}
3536
!all_points_are_unique(pts) && throw("The points must all be unique.")
3637
pt_order = randomise ? shuffle(_eachindex(pts)) : collect(_eachindex(pts))
@@ -44,6 +45,8 @@ function triangulate_berg(pts;
4445
for r in pt_order
4546
add_point_berg!(T, adj, adj2v, DG, HG, pts, r)
4647
end
48+
trim_empty_features && clear_empty_keys!(adj)
49+
trim_empty_features && clear_empty_points!(DG)
4750
trim && remove_bounding_triangle!(T, adj, adj2v, DG)
4851
return T, adj, adj2v, DG, HG
4952
end

test/triangulate.jl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
(4, 2) => 3, (2, 3) => 4, (3, 4) => 2,
3030
(4, 5) => 2, (5, 2) => 4, (2, 4) => 5,
3131
(4, 6) => 5, (6, 5) => 4, (5, 4) => 6,
32-
(((1, 5), (5, 6), (6, 4), (4, 3), (3, 1)) .=> DT.BoundaryIndex)...,
33-
(((1, -1), (3, -1), (-1, 2), (2, -2), (2, 6), (-3, 2), (3, 6)) .=> DT.DefaultAdjacentValue)...
32+
(((1, 5), (5, 6), (6, 4), (4, 3), (3, 1)) .=> DT.BoundaryIndex)...
3433
)
3534
)
3635
true_adj2v = Dict{IntegerType,EdgesType}(
@@ -93,9 +92,6 @@
9392
)
9493
true_adj = DefaultDict(DT.DefaultAdjacentValue,
9594
Dict{EdgeType,IntegerType}(
96-
(((-2, 1), (6, -2), (8, -1), (6, 5), (3, 9),
97-
(3, -1), (-1, 6), (9, 6), (-3, 8), (5, 3),
98-
(8, 6), (8, -2), (-3, 5), (8, 5)) .=> DT.DefaultAdjacentValue)...,
9995
(5, 10) => 2, (10, 2) => 5, (2, 5) => 10,
10096
(5, 9) => 7, (9, 7) => 5, (7, 5) => 9,
10197
(3, 6) => 2, (6, 2) => 3, (2, 3) => 6,
@@ -722,4 +718,17 @@ end
722718
T, adj, adj2v, dg, HG = DT.triangulate_berg(cells)
723719
@test DT.validate_triangulation(T, adj, adj2v, dg, cells)
724720
end
721+
end
722+
723+
@testset "Edges all exist" begin
724+
pts = rand(2, 500)
725+
T, adj, adj2v, DG = triangulate_bowyer(pts)
726+
for e in edges(adj)
727+
@test e edges(DG) || reverse(e) edges(DG)
728+
end
729+
for e in edges(DG)
730+
if DT.BoundaryIndex e
731+
@test e edges(adj)
732+
end
733+
end
725734
end

test/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ end
8181
p10 = (4.26, 0.0)
8282
pts = [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]
8383
Random.seed!(928881)
84-
T, adj, adj2v, DG, HG = DT.triangulate_berg(pts)
84+
T, adj, adj2v, DG, HG = DT.triangulate_berg(pts; trim_empty_features=false)
8585
p11 = (6.0, 2.5)
8686
push!(pts, p11)
8787
r = 11

0 commit comments

Comments
 (0)