diff --git a/js/ops/Graph.js b/js/ops/Graph.js index 07ef4d1..ddaf715 100644 --- a/js/ops/Graph.js +++ b/js/ops/Graph.js @@ -419,44 +419,44 @@ class Graph { needsLoop = false; for ( let i = 0; i < this.vertices.length; i++ ) { - const vertex = this.vertices[ i ]; - if ( vertex.incidentHalfEdges.length === 2 ) { - const aEdge = vertex.incidentHalfEdges[ 0 ].edge; - const bEdge = vertex.incidentHalfEdges[ 1 ].edge; - let aSegment = aEdge.segment; - let bSegment = bEdge.segment; - const aVertex = aEdge.getOtherVertex( vertex ); - const bVertex = bEdge.getOtherVertex( vertex ); - - assert && assert( this.loops.length === 0 ); - - // TODO: Can we avoid this in the inner loop? - if ( aEdge.startVertex === vertex ) { - aSegment = aSegment.reversed(); - } - if ( bEdge.endVertex === vertex ) { - bSegment = bSegment.reversed(); - } + const vertex = this.vertices[ i ]; + if ( vertex.incidentHalfEdges.length === 2 ) { + const aEdge = vertex.incidentHalfEdges[ 0 ].edge; + const bEdge = vertex.incidentHalfEdges[ 1 ].edge; + let aSegment = aEdge.segment; + let bSegment = bEdge.segment; + const aVertex = aEdge.getOtherVertex( vertex ); + const bVertex = bEdge.getOtherVertex( vertex ); + + assert && assert( this.loops.length === 0 ); + + // TODO: Can we avoid this in the inner loop? + if ( aEdge.startVertex === vertex ) { + aSegment = aSegment.reversed(); + } + if ( bEdge.endVertex === vertex ) { + bSegment = bSegment.reversed(); + } - if ( aSegment instanceof Line && bSegment instanceof Line ) { - // See if the lines are collinear, so that we can combine them into one edge - if ( aSegment.tangentAt( 0 ).normalized().distance( bSegment.tangentAt( 0 ).normalized() ) < 1e-6 ) { - this.removeEdge( aEdge ); - this.removeEdge( bEdge ); - aEdge.dispose(); - bEdge.dispose(); - arrayRemove( this.vertices, vertex ); - vertex.dispose(); - - const newSegment = new Line( aVertex.point, bVertex.point ); - this.addEdge( new Edge( newSegment, aVertex, bVertex ) ); - - needsLoop = true; - break; - } + if ( aSegment instanceof Line && bSegment instanceof Line ) { + // See if the lines are collinear, so that we can combine them into one edge + if ( aSegment.tangentAt( 0 ).normalized().distance( bSegment.tangentAt( 0 ).normalized() ) < 1e-6 ) { + this.removeEdge( aEdge ); + this.removeEdge( bEdge ); + aEdge.dispose(); + bEdge.dispose(); + arrayRemove( this.vertices, vertex ); + vertex.dispose(); + + const newSegment = new Line( aVertex.point, bVertex.point ); + this.addEdge( new Edge( newSegment, aVertex, bVertex ) ); + + needsLoop = true; + break; } } } + } } } @@ -935,25 +935,25 @@ class Graph { needsLoop = false; for ( let i = this.vertices.length - 1; i >= 0; i-- ) { - const vertex = this.vertices[ i ]; - - if ( vertex.incidentHalfEdges.length < 2 ) { - // Disconnect any existing edges - for ( let j = 0; j < vertex.incidentHalfEdges.length; j++ ) { - const edge = vertex.incidentHalfEdges[ j ].edge; - this.removeEdge( edge ); - this.replaceEdgeInLoops( edge, [] ); // remove the edge from the loops - edge.dispose(); - } + const vertex = this.vertices[ i ]; + + if ( vertex.incidentHalfEdges.length < 2 ) { + // Disconnect any existing edges + for ( let j = 0; j < vertex.incidentHalfEdges.length; j++ ) { + const edge = vertex.incidentHalfEdges[ j ].edge; + this.removeEdge( edge ); + this.replaceEdgeInLoops( edge, [] ); // remove the edge from the loops + edge.dispose(); + } - // Remove the vertex - this.vertices.splice( i, 1 ); - vertex.dispose(); + // Remove the vertex + this.vertices.splice( i, 1 ); + vertex.dispose(); - needsLoop = true; - break; - } + needsLoop = true; + break; } + } } assert && assert( _.every( this.edges, edge => _.includes( this.vertices, edge.startVertex ) ) ); assert && assert( _.every( this.edges, edge => _.includes( this.vertices, edge.endVertex ) ) ); diff --git a/js/segments/Arc.js b/js/segments/Arc.js index a57c819..de1aeee 100644 --- a/js/segments/Arc.js +++ b/js/segments/Arc.js @@ -625,7 +625,7 @@ class Arc extends Segment { if ( this.angleDifference < Math.PI * 2 - epsilon ) { largeArcFlag = this.angleDifference < Math.PI ? '0' : '1'; this._svgPathFragment = `A ${kite.svgNumber( this._radius )} ${kite.svgNumber( this._radius )} 0 ${largeArcFlag - } ${sweepFlag} ${kite.svgNumber( this.end.x )} ${kite.svgNumber( this.end.y )}`; + } ${sweepFlag} ${kite.svgNumber( this.end.x )} ${kite.svgNumber( this.end.y )}`; } else { // circle (or almost-circle) case needs to be handled differently @@ -638,9 +638,9 @@ class Arc extends Segment { largeArcFlag = '0'; // since we split it in 2, it's always the small arc const firstArc = `A ${kite.svgNumber( this._radius )} ${kite.svgNumber( this._radius )} 0 ${ - largeArcFlag} ${sweepFlag} ${kite.svgNumber( splitPoint.x )} ${kite.svgNumber( splitPoint.y )}`; + largeArcFlag} ${sweepFlag} ${kite.svgNumber( splitPoint.x )} ${kite.svgNumber( splitPoint.y )}`; const secondArc = `A ${kite.svgNumber( this._radius )} ${kite.svgNumber( this._radius )} 0 ${ - largeArcFlag} ${sweepFlag} ${kite.svgNumber( this.end.x )} ${kite.svgNumber( this.end.y )}`; + largeArcFlag} ${sweepFlag} ${kite.svgNumber( this.end.x )} ${kite.svgNumber( this.end.y )}`; this._svgPathFragment = `${firstArc} ${secondArc}`; } diff --git a/js/segments/Cubic.js b/js/segments/Cubic.js index 79c52d7..e2efa5d 100644 --- a/js/segments/Cubic.js +++ b/js/segments/Cubic.js @@ -722,8 +722,8 @@ class Cubic extends Segment { } if ( !this._svgPathFragment ) { this._svgPathFragment = `C ${kite.svgNumber( this._control1.x )} ${kite.svgNumber( this._control1.y )} ${ - kite.svgNumber( this._control2.x )} ${kite.svgNumber( this._control2.y )} ${ - kite.svgNumber( this._end.x )} ${kite.svgNumber( this._end.y )}`; + kite.svgNumber( this._control2.x )} ${kite.svgNumber( this._control2.y )} ${ + kite.svgNumber( this._end.x )} ${kite.svgNumber( this._end.y )}`; } if ( assert ) { if ( oldPathFragment ) { diff --git a/js/segments/EllipticalArc.js b/js/segments/EllipticalArc.js index 6251b43..5b56c2d 100644 --- a/js/segments/EllipticalArc.js +++ b/js/segments/EllipticalArc.js @@ -794,7 +794,7 @@ class EllipticalArc extends Segment { if ( this.getAngleDifference() < Math.PI * 2 - epsilon ) { largeArcFlag = this.getAngleDifference() < Math.PI ? '0' : '1'; this._svgPathFragment = `A ${kite.svgNumber( this._radiusX )} ${kite.svgNumber( this._radiusY )} ${degreesRotation - } ${largeArcFlag} ${sweepFlag} ${kite.svgNumber( this.getEnd().x )} ${kite.svgNumber( this.getEnd().y )}`; + } ${largeArcFlag} ${sweepFlag} ${kite.svgNumber( this.getEnd().x )} ${kite.svgNumber( this.getEnd().y )}`; } else { // ellipse (or almost-ellipse) case needs to be handled differently @@ -807,11 +807,11 @@ class EllipticalArc extends Segment { largeArcFlag = '0'; // since we split it in 2, it's always the small arc const firstArc = `A ${kite.svgNumber( this._radiusX )} ${kite.svgNumber( this._radiusY )} ${ - degreesRotation} ${largeArcFlag} ${sweepFlag} ${ - kite.svgNumber( splitPoint.x )} ${kite.svgNumber( splitPoint.y )}`; + degreesRotation} ${largeArcFlag} ${sweepFlag} ${ + kite.svgNumber( splitPoint.x )} ${kite.svgNumber( splitPoint.y )}`; const secondArc = `A ${kite.svgNumber( this._radiusX )} ${kite.svgNumber( this._radiusY )} ${ - degreesRotation} ${largeArcFlag} ${sweepFlag} ${ - kite.svgNumber( this.getEnd().x )} ${kite.svgNumber( this.getEnd().y )}`; + degreesRotation} ${largeArcFlag} ${sweepFlag} ${ + kite.svgNumber( this.getEnd().x )} ${kite.svgNumber( this.getEnd().y )}`; this._svgPathFragment = `${firstArc} ${secondArc}`; } diff --git a/js/segments/Quadratic.js b/js/segments/Quadratic.js index 95e4bd5..21e31f5 100644 --- a/js/segments/Quadratic.js +++ b/js/segments/Quadratic.js @@ -500,7 +500,7 @@ class Quadratic extends Segment { } if ( !this._svgPathFragment ) { this._svgPathFragment = `Q ${kite.svgNumber( this._control.x )} ${kite.svgNumber( this._control.y )} ${ - kite.svgNumber( this._end.x )} ${kite.svgNumber( this._end.y )}`; + kite.svgNumber( this._end.x )} ${kite.svgNumber( this._end.y )}`; } if ( assert ) { if ( oldPathFragment ) {