Skip to content

Commit

Permalink
Prevent a wire from forming a double connection short, see #117
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jun 1, 2016
1 parent 47a4924 commit e721af8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions js/common/model/Circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,24 @@ define( function( require ) {
return true;
} );

// (7) a wire vertex cannot connect if its neighbor is already proposing a connection
candidateVertices = candidateVertices.filter( function( candidateVertex ) {
var neighbors = circuit.getNeighborCircuitElements( candidateVertex );
for ( var i = 0; i < neighbors.length; i++ ) {
var neighbor = neighbors[ i ];
var oppositeVertex = neighbor.getOppositeVertex( candidateVertex );

// is another node proposing a match to that node?
for ( var k = 0; k < circuit.vertices.length; k++ ) {
var v = circuit.vertices.get( k );
if ( v !== vertex && v !== oppositeVertex && v.position.equals( oppositeVertex.position ) ) {
return false;
}
}
}
return true;
} );

if ( candidateVertices.length === 0 ) {
return null;
}
Expand Down

0 comments on commit e721af8

Please sign in to comment.