Browse Source

Safer CanvasRenderer's expand().

Mr.doob 14 years ago
parent
commit
0ceb528837
1 changed files with 6 additions and 3 deletions
  1. 6 3
      src/renderers/CanvasRenderer.js

+ 6 - 3
src/renderers/CanvasRenderer.js

@@ -986,15 +986,18 @@ THREE.CanvasRenderer = function ( parameters ) {
 		function expand( v1, v2 ) {
 
 			var x = v2.x - v1.x, y =  v2.y - v1.y,
-			unit = 1 / Math.sqrt( x * x + y * y );
+			det = x * x + y * y, idet;
 
-			x *= unit; y *= unit;
+			if ( det == 0 ) return;
+
+			idet = 1 / Math.sqrt( det );
+
+			x *= idet; y *= idet;
 
 			v2.x += x; v2.y += y;
 			v1.x -= x; v1.y -= y;
 
 		}
-
 	};
 
 	// Context cached methods.