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.
Example:
// 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);
Static Member Summary
Static Public Members | ||
public static |
Static anchor to use when none is passed. |
|
public static |
Static offset to use when none is passed. |
|
public static |
version: * The version of the module. |
Static Private Members | ||
private static |
logger: Logger The logger module this module uses to log errors / logs |
Constructor Summary
Public Constructor | ||
public |
constructor(pPoint: Point, pBounds: Bounds, pIconPoint: PositionalPoint) |
Member Summary
Private Members | ||
private |
bounds: Bounds An object storing the rectangle's size. |
|
private |
iconPoint: Point An object storing the position of the point that was set. |
|
private |
originalPoint: Point |
|
private |
point: Point An object storing the point's position with rotation taken into account. |
|
private |
positionalPoint: Point An object storing the position of the rectangle. |
Method Summary
Public Methods | ||
public |
Gets the new point's position inside a rectangle after taking pAngle into account. |
|
public |
Resets the point to the original point. |
|
public |
transform(pTransform: Transform) Transforms the point. |
|
public |
transformX(pTransformX: number) Transforms the x point. |
|
public |
transformY(pTransformY: number) Transforms the y point. |
|
public |
updateBounds(pBounds: Bounds) Updates the bounds of the rectangle this icon point exists inside/outside of. |
Private Methods | ||
private |
setPoint(pPoint: PositionalPoint) Sets the static point and defines the raw pixels value |
Static Public Members
public static defaultAnchor: * source
Static anchor to use when none is passed. Default value of 0.5 signifies the anchor stars in the middle.
Static Private Members
Public Constructors
public constructor(pPoint: Point, pBounds: Bounds, pIconPoint: PositionalPoint) source
Params:
Name | Type | Attribute | Description |
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. |
Private Members
private iconPoint: Point source
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 | | | |___|
private originalPoint: Point source
private point: Point source
An object storing the point's position with rotation taken into account.
Public Methods
public getPoint(pAngle: number, pOffset: Offset, pAnchor: Anchor): object source
Gets the new point's position inside a rectangle after taking pAngle into account.
Params:
Name | Type | Attribute | Description |
pAngle | number |
|
Rotation of the rectangle this point exists inside/outside of in radians. |
pOffset | Offset |
|
The offset of the rectangle. |
pAnchor | Anchor |
|
The anchor origin of the rectangle. |
Example:
// 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`.
public transform(pTransform: Transform) source
Transforms the point.
Params:
Name | Type | Attribute | Description |
pTransform | Transform | The transform to transform the point to. |
public transformX(pTransformX: number) source
Transforms the x point.
Params:
Name | Type | Attribute | Description |
pTransformX | number | The x transform to transform the x point to. |
public transformY(pTransformY: number) source
Transforms the y point.
Params:
Name | Type | Attribute | Description |
pTransformY | number | The y transform to transform the y point to. |
public updateBounds(pBounds: Bounds) source
Updates the bounds of the rectangle this icon point exists inside/outside of.
Params:
Name | Type | Attribute | Description |
pBounds | Bounds | The bounds to update the rectangle with. |
Private Methods
private setPoint(pPoint: PositionalPoint) source
Sets the static point and defines the raw pixels value
Params:
Name | Type | Attribute | Description |
pPoint | PositionalPoint | The point that exists inside/outside the rectangle. |