Skip to content

Commit

Permalink
Improve coordinate frames, see #95
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 19, 2024
1 parent d798975 commit bec5550
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion js/least-squares-regression/model/DataPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class DataPoint {
/**
* Function that animates the DataPoint back to the bucket.
*/
public animate(): void {
public animateBackToBucket(): void {
this.animatingProperty.set( true );

const distance = this.positionProperty.initialValue.distance( this.positionProperty.value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default class LeastSquaresRegressionModel {
*/
public returnAllDataPointsToBucket(): void {
this.dataPoints.forEach( dataPoint => {
dataPoint.animate();
dataPoint.animateBackToBucket();
} );
}

Expand All @@ -210,7 +210,7 @@ export default class LeastSquaresRegressionModel {
const isOnGraph = this.graph.isDataPointPositionOverlappingGraph( dataPoint.positionProperty.value );
if ( !isOnGraph && !userControlled ) {
// return the dataPoint to the bucket
dataPoint.animate();
dataPoint.animateBackToBucket();
}
};

Expand Down
6 changes: 4 additions & 2 deletions js/least-squares-regression/view/DataPointCreatorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ export default class DataPointCreatorNode extends Node {
this.addInputListener( DragListener.createForwardingListener( event => {

// Determine the initial position (set to be one circle radius above the pointer point)
const initialPosition = event.pointer.point;
const viewPosition = this.globalToParentPoint( event.pointer.point );

// Create and add the new model element.
const dataPoint = new DataPoint( modelViewTransform.viewToModelPosition( initialPosition ) );
const modelPosition = modelViewTransform.viewToModelPosition( viewPosition );

const dataPoint = new DataPoint( modelPosition );
dataPoint.userControlledProperty.set( true );
const dynamicDataPointNode = addDataPointToModel( dataPoint );

Expand Down

0 comments on commit bec5550

Please sign in to comment.