Skip to content

Commit

Permalink
Fix issue with exterior ghost vertices (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVandH authored Oct 1, 2024
1 parent 455b592 commit 0a77a36
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 384 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Bugfix: Introduced `is_linear` to fix issues with boundary enrichment of domains with `LineSegment`s. In particular, `LineSegment`s are no longer enriched. See [#195](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/195).
- Bugfix: `orientation_markers` now uses `uniquetol` instead of `unique` for the final set of markers (it already did it for the intermediate markers). See [#195](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/195).
- Bugfix: For large `Tuple`s, functions like `eval_fnc_at_het_tuple_two_elements` are problematic and allocate more than their non-type-stable counterparts. To get around this, for `Tuple`s of length `N > 32`, the non-type-stable version is used. See [#195](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/195).
- Bigfix: Fixed issue with `use_barriers` when a ghost edge is selected at random during point location. See [#196](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/196).
- Feature: Introduced the (currently internal) function `get_positive_curve_indices` for finding curves with positive orientation in a `Triangulation`. [#196](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/196).
- `is_exterior_curve`, `is_interior_curve`, `num_exterior_curves`, and `is_disjoint` are now defined based on `get_positive_curve_indices` rather than `get_exterior_curve_indices`. See [#196](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/196).

## 1.5.0

Expand Down
11 changes: 11 additions & 0 deletions src/data_structures/trees/polygon_hierarchy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ Returns the indices of the exterior curves of `hierarchy`.
"""
get_exterior_curve_indices(hierarchy::PolygonHierarchy) = keys(get_trees(hierarchy))

"""
get_positive_curve_indices(hierarchy::PolygonHierarchy) -> Generator
Returns the indices of the positively oriented curves of `hierarchy` as a generator, i.e.
as a lazy result.
"""
function get_positive_curve_indices(hierarchy::PolygonHierarchy)
orientations = get_polygon_orientations(hierarchy)
return (index for (index, orientation) in enumerate(orientations) if orientation)
end

"""
get_trees(hierarchy::PolygonHierarchy) -> Dict{I,PolygonTree{I}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Returns `true` if the `curve_index`th curve in `tri` is an exterior curve, and `false` otherwise.
"""
is_exterior_curve(tri::Triangulation, curve_index) = curve_index get_exterior_curve_indices(tri)
is_exterior_curve(tri::Triangulation, curve_index) = curve_index get_positive_curve_indices(tri)

"""
is_interior_curve(tri::Triangulation, curve_index) -> Bool
Expand All @@ -17,7 +17,7 @@ is_interior_curve(tri::Triangulation, curve_index) = !is_exterior_curve(tri, cur
Returns the number of exterior curves in `tri`.
"""
num_exterior_curves(tri::Triangulation) = (length get_exterior_curve_indices)(tri)
num_exterior_curves(tri::Triangulation) = count(get_polygon_orientations(get_polygon_hierarchy(tri)))

"""
is_disjoint(tri::Triangulation) -> Bool
Expand Down
8 changes: 8 additions & 0 deletions src/data_structures/triangulation/triangulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ Returns the set of all curve indices that correspond to exterior curves of `tri`
"""
get_exterior_curve_indices(tri::Triangulation) = get_exterior_curve_indices(get_polygon_hierarchy(tri))

"""
get_positive_curve_indices(tri::Triangulation) -> Generator
Returns the indices of the positively oriented curves of `hierarchy` as a generator, i.e.
as a lazy result.
"""
get_positive_curve_indices(tri::Triangulation) = get_positive_curve_indices(get_polygon_hierarchy(tri))

"""
get_boundary_enricher(tri::Triangulation) -> BoundaryEnricher
Expand Down
5 changes: 5 additions & 0 deletions test/data_structures/polygon_hierarchy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ for _ in 1:20 # Run many times to make sure the segfault is gone
@test DT.get_bounding_boxes(hierarchy) [DT.bounding_box(points)]
@test DT.get_bounding_box(hierarchy, 1) DT.bounding_box(points)
@test DT.get_exterior_curve_indices(hierarchy) == Set(1)
@test collect(DT.get_positive_curve_indices(hierarchy)) == findall(DT.get_polygon_orientations(hierarchy))
@test DT.get_trees(hierarchy) === hierarchy.trees
@test DT.get_tree(hierarchy, 1) === hierarchy.trees[1]
tree = DT.get_tree(hierarchy, 1)
Expand All @@ -144,6 +145,7 @@ for _ in 1:20 # Run many times to make sure the segfault is gone
@test DT.get_bounding_boxes(hierarchy) [DT.BoundingBox(DT.polygon_bounds(points, boundary_nodes)...)]
@test DT.get_bounding_box(hierarchy, 1) DT.BoundingBox(DT.polygon_bounds(points, boundary_nodes)...)
@test DT.get_exterior_curve_indices(hierarchy) == Set(1)
@test collect(DT.get_positive_curve_indices(hierarchy)) == findall(DT.get_polygon_orientations(hierarchy))
@test DT.get_trees(hierarchy) === hierarchy.trees
@test DT.get_tree(hierarchy, 1) === hierarchy.trees[1]
tree = DT.get_tree(hierarchy, 1)
Expand All @@ -161,6 +163,7 @@ for _ in 1:20 # Run many times to make sure the segfault is gone
@test DT.get_bounding_boxes(hierarchy) [DT.BoundingBox(DT.polygon_bounds(points, boundary_nodes)...)]
@test DT.get_bounding_box(hierarchy, 1) DT.BoundingBox(DT.polygon_bounds(points, boundary_nodes)...)
@test DT.get_exterior_curve_indices(hierarchy) == Set(1)
@test collect(DT.get_positive_curve_indices(hierarchy)) == findall(DT.get_polygon_orientations(hierarchy))
@test DT.get_trees(hierarchy) === hierarchy.trees
@test DT.get_tree(hierarchy, 1) === hierarchy.trees[1]
tree = DT.get_tree(hierarchy, 1)
Expand All @@ -179,6 +182,7 @@ for _ in 1:20 # Run many times to make sure the segfault is gone
@test DT.get_bounding_box(hierarchy, 1) DT.BoundingBox(DT.polygon_bounds(points, get_boundary_nodes(boundary_nodes, 1))...)
@test DT.get_bounding_box(hierarchy, 2) DT.BoundingBox(DT.polygon_bounds(points, get_boundary_nodes(boundary_nodes, 2))...)
@test DT.get_exterior_curve_indices(hierarchy) == Set(1)
@test collect(DT.get_positive_curve_indices(hierarchy)) == findall(DT.get_polygon_orientations(hierarchy))
@test DT.get_trees(hierarchy) === hierarchy.trees
@test DT.get_tree(hierarchy, 1) === hierarchy.trees[1]
tree = DT.get_tree(hierarchy, 1)
Expand Down Expand Up @@ -228,6 +232,7 @@ for _ in 1:20 # Run many times to make sure the segfault is gone
boundary_nodes, points = convert_boundary_points_to_indices([_Q1, _Q2, _Q3, _Q4, _Q5, _Q6, _Q7, _Q8, _Q9, _Q10, _Q11, _Q12, _Q13, _Q14, _Q15])
hierarchy = DT.construct_polygon_hierarchy(points, boundary_nodes)
@test DT.get_exterior_curve_indices(hierarchy) == Set([6, 5, 7, 15])
@test collect(DT.get_positive_curve_indices(hierarchy)) == findall(DT.get_polygon_orientations(hierarchy))
@test DT.get_bounding_boxes(hierarchy) [
DT.BoundingBox(-9.0, -2.0, -1.0, 7.0),
DT.BoundingBox(0.0, 10.0, -5.0, 6.0),
Expand Down
4 changes: 3 additions & 1 deletion test/data_structures/triangulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ refine!(tri_4; max_area=1.0e-1A, use_circumcenter=true, use_lens=false)
@test DT.get_convex_hull(tri) == tri.convex_hull
@test DT.get_representative_point_list(tri) == tri.representative_point_list
@test DT.get_exterior_curve_indices(tri) == keys(tri.polygon_hierarchy.trees)
@test collect(DT.get_positive_curve_indices(tri)) == findall(tri.polygon_hierarchy.polygon_orientations)
@test DT.get_boundary_enricher(tri) === tri.boundary_enricher
@test compare_trees(DT.get_polygon_hierarchy(tri), DT.construct_polygon_hierarchy(tri.points, tri.boundary_nodes))
@test compare_edge_vectors(collect(DT.get_all_segments(tri)), collect(tri.all_segments))
Expand Down Expand Up @@ -149,6 +150,7 @@ refine!(tri_4; max_area=1.0e-1A, use_circumcenter=true, use_lens=false)
@inferred DT.get_convex_hull(tri)
@inferred DT.get_representative_point_list(tri)
@inferred DT.get_exterior_curve_indices(tri)
@inferred DT.get_positive_curve_indices(tri)
@inferred DT.get_boundary_enricher(tri)
@inferred DT.get_polygon_hierarchy(tri)
@inferred DT.get_cache(tri)
Expand Down Expand Up @@ -1484,4 +1486,4 @@ end
@test validate_triangulation(tri2)
@test tri1 == tri2
@test !DT.has_boundary_nodes(tri2)
end
end
Loading

0 comments on commit 0a77a36

Please sign in to comment.