Skip to content

[BUG]: Failing to calculate polygons for a voronoi plot #234

@maltepuetz

Description

@maltepuetz

Describe the bug

The calculation of polygons for a voronoi plot fails for a specific choice of points (i.e. a grid on a triangle). The issue is inside grow_polygon_outside_of_box, where the function returns Inf. I have implemented a workaround locally and will create a PR which I will link to this issue.

Reproducer

You can reproduce the issue when trying to do a voronoi plot as below:

using CairoMakie
using LinearAlgebra

function generatePoints(n)
    points = Vector{NTuple{3,Float64}}(undef, n * (n + 1) ÷ 2)
    m = 1
    for (k, i) in enumerate(range(0, 1, n))
        for j in range(i, 1, n - k + 1)
            px = i
            py = j - i
            pz = 1 - j
            points[m] = (px, py, pz)
            m += 1
        end
    end
    return points
end
function projection(point; origin=[1 / 3, 1 / 3, 1 / 3], e1=normalize(cross(normalize([0.0, 0.0, 1.0] .- [1 / 3, 1 / 3, 1 / 3]), normalize([1 / 3, 1 / 3, 1 / 3]))), e2=normalize([0.0, 0.0, 1.0] .- [1 / 3, 1 / 3, 1 / 3]))
    return sum(e1 .* (point .- origin)), sum(e2 .* (point .- origin))
end

points = generatePoints(3)
points2d = [projection(p) for p in points]
voronoiplot([p[1] for p in points2d], [p[2] for p in points2d], randn(size(points2d)))

Environment information

using InteractiveUtils
versioninfo()

Julia Version 1.12.2
Commit ca9b6662be4 (2025-11-20 16:25 UTC)
Build Info:
Official https://julialang.org release
Platform Info:
OS: macOS (arm64-apple-darwin24.0.0)
CPU: 12 × Apple M3 Pro
WORD_SIZE: 64
LLVM: libLLVM-18.1.7 (ORCJIT, apple-m3)
GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 6 virtual cores)
Environment:
JULIA_EDITOR = code

and

using Pkg
Pkg.status()

Status /private/var/folders/bb/tp8g2s_95jb3x146dfglhw_h0000gn/T/jl_CI63nn/Project.toml
[13f3f980] CairoMakie v0.15.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions