[libgdx] Early out if all edges of a triangle are outside the clip region

This commit is contained in:
badlogic 2017-03-28 18:16:45 +02:00
parent 242eaf2bcc
commit 7245115a63

View File

@ -45,6 +45,8 @@ public class SutherlandHodgmanClipper {
final float[] inputVertices = input.items;
final int inputVerticesLength = input.size - 2;
int numOutside = 0;
for (int j = 0; j < inputVerticesLength; j += 2) {
final float inputX = inputVertices[j];
@ -71,6 +73,7 @@ public class SutherlandHodgmanClipper {
if (side2 < 0) {
// no output
clipped = true;
numOutside += 2;
}
// v1 outside, v2 inside
else {
@ -81,6 +84,12 @@ public class SutherlandHodgmanClipper {
}
}
}
// early out if all edges were outside
if (numOutside == inputVerticesLength) {
originalOutput.clear();
return true;
}
output.add(output.items[0]);
output.add(output.items[1]);