diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.cpp b/modules/juce_graphics/geometry/juce_AffineTransform.cpp index 59115696db..6a2574aa89 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.cpp +++ b/modules/juce_graphics/geometry/juce_AffineTransform.cpp @@ -39,8 +39,8 @@ AffineTransform::AffineTransform (const AffineTransform& other) noexcept { } -AffineTransform::AffineTransform (const float m00, const float m01, const float m02, - const float m10, const float m11, const float m12) noexcept +AffineTransform::AffineTransform (float m00, float m01, float m02, + float m10, float m11, float m12) noexcept : mat00 (m00), mat01 (m01), mat02 (m02), mat10 (m10), mat11 (m11), mat12 (m12) { @@ -76,12 +76,12 @@ bool AffineTransform::operator!= (const AffineTransform& other) const noexcept //============================================================================== bool AffineTransform::isIdentity() const noexcept { - return (mat01 == 0.0f) - && (mat02 == 0.0f) - && (mat10 == 0.0f) - && (mat12 == 0.0f) - && (mat00 == 1.0f) - && (mat11 == 1.0f); + return mat01 == 0.0f + && mat02 == 0.0f + && mat10 == 0.0f + && mat12 == 0.0f + && mat00 == 1.0f + && mat11 == 1.0f; } #if JUCE_ALLOW_STATIC_NULL_VARIABLES @@ -91,140 +91,141 @@ const AffineTransform AffineTransform::identity; //============================================================================== AffineTransform AffineTransform::followedBy (const AffineTransform& other) const noexcept { - return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10, - other.mat00 * mat01 + other.mat01 * mat11, - other.mat00 * mat02 + other.mat01 * mat12 + other.mat02, - other.mat10 * mat00 + other.mat11 * mat10, - other.mat10 * mat01 + other.mat11 * mat11, - other.mat10 * mat02 + other.mat11 * mat12 + other.mat12); + return { other.mat00 * mat00 + other.mat01 * mat10, + other.mat00 * mat01 + other.mat01 * mat11, + other.mat00 * mat02 + other.mat01 * mat12 + other.mat02, + other.mat10 * mat00 + other.mat11 * mat10, + other.mat10 * mat01 + other.mat11 * mat11, + other.mat10 * mat02 + other.mat11 * mat12 + other.mat12 }; } -AffineTransform AffineTransform::translated (const float dx, const float dy) const noexcept +AffineTransform AffineTransform::translated (float dx, float dy) const noexcept { - return AffineTransform (mat00, mat01, mat02 + dx, - mat10, mat11, mat12 + dy); + return { mat00, mat01, mat02 + dx, + mat10, mat11, mat12 + dy }; } -AffineTransform AffineTransform::translation (const float dx, const float dy) noexcept +AffineTransform AffineTransform::translation (float dx, float dy) noexcept { - return AffineTransform (1.0f, 0, dx, - 0, 1.0f, dy); + return { 1.0f, 0.0f, dx, + 0.0f, 1.0f, dy }; } -AffineTransform AffineTransform::withAbsoluteTranslation (const float tx, const float ty) const noexcept +AffineTransform AffineTransform::withAbsoluteTranslation (float tx, float ty) const noexcept { - return AffineTransform (mat00, mat01, tx, - mat10, mat11, ty); + return { mat00, mat01, tx, + mat10, mat11, ty }; } -AffineTransform AffineTransform::rotated (const float rad) const noexcept +AffineTransform AffineTransform::rotated (float rad) const noexcept { - const float cosRad = std::cos (rad); - const float sinRad = std::sin (rad); - - return AffineTransform (cosRad * mat00 + -sinRad * mat10, - cosRad * mat01 + -sinRad * mat11, - cosRad * mat02 + -sinRad * mat12, - sinRad * mat00 + cosRad * mat10, - sinRad * mat01 + cosRad * mat11, - sinRad * mat02 + cosRad * mat12); + auto cosRad = std::cos (rad); + auto sinRad = std::sin (rad); + + return { cosRad * mat00 - sinRad * mat10, + cosRad * mat01 - sinRad * mat11, + cosRad * mat02 - sinRad * mat12, + sinRad * mat00 + cosRad * mat10, + sinRad * mat01 + cosRad * mat11, + sinRad * mat02 + cosRad * mat12 }; } -AffineTransform AffineTransform::rotation (const float rad) noexcept +AffineTransform AffineTransform::rotation (float rad) noexcept { - const float cosRad = std::cos (rad); - const float sinRad = std::sin (rad); + auto cosRad = std::cos (rad); + auto sinRad = std::sin (rad); - return AffineTransform (cosRad, -sinRad, 0, - sinRad, cosRad, 0); + return { cosRad, -sinRad, 0, + sinRad, cosRad, 0 }; } -AffineTransform AffineTransform::rotation (const float rad, const float pivotX, const float pivotY) noexcept +AffineTransform AffineTransform::rotation (float rad, float pivotX, float pivotY) noexcept { - const float cosRad = std::cos (rad); - const float sinRad = std::sin (rad); + auto cosRad = std::cos (rad); + auto sinRad = std::sin (rad); - return AffineTransform (cosRad, -sinRad, -cosRad * pivotX + sinRad * pivotY + pivotX, - sinRad, cosRad, -sinRad * pivotX + -cosRad * pivotY + pivotY); + return { cosRad, -sinRad, -cosRad * pivotX + sinRad * pivotY + pivotX, + sinRad, cosRad, -sinRad * pivotX + -cosRad * pivotY + pivotY }; } -AffineTransform AffineTransform::rotated (const float angle, const float pivotX, const float pivotY) const noexcept +AffineTransform AffineTransform::rotated (float angle, float pivotX, float pivotY) const noexcept { return followedBy (rotation (angle, pivotX, pivotY)); } -AffineTransform AffineTransform::scaled (const float factorX, const float factorY) const noexcept +AffineTransform AffineTransform::scaled (float factorX, float factorY) const noexcept { - return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02, - factorY * mat10, factorY * mat11, factorY * mat12); + return { factorX * mat00, factorX * mat01, factorX * mat02, + factorY * mat10, factorY * mat11, factorY * mat12 }; } -AffineTransform AffineTransform::scaled (const float factor) const noexcept +AffineTransform AffineTransform::scaled (float factor) const noexcept { - return AffineTransform (factor * mat00, factor * mat01, factor * mat02, - factor * mat10, factor * mat11, factor * mat12); + return { factor * mat00, factor * mat01, factor * mat02, + factor * mat10, factor * mat11, factor * mat12 }; } -AffineTransform AffineTransform::scale (const float factorX, const float factorY) noexcept +AffineTransform AffineTransform::scale (float factorX, float factorY) noexcept { - return AffineTransform (factorX, 0, 0, 0, factorY, 0); + return { factorX, 0, 0, 0, factorY, 0 }; } -AffineTransform AffineTransform::scale (const float factor) noexcept +AffineTransform AffineTransform::scale (float factor) noexcept { - return AffineTransform (factor, 0, 0, 0, factor, 0); + return { factor, 0, 0, 0, factor, 0 }; } -AffineTransform AffineTransform::scaled (const float factorX, const float factorY, - const float pivotX, const float pivotY) const noexcept +AffineTransform AffineTransform::scaled (float factorX, float factorY, + float pivotX, float pivotY) const noexcept { - return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02 + pivotX * (1.0f - factorX), - factorY * mat10, factorY * mat11, factorY * mat12 + pivotY * (1.0f - factorY)); + return { factorX * mat00, factorX * mat01, factorX * mat02 + pivotX * (1.0f - factorX), + factorY * mat10, factorY * mat11, factorY * mat12 + pivotY * (1.0f - factorY) }; } -AffineTransform AffineTransform::scale (const float factorX, const float factorY, - const float pivotX, const float pivotY) noexcept +AffineTransform AffineTransform::scale (float factorX, float factorY, + float pivotX, float pivotY) noexcept { - return AffineTransform (factorX, 0, pivotX * (1.0f - factorX), - 0, factorY, pivotY * (1.0f - factorY)); + return { factorX, 0, pivotX * (1.0f - factorX), + 0, factorY, pivotY * (1.0f - factorY) }; } AffineTransform AffineTransform::shear (float shearX, float shearY) noexcept { - return AffineTransform (1.0f, shearX, 0, - shearY, 1.0f, 0); + return { 1.0f, shearX, 0, + shearY, 1.0f, 0 }; } -AffineTransform AffineTransform::sheared (const float shearX, const float shearY) const noexcept +AffineTransform AffineTransform::sheared (float shearX, float shearY) const noexcept { - return AffineTransform (mat00 + shearX * mat10, - mat01 + shearX * mat11, - mat02 + shearX * mat12, - mat10 + shearY * mat00, - mat11 + shearY * mat01, - mat12 + shearY * mat02); + return { mat00 + shearX * mat10, + mat01 + shearX * mat11, + mat02 + shearX * mat12, + mat10 + shearY * mat00, + mat11 + shearY * mat01, + mat12 + shearY * mat02 }; } -AffineTransform AffineTransform::verticalFlip (const float height) noexcept +AffineTransform AffineTransform::verticalFlip (float height) noexcept { - return AffineTransform (1.0f, 0, 0, 0, -1.0f, height); + return { 1.0f, 0.0f, 0.0f, + 0.0f, -1.0f, height }; } AffineTransform AffineTransform::inverted() const noexcept { double determinant = (mat00 * mat11 - mat10 * mat01); - if (determinant != 0.0) + if (determinant != 0) { determinant = 1.0 / determinant; - const float dst00 = (float) ( mat11 * determinant); - const float dst10 = (float) (-mat10 * determinant); - const float dst01 = (float) (-mat01 * determinant); - const float dst11 = (float) ( mat00 * determinant); + auto dst00 = (float) ( mat11 * determinant); + auto dst10 = (float) (-mat10 * determinant); + auto dst01 = (float) (-mat01 * determinant); + auto dst11 = (float) ( mat00 * determinant); - return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01, - dst10, dst11, -mat02 * dst10 - mat12 * dst11); + return { dst00, dst01, -mat02 * dst00 - mat12 * dst01, + dst10, dst11, -mat02 * dst10 - mat12 * dst11 }; } // singularity.. @@ -236,17 +237,17 @@ bool AffineTransform::isSingularity() const noexcept return (mat00 * mat11 - mat10 * mat01) == 0.0f; } -AffineTransform AffineTransform::fromTargetPoints (const float x00, const float y00, - const float x10, const float y10, - const float x01, const float y01) noexcept +AffineTransform AffineTransform::fromTargetPoints (float x00, float y00, + float x10, float y10, + float x01, float y01) noexcept { - return AffineTransform (x10 - x00, x01 - x00, x00, - y10 - y00, y01 - y00, y00); + return { x10 - x00, x01 - x00, x00, + y10 - y00, y01 - y00, y00 }; } -AffineTransform AffineTransform::fromTargetPoints (const float sx1, const float sy1, const float tx1, const float ty1, - const float sx2, const float sy2, const float tx2, const float ty2, - const float sx3, const float sy3, const float tx3, const float ty3) noexcept +AffineTransform AffineTransform::fromTargetPoints (float sx1, float sy1, float tx1, float ty1, + float sx2, float sy2, float tx2, float ty2, + float sx3, float sy3, float tx3, float ty3) noexcept { return fromTargetPoints (sx1, sy1, sx2, sy2, sx3, sy3) .inverted() @@ -255,10 +256,10 @@ AffineTransform AffineTransform::fromTargetPoints (const float sx1, const float bool AffineTransform::isOnlyTranslation() const noexcept { - return (mat01 == 0.0f) - && (mat10 == 0.0f) - && (mat00 == 1.0f) - && (mat11 == 1.0f); + return mat01 == 0.0f + && mat10 == 0.0f + && mat00 == 1.0f + && mat11 == 1.0f; } float AffineTransform::getScaleFactor() const noexcept diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.h b/modules/juce_graphics/geometry/juce_AffineTransform.h index 40811b0a20..d50a103d03 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.h +++ b/modules/juce_graphics/geometry/juce_AffineTransform.h @@ -235,6 +235,17 @@ public: float sourceX2, float sourceY2, float targetX2, float targetY2, float sourceX3, float sourceY3, float targetX3, float targetY3) noexcept; + /** Returns the transform that will map three specified points onto three target points. */ + template + static AffineTransform fromTargetPoints (PointType source1, PointType target1, + PointType source2, PointType target2, + PointType source3, PointType target3) noexcept + { + return fromTargetPoints (source1.x, source1.y, target1.x, target1.y, + source2.x, source2.y, target2.x, target2.y, + source3.x, source3.y, target3.x, target3.y); + } + //============================================================================== /** Returns the result of concatenating another transformation after this one. */ AffineTransform followedBy (const AffineTransform& other) const noexcept; diff --git a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp index 25ebc578fc..56a3062ebe 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLGraphicsContext.cpp @@ -510,9 +510,9 @@ struct ShaderPrograms : public ReferenceCountedObject void setMatrix (Point p1, Point p2, Point p3) { - auto t = AffineTransform::fromTargetPoints (p1.x, p1.y, 0.0f, 0.0f, - p2.x, p2.y, 1.0f, 0.0f, - p3.x, p3.y, 0.0f, 1.0f); + auto t = AffineTransform::fromTargetPoints (p1, Point(), + p2, Point (1.0f, 0.0f), + p3, Point (0.0f, 1.0f)); const GLfloat m[] = { t.mat00, t.mat01, t.mat02, t.mat10, t.mat11, t.mat12 }; matrix.set (m, 6); }