Skip to content

Conversation

@ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Nov 19, 2025

Description

This is a more low level fix for #5333. The errors in Menu and Textbox, and probably most around round_to_IRect2D as well, happen because text bounding boxes return NaN (or Inf, -Inf) when a string is zero length. And that happens because we prematurely make text positions per character, effectively removing positions for empty strings.

This pr reworks the text position pipeline to remain per-string as long as possible. They are then included in per-string (and plot) bounding boxes, changing them from Inf/NaN bounding boxes to Rect3d(string_pos, Vec3d(0)). With that:

  • raw_glyph_boundingboxes, fast_glyph_boundingboxes and glyph_boundingboxes should be unchanged
  • fast_string_boundingboxes now return Rect3d(Point3d(NaN), Vec3d(0)) instead of Rect3d(Point3d(Inf), Vec3d(-Inf)) for an empty string (These skip positions)
  • string_boundingboxes should now always be finite (if positions are finite). Before empty strings resulted in Rect3d(Point3d(NaN), Vec3d(0))
  • full_boundingbox and boundingboxes now consider empty strings to, i.e. include their position. All empty strings no longer results in Rect3d(Point3d(Inf, Inf, 0), Vec3d(-Inf, -Inf, 0))

Most of these are just plainly improvements imo. The only exception is the last case, where one might argue that an empty string should not be contributing to the bounding box of the plot, since it results in no visualization.

Type of change

Maybe slightly breaking because text.text_positions got deleted, and various other positions in text are now per-string instead of per-char. Though I'd consider those changes internal.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Added an entry in CHANGELOG.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@github-project-automation github-project-automation bot moved this to Work in progress in PR review Nov 19, 2025
@MakieBot
Copy link
Collaborator

MakieBot commented Nov 19, 2025

Benchmark Results

SHA: 36ce0633b0cb8c4edd6b04edce49c13c2598e446

Warning

These results are subject to substantial noise because GitHub's CI runs on shared machines that are not ideally suited for benchmarking.

GLMakie
CairoMakie
WGLMakie

@ffreyer
Copy link
Collaborator Author

ffreyer commented Nov 20, 2025

This fails colorbuffer(ax) because some text data_limits have become finite. Probably xlabel, ylabel, title: (before vs after, see top left and bottom right. The black dot is CairoMakie artifact)
image

function axis_bounds_with_decoration(axis::Axis)
# Filter out the zoomrect + background plot
lims = Makie.data_limits(axis.blockscene.plots, p -> p isa Mesh || p isa Poly)
return Makie.parent_transform(axis.blockscene) * lims
end

@jkrumbiegel Can't we calculate the pixel boundingbox of an Axis with decorations more directly from layoutobservables? Computedbbox with protrusions maybe?

@ffreyer
Copy link
Collaborator Author

ffreyer commented Nov 26, 2025

bbox + protrusions doesn't consider the font size so sometimes ticks can get cut off

@ffreyer ffreyer marked this pull request as ready for review November 26, 2025 21:55
@ffreyer ffreyer moved this from Work in progress to Ready to review in PR review Nov 26, 2025
@ffreyer ffreyer merged commit 23bbce0 into master Dec 2, 2025
@ffreyer ffreyer deleted the ff/text-bbox-fixes branch December 2, 2025 21:42
@github-project-automation github-project-automation bot moved this from Ready to review to Merged in PR review Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Merged

4 participants