Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ protected boolean setupFillPaint(Paint paint, float opacity) {
return false;
}

/**
* Returns the floor modulus of the float arguments. Java modulus will return a negative remainder
* when the divisor is negative. Modulus should always be positive. This mimics the behavior of
* Math.floorMod, introduced in Java 8.
*/
private float modulus(float x, float y) {
float remainder = x % y;
float modulus = remainder;
if (remainder < 0) {
modulus += y;
}
return modulus;
}

/**
* Creates a {@link Path} from an array of instructions constructed by JS
* (see ARTSerializablePath.js). Each instruction starts with a type (see PATH_TYPE_*) followed
Expand Down Expand Up @@ -232,11 +246,18 @@ private Path createPath(float[] data) {
float r = data[i++] * mScale;
float start = (float) Math.toDegrees(data[i++]);
float end = (float) Math.toDegrees(data[i++]);
boolean clockwise = data[i++] == 0f;
if (!clockwise) {
end = 360 - end;
boolean clockwise = data[i++] == 1f;
float sweep = end - start;
if (Math.abs(sweep) > 360) {
sweep = 360;
} else {
sweep = modulus(sweep, 360);
}
if (!clockwise && sweep < 360) {
start = end;
sweep = 360 - sweep;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If start === end already and sweep is 0, is this correct?

}
float sweep = start - end;

RectF oval = new RectF(x - r, y - r, x + r, y + r);
path.addArc(oval, start, sweep);
break;
Expand Down