phetsims/paper-land

Focus program paper affects markers on other program papers

Opened this issue · 3 comments

Describe the bug
When I move the focus program onto and off of the checked checkbox, the state of the checkbox is changes.
The focus program seems to the coming in between the mark and the checkbox program and thus unintentionally hiding and then revealing the marker on the checkbox program causing checking and unchecking events to fire.

To Reproduce
Steps to reproduce the behavior:

  1. Go to voicing-response-patterns space, look for 'checkbox-responses'
  2. Send to Playground
  3. Activate the programs and add a marker to the checkbox paper
  4. Move the focus program on and off of the checkbox paper ensuring to go over the marker.
movingFocusBug.mov

The original paper-programs project supports only one program per marker. Relevant code is

paper-land/client/utils.js

Lines 166 to 196 in 4a2ce24

/**
* Find the program that the marker is on. Based no based on
* http://demonstrations.wolfram.com/AnEfficientTestForAPointToBeInAConvexPolygon/
*
* @param markerPosition - center of the marker
* @param listOfPrograms - all Programs to see if the marker is inside any of them
* @returns {*} - program object or null if not inside a program
*/
export function findProgramContainingMarker( markerPosition, listOfPrograms ) {
return listOfPrograms.find( ( { points } ) => {
for ( let i = 0; i < 4; i++ ) {
const a = i;
const b = ( i + 1 ) % 4;
const sideA = diff( points[ a ], markerPosition );
const sideB = diff( points[ b ], markerPosition );
let angle = Math.atan2( sideB.y, sideB.x ) - Math.atan2( sideA.y, sideA.x );
if ( sideB.y < 0 && sideA.y > 0 ) {
angle += 2 * Math.PI;
}
if ( angle > Math.PI || angle < 0 ) {
return false;
}
}
return true;
} );
}

// Handle any changing markers - addition/removal/or position change
const currentMarkersForProgram = _.filter( currentMarkersInfo, marker => parseInt( marker.paperNumber, 10 ) === paperProgramNumber );
const previousMarkersForProgram = this.mapOfPaperProgramNumbersToPreviousMarkers.get( paperProgramNumber ) || [];
let markersMoved = false;

and the markers API https://github.com/janpaul123/paperprograms/blob/master/docs/api.md#marker-points

Lets discuss alternatives and decide if this is something we would like to work on changing.

Possible options, not sure of cost of any:

  1. Choose the smaller program (very specific to our use case)
  2. Ignore programs without marker code (no contents in onMarkerAdded/Removed/ChangedPosition)
  3. Allow markers to trigger multiple programs (nothing would happen if no marker code)

For now, we will try shifting the way we focus to a whisker instead of a position within bounds. If that is a problem we can revisit this. This might crop up elsewhere as a problem.