Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data_limits dispatch for Mesh to omit slow iteration over buffer #2874

Closed
wants to merge 10 commits into from
33 changes: 33 additions & 0 deletions src/layouting/data_limits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ function data_limits(plot::Surface)
return Rect3f(mini, maxi .- mini)
end

function data_limits(plot::Mesh)
xyz = plot.mesh[].position
mini, maxi = bbox_mesh(xyz)
if length(mini) == 2
koehlerson marked this conversation as resolved.
Show resolved Hide resolved
mini = Vec3f(mini...,0)
maxi = Vec3f(maxi...,0)
else
mini = Vec3f(mini)
maxi = Vec3f(maxi)
end
return Rectf(mini, maxi .- mini)
end

function data_limits(plot::Heatmap)
mini_maxi = extrema_nan.((plot.x[], plot.y[]))
mini = Vec3f(first.(mini_maxi)..., 0)
Expand All @@ -222,3 +235,23 @@ function data_limits(plot::Image)
maxi = Vec3f(last.(mini_maxi)..., 0)
return Rect3f(mini, maxi .- mini)
end

function bbox_mesh(coords)
dim = length(coords[1])
mini = [xyz for xyz in coords[1]]
maxi = [xyz for xyz in coords[1]]
for coord in coords
for d in 1:dim
if isnan(coord[d]) || isinf(coord[d])
continue
end
if coord[d] < mini[d]
mini[d] = coord[d]
elseif coord[d] > maxi[d]
maxi[d] = coord[d]
end
end
koehlerson marked this conversation as resolved.
Show resolved Hide resolved
end
return (mini,maxi)
end