Explorar o código

fixed rounding risk by comparing with EPSILON instead of 0

Juergen Ahting %!s(int64=11) %!d(string=hai) anos
pai
achega
441f4e9f42
Modificáronse 1 ficheiros con 16 adicións e 6 borrados
  1. 16 6
      src/extras/geometries/ExtrudeGeometry.js

+ 16 - 6
src/extras/geometries/ExtrudeGeometry.js

@@ -256,17 +256,27 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 			
 		} else {		// handle special case of colinear edges
 
-			if ( ( ( v_prev_x != 0 ) && ( Math.sign(v_prev_x) != Math.sign(v_next_x) ) ) ||
-				 ( ( v_prev_x == 0 ) && ( Math.sign(v_prev_y) != Math.sign(v_next_y) ) ) ) {
-				// console.log("Warning: lines are a straight spike");
-				v_trans_x = v_prev_x;
-				v_trans_y = v_prev_y;
-				shrink_by = Math.sqrt( v_prev_lensq / 2 );
+			var direction_eq = false;		// assumes: opposite
+			if ( v_prev_x > EPSILON ) {
+				if ( v_next_x > EPSILON ) { direction_eq = true; }
 			} else {
+				if ( v_prev_x < -EPSILON ) {
+					if ( v_next_x < -EPSILON ) { direction_eq = true; }
+				} else {
+					if ( Math.sign(v_prev_y) == Math.sign(v_next_y) ) { direction_eq = true; }
+				}
+			}
+
+			if ( direction_eq ) {
 				// console.log("Warning: lines are a straight sequence");
 				v_trans_x = -v_prev_y;
 				v_trans_y =  v_prev_x;
 				shrink_by = Math.sqrt( v_prev_lensq );
+			} else {
+				// console.log("Warning: lines are a straight spike");
+				v_trans_x = v_prev_x;
+				v_trans_y = v_prev_y;
+				shrink_by = Math.sqrt( v_prev_lensq / 2 );
 			}
 
 		}