@@ -339,24 +339,35 @@ public void ellipse(final double x, final double y,
339339 LOG .debug ("[" + id_ + "] ellipse()" );
340340 }
341341
342- final Point2D p = transformation_ .transform (new Point2D .Double (x , y ), null );
343- final double startX = p .getX () + radiusX * Math .cos (rotation ) * Math .cos (-startAngle )
344- - radiusY * Math .sin (rotation ) * Math .sin (-startAngle );
345- final double startY = p .getY () + radiusX * Math .sin (rotation ) * Math .cos (-startAngle )
346- + radiusY * Math .cos (rotation ) * Math .sin (-startAngle );
347- final double startAngleDegree = 360 - (startAngle * 180 / Math .PI );
348- final double endAngleDegree = 360 - (endAngle * 180 / Math .PI );
349-
350- double extendAngle = startAngleDegree - endAngleDegree ;
351- extendAngle = Math .min (360 , Math .abs (extendAngle ));
352- if (anticlockwise && extendAngle < 360 ) {
353- extendAngle = extendAngle - 360 ;
342+ if (startAngle == endAngle ) {
343+ return ;
354344 }
355345
346+ final Point2D p = transformation_ .transform (new Point2D .Double (x , y ), null );
356347 final AffineTransform transformation = new AffineTransform ();
357348 transformation .rotate (rotation , p .getX (), p .getY ());
358- final Arc2D arc = new Arc2D .Double (p .getX () - radiusX , p .getY () - radiusY , radiusX * 2 , radiusY * 2 ,
359- startAngleDegree , extendAngle * -1 , Arc2D .OPEN );
349+
350+ double startAngleDegree = Math .toDegrees (startAngle );
351+ double endAngleDegree = Math .toDegrees (endAngle );
352+
353+ double extendAngle = endAngleDegree - startAngleDegree ;
354+ final Arc2D arc ;
355+ if (Math .abs (extendAngle ) >= 360 ) {
356+ arc = new Arc2D .Double (p .getX () - radiusX , p .getY () - radiusY , radiusX * 2 , radiusY * 2 ,
357+ 0 , 360 , Arc2D .OPEN );
358+ }
359+ else {
360+ startAngleDegree = reverseAngle (startAngleDegree );
361+ endAngleDegree = reverseAngle (endAngleDegree );
362+
363+ extendAngle = endAngleDegree - startAngleDegree ;
364+ if (!anticlockwise ) {
365+ extendAngle = -reverseAngle (extendAngle );
366+ }
367+
368+ arc = new Arc2D .Double (p .getX () - radiusX , p .getY () - radiusY , radiusX * 2 , radiusY * 2 ,
369+ startAngleDegree , extendAngle , Arc2D .OPEN );
370+ }
360371
361372 // connect=true only if there is already a current point (implicit lineTo behaviour);
362373 // connect=false when the subpath is new so we don't get a spurious line from (0,0)
@@ -401,33 +412,11 @@ public void arc(final double x, final double y, final double radius, final doubl
401412 LOG .debug ("[" + id_ + "] arc()" );
402413 }
403414
404- final Point2D p = transformation_ .transform (new Point2D .Double (x , y ), null );
405- final double startX = p .getX () + radius * Math .cos (-startAngle );
406- final double startY = p .getY () + radius * Math .sin (-startAngle );
407- final double startAngleDegree = 360 - (startAngle * 180 / Math .PI );
408- final double endAngleDegree = 360 - (endAngle * 180 / Math .PI );
409-
410- double extendAngle = startAngleDegree - endAngleDegree ;
411- extendAngle = Math .min (360 , Math .abs (extendAngle ));
412- if (anticlockwise && extendAngle < 360 ) {
413- extendAngle = extendAngle - 360 ;
414- }
415- final Arc2D arc = new Arc2D .Double (p .getX () - radius , p .getY () - radius , radius * 2 , radius * 2 ,
416- startAngleDegree , extendAngle * -1 , Arc2D .OPEN );
415+ ellipse (x , y , radius , radius , 0 , startAngle , endAngle , anticlockwise );
416+ }
417417
418- // connect=true only if there is already a current point (implicit lineTo behaviour);
419- // connect=false when the subpath is new so we don't get a spurious line from (0,0)
420- // or from the moveTo seed point to the arc's own geometric start.
421- final boolean hasCurrentPoint ;
422- if (subPaths_ .isEmpty ()) {
423- final Path2D subPath = new Path2D .Double ();
424- subPaths_ .add (subPath );
425- hasCurrentPoint = false ;
426- }
427- else {
428- hasCurrentPoint = subPaths_ .get (subPaths_ .size () - 1 ).getCurrentPoint () != null ;
429- }
430- getCurrentSubPath ().append (arc , hasCurrentPoint );
418+ private static double reverseAngle (final double degrees ) {
419+ return ((-degrees % 360 ) + 360 ) % 360 ;
431420 }
432421
433422 /**
@@ -592,13 +581,19 @@ public String encodeToString(final String type) throws IOException {
592581 * {@inheritDoc}
593582 */
594583 @ Override
595- public void fill () {
584+ public void fill (final RenderingBackend . WindingRule windingRule ) {
596585 if (LOG .isDebugEnabled ()) {
597- LOG .debug ("[" + id_ + "] fill()" );
586+ LOG .debug ("[" + id_ + "] fill("
587+ + (windingRule == RenderingBackend .WindingRule .EVEN_ODD ? "evenOdd" : "nonZero" ) + ")" );
598588 }
599589
590+ final int awtRule = (windingRule == RenderingBackend .WindingRule .EVEN_ODD )
591+ ? Path2D .WIND_EVEN_ODD
592+ : Path2D .WIND_NON_ZERO ;
593+
600594 graphics2D_ .setColor (fillColor_ );
601595 for (final Path2D path2d : subPaths_ ) {
596+ path2d .setWindingRule (awtRule );
602597 graphics2D_ .fill (path2d );
603598 }
604599 }
0 commit comments