Skip to content

Commit

Permalink
Address review comments in LocationCountingObjectsLayerNode.ts, see: #32
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Dec 14, 2024
1 parent c2aa68a commit 1c3f287
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions js/common/view/LocationCountingObjectsLayerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,6 @@ export default class LocationCountingObjectsLayerNode extends Node {
countingObject.locationPositionProperty.value.y !== gridCoordinate.y ) );
}

/**
* Update the location of the countingObject to be within the correct addend area.
* @param countingObject
* @param addendType - We do not want to rely on listener order and therefore the addendType is passed in.
*/
public updateLocation( countingObject: CountingObject, addendType: AddendType ): void {
const addendBounds = ( addendType === AddendType.LEFT ? this.leftCountingAreaBounds : this.rightCountingAreaBounds ).dilated( -20 );

// Check to see if the countingObject is already in the correct addend area. If it is, we do not want to move it.
if ( !addendBounds.containsPoint( countingObject.locationPositionProperty.value ) ) {
countingObject.locationPositionProperty.value = dotRandom.sample( this.model.getGridCoordinates( addendBounds, COUNTING_AREA_MARGIN, COUNTING_AREA_MARGIN, 6 ) );
}
}

/**
* As the counting object changes location, we need to update the addend arrays.
* @param countingObject
Expand All @@ -175,6 +161,11 @@ export default class LocationCountingObjectsLayerNode extends Node {
public handleLocationChange( countingObject: CountingObject, newPosition: Vector2 ): void {
const leftAddendCountingObjects = this.model.leftAddendCountingObjectsProperty.value;
const rightAddendCountingObjects = this.model.rightAddendCountingObjectsProperty.value;

// If the countingObject is in the left addend area, remove it from the right addend area and add it to the
// left addend area and vice versa.
// This function will no-op if the countingObject is not in the left or right addend area, or if it is already in
// the correct countingObject array.
if ( this.leftCountingAreaBounds.containsPoint( newPosition ) &&
!leftAddendCountingObjects.includes( countingObject ) &&
rightAddendCountingObjects.includes( countingObject ) ) {
Expand Down

0 comments on commit 1c3f287

Please sign in to comment.