mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Made a few minor tweaks to reduce the number of pedantic -Wfloat-equals warnings
This commit is contained in:
parent
6bb3d9b1db
commit
bf94ab0e4c
26 changed files with 411 additions and 432 deletions
|
|
@ -71,10 +71,10 @@ bool AffineTransform::operator!= (const AffineTransform& other) const noexcept
|
|||
//==============================================================================
|
||||
bool AffineTransform::isIdentity() const noexcept
|
||||
{
|
||||
return (mat01 == 0)
|
||||
&& (mat02 == 0)
|
||||
&& (mat10 == 0)
|
||||
&& (mat12 == 0)
|
||||
return (mat01 == 0.0f)
|
||||
&& (mat02 == 0.0f)
|
||||
&& (mat10 == 0.0f)
|
||||
&& (mat12 == 0.0f)
|
||||
&& (mat00 == 1.0f)
|
||||
&& (mat11 == 1.0f);
|
||||
}
|
||||
|
|
@ -228,7 +228,7 @@ AffineTransform AffineTransform::inverted() const noexcept
|
|||
|
||||
bool AffineTransform::isSingularity() const noexcept
|
||||
{
|
||||
return (mat00 * mat11 - mat10 * mat01) == 0;
|
||||
return (mat00 * mat11 - mat10 * mat01) == 0.0f;
|
||||
}
|
||||
|
||||
AffineTransform AffineTransform::fromTargetPoints (const float x00, const float y00,
|
||||
|
|
@ -250,8 +250,8 @@ AffineTransform AffineTransform::fromTargetPoints (const float sx1, const float
|
|||
|
||||
bool AffineTransform::isOnlyTranslation() const noexcept
|
||||
{
|
||||
return (mat01 == 0)
|
||||
&& (mat10 == 0)
|
||||
return (mat01 == 0.0f)
|
||||
&& (mat10 == 0.0f)
|
||||
&& (mat00 == 1.0f)
|
||||
&& (mat11 == 1.0f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace PathHelpers
|
|||
{
|
||||
t = t.findEndOfWhitespace();
|
||||
|
||||
String::CharPointerType start (t);
|
||||
auto start = t;
|
||||
size_t numChars = 0;
|
||||
|
||||
while (! (t.isEmpty() || t.isWhitespace()))
|
||||
|
|
@ -44,7 +44,7 @@ namespace PathHelpers
|
|||
++numChars;
|
||||
}
|
||||
|
||||
return String (start, numChars);
|
||||
return { start, numChars };
|
||||
}
|
||||
|
||||
inline double lengthOf (float x1, float y1, float x2, float y2) noexcept
|
||||
|
|
@ -63,15 +63,19 @@ const float Path::closeSubPathMarker = 100005.0f;
|
|||
const float Path::defaultToleranceForTesting = 1.0f;
|
||||
const float Path::defaultToleranceForMeasurement = 0.6f;
|
||||
|
||||
static inline bool isMarker (float value, float marker) noexcept
|
||||
{
|
||||
return value == marker;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
Path::PathBounds::PathBounds() noexcept
|
||||
: pathXMin (0), pathXMax (0), pathYMin (0), pathYMax (0)
|
||||
{
|
||||
}
|
||||
|
||||
Rectangle<float> Path::PathBounds::getRectangle() const noexcept
|
||||
{
|
||||
return Rectangle<float> (pathXMin, pathYMin, pathXMax - pathXMin, pathYMax - pathYMin);
|
||||
return { pathXMin, pathYMin, pathXMax - pathXMin, pathYMax - pathYMin };
|
||||
}
|
||||
|
||||
void Path::PathBounds::reset() noexcept
|
||||
|
|
@ -120,7 +124,6 @@ void Path::PathBounds::extend (const float x1, const float y1, const float x2, c
|
|||
|
||||
//==============================================================================
|
||||
Path::Path()
|
||||
: numElements (0), useNonZeroWinding (true)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -214,8 +217,7 @@ void Path::setUsingNonZeroWinding (const bool isNonZero) noexcept
|
|||
useNonZeroWinding = isNonZero;
|
||||
}
|
||||
|
||||
void Path::scaleToFit (const float x, const float y, const float w, const float h,
|
||||
const bool preserveProportions) noexcept
|
||||
void Path::scaleToFit (float x, float y, float w, float h, bool preserveProportions) noexcept
|
||||
{
|
||||
applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
|
||||
}
|
||||
|
|
@ -227,15 +229,15 @@ bool Path::isEmpty() const noexcept
|
|||
|
||||
while (i < numElements)
|
||||
{
|
||||
const float type = data.elements [i++];
|
||||
auto type = data.elements[i++];
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
i += 2;
|
||||
}
|
||||
else if (type == lineMarker
|
||||
|| type == quadMarker
|
||||
|| type == cubicMarker)
|
||||
else if (isMarker (type, lineMarker)
|
||||
|| isMarker (type, quadMarker)
|
||||
|| isMarker (type, cubicMarker))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -271,9 +273,9 @@ void Path::startNewSubPath (const float x, const float y)
|
|||
|
||||
preallocateSpace (3);
|
||||
|
||||
data.elements [numElements++] = moveMarker;
|
||||
data.elements [numElements++] = x;
|
||||
data.elements [numElements++] = y;
|
||||
data.elements[numElements++] = moveMarker;
|
||||
data.elements[numElements++] = x;
|
||||
data.elements[numElements++] = y;
|
||||
}
|
||||
|
||||
void Path::startNewSubPath (const Point<float> start)
|
||||
|
|
@ -290,9 +292,9 @@ void Path::lineTo (const float x, const float y)
|
|||
|
||||
preallocateSpace (3);
|
||||
|
||||
data.elements [numElements++] = lineMarker;
|
||||
data.elements [numElements++] = x;
|
||||
data.elements [numElements++] = y;
|
||||
data.elements[numElements++] = lineMarker;
|
||||
data.elements[numElements++] = x;
|
||||
data.elements[numElements++] = y;
|
||||
|
||||
bounds.extend (x, y);
|
||||
}
|
||||
|
|
@ -313,11 +315,11 @@ void Path::quadraticTo (const float x1, const float y1,
|
|||
|
||||
preallocateSpace (5);
|
||||
|
||||
data.elements [numElements++] = quadMarker;
|
||||
data.elements [numElements++] = x1;
|
||||
data.elements [numElements++] = y1;
|
||||
data.elements [numElements++] = x2;
|
||||
data.elements [numElements++] = y2;
|
||||
data.elements[numElements++] = quadMarker;
|
||||
data.elements[numElements++] = x1;
|
||||
data.elements[numElements++] = y1;
|
||||
data.elements[numElements++] = x2;
|
||||
data.elements[numElements++] = y2;
|
||||
|
||||
bounds.extend (x1, y1, x2, y2);
|
||||
}
|
||||
|
|
@ -342,13 +344,13 @@ void Path::cubicTo (const float x1, const float y1,
|
|||
|
||||
preallocateSpace (7);
|
||||
|
||||
data.elements [numElements++] = cubicMarker;
|
||||
data.elements [numElements++] = x1;
|
||||
data.elements [numElements++] = y1;
|
||||
data.elements [numElements++] = x2;
|
||||
data.elements [numElements++] = y2;
|
||||
data.elements [numElements++] = x3;
|
||||
data.elements [numElements++] = y3;
|
||||
data.elements[numElements++] = cubicMarker;
|
||||
data.elements[numElements++] = x1;
|
||||
data.elements[numElements++] = y1;
|
||||
data.elements[numElements++] = x2;
|
||||
data.elements[numElements++] = y2;
|
||||
data.elements[numElements++] = x3;
|
||||
data.elements[numElements++] = y3;
|
||||
|
||||
bounds.extend (x1, y1, x2, y2);
|
||||
bounds.extend (x3, y3);
|
||||
|
|
@ -365,11 +367,10 @@ void Path::cubicTo (const Point<float> controlPoint1,
|
|||
|
||||
void Path::closeSubPath()
|
||||
{
|
||||
if (numElements > 0
|
||||
&& data.elements [numElements - 1] != closeSubPathMarker)
|
||||
if (numElements > 0 && ! isMarker (data.elements[numElements - 1], closeSubPathMarker))
|
||||
{
|
||||
preallocateSpace (1);
|
||||
data.elements [numElements++] = closeSubPathMarker;
|
||||
data.elements[numElements++] = closeSubPathMarker;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -377,11 +378,11 @@ Point<float> Path::getCurrentPosition() const
|
|||
{
|
||||
int i = (int) numElements - 1;
|
||||
|
||||
if (i > 0 && data.elements[i] == closeSubPathMarker)
|
||||
if (i > 0 && isMarker (data.elements[i], closeSubPathMarker))
|
||||
{
|
||||
while (i >= 0)
|
||||
{
|
||||
if (data.elements[i] == moveMarker)
|
||||
if (isMarker (data.elements[i], moveMarker))
|
||||
{
|
||||
i += 2;
|
||||
break;
|
||||
|
|
@ -392,9 +393,9 @@ Point<float> Path::getCurrentPosition() const
|
|||
}
|
||||
|
||||
if (i > 0)
|
||||
return Point<float> (data.elements [i - 1], data.elements [i]);
|
||||
return { data.elements[i - 1], data.elements[i] };
|
||||
|
||||
return Point<float>();
|
||||
return {};
|
||||
}
|
||||
|
||||
void Path::addRectangle (const float x, const float y,
|
||||
|
|
@ -422,19 +423,19 @@ void Path::addRectangle (const float x, const float y,
|
|||
bounds.pathYMax = jmax (bounds.pathYMax, y2);
|
||||
}
|
||||
|
||||
data.elements [numElements++] = moveMarker;
|
||||
data.elements [numElements++] = x1;
|
||||
data.elements [numElements++] = y2;
|
||||
data.elements [numElements++] = lineMarker;
|
||||
data.elements [numElements++] = x1;
|
||||
data.elements [numElements++] = y1;
|
||||
data.elements [numElements++] = lineMarker;
|
||||
data.elements [numElements++] = x2;
|
||||
data.elements [numElements++] = y1;
|
||||
data.elements [numElements++] = lineMarker;
|
||||
data.elements [numElements++] = x2;
|
||||
data.elements [numElements++] = y2;
|
||||
data.elements [numElements++] = closeSubPathMarker;
|
||||
data.elements[numElements++] = moveMarker;
|
||||
data.elements[numElements++] = x1;
|
||||
data.elements[numElements++] = y2;
|
||||
data.elements[numElements++] = lineMarker;
|
||||
data.elements[numElements++] = x1;
|
||||
data.elements[numElements++] = y1;
|
||||
data.elements[numElements++] = lineMarker;
|
||||
data.elements[numElements++] = x2;
|
||||
data.elements[numElements++] = y1;
|
||||
data.elements[numElements++] = lineMarker;
|
||||
data.elements[numElements++] = x2;
|
||||
data.elements[numElements++] = y2;
|
||||
data.elements[numElements++] = closeSubPathMarker;
|
||||
}
|
||||
|
||||
void Path::addRoundedRectangle (float x, float y, float w, float h, float csx, float csy)
|
||||
|
|
@ -449,10 +450,10 @@ void Path::addRoundedRectangle (const float x, const float y, const float w, con
|
|||
{
|
||||
csx = jmin (csx, w * 0.5f);
|
||||
csy = jmin (csy, h * 0.5f);
|
||||
const float cs45x = csx * 0.45f;
|
||||
const float cs45y = csy * 0.45f;
|
||||
const float x2 = x + w;
|
||||
const float y2 = y + h;
|
||||
auto cs45x = csx * 0.45f;
|
||||
auto cs45y = csy * 0.45f;
|
||||
auto x2 = x + w;
|
||||
auto y2 = y + h;
|
||||
|
||||
if (curveTopLeft)
|
||||
{
|
||||
|
|
@ -538,12 +539,12 @@ void Path::addEllipse (float x, float y, float w, float h)
|
|||
|
||||
void Path::addEllipse (Rectangle<float> area)
|
||||
{
|
||||
const float hw = area.getWidth() * 0.5f;
|
||||
const float hw55 = hw * 0.55f;
|
||||
const float hh = area.getHeight() * 0.5f;
|
||||
const float hh55 = hh * 0.55f;
|
||||
const float cx = area.getX() + hw;
|
||||
const float cy = area.getY() + hh;
|
||||
auto hw = area.getWidth() * 0.5f;
|
||||
auto hw55 = hw * 0.55f;
|
||||
auto hh = area.getHeight() * 0.5f;
|
||||
auto hh55 = hh * 0.55f;
|
||||
auto cx = area.getX() + hw;
|
||||
auto cy = area.getY() + hh;
|
||||
|
||||
startNewSubPath (cx, cy - hh);
|
||||
cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh55, cx + hw, cy);
|
||||
|
|
@ -559,8 +560,8 @@ void Path::addArc (const float x, const float y,
|
|||
const float toRadians,
|
||||
const bool startAsNewSubPath)
|
||||
{
|
||||
const float radiusX = w / 2.0f;
|
||||
const float radiusY = h / 2.0f;
|
||||
auto radiusX = w / 2.0f;
|
||||
auto radiusY = h / 2.0f;
|
||||
|
||||
addCentredArc (x + radiusX,
|
||||
y + radiusY,
|
||||
|
|
@ -580,8 +581,8 @@ void Path::addCentredArc (const float centreX, const float centreY,
|
|||
if (radiusX > 0.0f && radiusY > 0.0f)
|
||||
{
|
||||
const Point<float> centre (centreX, centreY);
|
||||
const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
|
||||
float angle = fromRadians;
|
||||
auto rotation = AffineTransform::rotation (rotationOfEllipse, centreX, centreY);
|
||||
auto angle = fromRadians;
|
||||
|
||||
if (startAsNewSubPath)
|
||||
startNewSubPath (centre.getPointOnCircumference (radiusX, radiusY, angle).transformedBy (rotation));
|
||||
|
|
@ -674,7 +675,7 @@ void Path::addPieSegment (Rectangle<float> segmentBounds,
|
|||
//==============================================================================
|
||||
void Path::addLineSegment (const Line<float>& line, float lineThickness)
|
||||
{
|
||||
const Line<float> reversed (line.reversed());
|
||||
auto reversed = line.reversed();
|
||||
lineThickness *= 0.5f;
|
||||
|
||||
startNewSubPath (line.getPointAlongLine (0, lineThickness));
|
||||
|
|
@ -687,7 +688,7 @@ void Path::addLineSegment (const Line<float>& line, float lineThickness)
|
|||
void Path::addArrow (const Line<float>& line, float lineThickness,
|
||||
float arrowheadWidth, float arrowheadLength)
|
||||
{
|
||||
const Line<float> reversed (line.reversed());
|
||||
auto reversed = line.reversed();
|
||||
lineThickness *= 0.5f;
|
||||
arrowheadWidth *= 0.5f;
|
||||
arrowheadLength = jmin (arrowheadLength, 0.8f * line.getLength());
|
||||
|
|
@ -709,12 +710,12 @@ void Path::addPolygon (const Point<float> centre, const int numberOfSides,
|
|||
|
||||
if (numberOfSides > 1)
|
||||
{
|
||||
const float angleBetweenPoints = float_Pi * 2.0f / numberOfSides;
|
||||
auto angleBetweenPoints = float_Pi * 2.0f / numberOfSides;
|
||||
|
||||
for (int i = 0; i < numberOfSides; ++i)
|
||||
{
|
||||
const float angle = startAngle + i * angleBetweenPoints;
|
||||
const Point<float> p (centre.getPointOnCircumference (radius, angle));
|
||||
auto angle = startAngle + i * angleBetweenPoints;
|
||||
auto p = centre.getPointOnCircumference (radius, angle);
|
||||
|
||||
if (i == 0)
|
||||
startNewSubPath (p);
|
||||
|
|
@ -733,12 +734,12 @@ void Path::addStar (const Point<float> centre, const int numberOfPoints,
|
|||
|
||||
if (numberOfPoints > 1)
|
||||
{
|
||||
const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
|
||||
auto angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
|
||||
|
||||
for (int i = 0; i < numberOfPoints; ++i)
|
||||
{
|
||||
const float angle = startAngle + i * angleBetweenPoints;
|
||||
const Point<float> p (centre.getPointOnCircumference (outerRadius, angle));
|
||||
auto angle = startAngle + i * angleBetweenPoints;
|
||||
auto p = centre.getPointOnCircumference (outerRadius, angle);
|
||||
|
||||
if (i == 0)
|
||||
startNewSubPath (p);
|
||||
|
|
@ -758,12 +759,12 @@ void Path::addBubble (const Rectangle<float>& bodyArea,
|
|||
const float cornerSize,
|
||||
const float arrowBaseWidth)
|
||||
{
|
||||
const float halfW = bodyArea.getWidth() / 2.0f;
|
||||
const float halfH = bodyArea.getHeight() / 2.0f;
|
||||
const float cornerSizeW = jmin (cornerSize, halfW);
|
||||
const float cornerSizeH = jmin (cornerSize, halfH);
|
||||
const float cornerSizeW2 = 2.0f * cornerSizeW;
|
||||
const float cornerSizeH2 = 2.0f * cornerSizeH;
|
||||
auto halfW = bodyArea.getWidth() / 2.0f;
|
||||
auto halfH = bodyArea.getHeight() / 2.0f;
|
||||
auto cornerSizeW = jmin (cornerSize, halfW);
|
||||
auto cornerSizeH = jmin (cornerSize, halfH);
|
||||
auto cornerSizeW2 = 2.0f * cornerSizeW;
|
||||
auto cornerSizeH2 = 2.0f * cornerSizeH;
|
||||
|
||||
startNewSubPath (bodyArea.getX() + cornerSizeW, bodyArea.getY());
|
||||
|
||||
|
|
@ -820,33 +821,33 @@ void Path::addBubble (const Rectangle<float>& bodyArea,
|
|||
void Path::addPath (const Path& other)
|
||||
{
|
||||
size_t i = 0;
|
||||
const float* const d = other.data.elements;
|
||||
const float* d = other.data.elements;
|
||||
|
||||
while (i < other.numElements)
|
||||
{
|
||||
const float type = d[i++];
|
||||
auto type = d[i++];
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
startNewSubPath (d[i], d[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
else if (type == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
lineTo (d[i], d[i + 1]);
|
||||
i += 2;
|
||||
}
|
||||
else if (type == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
quadraticTo (d[i], d[i + 1], d[i + 2], d[i + 3]);
|
||||
i += 4;
|
||||
}
|
||||
else if (type == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
cubicTo (d[i], d[i + 1], d[i + 2], d[i + 3], d[i + 4], d[i + 5]);
|
||||
i += 6;
|
||||
}
|
||||
else if (type == closeSubPathMarker)
|
||||
else if (isMarker (type, closeSubPathMarker))
|
||||
{
|
||||
closeSubPath();
|
||||
}
|
||||
|
|
@ -862,44 +863,44 @@ void Path::addPath (const Path& other,
|
|||
const AffineTransform& transformToApply)
|
||||
{
|
||||
size_t i = 0;
|
||||
const float* const d = other.data.elements;
|
||||
const float* d = other.data.elements;
|
||||
|
||||
while (i < other.numElements)
|
||||
{
|
||||
const float type = d [i++];
|
||||
auto type = d[i++];
|
||||
|
||||
if (type == closeSubPathMarker)
|
||||
if (isMarker (type, closeSubPathMarker))
|
||||
{
|
||||
closeSubPath();
|
||||
}
|
||||
else
|
||||
{
|
||||
float x = d[i++];
|
||||
float y = d[i++];
|
||||
auto x = d[i++];
|
||||
auto y = d[i++];
|
||||
transformToApply.transformPoint (x, y);
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
startNewSubPath (x, y);
|
||||
}
|
||||
else if (type == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
lineTo (x, y);
|
||||
}
|
||||
else if (type == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
float x2 = d [i++];
|
||||
float y2 = d [i++];
|
||||
auto x2 = d[i++];
|
||||
auto y2 = d[i++];
|
||||
transformToApply.transformPoint (x2, y2);
|
||||
|
||||
quadraticTo (x, y, x2, y2);
|
||||
}
|
||||
else if (type == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
float x2 = d [i++];
|
||||
float y2 = d [i++];
|
||||
float x3 = d [i++];
|
||||
float y3 = d [i++];
|
||||
auto x2 = d[i++];
|
||||
auto y2 = d[i++];
|
||||
auto x3 = d[i++];
|
||||
auto y3 = d[i++];
|
||||
transformToApply.transformPoints (x2, y2, x3, y3);
|
||||
|
||||
cubicTo (x, y, x2, y2, x3, y3);
|
||||
|
|
@ -919,13 +920,13 @@ void Path::applyTransform (const AffineTransform& transform) noexcept
|
|||
bounds.reset();
|
||||
bool firstPoint = true;
|
||||
float* d = data.elements;
|
||||
float* const end = d + numElements;
|
||||
auto* end = d + numElements;
|
||||
|
||||
while (d < end)
|
||||
{
|
||||
const float type = *d++;
|
||||
auto type = *d++;
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
transform.transformPoint (d[0], d[1]);
|
||||
|
||||
|
|
@ -941,19 +942,19 @@ void Path::applyTransform (const AffineTransform& transform) noexcept
|
|||
|
||||
d += 2;
|
||||
}
|
||||
else if (type == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
transform.transformPoint (d[0], d[1]);
|
||||
bounds.extend (d[0], d[1]);
|
||||
d += 2;
|
||||
}
|
||||
else if (type == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
transform.transformPoints (d[0], d[1], d[2], d[3]);
|
||||
bounds.extend (d[0], d[1], d[2], d[3]);
|
||||
d += 4;
|
||||
}
|
||||
else if (type == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
transform.transformPoints (d[0], d[1], d[2], d[3], d[4], d[5]);
|
||||
bounds.extend (d[0], d[1], d[2], d[3]);
|
||||
|
|
@ -977,7 +978,7 @@ AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
|
|||
const bool preserveProportions,
|
||||
Justification justification) const
|
||||
{
|
||||
Rectangle<float> boundsRect (getBounds());
|
||||
auto boundsRect = getBounds();
|
||||
|
||||
if (preserveProportions)
|
||||
{
|
||||
|
|
@ -985,7 +986,7 @@ AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
|
|||
return AffineTransform();
|
||||
|
||||
float newW, newH;
|
||||
const float srcRatio = boundsRect.getHeight() / boundsRect.getWidth();
|
||||
auto srcRatio = boundsRect.getHeight() / boundsRect.getWidth();
|
||||
|
||||
if (srcRatio > h / w)
|
||||
{
|
||||
|
|
@ -998,8 +999,8 @@ AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
|
|||
newH = w * srcRatio;
|
||||
}
|
||||
|
||||
float newXCentre = x;
|
||||
float newYCentre = y;
|
||||
auto newXCentre = x;
|
||||
auto newYCentre = y;
|
||||
|
||||
if (justification.testFlags (Justification::left)) newXCentre += newW * 0.5f;
|
||||
else if (justification.testFlags (Justification::right)) newXCentre += w - newW * 0.5f;
|
||||
|
|
@ -1040,7 +1041,7 @@ bool Path::contains (const float x, const float y, const float tolerance) const
|
|||
{
|
||||
if ((i.y1 <= y && i.y2 > y) || (i.y2 <= y && i.y1 > y))
|
||||
{
|
||||
const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
|
||||
auto intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
|
||||
|
||||
if (intersectX <= x)
|
||||
{
|
||||
|
|
@ -1091,7 +1092,7 @@ Line<float> Path::getClippedLine (Line<float> line, const bool keepSectionOutsid
|
|||
|
||||
while (i.next())
|
||||
{
|
||||
if (line.intersects (Line<float> (i.x1, i.y1, i.x2, i.y2), intersection))
|
||||
if (line.intersects ({ i.x1, i.y1, i.x2, i.y2 }, intersection))
|
||||
{
|
||||
if ((startInside && keepSectionOutsidePath) || (endInside && ! keepSectionOutsidePath))
|
||||
result.setStart (intersection);
|
||||
|
|
@ -1124,7 +1125,7 @@ Point<float> Path::getPointAlongPath (float distanceFromStart,
|
|||
while (i.next())
|
||||
{
|
||||
const Line<float> line (i.x1, i.y1, i.x2, i.y2);
|
||||
const float lineLength = line.getLength();
|
||||
auto lineLength = line.getLength();
|
||||
|
||||
if (distanceFromStart <= lineLength)
|
||||
return line.getPointAlongLine (distanceFromStart);
|
||||
|
|
@ -1132,7 +1133,7 @@ Point<float> Path::getPointAlongPath (float distanceFromStart,
|
|||
distanceFromStart -= lineLength;
|
||||
}
|
||||
|
||||
return Point<float> (i.x2, i.y2);
|
||||
return { i.x2, i.y2 };
|
||||
}
|
||||
|
||||
float Path::getNearestPoint (const Point<float> targetPoint, Point<float>& pointOnPath,
|
||||
|
|
@ -1147,7 +1148,7 @@ float Path::getNearestPoint (const Point<float> targetPoint, Point<float>& point
|
|||
while (i.next())
|
||||
{
|
||||
const Line<float> line (i.x1, i.y1, i.x2, i.y2);
|
||||
const float distance = line.getDistanceFromPoint (targetPoint, pointOnLine);
|
||||
auto distance = line.getDistanceFromPoint (targetPoint, pointOnLine);
|
||||
|
||||
if (distance < bestDistance)
|
||||
{
|
||||
|
|
@ -1168,73 +1169,73 @@ Path Path::createPathWithRoundedCorners (const float cornerRadius) const
|
|||
if (cornerRadius <= 0.01f)
|
||||
return *this;
|
||||
|
||||
Path p;
|
||||
size_t indexOfPathStart = 0, indexOfPathStartThis = 0;
|
||||
size_t n = 0;
|
||||
bool lastWasLine = false, firstWasLine = false;
|
||||
Path p;
|
||||
|
||||
while (n < numElements)
|
||||
{
|
||||
const float type = data.elements [n++];
|
||||
auto type = data.elements[n++];
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
indexOfPathStart = p.numElements;
|
||||
indexOfPathStartThis = n - 1;
|
||||
const float x = data.elements [n++];
|
||||
const float y = data.elements [n++];
|
||||
auto x = data.elements[n++];
|
||||
auto y = data.elements[n++];
|
||||
p.startNewSubPath (x, y);
|
||||
lastWasLine = false;
|
||||
firstWasLine = (data.elements [n] == lineMarker);
|
||||
firstWasLine = (isMarker (data.elements[n], lineMarker));
|
||||
}
|
||||
else if (type == lineMarker || type == closeSubPathMarker)
|
||||
else if (isMarker (type, lineMarker) || isMarker (type, closeSubPathMarker))
|
||||
{
|
||||
float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
|
||||
|
||||
if (type == lineMarker)
|
||||
if (isMarker (type, lineMarker))
|
||||
{
|
||||
endX = data.elements [n++];
|
||||
endY = data.elements [n++];
|
||||
endX = data.elements[n++];
|
||||
endY = data.elements[n++];
|
||||
|
||||
if (n > 8)
|
||||
{
|
||||
startX = data.elements [n - 8];
|
||||
startY = data.elements [n - 7];
|
||||
joinX = data.elements [n - 5];
|
||||
joinY = data.elements [n - 4];
|
||||
startX = data.elements[n - 8];
|
||||
startY = data.elements[n - 7];
|
||||
joinX = data.elements[n - 5];
|
||||
joinY = data.elements[n - 4];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
endX = data.elements [indexOfPathStartThis + 1];
|
||||
endY = data.elements [indexOfPathStartThis + 2];
|
||||
endX = data.elements[indexOfPathStartThis + 1];
|
||||
endY = data.elements[indexOfPathStartThis + 2];
|
||||
|
||||
if (n > 6)
|
||||
{
|
||||
startX = data.elements [n - 6];
|
||||
startY = data.elements [n - 5];
|
||||
joinX = data.elements [n - 3];
|
||||
joinY = data.elements [n - 2];
|
||||
startX = data.elements[n - 6];
|
||||
startY = data.elements[n - 5];
|
||||
joinX = data.elements[n - 3];
|
||||
joinY = data.elements[n - 2];
|
||||
}
|
||||
}
|
||||
|
||||
if (lastWasLine)
|
||||
{
|
||||
const double len1 = PathHelpers::lengthOf (startX, startY, joinX, joinY);
|
||||
auto len1 = PathHelpers::lengthOf (startX, startY, joinX, joinY);
|
||||
|
||||
if (len1 > 0)
|
||||
{
|
||||
const double propNeeded = jmin (0.5, cornerRadius / len1);
|
||||
auto propNeeded = jmin (0.5, cornerRadius / len1);
|
||||
|
||||
p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
|
||||
p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
|
||||
p.data.elements[p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
|
||||
p.data.elements[p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
|
||||
}
|
||||
|
||||
const double len2 = PathHelpers::lengthOf (endX, endY, joinX, joinY);
|
||||
auto len2 = PathHelpers::lengthOf (endX, endY, joinX, joinY);
|
||||
|
||||
if (len2 > 0)
|
||||
{
|
||||
const double propNeeded = jmin (0.5, cornerRadius / len2);
|
||||
auto propNeeded = jmin (0.5, cornerRadius / len2);
|
||||
|
||||
p.quadraticTo (joinX, joinY,
|
||||
(float) (joinX + (endX - joinX) * propNeeded),
|
||||
|
|
@ -1243,70 +1244,70 @@ Path Path::createPathWithRoundedCorners (const float cornerRadius) const
|
|||
|
||||
p.lineTo (endX, endY);
|
||||
}
|
||||
else if (type == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
p.lineTo (endX, endY);
|
||||
lastWasLine = true;
|
||||
}
|
||||
|
||||
if (type == closeSubPathMarker)
|
||||
if (isMarker (type, closeSubPathMarker))
|
||||
{
|
||||
if (firstWasLine)
|
||||
{
|
||||
startX = data.elements [n - 3];
|
||||
startY = data.elements [n - 2];
|
||||
startX = data.elements[n - 3];
|
||||
startY = data.elements[n - 2];
|
||||
joinX = endX;
|
||||
joinY = endY;
|
||||
endX = data.elements [indexOfPathStartThis + 4];
|
||||
endY = data.elements [indexOfPathStartThis + 5];
|
||||
endX = data.elements[indexOfPathStartThis + 4];
|
||||
endY = data.elements[indexOfPathStartThis + 5];
|
||||
|
||||
const double len1 = PathHelpers::lengthOf (startX, startY, joinX, joinY);
|
||||
auto len1 = PathHelpers::lengthOf (startX, startY, joinX, joinY);
|
||||
|
||||
if (len1 > 0)
|
||||
{
|
||||
const double propNeeded = jmin (0.5, cornerRadius / len1);
|
||||
auto propNeeded = jmin (0.5, cornerRadius / len1);
|
||||
|
||||
p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
|
||||
p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
|
||||
p.data.elements[p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
|
||||
p.data.elements[p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
|
||||
}
|
||||
|
||||
const double len2 = PathHelpers::lengthOf (endX, endY, joinX, joinY);
|
||||
auto len2 = PathHelpers::lengthOf (endX, endY, joinX, joinY);
|
||||
|
||||
if (len2 > 0)
|
||||
{
|
||||
const double propNeeded = jmin (0.5, cornerRadius / len2);
|
||||
auto propNeeded = jmin (0.5, cornerRadius / len2);
|
||||
|
||||
endX = (float) (joinX + (endX - joinX) * propNeeded);
|
||||
endY = (float) (joinY + (endY - joinY) * propNeeded);
|
||||
|
||||
p.quadraticTo (joinX, joinY, endX, endY);
|
||||
|
||||
p.data.elements [indexOfPathStart + 1] = endX;
|
||||
p.data.elements [indexOfPathStart + 2] = endY;
|
||||
p.data.elements[indexOfPathStart + 1] = endX;
|
||||
p.data.elements[indexOfPathStart + 2] = endY;
|
||||
}
|
||||
}
|
||||
|
||||
p.closeSubPath();
|
||||
}
|
||||
}
|
||||
else if (type == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
lastWasLine = false;
|
||||
const float x1 = data.elements [n++];
|
||||
const float y1 = data.elements [n++];
|
||||
const float x2 = data.elements [n++];
|
||||
const float y2 = data.elements [n++];
|
||||
auto x1 = data.elements[n++];
|
||||
auto y1 = data.elements[n++];
|
||||
auto x2 = data.elements[n++];
|
||||
auto y2 = data.elements[n++];
|
||||
p.quadraticTo (x1, y1, x2, y2);
|
||||
}
|
||||
else if (type == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
lastWasLine = false;
|
||||
const float x1 = data.elements [n++];
|
||||
const float y1 = data.elements [n++];
|
||||
const float x2 = data.elements [n++];
|
||||
const float y2 = data.elements [n++];
|
||||
const float x3 = data.elements [n++];
|
||||
const float y3 = data.elements [n++];
|
||||
auto x1 = data.elements[n++];
|
||||
auto y1 = data.elements[n++];
|
||||
auto x2 = data.elements[n++];
|
||||
auto y2 = data.elements[n++];
|
||||
auto x3 = data.elements[n++];
|
||||
auto y3 = data.elements[n++];
|
||||
p.cubicTo (x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
}
|
||||
|
|
@ -1323,38 +1324,38 @@ void Path::loadPathFromStream (InputStream& source)
|
|||
{
|
||||
case 'm':
|
||||
{
|
||||
const float x = source.readFloat();
|
||||
const float y = source.readFloat();
|
||||
auto x = source.readFloat();
|
||||
auto y = source.readFloat();
|
||||
startNewSubPath (x, y);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'l':
|
||||
{
|
||||
const float x = source.readFloat();
|
||||
const float y = source.readFloat();
|
||||
auto x = source.readFloat();
|
||||
auto y = source.readFloat();
|
||||
lineTo (x, y);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'q':
|
||||
{
|
||||
const float x1 = source.readFloat();
|
||||
const float y1 = source.readFloat();
|
||||
const float x2 = source.readFloat();
|
||||
const float y2 = source.readFloat();
|
||||
auto x1 = source.readFloat();
|
||||
auto y1 = source.readFloat();
|
||||
auto x2 = source.readFloat();
|
||||
auto y2 = source.readFloat();
|
||||
quadraticTo (x1, y1, x2, y2);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'b':
|
||||
{
|
||||
const float x1 = source.readFloat();
|
||||
const float y1 = source.readFloat();
|
||||
const float x2 = source.readFloat();
|
||||
const float y2 = source.readFloat();
|
||||
const float x3 = source.readFloat();
|
||||
const float y3 = source.readFloat();
|
||||
auto x1 = source.readFloat();
|
||||
auto y1 = source.readFloat();
|
||||
auto x2 = source.readFloat();
|
||||
auto y2 = source.readFloat();
|
||||
auto x3 = source.readFloat();
|
||||
auto y3 = source.readFloat();
|
||||
cubicTo (x1, y1, x2, y2, x3, y3);
|
||||
break;
|
||||
}
|
||||
|
|
@ -1391,42 +1392,41 @@ void Path::writePathToStream (OutputStream& dest) const
|
|||
{
|
||||
dest.writeByte (useNonZeroWinding ? 'n' : 'z');
|
||||
|
||||
size_t i = 0;
|
||||
while (i < numElements)
|
||||
for (size_t i = 0; i < numElements;)
|
||||
{
|
||||
const float type = data.elements [i++];
|
||||
auto type = data.elements[i++];
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
dest.writeByte ('m');
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
}
|
||||
else if (type == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
dest.writeByte ('l');
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
}
|
||||
else if (type == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
dest.writeByte ('q');
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
}
|
||||
else if (type == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
dest.writeByte ('b');
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements [i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
dest.writeFloat (data.elements[i++]);
|
||||
}
|
||||
else if (type == closeSubPathMarker)
|
||||
else if (isMarker (type, closeSubPathMarker))
|
||||
{
|
||||
dest.writeByte ('c');
|
||||
}
|
||||
|
|
@ -1446,48 +1446,48 @@ String Path::toString() const
|
|||
|
||||
while (i < numElements)
|
||||
{
|
||||
const float marker = data.elements [i++];
|
||||
auto type = data.elements[i++];
|
||||
char markerChar = 0;
|
||||
int numCoords = 0;
|
||||
|
||||
if (marker == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
markerChar = 'm';
|
||||
numCoords = 2;
|
||||
}
|
||||
else if (marker == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
markerChar = 'l';
|
||||
numCoords = 2;
|
||||
}
|
||||
else if (marker == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
markerChar = 'q';
|
||||
numCoords = 4;
|
||||
}
|
||||
else if (marker == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
markerChar = 'c';
|
||||
numCoords = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
jassert (marker == closeSubPathMarker);
|
||||
jassert (isMarker (type, closeSubPathMarker));
|
||||
markerChar = 'z';
|
||||
}
|
||||
|
||||
if (marker != lastMarker)
|
||||
if (! isMarker (type, lastMarker))
|
||||
{
|
||||
if (s.getDataSize() != 0)
|
||||
s << ' ';
|
||||
|
||||
s << markerChar;
|
||||
lastMarker = marker;
|
||||
lastMarker = type;
|
||||
}
|
||||
|
||||
while (--numCoords >= 0 && i < numElements)
|
||||
{
|
||||
String coord (data.elements [i++], 3);
|
||||
String coord (data.elements[i++], 3);
|
||||
|
||||
while (coord.endsWithChar ('0') && coord != "0")
|
||||
coord = coord.dropLastCharacters (1);
|
||||
|
|
@ -1510,15 +1510,15 @@ void Path::restoreFromString (StringRef stringVersion)
|
|||
clear();
|
||||
setUsingNonZeroWinding (true);
|
||||
|
||||
String::CharPointerType t (stringVersion.text);
|
||||
auto t = stringVersion.text;
|
||||
juce_wchar marker = 'm';
|
||||
int numValues = 2;
|
||||
float values [6];
|
||||
float values[6];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const String token (PathHelpers::nextToken (t));
|
||||
const juce_wchar firstChar = token[0];
|
||||
auto token = PathHelpers::nextToken (t);
|
||||
auto firstChar = token[0];
|
||||
int startNum = 0;
|
||||
|
||||
if (firstChar == 0)
|
||||
|
|
@ -1572,9 +1572,7 @@ void Path::restoreFromString (StringRef stringVersion)
|
|||
|
||||
//==============================================================================
|
||||
Path::Iterator::Iterator (const Path& p) noexcept
|
||||
: elementType (startNewSubPath),
|
||||
x1 (0), y1 (0), x2 (0), y2 (0), x3 (0), y3 (0),
|
||||
path (p), index (0)
|
||||
: elementType (startNewSubPath), path (p)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -1584,43 +1582,43 @@ Path::Iterator::~Iterator() noexcept
|
|||
|
||||
bool Path::Iterator::next() noexcept
|
||||
{
|
||||
const float* const elements = path.data.elements;
|
||||
const float* elements = path.data.elements;
|
||||
|
||||
if (index < path.numElements)
|
||||
{
|
||||
const float type = elements [index++];
|
||||
auto type = elements[index++];
|
||||
|
||||
if (type == moveMarker)
|
||||
if (isMarker (type, moveMarker))
|
||||
{
|
||||
elementType = startNewSubPath;
|
||||
x1 = elements [index++];
|
||||
y1 = elements [index++];
|
||||
x1 = elements[index++];
|
||||
y1 = elements[index++];
|
||||
}
|
||||
else if (type == lineMarker)
|
||||
else if (isMarker (type, lineMarker))
|
||||
{
|
||||
elementType = lineTo;
|
||||
x1 = elements [index++];
|
||||
y1 = elements [index++];
|
||||
x1 = elements[index++];
|
||||
y1 = elements[index++];
|
||||
}
|
||||
else if (type == quadMarker)
|
||||
else if (isMarker (type, quadMarker))
|
||||
{
|
||||
elementType = quadraticTo;
|
||||
x1 = elements [index++];
|
||||
y1 = elements [index++];
|
||||
x2 = elements [index++];
|
||||
y2 = elements [index++];
|
||||
x1 = elements[index++];
|
||||
y1 = elements[index++];
|
||||
x2 = elements[index++];
|
||||
y2 = elements[index++];
|
||||
}
|
||||
else if (type == cubicMarker)
|
||||
else if (isMarker (type, cubicMarker))
|
||||
{
|
||||
elementType = cubicTo;
|
||||
x1 = elements [index++];
|
||||
y1 = elements [index++];
|
||||
x2 = elements [index++];
|
||||
y2 = elements [index++];
|
||||
x3 = elements [index++];
|
||||
y3 = elements [index++];
|
||||
x1 = elements[index++];
|
||||
y1 = elements[index++];
|
||||
x2 = elements[index++];
|
||||
y2 = elements[index++];
|
||||
x3 = elements[index++];
|
||||
y3 = elements[index++];
|
||||
}
|
||||
else if (type == closeSubPathMarker)
|
||||
else if (isMarker (type, closeSubPathMarker))
|
||||
{
|
||||
elementType = closePath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -746,12 +746,12 @@ public:
|
|||
|
||||
PathElementType elementType;
|
||||
|
||||
float x1, y1, x2, y2, x3, y3;
|
||||
float x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0;
|
||||
|
||||
//==============================================================================
|
||||
private:
|
||||
const Path& path;
|
||||
size_t index;
|
||||
size_t index = 0;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE (Iterator)
|
||||
};
|
||||
|
|
@ -802,7 +802,7 @@ private:
|
|||
friend class PathFlatteningIterator;
|
||||
friend class Path::Iterator;
|
||||
ArrayAllocationBase<float, DummyCriticalSection> data;
|
||||
size_t numElements;
|
||||
size_t numElements = 0;
|
||||
|
||||
struct PathBounds
|
||||
{
|
||||
|
|
@ -813,11 +813,11 @@ private:
|
|||
void extend (float, float) noexcept;
|
||||
void extend (float, float, float, float) noexcept;
|
||||
|
||||
float pathXMin, pathXMax, pathYMin, pathYMax;
|
||||
float pathXMin = 0, pathXMax = 0, pathYMin = 0, pathYMax = 0;
|
||||
};
|
||||
|
||||
PathBounds bounds;
|
||||
bool useNonZeroWinding;
|
||||
bool useNonZeroWinding = true;
|
||||
|
||||
static const float lineMarker;
|
||||
static const float moveMarker;
|
||||
|
|
|
|||
|
|
@ -38,12 +38,7 @@ PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
|
|||
transform (transform_),
|
||||
points (path_.data.elements),
|
||||
toleranceSquared (tolerance * tolerance),
|
||||
subPathCloseX (0),
|
||||
subPathCloseY (0),
|
||||
isIdentityTransform (transform_.isIdentity()),
|
||||
stackBase (32),
|
||||
index (0),
|
||||
stackSize (32)
|
||||
isIdentityTransform (transform_.isIdentity())
|
||||
{
|
||||
stackPos = stackBase;
|
||||
}
|
||||
|
|
@ -55,7 +50,7 @@ PathFlatteningIterator::~PathFlatteningIterator()
|
|||
bool PathFlatteningIterator::isLastInSubpath() const noexcept
|
||||
{
|
||||
return stackPos == stackBase.getData()
|
||||
&& (index >= path.numElements || points [index] == Path::moveMarker);
|
||||
&& (index >= path.numElements || isMarker (points[index], Path::moveMarker));
|
||||
}
|
||||
|
||||
bool PathFlatteningIterator::next()
|
||||
|
|
@ -79,12 +74,12 @@ bool PathFlatteningIterator::next()
|
|||
|
||||
type = points [index++];
|
||||
|
||||
if (type != Path::closeSubPathMarker)
|
||||
if (! isMarker (type, Path::closeSubPathMarker))
|
||||
{
|
||||
x2 = points [index++];
|
||||
y2 = points [index++];
|
||||
|
||||
if (type == Path::quadMarker)
|
||||
if (isMarker (type, Path::quadMarker))
|
||||
{
|
||||
x3 = points [index++];
|
||||
y3 = points [index++];
|
||||
|
|
@ -92,7 +87,7 @@ bool PathFlatteningIterator::next()
|
|||
if (! isIdentityTransform)
|
||||
transform.transformPoints (x2, y2, x3, y3);
|
||||
}
|
||||
else if (type == Path::cubicMarker)
|
||||
else if (isMarker (type, Path::cubicMarker))
|
||||
{
|
||||
x3 = points [index++];
|
||||
y3 = points [index++];
|
||||
|
|
@ -113,17 +108,17 @@ bool PathFlatteningIterator::next()
|
|||
{
|
||||
type = *--stackPos;
|
||||
|
||||
if (type != Path::closeSubPathMarker)
|
||||
if (! isMarker (type, Path::closeSubPathMarker))
|
||||
{
|
||||
x2 = *--stackPos;
|
||||
y2 = *--stackPos;
|
||||
|
||||
if (type == Path::quadMarker)
|
||||
if (isMarker (type, Path::quadMarker))
|
||||
{
|
||||
x3 = *--stackPos;
|
||||
y3 = *--stackPos;
|
||||
}
|
||||
else if (type == Path::cubicMarker)
|
||||
else if (isMarker (type, Path::cubicMarker))
|
||||
{
|
||||
x3 = *--stackPos;
|
||||
y3 = *--stackPos;
|
||||
|
|
@ -133,7 +128,7 @@ bool PathFlatteningIterator::next()
|
|||
}
|
||||
}
|
||||
|
||||
if (type == Path::lineMarker)
|
||||
if (isMarker (type, Path::lineMarker))
|
||||
{
|
||||
++subPathIndex;
|
||||
|
||||
|
|
@ -146,7 +141,7 @@ bool PathFlatteningIterator::next()
|
|||
return true;
|
||||
}
|
||||
|
||||
if (type == Path::quadMarker)
|
||||
if (isMarker (type, Path::quadMarker))
|
||||
{
|
||||
const size_t offset = (size_t) (stackPos - stackBase);
|
||||
|
||||
|
|
@ -157,15 +152,15 @@ bool PathFlatteningIterator::next()
|
|||
stackPos = stackBase + offset;
|
||||
}
|
||||
|
||||
const float m1x = (x1 + x2) * 0.5f;
|
||||
const float m1y = (y1 + y2) * 0.5f;
|
||||
const float m2x = (x2 + x3) * 0.5f;
|
||||
const float m2y = (y2 + y3) * 0.5f;
|
||||
const float m3x = (m1x + m2x) * 0.5f;
|
||||
const float m3y = (m1y + m2y) * 0.5f;
|
||||
auto m1x = (x1 + x2) * 0.5f;
|
||||
auto m1y = (y1 + y2) * 0.5f;
|
||||
auto m2x = (x2 + x3) * 0.5f;
|
||||
auto m2y = (y2 + y3) * 0.5f;
|
||||
auto m3x = (m1x + m2x) * 0.5f;
|
||||
auto m3y = (m1y + m2y) * 0.5f;
|
||||
|
||||
const float errorX = m3x - x2;
|
||||
const float errorY = m3y - y2;
|
||||
auto errorX = m3x - x2;
|
||||
auto errorY = m3y - y2;
|
||||
|
||||
if (errorX * errorX + errorY * errorY > toleranceSquared)
|
||||
{
|
||||
|
|
@ -194,7 +189,7 @@ bool PathFlatteningIterator::next()
|
|||
|
||||
jassert (stackPos < stackBase + stackSize);
|
||||
}
|
||||
else if (type == Path::cubicMarker)
|
||||
else if (isMarker (type, Path::cubicMarker))
|
||||
{
|
||||
const size_t offset = (size_t) (stackPos - stackBase);
|
||||
|
||||
|
|
@ -205,21 +200,21 @@ bool PathFlatteningIterator::next()
|
|||
stackPos = stackBase + offset;
|
||||
}
|
||||
|
||||
const float m1x = (x1 + x2) * 0.5f;
|
||||
const float m1y = (y1 + y2) * 0.5f;
|
||||
const float m2x = (x3 + x2) * 0.5f;
|
||||
const float m2y = (y3 + y2) * 0.5f;
|
||||
const float m3x = (x3 + x4) * 0.5f;
|
||||
const float m3y = (y3 + y4) * 0.5f;
|
||||
const float m4x = (m1x + m2x) * 0.5f;
|
||||
const float m4y = (m1y + m2y) * 0.5f;
|
||||
const float m5x = (m3x + m2x) * 0.5f;
|
||||
const float m5y = (m3y + m2y) * 0.5f;
|
||||
auto m1x = (x1 + x2) * 0.5f;
|
||||
auto m1y = (y1 + y2) * 0.5f;
|
||||
auto m2x = (x3 + x2) * 0.5f;
|
||||
auto m2y = (y3 + y2) * 0.5f;
|
||||
auto m3x = (x3 + x4) * 0.5f;
|
||||
auto m3y = (y3 + y4) * 0.5f;
|
||||
auto m4x = (m1x + m2x) * 0.5f;
|
||||
auto m4y = (m1y + m2y) * 0.5f;
|
||||
auto m5x = (m3x + m2x) * 0.5f;
|
||||
auto m5y = (m3y + m2y) * 0.5f;
|
||||
|
||||
const float error1X = m4x - x2;
|
||||
const float error1Y = m4y - y2;
|
||||
const float error2X = m5x - x3;
|
||||
const float error2Y = m5y - y3;
|
||||
auto error1X = m4x - x2;
|
||||
auto error1Y = m4y - y2;
|
||||
auto error2X = m5x - x3;
|
||||
auto error2Y = m5y - y3;
|
||||
|
||||
if (error1X * error1X + error1Y * error1Y > toleranceSquared
|
||||
|| error2X * error2X + error2Y * error2Y > toleranceSquared)
|
||||
|
|
@ -255,7 +250,7 @@ bool PathFlatteningIterator::next()
|
|||
*stackPos++ = Path::lineMarker;
|
||||
}
|
||||
}
|
||||
else if (type == Path::closeSubPathMarker)
|
||||
else if (isMarker (type, Path::closeSubPathMarker))
|
||||
{
|
||||
if (x2 != subPathCloseX || y2 != subPathCloseY)
|
||||
{
|
||||
|
|
@ -270,7 +265,7 @@ bool PathFlatteningIterator::next()
|
|||
}
|
||||
else
|
||||
{
|
||||
jassert (type == Path::moveMarker);
|
||||
jassert (isMarker (type, Path::moveMarker));
|
||||
|
||||
subPathIndex = -1;
|
||||
subPathCloseX = x1 = x2;
|
||||
|
|
|
|||
|
|
@ -95,12 +95,12 @@ private:
|
|||
const AffineTransform transform;
|
||||
float* points;
|
||||
const float toleranceSquared;
|
||||
float subPathCloseX, subPathCloseY;
|
||||
float subPathCloseX = 0, subPathCloseY = 0;
|
||||
const bool isIdentityTransform;
|
||||
|
||||
HeapBlock<float> stackBase;
|
||||
HeapBlock<float> stackBase { 32 };
|
||||
float* stackPos;
|
||||
size_t index, stackSize;
|
||||
size_t index = 0, stackSize = 32;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PathFlatteningIterator)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -76,19 +76,19 @@ namespace PathStrokeHelpers
|
|||
{
|
||||
if (x2 != x3 || y2 != y3)
|
||||
{
|
||||
const float dx1 = x2 - x1;
|
||||
const float dy1 = y2 - y1;
|
||||
const float dx2 = x4 - x3;
|
||||
const float dy2 = y4 - y3;
|
||||
const float divisor = dx1 * dy2 - dx2 * dy1;
|
||||
auto dx1 = x2 - x1;
|
||||
auto dy1 = y2 - y1;
|
||||
auto dx2 = x4 - x3;
|
||||
auto dy2 = y4 - y3;
|
||||
auto divisor = dx1 * dy2 - dx2 * dy1;
|
||||
|
||||
if (divisor == 0)
|
||||
if (divisor == 0.0f)
|
||||
{
|
||||
if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
|
||||
if (! ((dx1 == 0.0f && dy1 == 0.0f) || (dx2 == 0.0f && dy2 == 0.0f)))
|
||||
{
|
||||
if (dy1 == 0 && dy2 != 0)
|
||||
if (dy1 == 0.0f && dy2 != 0.0f)
|
||||
{
|
||||
const float along = (y1 - y3) / dy2;
|
||||
auto along = (y1 - y3) / dy2;
|
||||
intersectionX = x3 + along * dx2;
|
||||
intersectionY = y1;
|
||||
|
||||
|
|
@ -100,9 +100,9 @@ namespace PathStrokeHelpers
|
|||
return along >= 0 && along <= 1.0f;
|
||||
}
|
||||
|
||||
if (dy2 == 0 && dy1 != 0)
|
||||
if (dy2 == 0.0f && dy1 != 0.0f)
|
||||
{
|
||||
const float along = (y3 - y1) / dy1;
|
||||
auto along = (y3 - y1) / dy1;
|
||||
intersectionX = x1 + along * dx1;
|
||||
intersectionY = y3;
|
||||
|
||||
|
|
@ -114,9 +114,9 @@ namespace PathStrokeHelpers
|
|||
return along >= 0 && along <= 1.0f;
|
||||
}
|
||||
|
||||
if (dx1 == 0 && dx2 != 0)
|
||||
if (dx1 == 0.0f && dx2 != 0.0f)
|
||||
{
|
||||
const float along = (x1 - x3) / dx2;
|
||||
auto along = (x1 - x3) / dx2;
|
||||
intersectionX = x1;
|
||||
intersectionY = y3 + along * dy2;
|
||||
|
||||
|
|
@ -129,9 +129,9 @@ namespace PathStrokeHelpers
|
|||
return along >= 0 && along <= 1.0f;
|
||||
}
|
||||
|
||||
if (dx2 == 0 && dx1 != 0)
|
||||
if (dx2 == 0.0f && dx1 != 0.0f)
|
||||
{
|
||||
const float along = (x3 - x1) / dx1;
|
||||
auto along = (x3 - x1) / dx1;
|
||||
intersectionX = x3;
|
||||
intersectionY = y1 + along * dy1;
|
||||
|
||||
|
|
@ -151,14 +151,14 @@ namespace PathStrokeHelpers
|
|||
return false;
|
||||
}
|
||||
|
||||
const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
|
||||
auto along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
|
||||
|
||||
intersectionX = x1 + along1 * dx1;
|
||||
intersectionY = y1 + along1 * dy1;
|
||||
|
||||
if (along1 >= 0 && along1 <= 1.0f)
|
||||
{
|
||||
const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
|
||||
auto along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
|
||||
|
||||
if (along2 >= 0 && along2 <= 1.0f)
|
||||
{
|
||||
|
|
@ -293,18 +293,18 @@ namespace PathStrokeHelpers
|
|||
{
|
||||
float offx1, offy1, offx2, offy2;
|
||||
|
||||
float dx = x2 - x1;
|
||||
float dy = y2 - y1;
|
||||
const float len = juce_hypot (dx, dy);
|
||||
auto dx = x2 - x1;
|
||||
auto dy = y2 - y1;
|
||||
auto len = juce_hypot (dx, dy);
|
||||
|
||||
if (len == 0)
|
||||
if (len == 0.0f)
|
||||
{
|
||||
offx1 = offx2 = x1;
|
||||
offy1 = offy2 = y1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const float offset = width / len;
|
||||
auto offset = width / len;
|
||||
dx *= offset;
|
||||
dy *= offset;
|
||||
|
||||
|
|
@ -324,8 +324,8 @@ namespace PathStrokeHelpers
|
|||
else
|
||||
{
|
||||
// rounded ends
|
||||
const float midx = (offx1 + offx2) * 0.5f;
|
||||
const float midy = (offy1 + offy2) * 0.5f;
|
||||
auto midx = (offx1 + offx2) * 0.5f;
|
||||
auto midy = (offy1 + offy2) * 0.5f;
|
||||
|
||||
destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
|
||||
offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
|
||||
|
|
@ -369,10 +369,10 @@ namespace PathStrokeHelpers
|
|||
{
|
||||
while (amountAtEnd > 0 && subPath.size() > 0)
|
||||
{
|
||||
LineSection& l = subPath.getReference (subPath.size() - 1);
|
||||
float dx = l.rx2 - l.rx1;
|
||||
float dy = l.ry2 - l.ry1;
|
||||
const float len = juce_hypot (dx, dy);
|
||||
auto& l = subPath.getReference (subPath.size() - 1);
|
||||
auto dx = l.rx2 - l.rx1;
|
||||
auto dy = l.ry2 - l.ry1;
|
||||
auto len = juce_hypot (dx, dy);
|
||||
|
||||
if (len <= amountAtEnd && subPath.size() > 1)
|
||||
{
|
||||
|
|
@ -384,7 +384,7 @@ namespace PathStrokeHelpers
|
|||
}
|
||||
else
|
||||
{
|
||||
const float prop = jmin (0.9999f, amountAtEnd / len);
|
||||
auto prop = jmin (0.9999f, amountAtEnd / len);
|
||||
dx *= prop;
|
||||
dy *= prop;
|
||||
l.rx1 += dx;
|
||||
|
|
@ -397,10 +397,10 @@ namespace PathStrokeHelpers
|
|||
|
||||
while (amountAtStart > 0 && subPath.size() > 0)
|
||||
{
|
||||
LineSection& l = subPath.getReference (0);
|
||||
float dx = l.rx2 - l.rx1;
|
||||
float dy = l.ry2 - l.ry1;
|
||||
const float len = juce_hypot (dx, dy);
|
||||
auto& l = subPath.getReference (0);
|
||||
auto dx = l.rx2 - l.rx1;
|
||||
auto dy = l.ry2 - l.ry1;
|
||||
auto len = juce_hypot (dx, dy);
|
||||
|
||||
if (len <= amountAtStart && subPath.size() > 1)
|
||||
{
|
||||
|
|
@ -412,7 +412,7 @@ namespace PathStrokeHelpers
|
|||
}
|
||||
else
|
||||
{
|
||||
const float prop = jmin (0.9999f, amountAtStart / len);
|
||||
auto prop = jmin (0.9999f, amountAtStart / len);
|
||||
dx *= prop;
|
||||
dy *= prop;
|
||||
l.rx2 -= dx;
|
||||
|
|
@ -434,12 +434,12 @@ namespace PathStrokeHelpers
|
|||
if (arrowhead != nullptr)
|
||||
shortenSubPath (subPath, arrowhead->startLength, arrowhead->endLength);
|
||||
|
||||
const LineSection& firstLine = subPath.getReference (0);
|
||||
auto& firstLine = subPath.getReference (0);
|
||||
|
||||
float lastX1 = firstLine.lx1;
|
||||
float lastY1 = firstLine.ly1;
|
||||
float lastX2 = firstLine.lx2;
|
||||
float lastY2 = firstLine.ly2;
|
||||
auto lastX1 = firstLine.lx1;
|
||||
auto lastY1 = firstLine.ly1;
|
||||
auto lastX2 = firstLine.lx2;
|
||||
auto lastY2 = firstLine.ly2;
|
||||
|
||||
if (isClosed)
|
||||
{
|
||||
|
|
@ -472,11 +472,11 @@ namespace PathStrokeHelpers
|
|||
lastY2 = l.ly2;
|
||||
}
|
||||
|
||||
const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
|
||||
auto& lastLine = subPath.getReference (subPath.size() - 1);
|
||||
|
||||
if (isClosed)
|
||||
{
|
||||
const LineSection& l = subPath.getReference (0);
|
||||
auto& l = subPath.getReference (0);
|
||||
|
||||
addEdgeAndJoint (destPath, jointStyle,
|
||||
maxMiterExtensionSquared, width,
|
||||
|
|
@ -505,7 +505,7 @@ namespace PathStrokeHelpers
|
|||
|
||||
for (int i = subPath.size() - 1; --i >= 0;)
|
||||
{
|
||||
const LineSection& l = subPath.getReference (i);
|
||||
auto& l = subPath.getReference (i);
|
||||
|
||||
addEdgeAndJoint (destPath, jointStyle,
|
||||
maxMiterExtensionSquared, width,
|
||||
|
|
@ -572,7 +572,7 @@ namespace PathStrokeHelpers
|
|||
// left/right-hand lines along either side of it...
|
||||
PathFlatteningIterator it (*sourcePath, transform, Path::defaultToleranceForMeasurement / extraAccuracy);
|
||||
|
||||
Array <LineSection> subPath;
|
||||
Array<LineSection> subPath;
|
||||
subPath.ensureStorageAllocated (512);
|
||||
LineSection l;
|
||||
l.x1 = 0;
|
||||
|
|
@ -600,20 +600,20 @@ namespace PathStrokeHelpers
|
|||
float dx = l.x2 - l.x1;
|
||||
float dy = l.y2 - l.y1;
|
||||
|
||||
const float hypotSquared = dx*dx + dy*dy;
|
||||
auto hypotSquared = dx * dx + dy * dy;
|
||||
|
||||
if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
|
||||
{
|
||||
const float len = std::sqrt (hypotSquared);
|
||||
auto len = std::sqrt (hypotSquared);
|
||||
|
||||
if (len == 0)
|
||||
if (len == 0.0f)
|
||||
{
|
||||
l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
|
||||
l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const float offset = width / len;
|
||||
auto offset = width / len;
|
||||
dx *= offset;
|
||||
dy *= offset;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue