Skip to content

Commit 586d888

Browse files
authored
Implement copy/deepcopy for Triangulation/VoronoiTessellation (#201)
1 parent 8606710 commit 586d888

37 files changed

+897
-154
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
- `PointLocationHistory` was not marked as public. This has been fixed. See [#198](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/198).
1515
- Fixed an issue with missing docstrings and duplicate docstrings in the documentation. See [#198](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/198).
1616
- `copy` and `deepcopy` are now correctly implemented for `PolygonTree`s and `PolygonHierarchy`s. See [#199](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/199)
17+
- Implemented `copy` and `deepcopy` for `Triangulation` and `VoronoiTessellation`. See [#201](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/201).
18+
- Fixed a bug with `Triangulation`s `polygon_hierarchy` not being correctly aliased with the `polygon_hierarchy` from the `BoundaryEnricher`, and similarly for the `boundary_edge_map`. See [#201](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/201).
19+
- Implemented `==` for `VoronoiTessellation`. See [#201](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/201).
1720

1821
## 1.5.0
1922

src/algorithms/triangulation/constrained_triangulation.jl

+11-7
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,13 @@ function remake_triangulation_with_constraints(tri::Triangulation, segments, bou
316316
boundary_curves = get_boundary_curves(tri)
317317
I = integer_type(tri)
318318
E = edge_type(tri)
319-
boundary_edge_map = construct_boundary_edge_map(boundary_nodes, I, E)
319+
if is_curve_bounded(tri)
320+
boundary_edge_map = get_boundary_edge_map(get_boundary_enricher(tri))
321+
empty!(boundary_edge_map)
322+
_construct_boundary_edge_map!(boundary_edge_map, boundary_nodes)
323+
else
324+
boundary_edge_map = construct_boundary_edge_map(boundary_nodes, I, E)
325+
end
320326
ghost_vertex_map = get_ghost_vertex_map(tri)
321327
new_ghost_vertex_map = construct_ghost_vertex_map(boundary_nodes, I) # Delay putting these in until we are done with the triangulation
322328
ghost_vertex_ranges = get_ghost_vertex_ranges(tri)
@@ -349,7 +355,7 @@ function remake_triangulation_with_constraints(tri::Triangulation, segments, bou
349355
end
350356

351357
"""
352-
replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges) -> Triangulation
358+
replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges, polygon_hierarchy) -> Triangulation
353359
354360
Replaces the ghost vertex information in `tri` with `ghost_vertex_map` and `ghost_vertex_ranges`, using the results from
355361
[`remake_triangulation_with_constraints`](@ref).
@@ -358,11 +364,12 @@ Replaces the ghost vertex information in `tri` with `ghost_vertex_map` and `ghos
358364
- `tri::Triangulation`: The triangulation to remake.
359365
- `ghost_vertex_map`: The ghost vertex map to add to the triangulation.
360366
- `ghost_vertex_ranges`: The ghost vertex ranges to add to the triangulation.
367+
- `polygon_hierarchy`: The polygon hierarchy to add to the triangulation.
361368
362369
# Outputs
363370
- `new_tri::Triangulation`: The new triangulation, now containing `ghost_vertex_map` in the `ghost_vertex_map` field and `ghost_vertex_ranges` in the `ghost_vertex_ranges` field.
364371
"""
365-
function replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges)
372+
function replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges, polygon_hierarchy = get_polygon_hierarchy(tri))
366373
points = get_points(tri)
367374
triangles = get_triangles(tri)
368375
boundary_nodes = get_boundary_nodes(tri)
@@ -376,7 +383,6 @@ function replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map,
376383
boundary_edge_map = get_boundary_edge_map(tri)
377384
ch = get_convex_hull(tri)
378385
representative_point_list = get_representative_point_list(tri)
379-
polygon_hierarchy = get_polygon_hierarchy(tri)
380386
boundary_enricher = get_boundary_enricher(tri)
381387
cache = get_cache(tri)
382388
return Triangulation(
@@ -828,13 +834,11 @@ function constrained_triangulation!(tri::Triangulation, segments, boundary_nodes
828834
for e in each_edge(all_segments)
829835
add_segment!(new_tri, e; predicates, rng)
830836
end
831-
new_tri_2 = replace_ghost_vertex_information(new_tri, ghost_vertex_map, ghost_vertex_ranges)
837+
new_tri_2 = replace_ghost_vertex_information(new_tri, ghost_vertex_map, ghost_vertex_ranges, full_polygon_hierarchy)
832838
if !(isnothing(boundary_nodes) || !has_boundary_nodes(boundary_nodes)) && delete_holes
833839
delete_holes!(new_tri_2)
834840
add_boundary_information!(new_tri_2)
835841
add_ghost_triangles!(new_tri_2) # fix the ghost triangles
836-
polygon_hierarchy = get_polygon_hierarchy(new_tri_2)
837-
copyto!(polygon_hierarchy, full_polygon_hierarchy)
838842
end
839843
return new_tri_2
840844
end

src/data_structures/convex_hull.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Struct for representing a convex hull. See also [`convex_hull`](@ref).
99
1010
# Constructors
1111
ConvexHull(points, vertices)
12-
convex_hull(points; IntegerType=Int)
12+
convex_hull(points; predicates=AdaptiveKernel(), IntegerType=Int)
1313
"""
1414
struct ConvexHull{P, I}
1515
points::P
@@ -32,6 +32,12 @@ function Base.show(io::IO, m::MIME"text/plain", ch::ConvexHull)
3232
end
3333
Base.sizehint!(ch::ConvexHull, n) = Base.sizehint!(get_vertices(ch), n)
3434

35+
function Base.copy(ch::ConvexHull)
36+
p = get_points(ch)
37+
v = get_vertices(ch)
38+
return ConvexHull(copy(p), copy(v))
39+
end
40+
3541
@doc """
3642
get_points(convex_hull::ConvexHull) -> Points
3743

0 commit comments

Comments
 (0)