Skip to content

ModelViewTransform2

Under Construction

This documentation is auto-generated, and is a work in progress. Please see the source code at https://github.com/phetsims/phetcommon/blob/main/js/view/ModelViewTransform2.ts for the most up-to-date information.

Overview

Transform between model and view coordinate frames, and provides convenience methods beyond phet.dot.Transform3

Requires that the transform is "aligned", i.e., it can be built only from component-wise translation and scaling. Equivalently, the output x coordinate should not depend on the input y, and the output y shouldn't depend on the input x.

@author Jonathan Olson <jonathan.olson@colorado.edu> @author Sam Reid (PhET Interactive Simulations)

Class ModelViewTransform2

import { ModelViewTransform2 } from 'scenerystack/phetcommon';

Instance Methods

modelToViewPosition( point : Vector2 ) : Vector2


convenience model => view

modelToViewXY( x : number, y : number ) : Vector2

modelToViewX( x : number ) : number

modelToViewY( y : number ) : number

modelToViewDelta( vector : Vector2 ) : Vector2

modelToViewNormal( normal : Vector2 ) : Vector2

modelToViewDeltaX( x : number ) : number

modelToViewDeltaY( y : number ) : number

modelToViewBounds( bounds : Bounds2 ) : Bounds2

modelToViewShape( shape : Shape ) : Shape

modelToViewRay( ray : Ray2 ) : Ray2

viewToModelPosition( point : Vector2 ) : Vector2


convenience view => model

viewToModelXY( x : number, y : number ) : Vector2

viewToModelX( x : number ) : number

viewToModelY( y : number ) : number

viewToModelDelta( vector : Vector2 ) : Vector2

viewToModelDeltaXY( x : number, y : number ) : Vector2

viewToModelNormal( normal : Vector2 ) : Vector2

viewToModelDeltaX( x : number ) : number

viewToModelDeltaY( y : number ) : number

viewToModelBounds( bounds : Bounds2 ) : Bounds2

viewToModelShape( shape : Shape ) : Shape

viewToModelRay( ray : Ray2 ) : Ray2

validateMatrix( matrix : Matrix3 )

(protected)

setToRectangleMapping( modelBounds : Bounds2, viewBounds : Bounds2 ) : this

See ModelViewTransform2.createRectangleMapping

setToRectangleInvertedYMapping( modelBounds : Bounds2, viewBounds : Bounds2 ) : this

See ModelViewTransform2.createRectangleInvertedYMapping

Static Methods

createIdentity() : ModelViewTransform2

Creates a ModelViewTransform2 that uses the identity transform (i.e. model coordinates are the same as view coordinates)

createOffsetScaleMapping( offset : Vector2, scale : number ) : ModelViewTransform2

Creates a ModelViewTransform2 that has the specified scale and offset such that view = model * scale + offset

@param offset - the offset in view coordinates @param scale - the scale to map model to view

createOffsetXYScaleMapping( offset : Vector2, xScale : number, yScale : number ) : ModelViewTransform2

Creates a shearless ModelViewTransform2 that has the specified scale and offset such that view.x = model.x * xScale + offset.x view.y = model.y * yScale + offset.y

@param offset - the offset in view coordinates @param xScale - the scale to map model to view in the x-dimension @param yScale - the scale to map model to view in the y-dimension

createSinglePointXYScaleMapping( modelPoint : Vector2, viewPoint : Vector2, xScale : number, yScale : number ) : ModelViewTransform2

Creates a shearless ModelViewTransform2 that maps the specified model point to the specified view point, with the given x and y scales.

@param modelPoint - the reference point in the model which maps to the specified view point @param viewPoint - the reference point in the view @param xScale - the amount to scale in the x direction @param yScale - the amount to scale in the y direction

createSinglePointScaleMapping( modelPoint : Vector2, viewPoint : Vector2, scale : number ) : ModelViewTransform2

Creates a shearless ModelViewTransform2 that maps the specified model point to the specified view point, with the given scale factor for both x and y dimensions.

@param modelPoint - the reference point in the model which maps to the specified view point @param viewPoint - the reference point in the view @param scale - the amount to scale in the x and y directions

createSinglePointScaleInvertedYMapping( modelPoint : Vector2, viewPoint : Vector2, scale : number ) : ModelViewTransform2

Creates a shearless ModelViewTransform2 that maps the specified model point to the specified view point, with the given scale factor for both x and y dimensions, but inverting the y axis so that +y in the model corresponds to -y in the view. Inverting the y axis is commonly necessary since +y is usually up in textbooks and -y is down in pixel coordinates.

@param modelPoint - the reference point in the model which maps to the specified view point @param viewPoint - the reference point in the view @param scale - the amount to scale in the x and y directions

createRectangleMapping( modelBounds : Bounds2, viewBounds : Bounds2 ) : ModelViewTransform2

Creates a shearless ModelViewTransform2 that maps the specified rectangle in the model to the specified rectangle in the view, so that any point x% of the way across and y% down in the model rectangle will be mapped to the corresponding point x% across and y% down in the view rectangle. Linear extrapolation is performed outside of the rectangle bounds.

@param modelBounds - the reference rectangle in the model, must have area > 0 @param viewBounds - the reference rectangle in the view, must have area > 0

createRectangleInvertedYMapping( modelBounds : Bounds2, viewBounds : Bounds2 ) : ModelViewTransform2

Creates a shearless ModelViewTransform2 that maps the specified rectangle in the model to the specified rectangle in the view, so that any point x% of the way across and y% down in the model rectangle will be mapped to the corresponding point x% across and (100-y)% down in the view rectangle. Linear extrapolation is performed outside of the rectangle bounds. Inverting the y axis is commonly necessary since +y is usually up in textbooks and -y is down in pixel coordinates.

@param modelBounds - the reference rectangle in the model, must have area > 0 @param viewBounds - the reference rectangle in the view, must have area > 0

Source Code

See the source for ModelViewTransform2.ts in the phetcommon repository.