new Transform( [options])
Creates a new Transform instance
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
options |
TransformParameters |
<optional> |
Transform configuration |
- Source:
Example
```javascript // Create identity transform const t1 = new Transform(); // Create custom transform const t2 = new Transform({ x: 100, // Translate 100 units in x y: 50, // Translate 50 units in y a: 45, // Rotate 45 degrees z: 2 // Scale by factor of 2 }); ```
Methods
-
<static> interpolate(source, target, time, easing)
-
Interpolates between two transforms
Parameters:
Name Type Description source
Transform Starting transform
target
Transform Ending transform
time
number Current time for interpolation
easing
EasingFunction Easing function type
- Source:
Returns:
Interpolated transform
- Type
- Transform
Example
```javascript const start = new Transform({x: 0, y: 0}); const end = new Transform({x: 100, y: 100}); const mid = Transform.interpolate(start, end, 500, 'ease-out'); ```
-
<static> normalizeAngle(a)
-
Normalizes angle to range [0, 360]
Parameters:
Name Type Description a
number Angle in degrees
- Source:
Returns:
Normalized angle
- Type
- number
-
<static> rotate(x, y, a)
-
Rotates point (x,y) by angle a around Z axis
Parameters:
Name Type Description x
number X coordinate to rotate
y
number Y coordinate to rotate
a
number Rotation angle in degrees
- Source:
Returns:
Rotated point
- Type
- Point
-
apply(x, y)
-
Applies transform to a point (x,y) Performs full affine transformation: scale, rotate, translate
Parameters:
Name Type Description x
number X coordinate to transform
y
number Y coordinate to transform
- Source:
Returns:
Transformed point
- Type
- Point
Example
```javascript const transform = new Transform({x: 10, y: 20, a: 45, z: 2}); const result = transform.apply(5, 5); // Returns rotated, scaled, and translated point ```
-
compose(transform)
-
Composes two transforms: this * transform Applies this transform first, then the provided transform
Parameters:
Name Type Description transform
Transform Transform to compose with
- Source:
Returns:
Combined transformation
- Type
- Transform
Example
```javascript const t1 = new Transform({x: 10, a: 45}); const t2 = new Transform({z: 2}); const combined = t1.compose(t2); // Results in rotation, then scale, then translation ```
-
copy()
-
Creates a deep copy of the transform
- Source:
Returns:
New transform with identical parameters
- Type
- Transform
-
getInverseBox(viewport)
-
Computes viewport bounds in image space Accounts for coordinate system differences between viewport and image
Parameters:
Name Type Description viewport
Viewport Current viewport
- Source:
Returns:
Bounds in image space
- Type
- BoundingBox
-
inverse()
-
Computes inverse transformation Creates transform that undoes this transform's effects
- Source:
Returns:
Inverse transform
- Type
- Transform
-
print( [str] [, precision])
-
Prints transform parameters for debugging
Parameters:
Name Type Argument Default Description str
string <optional>
"" Prefix string
precision
number <optional>
0 Decimal precision
- Source:
-
projectionMatrix(viewport)
-
Generates WebGL projection matrix Combines transform with viewport for rendering
Parameters:
Name Type Description viewport
Viewport Current viewport
- Source:
Returns:
4x4 projection matrix in column-major order
- Type
- Array.<number>
-
sceneToViewportCoords(viewport, p)
-
Converts scene coordinates to viewport coordinates
Parameters:
Name Type Description viewport
Viewport Current viewport
p
APoint Point in scene space
- Source:
Returns:
Point in viewport space [0..w-1, 0..h-1]
- Type
- APoint
-
transformBox(box)
-
Transforms a bounding box through this transform
Parameters:
Name Type Description box
BoundingBox Box to transform
- Source:
Returns:
Transformed bounding box
- Type
- BoundingBox
-
viewportToSceneCoords(viewport, p)
-
Converts viewport coordinates to scene coordinates
Parameters:
Name Type Description viewport
Viewport Current viewport
p
APoint Point in viewport space [0..w-1, 0..h-1]
- Source:
Returns:
Point in scene space
- Type
- APoint