@@ -167,6 +167,9 @@ Path& Path::addLine (const Line<float>& line)
167167
168168Path& Path::addRectangle (float x, float y, float width, float height)
169169{
170+ width = jmax (0 .0f , width);
171+ height = jmax (0 .0f , height);
172+
170173 reserveSpace (size () + 5 );
171174
172175 moveTo (x, y);
@@ -189,6 +192,9 @@ Path& Path::addRoundedRectangle (float x, float y, float width, float height, fl
189192{
190193 reserveSpace (size () + 9 );
191194
195+ width = jmax (0 .0f , width);
196+ height = jmax (0 .0f , height);
197+
192198 const float centerWidth = width * 0 .5f ;
193199 const float centerHeight = height * 0 .5f ;
194200 radiusTopLeft = jmin (radiusTopLeft, centerWidth, centerHeight);
@@ -245,6 +251,9 @@ Path& Path::addEllipse (float x, float y, float width, float height)
245251{
246252 reserveSpace (size () + 6 );
247253
254+ width = jmax (0 .0f , width);
255+ height = jmax (0 .0f , height);
256+
248257 const float rx = width * 0 .5f ;
249258 const float ry = height * 0 .5f ;
250259 const float cx = x + rx;
@@ -273,6 +282,9 @@ Path& Path::addCenteredEllipse (float centerX, float centerY, float radiusX, flo
273282{
274283 reserveSpace (size () + 6 );
275284
285+ radiusX = jmax (0 .0f , radiusX);
286+ radiusY = jmax (0 .0f , radiusY);
287+
276288 const float rx = radiusX;
277289 const float ry = radiusY;
278290 const float cx = centerX;
@@ -304,6 +316,9 @@ Path& Path::addCenteredEllipse (const Point<float>& center, const Size<float>& d
304316
305317Path& Path::addArc (float x, float y, float width, float height, float fromRadians, float toRadians, bool startAsNewSubPath)
306318{
319+ width = jmax (0 .0f , width);
320+ height = jmax (0 .0f , height);
321+
307322 const float radiusX = width * 0 .5f ;
308323 const float radiusY = height * 0 .5f ;
309324
@@ -329,6 +344,9 @@ Path& Path::addCenteredArc (float centerX, float centerY, float radiusX, float r
329344 const float sinTheta = std::sin (rotationOfEllipse);
330345
331346 // Initialize variables for the loop
347+ radiusX = jmax (0 .0f , radiusX);
348+ radiusY = jmax (0 .0f , radiusY);
349+
332350 float x = std::cos (fromRadians) * radiusX;
333351 float y = std::sin (fromRadians) * radiusY;
334352 float rotatedX = x * cosTheta - y * sinTheta + centerX;
@@ -369,14 +387,15 @@ Path& Path::addCenteredArc (const Point<float>& center, const Size<float>& diame
369387}
370388
371389// ==============================================================================
372- void Path::addPolygon (Point<float > centre, int numberOfSides, float radius, float startAngle)
390+ Path& Path::addPolygon (Point<float > centre, int numberOfSides, float radius, float startAngle)
373391{
374- if (numberOfSides < 3 || radius <= 0 . 0f )
375- return ;
392+ if (numberOfSides < 3 )
393+ return * this ;
376394
377395 reserveSpace (size () + numberOfSides + 1 );
378396
379397 const float angleIncrement = MathConstants<float >::twoPi / numberOfSides;
398+ radius = jmax (0 .0f , radius);
380399
381400 // Start with the first vertex
382401 float angle = startAngle;
@@ -395,17 +414,21 @@ void Path::addPolygon (Point<float> centre, int numberOfSides, float radius, flo
395414 }
396415
397416 close ();
417+
418+ return *this ;
398419}
399420
400421// ==============================================================================
401- void Path::addStar (Point<float > centre, int numberOfPoints, float innerRadius, float outerRadius, float startAngle)
422+ Path& Path::addStar (Point<float > centre, int numberOfPoints, float innerRadius, float outerRadius, float startAngle)
402423{
403- if (numberOfPoints < 3 || innerRadius <= 0 . 0f || outerRadius <= 0 . 0f )
404- return ;
424+ if (numberOfPoints < 3 )
425+ return * this ;
405426
406427 reserveSpace (size () + numberOfPoints * 2 + 1 );
407428
408429 const float angleIncrement = MathConstants<float >::twoPi / (numberOfPoints * 2 );
430+ innerRadius = jmax (0 .0f , innerRadius);
431+ outerRadius = jmax (0 .0f , outerRadius);
409432
410433 // Start with the first outer vertex
411434 float angle = startAngle;
@@ -425,13 +448,15 @@ void Path::addStar (Point<float> centre, int numberOfPoints, float innerRadius,
425448 }
426449
427450 close ();
451+
452+ return *this ;
428453}
429454
430455// ==============================================================================
431- void Path::addBubble (Rectangle<float > bodyArea, Rectangle<float > maximumArea, Point<float > arrowTipPosition, float cornerSize, float arrowBaseWidth)
456+ Path& Path::addBubble (Rectangle<float > bodyArea, Rectangle<float > maximumArea, Point<float > arrowTipPosition, float cornerSize, float arrowBaseWidth)
432457{
433458 if (bodyArea.isEmpty () || maximumArea.isEmpty () || arrowBaseWidth <= 0 .0f )
434- return ;
459+ return * this ;
435460
436461 // Clamp corner size to reasonable bounds
437462 cornerSize = jmin (cornerSize, bodyArea.getWidth () * 0 .5f , bodyArea.getHeight () * 0 .5f );
@@ -609,6 +634,8 @@ void Path::addBubble (Rectangle<float> bodyArea, Rectangle<float> maximumArea, P
609634
610635 // Close the path
611636 close ();
637+
638+ return *this ;
612639}
613640
614641// ==============================================================================
0 commit comments