Repository: JuliaPlots/Makie.jl (julia)

Issue:
`boundingbox(plot)` is broken
Most `boundingbox(plot)` calls just return NaN. This includes:
- mesh
- scatter
- lines
- linesegments
- meshscatter
- volume
- surface
- heatmap
- image

The only one that works is `text`. Though that one currently transforms to pixel space which probably shouldn't happen by default.

Pull request:
# Description

Fixes #2145 (boundingbox returning NaN)

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist

- [ ] Added an entry in NEWS.md (for new features and breaking changes)
- [x] Added unit tests for new algorithms, conversion methods, etc.

Should this have a NEWS entry?

Patch:
diff --git a/src/layouting/data_limits.jl b/src/layouting/data_limits.jl
index 31c00650f00..e9f5ad05f70 100644
--- a/src/layouting/data_limits.jl
+++ b/src/layouting/data_limits.jl
@@ -131,8 +131,14 @@ end
 
 foreach_plot(f, s::Figure) = foreach_plot(f, s.scene)
 foreach_plot(f, s::FigureAxisPlot) = foreach_plot(f, s.figure)
-foreach_plot(f, plot::Combined) = foreach_plot(f, plot.plots)
 foreach_plot(f, list::AbstractVector) = foreach(f, list)
+function foreach_plot(f, plot::Combined)
+    if isempty(plot.plots)
+        f(plot)
+    else
+        foreach_plot(f, plot.plots)
+    end
+end
 
 function foreach_transformed(f, point_iterator, model, trans_func)
     for point in point_iterator


Test patch:
diff --git a/test/boundingboxes.jl b/test/boundingboxes.jl
new file mode 100644
index 00000000000..57b033b65fc
--- /dev/null
+++ b/test/boundingboxes.jl
@@ -0,0 +1,58 @@
+@testset "boundingbox(plot)" begin
+    cat = FileIO.load(Makie.assetpath("cat.obj"))
+
+    # Testing atomic plots here. Everything else should be derived from them
+
+    fig, ax, p = mesh(cat)
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(-0.1678, -0.002068, -0.358661)
+    @test bb.widths ≈ Vec3f(0.339423, 0.92186, 1.3318559)
+
+    fig, ax, p = surface([x*y for x in 1:10, y in 1:10])
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(0.0, 0.0, 1.0)
+    @test bb.widths ≈ Vec3f(10.0, 10.0, 99.0)
+
+    fig, ax, p = meshscatter([Point3f(x, y, z) for x in 1:5 for y in 1:5 for z in 1:5])
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(1)
+    @test bb.widths ≈ Vec3f(4)
+
+    fig, ax, p = volume(rand(5, 5, 5))
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(0)
+    @test bb.widths ≈ Vec3f(5)
+
+    fig, ax, p = scatter(1:10)
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(1, 1, 0)
+    @test bb.widths ≈ Vec3f(9, 9, 0)
+
+    fig, ax, p = lines(1:10)
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(1, 1, 0)
+    @test bb.widths ≈ Vec3f(9, 9, 0)
+
+    fig, ax, p = linesegments(1:10)
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(1, 1, 0)
+    @test bb.widths ≈ Vec3f(9, 9, 0)
+
+    fig, ax, p = heatmap(rand(10, 10))
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(0.5, 0.5, 0)
+    @test bb.widths ≈ Vec3f(10.0, 10.0, 0)
+    
+    fig, ax, p = image(rand(10, 10))
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(0)
+    @test bb.widths ≈ Vec3f(10.0, 10.0, 0)
+
+    # text transforms to pixel space atm (TODO)
+    fig = Figure(resolution = (400, 400))
+    ax = Axis(fig[1, 1])
+    p = text!(ax, Point2f(10), text = "test")
+    bb = boundingbox(p)
+    @test bb.origin ≈ Point3f(340, 341, 0)
+    @test bb.widths ≈ Vec3f(32.24, 23.3, 0)
+end
\ No newline at end of file
diff --git a/test/runtests.jl b/test/runtests.jl
index 9c89ac747be..1a03c8e5ec6 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -28,4 +28,5 @@ using Makie: volume
     include("stack.jl")
     include("events.jl")
     include("text.jl")
+    include("boundingboxes.jl")
 end