Browse Source

Fixed an undefined behaviour warning in the demo app, and tidied up a couple of path functions

tags/2021-05-28
jules 7 years ago
parent
commit
430948ad91
4 changed files with 39 additions and 49 deletions
  1. +4
    -1
      examples/Demo/Source/Demos/AudioPlaybackDemo.cpp
  2. +22
    -41
      modules/juce_graphics/geometry/juce_Path.cpp
  3. +7
    -1
      modules/juce_graphics/geometry/juce_Path.h
  4. +6
    -6
      modules/juce_gui_basics/drawables/juce_DrawableRectangle.cpp

+ 4
- 1
examples/Demo/Source/Demos/AudioPlaybackDemo.cpp View File

@@ -190,7 +190,10 @@ private:
float timeToX (const double time) const
{
return getWidth() * (float) ((time - visibleRange.getStart()) / (visibleRange.getLength()));
if (visibleRange.getLength() <= 0)
return 0;
return getWidth() * (float) ((time - visibleRange.getStart()) / visibleRange.getLength());
}
double xToTime (const float x) const


+ 22
- 41
modules/juce_graphics/geometry/juce_Path.cpp View File

@@ -88,43 +88,19 @@ void Path::PathBounds::reset() noexcept
pathXMin = pathYMin = pathYMax = pathXMax = 0;
}
void Path::PathBounds::reset (const float x, const float y) noexcept
void Path::PathBounds::reset (float x, float y) noexcept
{
pathXMin = pathXMax = x;
pathYMin = pathYMax = y;
}
void Path::PathBounds::extend (const float x, const float y) noexcept
void Path::PathBounds::extend (float x, float y) noexcept
{
pathXMin = jmin (pathXMin, x);
pathXMax = jmax (pathXMax, x);
pathYMin = jmin (pathYMin, y);
pathYMax = jmax (pathYMax, y);
}
void Path::PathBounds::extend (const float x1, const float y1, const float x2, const float y2) noexcept
{
if (x1 < x2)
{
pathXMin = jmin (pathXMin, x1);
pathXMax = jmax (pathXMax, x2);
}
else
{
pathXMin = jmin (pathXMin, x2);
pathXMax = jmax (pathXMax, x1);
}
if (x < pathXMin) pathXMin = x;
else if (x > pathXMax) pathXMax = x;
if (y1 < y2)
{
pathYMin = jmin (pathYMin, y1);
pathYMax = jmax (pathYMax, y2);
}
else
{
pathYMin = jmin (pathYMin, y2);
pathYMax = jmax (pathYMax, y1);
}
if (y < pathYMin) pathYMin = y;
else if (y > pathYMax) pathYMax = y;
}
//==============================================================================
@@ -240,7 +216,7 @@ void Path::preallocateSpace (int numExtraCoordsToMakeSpaceFor)
void Path::startNewSubPath (const float x, const float y)
{
JUCE_CHECK_COORDS_ARE_VALID (x, y);
JUCE_CHECK_COORDS_ARE_VALID (x, y)
if (data.isEmpty())
bounds.reset (x, y);
@@ -257,7 +233,7 @@ void Path::startNewSubPath (Point<float> start)
void Path::lineTo (const float x, const float y)
{
JUCE_CHECK_COORDS_ARE_VALID (x, y);
JUCE_CHECK_COORDS_ARE_VALID (x, y)
if (data.isEmpty())
startNewSubPath (0, 0);
@@ -274,8 +250,8 @@ void Path::lineTo (Point<float> end)
void Path::quadraticTo (const float x1, const float y1,
const float x2, const float y2)
{
JUCE_CHECK_COORDS_ARE_VALID (x1, y1);
JUCE_CHECK_COORDS_ARE_VALID (x2, y2);
JUCE_CHECK_COORDS_ARE_VALID (x1, y1)
JUCE_CHECK_COORDS_ARE_VALID (x2, y2)
if (data.isEmpty())
startNewSubPath (0, 0);
@@ -294,16 +270,15 @@ void Path::cubicTo (const float x1, const float y1,
const float x2, const float y2,
const float x3, const float y3)
{
JUCE_CHECK_COORDS_ARE_VALID (x1, y1);
JUCE_CHECK_COORDS_ARE_VALID (x2, y2);
JUCE_CHECK_COORDS_ARE_VALID (x3, y3);
JUCE_CHECK_COORDS_ARE_VALID (x1, y1)
JUCE_CHECK_COORDS_ARE_VALID (x2, y2)
JUCE_CHECK_COORDS_ARE_VALID (x3, y3)
if (data.isEmpty())
startNewSubPath (0, 0);
data.add (cubicMarker, x1, y1, x2, y2, x3, y3);
bounds.extend (x1, y1, x2, y2);
bounds.extend (x3, y3);
bounds.extend (x1, y1, x2, y2, x3, y3);
}
void Path::cubicTo (Point<float> controlPoint1,
@@ -858,6 +833,7 @@ void Path::applyTransform (const AffineTransform& transform) noexcept
if (isMarker (type, moveMarker))
{
transform.transformPoint (d[0], d[1]);
JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
if (firstPoint)
{
@@ -874,20 +850,25 @@ void Path::applyTransform (const AffineTransform& transform) noexcept
else if (isMarker (type, lineMarker))
{
transform.transformPoint (d[0], d[1]);
JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
bounds.extend (d[0], d[1]);
d += 2;
}
else if (isMarker (type, quadMarker))
{
transform.transformPoints (d[0], d[1], d[2], d[3]);
JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
JUCE_CHECK_COORDS_ARE_VALID (d[2], d[3])
bounds.extend (d[0], d[1], d[2], d[3]);
d += 4;
}
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]);
bounds.extend (d[4], d[5]);
JUCE_CHECK_COORDS_ARE_VALID (d[0], d[1])
JUCE_CHECK_COORDS_ARE_VALID (d[2], d[3])
JUCE_CHECK_COORDS_ARE_VALID (d[4], d[5])
bounds.extend (d[0], d[1], d[2], d[3], d[4], d[5]);
d += 6;
}
}


+ 7
- 1
modules/juce_graphics/geometry/juce_Path.h View File

@@ -812,7 +812,13 @@ private:
void reset() noexcept;
void reset (float, float) noexcept;
void extend (float, float) noexcept;
void extend (float, float, float, float) noexcept;
template <typename... Coords>
void extend (float x, float y, Coords... coords) noexcept
{
extend (x, y);
extend (coords...);
}
float pathXMin = 0, pathXMax = 0, pathYMin = 0, pathYMax = 0;
};


+ 6
- 6
modules/juce_gui_basics/drawables/juce_DrawableRectangle.cpp View File

@@ -71,7 +71,7 @@ void DrawableRectangle::rebuildPath()
{
if (bounds.isDynamic() || cornerSize.isDynamic())
{
Drawable::Positioner<DrawableRectangle>* const p = new Drawable::Positioner<DrawableRectangle> (*this);
auto p = new Drawable::Positioner<DrawableRectangle> (*this);
setPositioner (p);
p->apply();
}
@@ -95,11 +95,11 @@ void DrawableRectangle::recalculateCoordinates (Expression::Scope* scope)
Point<float> points[3];
bounds.resolveThreePoints (points, scope);
const float cornerSizeX = (float) cornerSize.x.resolve (scope);
const float cornerSizeY = (float) cornerSize.y.resolve (scope);
auto cornerSizeX = (float) cornerSize.x.resolve (scope);
auto cornerSizeY = (float) cornerSize.y.resolve (scope);
const float w = Line<float> (points[0], points[1]).getLength();
const float h = Line<float> (points[0], points[2]).getLength();
auto w = Line<float> (points[0], points[1]).getLength();
auto h = Line<float> (points[0], points[2]).getLength();
Path newPath;
@@ -154,7 +154,7 @@ void DrawableRectangle::ValueTreeWrapper::setCornerSize (const RelativePoint& ne
RelativePoint DrawableRectangle::ValueTreeWrapper::getCornerSize() const
{
return RelativePoint (state [cornerSize]);
return RelativePoint (state[cornerSize]);
}
Value DrawableRectangle::ValueTreeWrapper::getCornerSizeValue (UndoManager* undoManager)


Loading…
Cancel
Save