From edec7b34b262cd642820aeef300b3de22e0273ff Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 22 Dec 2015 17:46:31 +0000 Subject: [PATCH] Replaced some uses of AffineTransform::identity with a default-constructed object --- examples/Demo/Source/Demos/GraphicsDemo.cpp | 4 ++-- .../audio plugin host/Source/GraphEditorPanel.cpp | 2 +- .../contexts/juce_GraphicsContext.cpp | 8 +++++++- .../juce_graphics/contexts/juce_GraphicsContext.h | 10 ++++++---- .../juce_LowLevelGraphicsPostScriptRenderer.cpp | 6 +++--- .../geometry/juce_AffineTransform.cpp | 8 +++----- .../juce_graphics/geometry/juce_AffineTransform.h | 4 ++-- modules/juce_graphics/geometry/juce_Path.cpp | 8 ++++---- modules/juce_graphics/geometry/juce_Path.h | 6 +++--- modules/juce_graphics/geometry/juce_PathIterator.h | 2 +- .../juce_graphics/geometry/juce_PathStrokeType.cpp | 2 +- .../juce_graphics/geometry/juce_PathStrokeType.h | 6 +++--- .../juce_graphics/native/juce_RenderingHelpers.h | 14 +++++++------- .../native/juce_mac_CoreGraphicsContext.mm | 2 +- modules/juce_graphics/native/juce_mac_Fonts.mm | 4 ++-- .../placement/juce_RectanglePlacement.cpp | 2 +- .../juce_gui_basics/components/juce_Component.cpp | 2 +- .../juce_gui_basics/components/juce_Component.h | 2 +- modules/juce_gui_basics/drawables/juce_Drawable.h | 2 +- .../drawables/juce_DrawableComposite.cpp | 2 +- .../drawables/juce_DrawableImage.cpp | 2 +- .../drawables/juce_DrawableShape.cpp | 6 +++--- 22 files changed, 55 insertions(+), 49 deletions(-) diff --git a/examples/Demo/Source/Demos/GraphicsDemo.cpp b/examples/Demo/Source/Demos/GraphicsDemo.cpp index b9c935b800..4d1dc5d246 100644 --- a/examples/Demo/Source/Demos/GraphicsDemo.cpp +++ b/examples/Demo/Source/Demos/GraphicsDemo.cpp @@ -208,7 +208,7 @@ public: pathSize * 0.5f, clipPathAngle.getValue()); - g.reduceClipRegion (p, AffineTransform::identity); + g.reduceClipRegion (p, AffineTransform()); } void clipToImage (Graphics& g) @@ -384,7 +384,7 @@ public: PathStrokeType stroke (0.5f + 10.0f * thickness.getValue()); g.setColour (Colours::purple.withAlpha (getAlpha())); - g.strokePath (p, stroke, AffineTransform::identity); + g.strokePath (p, stroke, AffineTransform()); } SlowerBouncingNumber points[2 + 4 * 8], thickness; diff --git a/examples/audio plugin host/Source/GraphEditorPanel.cpp b/examples/audio plugin host/Source/GraphEditorPanel.cpp index 94696a6494..7be63aaa86 100644 --- a/examples/audio plugin host/Source/GraphEditorPanel.cpp +++ b/examples/audio plugin host/Source/GraphEditorPanel.cpp @@ -757,7 +757,7 @@ public: -arrowL, -arrowW, arrowL, 0.0f); - arrow.applyTransform (AffineTransform::identity + arrow.applyTransform (AffineTransform() .rotated (float_Pi * 0.5f - (float) atan2 (x2 - x1, y2 - y1)) .translated ((x1 + x2) * 0.5f, (y1 + y2) * 0.5f)); diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index c6747f7861..2efb3aa991 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -394,9 +394,15 @@ void Graphics::fillAll (Colour colourToUse) const //============================================================================== +void Graphics::fillPath (const Path& path) const +{ + if (! (context.isClipEmpty() || path.isEmpty())) + context.fillPath (path, AffineTransform()); +} + void Graphics::fillPath (const Path& path, const AffineTransform& transform) const { - if ((! context.isClipEmpty()) && ! path.isEmpty()) + if (! (context.isClipEmpty() || path.isEmpty())) context.fillPath (path, transform); } diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index bf54581350..3cfcc8cf62 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -436,13 +436,15 @@ public: //============================================================================== /** Fills a path using the currently selected colour or brush. */ - void fillPath (const Path& path, - const AffineTransform& transform = AffineTransform::identity) const; + void fillPath (const Path& path) const; + + /** Fills a path using the currently selected colour or brush, and adds a transform. */ + void fillPath (const Path& path, const AffineTransform& transform) const; /** Draws a path's outline using the currently selected colour or brush. */ void strokePath (const Path& path, const PathStrokeType& strokeType, - const AffineTransform& transform = AffineTransform::identity) const; + const AffineTransform& transform = AffineTransform()) const; /** Draws a line with an arrowhead at its end. @@ -607,7 +609,7 @@ public: @returns true if the resulting clipping region is non-zero in size @see reduceClipRegion */ - bool reduceClipRegion (const Path& path, const AffineTransform& transform = AffineTransform::identity); + bool reduceClipRegion (const Path& path, const AffineTransform& transform = AffineTransform()); /** Intersects the current clipping region with an image's alpha-channel. diff --git a/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp b/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp index d2d6a1ea4b..3b7c1cf72f 100644 --- a/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp +++ b/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.cpp @@ -355,13 +355,13 @@ void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle& r) { Path p; p.addRectangle (r); - fillPath (p, AffineTransform::identity); + fillPath (p, AffineTransform()); } } void LowLevelGraphicsPostScriptRenderer::fillRectList (const RectangleList& list) { - fillPath (list.toPath(), AffineTransform::identity); + fillPath (list.toPath(), AffineTransform()); } //============================================================================== @@ -510,7 +510,7 @@ void LowLevelGraphicsPostScriptRenderer::drawLine (const Line & line) { Path p; p.addLineSegment (line, 1.0f); - fillPath (p, AffineTransform::identity); + fillPath (p, AffineTransform()); } //============================================================================== diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.cpp b/modules/juce_graphics/geometry/juce_AffineTransform.cpp index 3f17bb9208..a4c1a7e493 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.cpp +++ b/modules/juce_graphics/geometry/juce_AffineTransform.cpp @@ -219,11 +219,9 @@ AffineTransform AffineTransform::inverted() const noexcept return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01, dst10, dst11, -mat02 * dst10 - mat12 * dst11); } - else - { - // singularity.. - return *this; - } + + // singularity.. + return *this; } bool AffineTransform::isSingularity() const noexcept diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.h b/modules/juce_graphics/geometry/juce_AffineTransform.h index f9773f3923..77bb8ab7bb 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.h +++ b/modules/juce_graphics/geometry/juce_AffineTransform.h @@ -71,8 +71,8 @@ public: transformations to. e.g. @code - AffineTransform myTransform = AffineTransform::identity.rotated (.5f) - .scaled (2.0f); + AffineTransform myTransform = AffineTransform().rotated (.5f) + .scaled (2.0f); @endcode */ static const AffineTransform identity; diff --git a/modules/juce_graphics/geometry/juce_Path.cpp b/modules/juce_graphics/geometry/juce_Path.cpp index 0c67dd103c..7eecd66218 100644 --- a/modules/juce_graphics/geometry/juce_Path.cpp +++ b/modules/juce_graphics/geometry/juce_Path.cpp @@ -981,7 +981,7 @@ AffineTransform Path::getTransformToScaleToFit (const float x, const float y, if (preserveProportions) { if (w <= 0 || h <= 0 || boundsRect.isEmpty()) - return AffineTransform::identity; + return AffineTransform(); float newW, newH; const float srcRatio = boundsRect.getHeight() / boundsRect.getWidth(); @@ -1030,7 +1030,7 @@ bool Path::contains (const float x, const float y, const float tolerance) const || y <= bounds.pathYMin || y >= bounds.pathYMax) return false; - PathFlatteningIterator i (*this, AffineTransform::identity, tolerance); + PathFlatteningIterator i (*this, AffineTransform(), tolerance); int positiveCrossings = 0; int negativeCrossings = 0; @@ -1062,7 +1062,7 @@ bool Path::contains (const Point point, const float tolerance) const bool Path::intersectsLine (const Line& line, const float tolerance) { - PathFlatteningIterator i (*this, AffineTransform::identity, tolerance); + PathFlatteningIterator i (*this, AffineTransform(), tolerance); Point intersection; while (i.next()) @@ -1085,7 +1085,7 @@ Line Path::getClippedLine (const Line& line, const bool keepSectio } else { - PathFlatteningIterator i (*this, AffineTransform::identity); + PathFlatteningIterator i (*this, AffineTransform()); Point intersection; while (i.next()) diff --git a/modules/juce_graphics/geometry/juce_Path.h b/modules/juce_graphics/geometry/juce_Path.h index 3b28248f82..215314f2d4 100644 --- a/modules/juce_graphics/geometry/juce_Path.h +++ b/modules/juce_graphics/geometry/juce_Path.h @@ -158,7 +158,7 @@ public: /** Returns the length of the path. @see getPointAlongPath */ - float getLength (const AffineTransform& transform = AffineTransform::identity) const; + float getLength (const AffineTransform& transform = AffineTransform()) const; /** Returns a point that is the specified distance along the path. If the distance is greater than the total length of the path, this will return the @@ -166,7 +166,7 @@ public: @see getLength */ Point getPointAlongPath (float distanceFromStart, - const AffineTransform& transform = AffineTransform::identity) const; + const AffineTransform& transform = AffineTransform()) const; /** Finds the point along the path which is nearest to a given position. This sets pointOnPath to the nearest point, and returns the distance of this point from the start @@ -174,7 +174,7 @@ public: */ float getNearestPoint (const Point targetPoint, Point& pointOnPath, - const AffineTransform& transform = AffineTransform::identity) const; + const AffineTransform& transform = AffineTransform()) const; //============================================================================== /** Removes all lines and curves, resetting the path completely. */ diff --git a/modules/juce_graphics/geometry/juce_PathIterator.h b/modules/juce_graphics/geometry/juce_PathIterator.h index 899988ae0e..6994e28c32 100644 --- a/modules/juce_graphics/geometry/juce_PathIterator.h +++ b/modules/juce_graphics/geometry/juce_PathIterator.h @@ -52,7 +52,7 @@ public: less lines, so can be generated faster, but will be less smooth. */ PathFlatteningIterator (const Path& path, - const AffineTransform& transform = AffineTransform::identity, + const AffineTransform& transform = AffineTransform(), float tolerance = defaultTolerance); /** Destructor. */ diff --git a/modules/juce_graphics/geometry/juce_PathStrokeType.cpp b/modules/juce_graphics/geometry/juce_PathStrokeType.cpp index a762aab4d9..dbb5cb944c 100644 --- a/modules/juce_graphics/geometry/juce_PathStrokeType.cpp +++ b/modules/juce_graphics/geometry/juce_PathStrokeType.cpp @@ -695,7 +695,7 @@ void PathStrokeType::createDashedStroke (Path& destPath, if (isSolid && ! first) newDestPath.lineTo (it.x2, it.y2); - createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy); + createStrokedPath (destPath, newDestPath, AffineTransform(), extraAccuracy); return; } diff --git a/modules/juce_graphics/geometry/juce_PathStrokeType.h b/modules/juce_graphics/geometry/juce_PathStrokeType.h index b390838fcb..2f17bc5bf3 100644 --- a/modules/juce_graphics/geometry/juce_PathStrokeType.h +++ b/modules/juce_graphics/geometry/juce_PathStrokeType.h @@ -104,7 +104,7 @@ public: */ void createStrokedPath (Path& destPath, const Path& sourcePath, - const AffineTransform& transform = AffineTransform::identity, + const AffineTransform& transform = AffineTransform(), float extraAccuracy = 1.0f) const; @@ -136,7 +136,7 @@ public: const Path& sourcePath, const float* dashLengths, int numDashLengths, - const AffineTransform& transform = AffineTransform::identity, + const AffineTransform& transform = AffineTransform(), float extraAccuracy = 1.0f) const; //============================================================================== @@ -163,7 +163,7 @@ public: const Path& sourcePath, float arrowheadStartWidth, float arrowheadStartLength, float arrowheadEndWidth, float arrowheadEndLength, - const AffineTransform& transform = AffineTransform::identity, + const AffineTransform& transform = AffineTransform(), float extraAccuracy = 1.0f) const; //============================================================================== diff --git a/modules/juce_graphics/native/juce_RenderingHelpers.h b/modules/juce_graphics/native/juce_RenderingHelpers.h index d906a12372..1930f11675 100644 --- a/modules/juce_graphics/native/juce_RenderingHelpers.h +++ b/modules/juce_graphics/native/juce_RenderingHelpers.h @@ -2044,7 +2044,7 @@ public: { Path p; p.addRectangle (r); - clipToPath (p, AffineTransform::identity); + clipToPath (p, AffineTransform()); } } @@ -2074,7 +2074,7 @@ public: } else { - clipToPath (r.toPath(), AffineTransform::identity); + clipToPath (r.toPath(), AffineTransform()); } } @@ -2112,7 +2112,7 @@ public: p.applyTransform (transform.complexTransform); p.addRectangle (clip->getClipBounds().toFloat()); p.setUsingNonZeroWinding (false); - clip = clip->clipToPath (p, AffineTransform::identity); + clip = clip->clipToPath (p, AffineTransform()); } } @@ -2205,7 +2205,7 @@ public: { Path p; p.addRectangle (r); - fillPath (p, AffineTransform::identity); + fillPath (p, AffineTransform()); } void fillRect (const Rectangle& r, const bool replaceContents) @@ -2258,7 +2258,7 @@ public: } else { - fillPath (list.toPath(), AffineTransform::identity); + fillPath (list.toPath(), AffineTransform()); } } } @@ -2298,7 +2298,7 @@ public: { Path p; p.addLineSegment (line, 1.0f); - fillPath (p, AffineTransform::identity); + fillPath (p, AffineTransform()); } void drawImage (const Image& sourceImage, const AffineTransform& trans) @@ -2394,7 +2394,7 @@ public: // If our translation doesn't involve any distortion, we can speed it up.. g2.point1.applyTransform (t); g2.point2.applyTransform (t); - t = AffineTransform::identity; + t = AffineTransform(); } shapeToFill->fillAllWithGradient (getThis(), g2, t, isIdentity); diff --git a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm index 4c6c5ad8dd..76ac98f30a 100644 --- a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm +++ b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm @@ -545,7 +545,7 @@ void CoreGraphicsContext::drawLine (const Line& line) { Path p; p.addLineSegment (line, 1.0f); - fillPath (p, AffineTransform::identity); + fillPath (p, AffineTransform()); } } diff --git a/modules/juce_graphics/native/juce_mac_Fonts.mm b/modules/juce_graphics/native/juce_mac_Fonts.mm index 157f40990d..80a4630dcb 100644 --- a/modules/juce_graphics/native/juce_mac_Fonts.mm +++ b/modules/juce_graphics/native/juce_mac_Fonts.mm @@ -571,7 +571,7 @@ public: ascent = ctAscent / ctTotalHeight; unitsToHeightScaleFactor = 1.0f / ctTotalHeight; - pathTransform = AffineTransform::identity.scale (unitsToHeightScaleFactor); + pathTransform = AffineTransform::scale (unitsToHeightScaleFactor); fontHeightToPointsFactor = referenceFontSize / ctTotalHeight; @@ -847,7 +847,7 @@ public: fontHeightToPointsFactor = referenceFontSize / (nsFontAscent + nsFontDescent); - pathTransform = AffineTransform::identity.scale (unitsToHeightScaleFactor); + pathTransform = AffineTransform::scale (unitsToHeightScaleFactor); } } diff --git a/modules/juce_graphics/placement/juce_RectanglePlacement.cpp b/modules/juce_graphics/placement/juce_RectanglePlacement.cpp index c13e505b2a..1cfed08f68 100644 --- a/modules/juce_graphics/placement/juce_RectanglePlacement.cpp +++ b/modules/juce_graphics/placement/juce_RectanglePlacement.cpp @@ -89,7 +89,7 @@ void RectanglePlacement::applyTo (double& x, double& y, double& w, double& h, AffineTransform RectanglePlacement::getTransformToFit (const Rectangle& source, const Rectangle& destination) const noexcept { if (source.isEmpty()) - return AffineTransform::identity; + return AffineTransform(); float newX = destination.getX(); float newY = destination.getY(); diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 925da676fe..1006434423 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1359,7 +1359,7 @@ bool Component::isTransformed() const noexcept AffineTransform Component::getTransform() const { - return affineTransform != nullptr ? *affineTransform : AffineTransform::identity; + return affineTransform != nullptr ? *affineTransform : AffineTransform(); } //============================================================================== diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 9ba0fdcbfd..7100365fdf 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -574,7 +574,7 @@ public: Currently, transforms are not supported for desktop windows, so the transform will be ignored if you put a component on the desktop. - To remove a component's transform, simply pass AffineTransform::identity as the parameter to this method. + To remove a component's transform, simply pass AffineTransform() as the parameter to this method. */ void setTransform (const AffineTransform& transform); diff --git a/modules/juce_gui_basics/drawables/juce_Drawable.h b/modules/juce_gui_basics/drawables/juce_Drawable.h index f297d9c558..88e6936fe4 100644 --- a/modules/juce_gui_basics/drawables/juce_Drawable.h +++ b/modules/juce_gui_basics/drawables/juce_Drawable.h @@ -63,7 +63,7 @@ public: @see drawWithin */ void draw (Graphics& g, float opacity, - const AffineTransform& transform = AffineTransform::identity) const; + const AffineTransform& transform = AffineTransform()) const; /** Renders the Drawable at a given offset within the Graphics context. diff --git a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp index b99c90876b..0c0f6737d1 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableComposite.cpp @@ -148,7 +148,7 @@ void DrawableComposite::recalculateCoordinates (Expression::Scope* scope) content.getX(), content.getBottom(), resolved[2].x, resolved[2].y)); if (t.isSingularity()) - t = AffineTransform::identity; + t = AffineTransform(); setTransform (t); } diff --git a/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp b/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp index 8eb51d26c3..768364352b 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp @@ -111,7 +111,7 @@ void DrawableImage::recalculateCoordinates (Expression::Scope* scope) bl.x, bl.y)); if (t.isSingularity()) - t = AffineTransform::identity; + t = AffineTransform(); setTransform (t); } diff --git a/modules/juce_gui_basics/drawables/juce_DrawableShape.cpp b/modules/juce_gui_basics/drawables/juce_DrawableShape.cpp index 16aad5ebb0..b2a65d70bd 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableShape.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableShape.cpp @@ -178,7 +178,7 @@ void DrawableShape::pathChanged() void DrawableShape::strokeChanged() { strokePath.clear(); - strokeType.createStrokedPath (strokePath, path, AffineTransform::identity, 4.0f); + strokeType.createStrokedPath (strokePath, path, AffineTransform(), 4.0f); setBoundsToEnclose (getDrawableBounds()); repaint(); @@ -224,7 +224,7 @@ DrawableShape::RelativeFillType::RelativeFillType (const FillType& fill_) gradientPoint3 = Point (g.point1.x + g.point2.y - g.point1.y, g.point1.y + g.point1.x - g.point2.x) .transformedBy (fill.transform); - fill.transform = AffineTransform::identity; + fill.transform = AffineTransform(); } } @@ -375,7 +375,7 @@ bool DrawableShape::RelativeFillType::readFrom (const ValueTree& v, ComponentBui if (imageProvider != nullptr) im = imageProvider->getImageForIdentifier (v [FillAndStrokeState::imageId]); - fill.setTiledImage (im, AffineTransform::identity); + fill.setTiledImage (im, AffineTransform()); fill.setOpacity ((float) v.getProperty (FillAndStrokeState::imageOpacity, 1.0f)); return true; }