Skip to content

Commit

Permalink
Added ability to create a Triangulation with only points and triangle…
Browse files Browse the repository at this point in the history
…s as input (#192)

Co-authored-by: Daniel VandenHeuvel <95613936+DanielVandH@users.noreply.github.com>
  • Loading branch information
matgrand and DanielVandH authored Sep 27, 2024
1 parent f7485ec commit b094882
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.5.0

- Introduced the ability to reconstruct unconstrained triangulations from an existing set of points and triangles using `Triangulation(points, triangles)`. See [#192](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/192)

## 1.4.0

- Updated to AdaptivePredicates.jl v1.2, now allowing caches to be passed to the predicates involving `incircle` and `orient3`. These are only useful when using the `AdaptiveKernel()` kernel. Outside of triangulating, these caches are not passed by default, but can be provided. The functions `get_incircle_cache` and `get_orient3_cache` can be used for this purpose on a triangulation (without a triangulation, refer to AdaptivePredicate.jl's `incircleadapt_cache` and `orient3adapt_cache`). See [#185](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/185).
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DelaunayTriangulation"
uuid = "927a84f5-c5f4-47a5-9785-b46e178433df"
authors = ["Daniel VandenHeuvel <danj.vandenheuvel@gmail.com>"]
version = "1.4.2"
version = "1.5.0"

[deps]
AdaptivePredicates = "35492f91-a3bd-45ad-95db-fcad7dcfedb7"
Expand Down
49 changes: 48 additions & 1 deletion src/data_structures/triangulation/triangulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ Returns the `Triangulation` corresponding to the triangulation of `points` with
# Arguments
- `points`: The points that the triangulation is of.
- `triangles`: The triangles of the triangulation. These should be given in counter-clockwise order, with vertices corresponding to `points`. These should not include any ghost triangles.
- `triangles`: The triangles of the triangulation. These should be given in counter-clockwise order, with vertices corresponding to `points`. Ghost triangles should not be included (and are ignored if they are).
- `boundary_nodes`: The boundary nodes of the triangulation. These should match the specification given in the documentation or in [`check_args`](@ref).
# Keyword Arguments
Expand Down Expand Up @@ -520,6 +520,52 @@ Returns the `Triangulation` corresponding to the triangulation of `points` with
return build_triangulation_from_data!(tri, triangles, _bn, delete_ghosts, predicates)
end

"""
Triangulation(points, triangles; kwargs...) -> Triangulation
Returns the unconstrained `Triangulation` corresponding to the triangulation of `points` with `triangles`.
!!! note "Valid boundary"
This constructor uses the [`convex_hull`](@ref) of `points` to determine the triangulation's boundary.
If the set of triangles does not form a valid unconstrained triangulation, then this constructor may not
return a valid triangulation. Similarly, if there is a point in `points` that is not a vertex of some
triangle, but is a vertex of the convex hull, the triangulation will not be valid.
# Arguments
- `points`: The points that the triangulation is of. There should not be any points not referenced in `triangles`.
- `triangles`: The triangles of the triangulation. These should be given in counter-clockwise order, with vertices corresponding to `points`. Ghost triangles should not be included (and are ignored if they are).
# Keyword Arguments
- `predicates::AbstractPredicateKernel=AdaptiveKernel()`: Method to use for computing predicates. Can be one of [`FastKernel`](@ref), [`ExactKernel`](@ref), and [`AdaptiveKernel`](@ref). See the documentation for a further discussion of these methods.
- `IntegerType=Int`: The integer type to use for the triangulation. This is used for representing vertices.
- `EdgeType=isnothing(segments) ? NTuple{2,IntegerType} : (edge_type ∘ typeof)(segments)`: The edge type to use for the triangulation.
- `TriangleType=NTuple{3,IntegerType}`: The triangle type to use for the triangulation.
- `EdgesType=isnothing(segments) ? Set{EdgeType} : typeof(segments)`: The type to use for storing the edges of the triangulation.
- `TrianglesType=Set{TriangleType}`: The type to use for storing the triangles of the triangulation.
- `weights=ZeroWeight()`: The weights associated with the triangulation.
- `delete_ghosts=false`: Whether to delete the ghost triangles after the triangulation is computed. This is done using [`delete_ghost_triangles!`](@ref).
# Output
- `tri`: The [`Triangulation`](@ref).
"""
@inline function Triangulation(
points::P, triangles::T;
IntegerType::Type{I}=Int,
EdgeType::Type{E}=NTuple{2,IntegerType},
TriangleType::Type{V}=NTuple{3,IntegerType},
EdgesType::Type{Es}=Set{EdgeType},
TrianglesType::Type{Ts}=Set{TriangleType},
weights=ZeroWeight(),
delete_ghosts=false,
predicates::AbstractPredicateKernel=AdaptiveKernel(),
) where {P,T,I,E,V,Es,Ts}
bn = get_vertices(convex_hull(points; predicates, IntegerType))
tri = Triangulation(points, triangles, bn; IntegerType, EdgeType, TriangleType, EdgesType, TrianglesType, weights, delete_ghosts, predicates)
unlock_convex_hull!(tri)
return tri
end

"""
build_triangulation_from_data!(tri::Triangulation, triangles, boundary_nodes, delete_ghosts, predicates::AbstractPredicateKernel=AdaptiveKernel())
Expand All @@ -540,6 +586,7 @@ See the documentation for more information about these choices.
graph = get_graph(tri)
tris = get_triangles(tri)
for τ in each_triangle(triangles)
is_ghost_triangle(τ) && continue
add_triangle!(adj, τ)
add_triangle!(adj2v, τ)
add_triangle!(graph, τ)
Expand Down
10 changes: 10 additions & 0 deletions test/data_structures/triangulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1475,3 +1475,13 @@ end
end
end
end

@testset "Constructor with only points and triangles" begin
points = [(0.0, 0.0), (0.87, 0.0), (1.0006, 0.7766), (0.0, 1.0), (0.5, 0.5)]
tri1 = triangulate(points)
triangles = tri1.triangles
tri2 = DT.Triangulation(points, triangles)
@test validate_triangulation(tri2)
@test tri1 == tri2
@test !DT.has_boundary_nodes(tri2)
end
2 changes: 1 addition & 1 deletion test/triangulation/triangulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ end
@test validate_triangulation(tri; predicates = PT())
end
end
end
end

2 comments on commit b094882

@DanielVandH
Copy link
Member

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/116175

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.5.0 -m "<description of version>" b0948821557c65818a8efd679ca538406e368a34
git push origin v1.5.0

Please sign in to comment.