diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index 221d48e9b..29cf91828 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -67,8 +67,8 @@ function raw_boundingbox(plots::Vector) plot_idx = iterate(plots, idx) # isvisible(plot) || continue bb2 = boundingbox(plot) - isfinite(bb) || (bb = bb2) - isfinite(bb2) || continue + isfinite_rect(bb) || (bb = bb2) + isfinite_rect(bb2) || continue bb = union(bb, bb2) end return bb @@ -192,7 +192,7 @@ function boundingbox( # bb = rectdiv(bb, 1.5) shifted_bb = FRect3D(rotated_bb) + position[i] bboxc = bbox[] - if !isfinite(bboxc) + if !isfinite_rect(bboxc) bbox[] = shifted_bb else bbox[] = union(bboxc, shifted_bb) diff --git a/src/layouting/data_limits.jl b/src/layouting/data_limits.jl index c442fa7b6..41e07ad98 100644 --- a/src/layouting/data_limits.jl +++ b/src/layouting/data_limits.jl @@ -57,7 +57,7 @@ function extrema_nan(itr) end function xyz_boundingbox(transform_func, mesh::GeometryBasics.Mesh) - xyz_boundingbox(transform_func, coordinates(mesh)) + xyz_boundingbox(transform_func, decompose(Point, mesh)) end function xyz_boundingbox(transform_func, xyz) @@ -121,7 +121,7 @@ function data_limits(x::Annotations) return inv(modelmatrix(x)) * bb end -Base.isfinite(x::Rect) = all(isfinite.(minimum(x))) && all(isfinite.(maximum(x))) +isfinite_rect(x::Rect) = all(isfinite.(minimum(x))) && all(isfinite.(maximum(x))) function data_limits(plots::Vector) isempty(plots) && return @@ -133,8 +133,8 @@ function data_limits(plots::Vector) # axis shouldn't be part of the data limit isaxis(plot) && continue bb2 = data_limits(plot)::FRect3D - isfinite(bb) || (bb = bb2) - isfinite(bb2) || continue + isfinite_rect(bb) || (bb = bb2) + isfinite_rect(bb2) || continue bb = union(bb, bb2) end bb diff --git a/src/layouting/transformation.jl b/src/layouting/transformation.jl index e02488084..dc670123c 100644 --- a/src/layouting/transformation.jl +++ b/src/layouting/transformation.jl @@ -214,6 +214,30 @@ apply_transform(f::typeof(identity), positions::AbstractArray) = positions apply_transform(f::typeof(identity), positions::AbstractVector) = positions apply_transform(f::typeof(identity), position::VecTypes) = position +struct PointTrans{N, F} + f::F +end + +PointTrans{N}(func::F) where {N, F} = PointTrans{N, F}(func) +Base.broadcastable(x::PointTrans) = (x,) + +function apply_transform(f::PointTrans{N}, point::Point{N}) where N + return f.f(point) +end + +function apply_transform(f::PointTrans{N1}, point::Point{N2}) where {N1, N2} + p_dim = to_ndim(Point{N1, Float32}, point, 0.0) + p_trans = f.f(p_dim) + if N1 < N2 + p_large = ntuple(i-> i <= N1 ? p_trans[i] : point[i], N2) + return Point{N2, Float32}(p_large) + else + return to_ndim(Point{N2, Float32}, p_trans, 0.0) + end +end + + + function apply_transform(f, data::AbstractArray) return map(point-> apply_transform(f, point), data) end diff --git a/src/makielayout/layoutables/axis.jl b/src/makielayout/layoutables/axis.jl index b1012c733..2c73c625c 100644 --- a/src/makielayout/layoutables/axis.jl +++ b/src/makielayout/layoutables/axis.jl @@ -166,7 +166,7 @@ function Axis(fig_or_scene; bbox = nothing, kwargs...) ticksvisible = yticksvisible, spinevisible = yspinevisible, spinecolor = yspinecolor, spinewidth = spinewidth, trimspine = ytrimspine, ticklabelsize = yticklabelsize, ticksize = yticksize, flip_vertical_label = flip_ylabel, reversed = yreversed, tickwidth = ytickwidth, tickcolor = ytickcolor) - + decorations[:yaxis] = yaxis xoppositelinepoints = lift(scene.px_area, spinewidth, xaxisposition) do r, sw, xaxpos @@ -436,7 +436,7 @@ function getlimits(la::Axis, dim) plots_with_autolimits) bboxes = [FRect2D(AbstractPlotting.data_limits(p)) for p in visible_plots] - finite_bboxes = filter(isfinite, bboxes) + finite_bboxes = filter(AbstractPlotting.isfinite_rect, bboxes) isempty(finite_bboxes) && return nothing diff --git a/test/unit_tests/runtests.jl b/test/unit_tests/runtests.jl index 34fa59817..01ef8e26c 100644 --- a/test/unit_tests/runtests.jl +++ b/test/unit_tests/runtests.jl @@ -13,4 +13,5 @@ include("liftmacro.jl") include("makielayout.jl") include("figures.jl") + include("transformations.jl") end diff --git a/test/unit_tests/transformations.jl b/test/unit_tests/transformations.jl new file mode 100644 index 000000000..6b8513b2a --- /dev/null +++ b/test/unit_tests/transformations.jl @@ -0,0 +1,24 @@ +using AbstractPlotting: PointTrans, xyz_boundingbox + +@testset "Basic transforms" begin + function point2(x::Point2) + return Point2f0(x[1] + 10, x[2] - 77) + end + + function point3(x::Point3) + return Point3f0(x[1] + 10, x[2] - 77, x[3] / 4) + end + trans2 = PointTrans{2}(point2) + trans3 = PointTrans{3}(point3) + points = [Point2f0(0, 0), Point2f0(0, 1)] + bb = xyz_boundingbox(trans2, points) + @test bb == Rect(Vec3f0(10, -77, 0), Vec3f0(0, 1, 0)) + bb = xyz_boundingbox(trans3, points) + @test bb == Rect(Vec3f0(10, -77, 0), Vec3f0(0, 1, 0)) + + points = [Point3f0(0, 0, 4), Point3f0(0, 1, -8)] + bb = xyz_boundingbox(trans2, points) + @test bb == Rect(Vec3f0(10, -77, -8), Vec3f0(0, 1, 12)) + bb = xyz_boundingbox(trans3, points) + @test bb == Rect(Vec3f0(10, -77, -2.0), Vec3f0(0, 1, 3.0)) +end