Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement copy/deepcopy for Triangulation/VoronoiTessellation #201

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- `PointLocationHistory` was not marked as public. This has been fixed. See [#198](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/198).
- Fixed an issue with missing docstrings and duplicate docstrings in the documentation. See [#198](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/198).
- `copy` and `deepcopy` are now correctly implemented for `PolygonTree`s and `PolygonHierarchy`s. See [#199](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/199)
- Implemented `copy` and `deepcopy` for `Triangulation` and `VoronoiTessellation`. See [#201](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/201).
- 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).
- Implemented `==` for `VoronoiTessellation`. See [#201](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/201).

## 1.5.0

Expand Down
18 changes: 11 additions & 7 deletions src/algorithms/triangulation/constrained_triangulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,13 @@ function remake_triangulation_with_constraints(tri::Triangulation, segments, bou
boundary_curves = get_boundary_curves(tri)
I = integer_type(tri)
E = edge_type(tri)
boundary_edge_map = construct_boundary_edge_map(boundary_nodes, I, E)
if is_curve_bounded(tri)
boundary_edge_map = get_boundary_edge_map(get_boundary_enricher(tri))
empty!(boundary_edge_map)
_construct_boundary_edge_map!(boundary_edge_map, boundary_nodes)
else
boundary_edge_map = construct_boundary_edge_map(boundary_nodes, I, E)
end
ghost_vertex_map = get_ghost_vertex_map(tri)
new_ghost_vertex_map = construct_ghost_vertex_map(boundary_nodes, I) # Delay putting these in until we are done with the triangulation
ghost_vertex_ranges = get_ghost_vertex_ranges(tri)
Expand Down Expand Up @@ -349,7 +355,7 @@ function remake_triangulation_with_constraints(tri::Triangulation, segments, bou
end

"""
replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges) -> Triangulation
replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges, polygon_hierarchy) -> Triangulation

Replaces the ghost vertex information in `tri` with `ghost_vertex_map` and `ghost_vertex_ranges`, using the results from
[`remake_triangulation_with_constraints`](@ref).
Expand All @@ -358,11 +364,12 @@ Replaces the ghost vertex information in `tri` with `ghost_vertex_map` and `ghos
- `tri::Triangulation`: The triangulation to remake.
- `ghost_vertex_map`: The ghost vertex map to add to the triangulation.
- `ghost_vertex_ranges`: The ghost vertex ranges to add to the triangulation.
- `polygon_hierarchy`: The polygon hierarchy to add to the triangulation.

# Outputs
- `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.
"""
function replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges)
function replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map, ghost_vertex_ranges, polygon_hierarchy = get_polygon_hierarchy(tri))
points = get_points(tri)
triangles = get_triangles(tri)
boundary_nodes = get_boundary_nodes(tri)
Expand All @@ -376,7 +383,6 @@ function replace_ghost_vertex_information(tri::Triangulation, ghost_vertex_map,
boundary_edge_map = get_boundary_edge_map(tri)
ch = get_convex_hull(tri)
representative_point_list = get_representative_point_list(tri)
polygon_hierarchy = get_polygon_hierarchy(tri)
boundary_enricher = get_boundary_enricher(tri)
cache = get_cache(tri)
return Triangulation(
Expand Down Expand Up @@ -828,13 +834,11 @@ function constrained_triangulation!(tri::Triangulation, segments, boundary_nodes
for e in each_edge(all_segments)
add_segment!(new_tri, e; predicates, rng)
end
new_tri_2 = replace_ghost_vertex_information(new_tri, ghost_vertex_map, ghost_vertex_ranges)
new_tri_2 = replace_ghost_vertex_information(new_tri, ghost_vertex_map, ghost_vertex_ranges, full_polygon_hierarchy)
if !(isnothing(boundary_nodes) || !has_boundary_nodes(boundary_nodes)) && delete_holes
delete_holes!(new_tri_2)
add_boundary_information!(new_tri_2)
add_ghost_triangles!(new_tri_2) # fix the ghost triangles
polygon_hierarchy = get_polygon_hierarchy(new_tri_2)
copyto!(polygon_hierarchy, full_polygon_hierarchy)
end
return new_tri_2
end
8 changes: 7 additions & 1 deletion src/data_structures/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Struct for representing a convex hull. See also [`convex_hull`](@ref).

# Constructors
ConvexHull(points, vertices)
convex_hull(points; IntegerType=Int)
convex_hull(points; predicates=AdaptiveKernel(), IntegerType=Int)
"""
struct ConvexHull{P, I}
points::P
Expand All @@ -32,6 +32,12 @@ function Base.show(io::IO, m::MIME"text/plain", ch::ConvexHull)
end
Base.sizehint!(ch::ConvexHull, n) = Base.sizehint!(get_vertices(ch), n)

function Base.copy(ch::ConvexHull)
p = get_points(ch)
v = get_vertices(ch)
return ConvexHull(copy(p), copy(v))
end

@doc """
get_points(convex_hull::ConvexHull) -> Points

Expand Down
Loading
Loading