From 2867f9913811f7aa364cc197e145c9240fa06744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 12 Oct 2023 00:03:39 +0200 Subject: [PATCH] Text: use Math::join() on ranges instead of custom code. It does the same in a shorter and less error-prone way. --- src/Magnum/Text/AbstractFont.cpp | 8 +++----- src/Magnum/Text/Renderer.cpp | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Magnum/Text/AbstractFont.cpp b/src/Magnum/Text/AbstractFont.cpp index d96f3ac15..f8f66975e 100644 --- a/src/Magnum/Text/AbstractFont.cpp +++ b/src/Magnum/Text/AbstractFont.cpp @@ -340,11 +340,9 @@ Containers::Pair AbstractLayouter::renderGlyph(const UnsignedI /* Move the quad to cursor */ const Range2D quadPosition = quadPositionTextureCoordinatesAdvance.first().translated(cursorPosition); - /* Extend rectangle with current quad bounds. If zero size, replace it. */ - if(!rectangle.size().isZero()) { - rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), quadPosition.bottomLeft()); - rectangle.topRight() = Math::max(rectangle.topRight(), quadPosition.topRight()); - } else rectangle = quadPosition; + /* Extend the rectangle with current quad bounds. If the original is zero + size, it gets replaced. */ + rectangle = Math::join(rectangle, quadPosition); /* Advance cursor position to next character */ cursorPosition += quadPositionTextureCoordinatesAdvance.third(); diff --git a/src/Magnum/Text/Renderer.cpp b/src/Magnum/Text/Renderer.cpp index f3b736d7e..f36cfc8a7 100644 --- a/src/Magnum/Text/Renderer.cpp +++ b/src/Magnum/Text/Renderer.cpp @@ -150,11 +150,9 @@ std::tuple, Range2D> renderVerticesInternal(AbstractFont& fo for(auto it = vertices.begin()+lastLineLastVertex; it != vertices.end(); ++it) it->position.x() += alignmentOffsetX; - /* Add final line bounds to total bounds, similarly to AbstractFont::renderGlyph() */ - if(!rectangle.size().isZero()) { - rectangle.bottomLeft() = Math::min(rectangle.bottomLeft(), lineRectangle.bottomLeft()); - rectangle.topRight() = Math::max(rectangle.topRight(), lineRectangle.topRight()); - } else rectangle = lineRectangle; + /* Extend the rectangle with final line bounds, similarly to + AbstractFont::renderGlyph() */ + rectangle = Math::join(rectangle, lineRectangle); /* Move to next line */ } while(prevPos = pos+1,