}
float radiusX = (float)location.getWidth() / 2;
float radiusY = (float)location.getHeight() / 2;
final Point2D center = new Point2D.Double(
location.getX() + radiusX,
location.getY() + radiusY
);
double radians1 = Math.toRadians(startAngle);
Point2D point1 = new Point2D.Double(
center.getX() + Math.cos(radians1) * radiusX,
center.getY() - Math.sin(radians1) * radiusY
);
if(beginPath)
{beginSubpath(point1);}
final double endRadians = Math.toRadians(endAngle);
final double quadrantRadians = Math.PI / 2;
double radians2 = Math.min(
radians1 + quadrantRadians - radians1 % quadrantRadians,
endRadians
);
final double kappa = 0.5522847498;
while(true)
{
double segmentX = radiusX * kappa;
double segmentY = radiusY * kappa;
// Endpoint 2.
Point2D point2 = new Point2D.Double(
center.getX() + Math.cos(radians2) * radiusX,
center.getY() - Math.sin(radians2) * radiusY
);
// Control point 1.
double tangentialRadians1 = Math.atan(
-(Math.pow(radiusY,2) * (point1.getX()-center.getX()))
/ (Math.pow(radiusX,2) * (point1.getY()-center.getY()))
);
double segment1 = (
segmentY * (1 - Math.abs(Math.sin(radians1)))
+ segmentX * (1 - Math.abs(Math.cos(radians1)))
) * (radians2-radians1) / quadrantRadians; // TODO: control segment calculation is still not so accurate as it should -- verify how to improve it!!!
Point2D control1 = new Point2D.Double(
point1.getX() + Math.abs(Math.cos(tangentialRadians1) * segment1) * Math.signum(-Math.sin(radians1)),
point1.getY() + Math.abs(Math.sin(tangentialRadians1) * segment1) * Math.signum(-Math.cos(radians1))
);
// Control point 2.
double tangentialRadians2 = Math.atan(
-(Math.pow(radiusY,2) * (point2.getX()-center.getX()))
/ (Math.pow(radiusX,2) * (point2.getY()-center.getY()))
);
double segment2 = (
segmentY * (1 - Math.abs(Math.sin(radians2)))
+ segmentX * (1 - Math.abs(Math.cos(radians2)))
) * (radians2-radians1) / quadrantRadians; // TODO: control segment calculation is still not so accurate as it should -- verify how to improve it!!!
Point2D control2 = new Point2D.Double(
point2.getX() + Math.abs(Math.cos(tangentialRadians2) * segment2) * Math.signum(Math.sin(radians2)),
point2.getY() + Math.abs(Math.sin(tangentialRadians2) * segment2) * Math.signum(Math.cos(radians2))
);
// Draw the current quadrant curve!