mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[libgdx] Inlined line intersection in clipper, faster on Android
This commit is contained in:
parent
7245115a63
commit
a665b0e598
@ -65,7 +65,15 @@ public class SutherlandHodgmanClipper {
|
|||||||
}
|
}
|
||||||
// v1 inside, v2 outside
|
// v1 inside, v2 outside
|
||||||
else {
|
else {
|
||||||
intersectLines(edgeX, edgeY, edgeX2, edgeY2, inputX, inputY, inputX2, inputY2, output);
|
float c0 = inputY2 - inputY;
|
||||||
|
float c1 = edgeX2 - edgeX;
|
||||||
|
float c2 = inputX2 - inputX;
|
||||||
|
float c3 = edgeY2 - edgeY;
|
||||||
|
float d = c0 * c1 - c2 * c3;
|
||||||
|
|
||||||
|
float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / d;
|
||||||
|
output.add(edgeX + (edgeX2 - edgeX) * ua);
|
||||||
|
output.add(edgeY + (edgeY2 - edgeY) * ua);
|
||||||
clipped = true;
|
clipped = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -77,7 +85,16 @@ public class SutherlandHodgmanClipper {
|
|||||||
}
|
}
|
||||||
// v1 outside, v2 inside
|
// v1 outside, v2 inside
|
||||||
else {
|
else {
|
||||||
intersectLines(edgeX, edgeY, edgeX2, edgeY2, inputX, inputY, inputX2, inputY2, output);
|
float c0 = inputY2 - inputY;
|
||||||
|
float c1 = edgeX2 - edgeX;
|
||||||
|
float c2 = inputX2 - inputX;
|
||||||
|
float c3 = edgeY2 - edgeY;
|
||||||
|
float d = c0 * c1 - c2 * c3;
|
||||||
|
|
||||||
|
float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / d;
|
||||||
|
output.add(edgeX + (edgeX2 - edgeX) * ua);
|
||||||
|
output.add(edgeY + (edgeY2 - edgeY) * ua);
|
||||||
|
|
||||||
output.add(inputX2);
|
output.add(inputX2);
|
||||||
output.add(inputY2);
|
output.add(inputY2);
|
||||||
clipped = true;
|
clipped = true;
|
||||||
@ -112,19 +129,6 @@ public class SutherlandHodgmanClipper {
|
|||||||
return clipped;
|
return clipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void intersectLines (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4,
|
|
||||||
FloatArray output) {
|
|
||||||
float c0 = y4 - y3;
|
|
||||||
float c1 = x2 - x1;
|
|
||||||
float c2 = x4 - x3;
|
|
||||||
float c3 = y2 - y1;
|
|
||||||
float d = c0 * c1 - c2 * c3;
|
|
||||||
|
|
||||||
float ua = (c2 * (y1 - y3) - c0 * (x1 - x3)) / d;
|
|
||||||
output.add(x1 + (x2 - x1) * ua);
|
|
||||||
output.add(y1 + (y2 - y1) * ua);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void makeClockwise (FloatArray poly) {
|
public static void makeClockwise (FloatArray poly) {
|
||||||
if (clockwise(poly)) return;
|
if (clockwise(poly)) return;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user