From 1f351727e31ad752a1af3d1358c6bc6d293cb270 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Thu, 12 Oct 2023 17:44:36 +0200 Subject: [PATCH] allow scene to report multiple spaces --- src/camera/projection_math.jl | 16 +++++++++++++--- src/interfaces.jl | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/camera/projection_math.jl b/src/camera/projection_math.jl index c32de935a57..5fca35e5957 100644 --- a/src/camera/projection_math.jl +++ b/src/camera/projection_math.jl @@ -344,11 +344,21 @@ function clip_to_space(cam::Camera, space::Symbol) end end -get_space(scene::Scene) = get_space(cameracontrols(scene)) -# TODO: Should we default to something invalid? +function get_space(scene::Scene) + space = get_space(cameracontrols(scene))::Symbol + space === :data ? (:data,) : (:data, space) +end get_space(::AbstractCamera) = :data # TODO: Should this be less specialized? ScenePlot? AbstractPlot? -get_space(plot::Combined) = to_value(get(plot, :space, :data)) +get_space(plot::Combined) = to_value(get(plot, :space, :data))::Symbol + +is_space_compatible(a, b) = is_space_compatible(get_space(a), get_space(b)) +is_space_compatible(a::Symbol, b::Symbol) = a === b +is_space_compatible(a::Symbol, b::Union{Tuple, Vector}) = a in b +function is_space_compatible(a::Union{Tuple, Vector}, b::Union{Tuple, Vector}) + any(x -> is_space_compatible(x, b), a) +end +is_space_compatible(a::Union{Tuple, Vector}, b::Symbol) = is_space_compatible(b, a) function project(cam::Camera, input_space::Symbol, output_space::Symbol, pos) input_space === output_space && return to_ndim(Point3f, pos, 0) diff --git a/src/interfaces.jl b/src/interfaces.jl index 77281e34c2c..417a791c221 100644 --- a/src/interfaces.jl +++ b/src/interfaces.jl @@ -228,7 +228,7 @@ function connect_plot!(parent::SceneLike, plot::Combined{F}) where {F} transform!(t, t_user) plot.transformation = t end - if get_space(parent) === get_space(plot) + if is_space_compatible(plot, parent) connect!(transformation(parent), transformation(plot)) end end