Class IconPoint

The IconPoint class
A point that exists inside/outside a virtual rectangle. The point's position inside/outside of the rectangle is maintained when the rectangle is rotated.

// Create a rectangle at the position of (0,0)
const rectangle = { x: 0, y: 0 };
// Make the dimensions of the rectangle 100x50
const bounds = { width: 100, height: 50 };
// Create a point at the top left corner of the rectangle
const point = { x: 1, y: 1 };
// Create an icon point that will track the point on this rectangle when it moves/rotates
const tlPoint = new IconPoint(rectangle, bounds, point);

Constructors

  • Parameters

    • pPoint: Point

      The rectangle this icon point exists inside/outside of.

    • pBounds: Bounds

      The size of the rectangle.

    • pIconPoint: PositionalPoint

      The point that exists inside/outside the rectangle. This is in relative positioning to the rectangle.

    Returns IconPoint

Properties

defaultOffset: Offset = ...

Static offset to use when none is passed.

defaultAnchor: Anchor = ...

Static anchor to use when none is passed. Default value of 0.5 signifies the anchor stars in the middle.

version: string = "VERSION_REPLACE_ME"

The version of the module.

iconPoint: Point = ...

An object storing the position of the point that was set. This is the point on the rectangle.
It can be changed at runtime.


| |
| x |
| |
|_______|

Methods

  • Gets the new point's position inside a rectangle after taking pAngle into account.

    Parameters

    • OptionalpAngle: number = 0

      Rotation of the rectangle this point exists inside/outside of in radians.

    • OptionalpOffset: Offset = IconPoint.defaultOffset

      The offset of the rectangle.

    • OptionalpAnchor: Anchor = IconPoint.defaultAnchor

      The anchor origin of the rectangle.

    Returns void | Point

    The point inside/outside of the rectangle after rotating.

    // Create a rectangle at the position of (0,0)
    const rectangle = { x: 0, y: 0 };
    // Make the dimensions of the rectangle 100x50
    const bounds = { width: 100, height: 50 };
    // Create a point at the top left corner of the rectangle
    const point = { x: 1, y: 1 };
    // Create an icon point that will track the point on this rectangle when it moves/rotates
    const tlPoint = new IconPoint(rectangle, bounds, point);

    // Verify the point is where it should be
    console.log(tlPoint.getPoint()) // { x: 0, y: 0 } This shows that the point is at the position (0,0) which is the top left position of the rectangle

    // Changing the position of the rectangle
    rectangle.x += 100;
    // Verify the point is where it should be after the rectangle changes positions
    console.log(tlPoint.getPoint()) // { x: 100, y: 0 } This shows that the point has moved to the updated position of the rectangle

    // Applying some offsets to the rectangle
    const rectangleOffsets = { x: 25, y: 25 };
    // Verify the point is where it should be after offsets have been applied to the rectangle
    console.log(tlPoint.getPoint(undefined, rectangleOffsets)) // { x: 125, y: 25 } This shows that the point has moved to the updated position based on the offsets of the rectangle

    // Applying some rotation to the rectangle
    const angle = Math.PI;
    // Verify the point is where it should be after rotating the rectangle by `angle`
    console.log(tlPoint.getPoint(angle)) // {x: 200, y: 50.00000000000001} This shows that the point has moved to the updated position after the rectangle had been rotated by `angle`.
  • Resets the point to the original point.

    Returns void

  • Updates the bounds of the rectangle this icon point exists inside/outside of.

    Parameters

    • pBounds: Bounds

      The bounds to update the rectangle with.

    Returns void

  • Transforms the x point.

    Parameters

    • pTransformX: number

      The x transform to transform the x point to.

    Returns void

  • Transforms the y point.

    Parameters

    • pTransformY: number

      The y transform to transform the y point to.

    Returns void

  • Transforms the point.

    Parameters

    • pTransform: Transform

      The transform to transform the point to.

    Returns void