JuliaGeometry/DelaunayTriangulation.jl

de Berg fails in this example

Closed this issue · 1 comments

Random.seed!(292888111)
L = 2.0
R = 1.0
num_boundary_cells = 250
num_interior_cells = 500

## The boundary 
boundary_cells = [
    [[x, 0.0] for x in LinRange(0, L, num_boundary_cells ÷ 4)]...,
    [[L, y] for y in LinRange(0, L, num_boundary_cells ÷ 4)]...,
    [[x, L] for x in LinRange(L, 0, num_boundary_cells ÷ 4)]...,
    [[0.0, y] for y in LinRange(L, 0, num_boundary_cells ÷ 4)]...
]

## Generate the interior 
x = L * rand(num_interior_cells)
y = L * rand(num_interior_cells)
interior_cells = [[x, y] for (x, y) in zip(x, y)]

# Filter out the circle 
bad_idx = Int64[]
void_centre = [L/2, L/2]
for i in eachindex(interior_cells)
    @views _x, _y = interior_cells[i]
    radsq = (_x - void_centre[1])^2 + (_y - void_centre[2])^2 
    radsq < R^2 && push!(bad_idx, i)
end
deleteat!(interior_cells, bad_idx)

## Combine the boundary and interior cells
cells = vcat(interior_cells, boundary_cells)
interior_cell_idx = eachindex(interior_cells)
boundary_cell_idx = lastindex(interior_cells) .+ eachindex(boundary_cells)
cells = reduce(hcat, cells)

## Triangulate 
_, _, _, dg = DT.triangulate_berg(cells)
ERROR: KeyError: key -4 not found
Stacktrace:
  [1] getindex
    @ .\dict.jl:498 [inlined]
  [2] get_edge
    @ C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\data_structures.jl:126 [inlined]
  [3] delete_edge!(adj2v::DelaunayTriangulation.Adjacent2Vertex{Int64, Set{Tuple{Int64, Int64}}, Tuple{Int64, Int64}}, w::Int64, uv::Tuple{Int64, Int64})
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\data_structures.jl:147
  [4] delete_edge!
    @ C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\data_structures.jl:154 [inlined]
  [5] delete_triangle!(i::Int64, j::Int64, k::Int64, T::Set{Tuple{Int64, Int64, Int64}}, adj::DelaunayTriangulation.Adjacent{Int64, Tuple{Int64, Int64}}, adj2v::DelaunayTriangulation.Adjacent2Vertex{Int64, Set{Tuple{Int64, Int64}}, Tuple{Int64, Int64}}, DG::DelaunayTriangulation.DelaunayGraph{Int64}; protect_boundary::Bool, update_ghost_edges::Bool)
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\operations.jl:191
  [6] split_edge!(i::Int64, j::Int64, r::Int64, T::Set{Tuple{Int64, Int64, Int64}}, adj::DelaunayTriangulation.Adjacent{Int64, Tuple{Int64, Int64}}, adj2v::DelaunayTriangulation.Adjacent2Vertex{Int64, Set{Tuple{Int64, Int64}}, Tuple{Int64, Int64}}, DG::DelaunayTriangulation.DelaunayGraph{Int64})
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\operations.jl:362
  [7] split_edge!(i::Int64, j::Int64, r::Int64, T::Set{Tuple{Int64, Int64, Int64}}, adj::DelaunayTriangulation.Adjacent{Int64, Tuple{Int64, Int64}}, adj2v::DelaunayTriangulation.Adjacent2Vertex{Int64, Set{Tuple{Int64, Int64}}, Tuple{Int64, Int64}}, DG::DelaunayTriangulation.DelaunayGraph{Int64}, HG::DelaunayTriangulation.HistoryGraph{Tuple{Int64, Int64, Int64}})
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\operations.jl:368
  [8] add_point_berg!(T::Set{Tuple{Int64, Int64, Int64}}, adj::DelaunayTriangulation.Adjacent{Int64, Tuple{Int64, Int64}}, adj2v::DelaunayTriangulation.Adjacent2Vertex{Int64, Set{Tuple{Int64, Int64}}, Tuple{Int64, Int64}}, DG::DelaunayTriangulation.DelaunayGraph{Int64}, HG::DelaunayTriangulation.HistoryGraph{Tuple{Int64, Int64, Int64}}, pts::Matrix{Float64}, r::Int64)
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\deberg.jl:14
  [9] triangulate_berg(pts::Matrix{Float64}; IntegerType::Type{Int64}, EdgeType::Type{Tuple{Int64, Int64}}, TriangleType::Type{Tuple{Int64, Int64, Int64}}, EdgesType::Type{Set{Tuple{Int64, Int64}}}, TrianglesType::Type{Set{Tuple{Int64, Int64, Int64}}}, randomise::Bool, trim::Bool)
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\deberg.jl:42
 [10] triangulate_berg(pts::Matrix{Float64})
    @ DelaunayTriangulation C:\Users\licer\.julia\packages\DelaunayTriangulation\jJmNg\src\deberg.jl:26
 [11] top-level scope
    @ c:\Users\licer\.julia\dev\CellSimulations\work\main_algorithm.jl:373

Issue is related to collinear points, though I thought this was resolved with de Berg