Fix ARTShape arc
Reviewed By: AaaChiuuu Differential Revision: D4871406 fbshipit-source-id: 7f777048c6756399b309e34cf3341c4263467b0b
This commit is contained in:
parent
6b900dc7fb
commit
8290cd7ce2
|
@ -191,6 +191,20 @@ public class ARTShapeShadowNode extends ARTVirtualNode {
|
|||
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
|
||||
|
@ -232,13 +246,21 @@ public class ARTShapeShadowNode extends ARTVirtualNode {
|
|||
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);
|
||||
}
|
||||
float sweep = start - end;
|
||||
if (!clockwise && sweep < 360) {
|
||||
start = end;
|
||||
sweep = 360 - sweep;
|
||||
}
|
||||
|
||||
RectF oval = new RectF(x - r, y - r, x + r, y + r);
|
||||
path.addArc(oval, start, sweep);
|
||||
path.arcTo(oval, start, sweep);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue