Преглед изворни кода

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

badlogic пре 8 година
родитељ
комит
7245115a63

+ 9 - 0
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SutherlandHodgmanClipper.java

@@ -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]);