viewportTransform

Create a point that is in the same position relative to the destination rectangle, as is the input point relative to the source rectangle.

Relation is expressed is in term of a fraction or percentage. If the point is in the center of the source rectangle, the returned point will be in the center of the destination rectangle.

Parameters

point Vector2

Point to transform.

source Rectangle

Original viewport; source point is relative to this viewport.

destination Rectangle

Viewport used as destination. Resulting point will be relative to this viewport.

Return Value

Type: Vector2

A point located in the same place, relative to the other viewport.

Examples

const source      = Rectangle(100, 100,  50,  50);
const destination = Rectangle(100,   0, 100, 100);

// Corners and center
assert(source.start .viewportTransform(source, destination) == destination.start);
assert(source.center.viewportTransform(source, destination) == destination.center);
assert(source.end   .viewportTransform(source, destination) == destination.end);

// Arbitrary positions
assert(Vector2(125, 100).viewportTransform(source, destination) == Vector2( 150,    0));
assert(Vector2(  0,   0).viewportTransform(source, destination) == Vector2(-100, -200));

Meta