Skip to content

Commit

Permalink
fix bb with NaNs
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Sep 4, 2023
1 parent ac02141 commit 0050ee8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}
x, y, z = plot[1:3]
zrange = lift(nan_extrema, plot, z)
levels = lift(plot, plot.levels, zrange) do levels, zrange
@show levels zrange
if levels isa AbstractVector{<: Number}
return levels
elseif levels isa Integer
Expand Down Expand Up @@ -280,8 +281,11 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}
labels || return
return broadcast(texts.plots[1][1].val, texts.positions.val, texts.rotation.val) do gc, pt, rot
# drop the depth component of the bounding box for 3D
any(isnan, pt) && return Rect2f()
px_pos = project(scene, apply_transform(transform_func(plot), pt, space))
Rect2f(boundingbox(gc, to_ndim(Point3f, px_pos, 0f0), to_rotation(rot)))
bb = unsafe_boundingbox(gc, to_ndim(Point3f, px_pos, 0f0), to_rotation(rot))
isfinite_rect(bb) || return Rect2f()
Rect2f(bb)
end
end

Expand Down
16 changes: 10 additions & 6 deletions src/layouting/boundingbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ end

_inkboundingbox(ext::GlyphExtent) = ext.ink_bounding_box

function boundingbox(glyphcollection::GlyphCollection, position::Point3f, rotation::Quaternion)
return boundingbox(glyphcollection, rotation) + position
function unsafe_boundingbox(glyphcollection::GlyphCollection, position::Point3f, rotation::Quaternion)
return unsafe_boundingbox(glyphcollection, rotation) + position
end

function boundingbox(glyphcollection::GlyphCollection, rotation::Quaternion)
function unsafe_boundingbox(glyphcollection::GlyphCollection, rotation::Quaternion)
if isempty(glyphcollection.glyphs)
return Rect3f(Point3f(0), Vec3f(0))
end
Expand All @@ -69,11 +69,10 @@ function boundingbox(glyphcollection::GlyphCollection, rotation::Quaternion)
bb = union(bb, charbb)
end
end
!isfinite_rect(bb) && error("Invalid text boundingbox")
return bb
end

function boundingbox(layouts::AbstractArray{<:GlyphCollection}, positions, rotations)
function unsafe_boundingbox(layouts::AbstractArray{<:GlyphCollection}, positions, rotations)
if isempty(layouts)
return Rect3f((0, 0, 0), (0, 0, 0))
else
Expand All @@ -85,11 +84,16 @@ function boundingbox(layouts::AbstractArray{<:GlyphCollection}, positions, rotat
bb = union(bb, boundingbox(layout, pos, rot))
end
end
!isfinite_rect(bb) && error("Invalid text boundingbox")
return bb
end
end

function boundingbox(args...)
bb = unsafe_boundingbox(args...)
isfinite_rect(bb) || error("Invalid text boundingbox")
bb
end

function boundingbox(x::Text{<:Tuple{<:GlyphCollection}})
if x.space[] == x.markerspace[]
pos = to_ndim(Point3f, x.position[], 0)
Expand Down

0 comments on commit 0050ee8

Please sign in to comment.