From 0050ee897b3e6c92b74947de69f38a2e837119b4 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Mon, 4 Sep 2023 18:30:41 +0200 Subject: [PATCH] fix bb with NaNs --- src/basic_recipes/contours.jl | 6 +++++- src/layouting/boundingbox.jl | 16 ++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/basic_recipes/contours.jl b/src/basic_recipes/contours.jl index ed02afc1e69..bc3e636a401 100644 --- a/src/basic_recipes/contours.jl +++ b/src/basic_recipes/contours.jl @@ -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 @@ -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 diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index 18757dcb7a5..fdf53d0dacf 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -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 @@ -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 @@ -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)