Skip to content

Commit

Permalink
Addressed fuzz testing issues, see phetsims/circuit-construction-kit-…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jul 26, 2017
1 parent 6919f69 commit 14eaba1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions js/model/Circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,16 @@ define( function( require ) {
var distance = vertex.positionProperty.value.distance( pivotVertex.positionProperty.value );

// If the vertices are too close, they must be translated way
if ( distance < BUMP_AWAY_RADIUS && distance > 0 ) {
if ( distance < BUMP_AWAY_RADIUS ) {

var delta = pivotVertex.positionProperty.value.minus( vertex.positionProperty.value )
.normalized()
.times( -SNAP_RADIUS * 1.5 );
var difference = pivotVertex.positionProperty.value.minus( vertex.positionProperty.value );

// Support when vertex is on the pivot, mainly for fuzz testing. In that case, just move directly to the right
if ( difference.magnitude() === 0 ) {
difference = new Vector2( 1, 0 );
}

var delta = difference.normalized().times( -SNAP_RADIUS * 1.5 );
this.translateVertexGroup( vertex, delta );
}
else {
Expand Down
6 changes: 4 additions & 2 deletions js/view/CircuitElementNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ define( function( require ) {
else {

// End drag for each of the vertices
vertices.forEach( function( vertexProperty ) {
circuitLayerNode.endDrag( event, vertexProperty, dragged );
vertices.forEach( function( vertex ) {
if ( circuitConstructionKitScreenView.circuitConstructionKitModel.circuit.vertices.contains( vertex ) ) {
circuitLayerNode.endDrag( event, vertex, dragged );
}
} );

// Only show the editor when tapped, not on every drag. Also, event could be undefined if this end() was
Expand Down
7 changes: 5 additions & 2 deletions js/view/CircuitLayerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ define( function( require ) {
// before CircuitElements, but solder should be in front of Wires, see
// https://github.com/phetsims/circuit-construction-kit-common/issues/386
self.stepListeners.push( function() {
self.fixSolderLayeringForVertex( vertex );

// make sure the vertex didn't already get removed (like in fuzz testing)
if ( self.mainLayer.indexOfChild( vertex ) >= 0 ) {
self.fixSolderLayeringForVertex( vertex );
}
} );
};
circuit.vertices.addItemAddedListener( addVertexNode );
Expand Down Expand Up @@ -363,7 +367,6 @@ define( function( require ) {
fixSolderLayeringForVertex: function( vertex ) {
var self = this;

// wires in the back, then solder, then fixed length components.
var solderNode = this.getSolderNode( vertex );
var adjacentCircuitElements = this.circuit.getNeighborCircuitElements( vertex );
var adjacentWires = adjacentCircuitElements.filter( function( component ) {return component instanceof Wire;} );
Expand Down

0 comments on commit 14eaba1

Please sign in to comment.