Skip to content

Commit

Permalink
Merge branch 'main' of github.com:DanielVandH/DelaunayTriangulation.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVandH committed Aug 4, 2023
2 parents 1cd6660 + 1fea213 commit aae9e30
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/data_structures/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ is omitted.)
- `num_edges(G)`
- `num_neighbours(G, u)`
- `num_vertices(G)`
- `has_vertex(G, u)`
- `has_boundary_vertices(G)`
"""
struct Graph{I}
graph::UndirectedGraph{I}
Expand Down Expand Up @@ -129,6 +131,14 @@ Returns the number of vertices in the graph `G`.
"""
num_vertices(G::Graph) = length(get_vertices(G))

"""
has_vertex(G::Graph, u)
Returns `true` if the vertex `u` is in the graph `G`,
and `false` otherwise.
"""
has_vertex(G::Graph, u) = has(get_graph(G), u)

"""
add_vertex!(G::Graph, u...)
Expand Down Expand Up @@ -276,6 +286,15 @@ function delete_boundary_vertices_from_graph!(G::Graph{I}) where {I}
return nothing
end

"""
has_boundary_vertices(G::Graph{I}) where {I}
Returns `true` if the graph `G` has any boundary vertices, and `false` otherwise.
"""
function has_boundary_vertices(G::Graph{I}) where {I}
return any((I(BoundaryIndex)), get_vertices(G))
end

"""
clear_empty_points!(G::Graph)
Expand Down
17 changes: 16 additions & 1 deletion src/data_structures/triangulation/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,19 @@ in the triangulation.
Returns `num_vertices(get_graph(tri))`, the number of vertices in the triangulation.
"""
@inline num_vertices(tri::Triangulation) = num_vertices(get_graph(tri))
@inline num_vertices(tri::Triangulation) = num_vertices(get_graph(tri))

"""
has_vertex(tri::Triangulation, u)
Returns `true` if the vertex `u` is in the triangulation,
and `false` otherwise.
"""
@inline has_vertex(tri::Triangulation, u) = has_vertex(get_graph(tri), u)

"""
has_boundary_vertices(tri::Triangulation)
Returns `true` if the triangulation has any ghost vertices, and `false` otherwise.
"""
@inline has_boundary_vertices(tri::Triangulation) = has_boundary_vertices(get_graph(tri))
6 changes: 3 additions & 3 deletions src/data_structures/triangulation/points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Sets the `i`th point of `tri` to `p = (x, y)`.
Returns the number of ghost vertices of `tri`.
"""
num_ghost_vertices(tri::Triangulation) = length(all_boundary_indices(tri))
num_ghost_vertices(tri::Triangulation) = length(all_boundary_indices(tri)) * has_boundary_vertices(tri)

"""
num_solid_vertices(tri::Triangulation)
Expand All @@ -102,7 +102,7 @@ struct EachSolidVertex{V,T} <: AbstractEachVertex{V}
vertices::V
tri::T
end
Base.length(verts::EachSolidVertex) = num_solid_vertices(verts.tri)
Base.length(verts::EachSolidVertex) = num_solid_vertices(verts.tri)
struct EachGhostVertex{V,T} <: AbstractEachVertex{V}
vertices::V
tri::T
Expand All @@ -119,7 +119,7 @@ function Base.iterate(itr::EachSolidVertex, state...)
end
return vertices, state
end
Base.iterate(itr::EachGhostVertex, state...) = Base.iterate(itr.vertices, state...)
Base.iterate(itr::EachGhostVertex, state...) = has_boundary_vertices(itr.tri) ? Base.iterate(itr.vertices, state...) : nothing

"""
each_solid_vertex(tri::Triangulation)
Expand Down
11 changes: 11 additions & 0 deletions test/data_structures/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,15 @@ end
@testset "Number of vertices and each_vertex" begin
@test num_vertices(g) == 6
@test each_vertex(g) == get_vertices(g)
end

@testset "has_vertex and has_boundary_vertices" begin
bidx = DT.BoundaryIndex
DT.add_vertex!(g, bidx, bidx - 1, bidx - 2, bidx - 3, bidx - 4)
@test DT.has_vertex(g, bidx)
@test DT.has_vertex(g, bidx - 4)
@test DT.has_vertex(g, 5)
@test DT.has_boundary_vertices(g)
DT.delete_boundary_vertices_from_graph!(g)
@test !DT.has_boundary_vertices(g)
end
23 changes: 23 additions & 0 deletions test/data_structures/triangulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -862,4 +862,27 @@ end
Base.Threads.@threads for _ in 1:5000
get_adjacent(tri, -5, rand(1:1000))
end
end

@testset "has_vertex and has_boundary_vertices" begin
tri = triangulate(rand(2, 50), delete_ghosts=false)
@test DT.has_vertex(tri, 1)
@test !DT.has_vertex(tri, 57)
@test DT.has_boundary_vertices(tri)
@test DT.has_vertex(tri, -1)
DT.delete_boundary_vertices_from_graph!(tri)
@test !DT.has_vertex(tri, -1)
@test !DT.has_boundary_vertices(tri)
end

@testset "Issue #70" begin
points = [(-1.0, -1.0), (1.0, -1.0), (0.0, 1.0)]
tri = triangulate(points)
delete_ghost_triangles!(tri)
DelaunayTriangulation.delete_boundary_vertices_from_graph!(tri)
@test collect(each_solid_vertex(tri)) == collect(each_vertex(tri))
@test !DelaunayTriangulation.has_boundary_vertices(tri)
@test DelaunayTriangulation.num_ghost_vertices(tri) == 0
@test DelaunayTriangulation.num_solid_vertices(tri) == 3
@test isempty(collect(each_ghost_vertex(tri)))
end

2 comments on commit aae9e30

@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/89000

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 v0.8.2 -m "<description of version>" aae9e303b34d63f560dce274efb50288e1e52e88
git push origin v0.8.2

Please sign in to comment.