Skip to content

Commit

Permalink
Implement copy/deepcopy for Triangulation/VoronoiTessellation (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVandH authored Oct 1, 2024
1 parent 8606710 commit 586d888
Show file tree
Hide file tree
Showing 37 changed files with 897 additions and 154 deletions.
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

2 comments on commit 586d888

@DanielVandH
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116442

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.6.0 -m "<description of version>" 586d88820bf8b22bf132d592e69f9c44355a9699
git push origin v1.6.0

Please sign in to comment.