Skip to content

Commit

Permalink
allow scene to report multiple spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Oct 12, 2023
1 parent 5a495ce commit 1f35172
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/camera/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f35172

Please sign in to comment.