Sfoglia il codice sorgente

move check into parse arc function

Greg Zanchelli 4 anni fa
parent
commit
139866dd3f
1 ha cambiato i file con 20 aggiunte e 25 eliminazioni
  1. 20 25
      examples/jsm/loaders/SVGLoader.js

+ 20 - 25
examples/jsm/loaders/SVGLoader.js

@@ -282,7 +282,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 						}
 
 						break;
-	
+
 					case 'L':
 						var numbers = parseFloats( data );
 
@@ -398,25 +398,18 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 						var numbers = parseFloats( data );
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
+							
 							// skip command if start point == end point
-							if( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue
+							if( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue;
 
-							
 							var start = point.clone();
 							point.x = numbers[ j + 5 ];
 							point.y = numbers[ j + 6 ];
 							control.x = point.x;
 							control.y = point.y;
-
-							if( numbers[ j ] == 0 || numbers[ j + 1 ] == 0 ) {
-								// draw a line if either of the radii == 0
-								path.lineTo( point.x, point.y );
-							}
-							else {
-								parseArcCommand(
-									path, numbers[ j ], numbers[ j + 1 ], numbers[ j + 2 ], numbers[ j + 3 ], numbers[ j + 4 ], start, point
-								);
-							}
+							parseArcCommand(
+								path, numbers[ j ], numbers[ j + 1 ], numbers[ j + 2 ], numbers[ j + 3 ], numbers[ j + 4 ], start, point
+							);
 
 							if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
 
@@ -595,27 +588,23 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 					case 'a':
 						var numbers = parseFloats( data );
+
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
-							// skip command if start point == end point
-							if( numbers[ j + 5 ] == 0 && numbers[ j + 6 ] == 0 ) continue
+
+							// skip command if no displacement
+							if( numbers[ j + 5 ] == 0 && numbers[ j + 6 ] == 0 ) continue;
 
 							var start = point.clone();
 							point.x += numbers[ j + 5 ];
 							point.y += numbers[ j + 6 ];
 							control.x = point.x;
 							control.y = point.y;
-
-							if( numbers[ j ] == 0 || numbers[ j + 1 ] == 0 ) {
-								// draw a line if either of the radii == 0
-								path.lineTo( point.x, point.y );
-							}
-							else {
-								parseArcCommand(
-									path, numbers[ j ], numbers[ j + 1 ], numbers[ j + 2 ], numbers[ j + 3 ], numbers[ j + 4 ], start, point
-								);
-							}
+							parseArcCommand(
+								path, numbers[ j ], numbers[ j + 1 ], numbers[ j + 2 ], numbers[ j + 3 ], numbers[ j + 4 ], start, point
+							);
 
 							if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
+
 						}
 
 						break;
@@ -689,6 +678,12 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 		function parseArcCommand( path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end ) {
 
+			if( rx == 0 || ry == 0 ) {
+				// draw a line if either of the radii == 0
+				path.lineTo( end.x, end.y );
+				return;
+			}
+
 			x_axis_rotation = x_axis_rotation * Math.PI / 180;
 
 			// Ensure radii are positive