From bd2aea967644a650e1265b0bd06791374cb36bb8 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 8 May 2024 19:49:57 +0100 Subject: [PATCH] AffineTransform: Add isOnlyTranslationOrScale() helper --- modules/juce_graphics/geometry/juce_AffineTransform.cpp | 5 +++++ modules/juce_graphics/geometry/juce_AffineTransform.h | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.cpp b/modules/juce_graphics/geometry/juce_AffineTransform.cpp index d2420325db..af0c1f7748 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.cpp +++ b/modules/juce_graphics/geometry/juce_AffineTransform.cpp @@ -239,6 +239,11 @@ bool AffineTransform::isOnlyTranslation() const noexcept && exactlyEqual (mat11, 1.0f); } +bool AffineTransform::isOnlyTranslationOrScale() const noexcept +{ + return exactlyEqual (mat01, 0.0f) && exactlyEqual (mat10, 0.0f); +} + float AffineTransform::getDeterminant() const noexcept { return (mat00 * mat11) - (mat01 * mat10); diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.h b/modules/juce_graphics/geometry/juce_AffineTransform.h index f6e42da45b..5cf724797c 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.h +++ b/modules/juce_graphics/geometry/juce_AffineTransform.h @@ -258,10 +258,12 @@ public: /** Returns true if this transform maps to a singularity - i.e. if it has no inverse. */ bool isSingularity() const noexcept; - /** Returns true if the transform only translates, and doesn't scale or rotate the - points. */ + /** Returns true if the transform only translates, and doesn't scale or rotate the points. */ bool isOnlyTranslation() const noexcept; + /** Returns true if the transform only translates and/or scales. */ + bool isOnlyTranslationOrScale() const noexcept; + /** If this transform is only a translation, this returns the X offset. @see isOnlyTranslation */