editor › Globals › SafeMargin
Class: SafeMargin
A class that maps interaction coordinates inside the target plate.
Hierarchy
- SafeMargin
Index
Constructors
Properties
Methods
- _getBorderPoints
- _getFittingPosition
- _getOutline
- _moveToSafety
- _outlinesOverlap
- mapPoint
- setSize
- sizeFits
Object literals
Constructors
constructor
+ new SafeMargin(plate: Plate): SafeMargin
Defined in src/util/SafeMargin.ts:50
Parameters:
| Name | Type |
|---|---|
plate |
Plate |
Returns: SafeMargin
Properties
Private borderpoints
• borderpoints: IPoint2[] = [ { x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 0 }, ]
Defined in src/util/SafeMargin.ts:34
Points at the corners and on the middle of each edge of the object to test if it is outside of the outline.
Private borderpointsNeedUpdate
• borderpointsNeedUpdate: boolean = true
Defined in src/util/SafeMargin.ts:45
Private lastLocalPosition
• lastLocalPosition: Vector3
Defined in src/util/SafeMargin.ts:29
Stores the last position assigned by mapPoint
Private Readonly plate
• plate: Plate
Defined in src/util/SafeMargin.ts:24
The plate on which the ornament is placed
Private size
• size: object
Defined in src/util/SafeMargin.ts:14
The size of the object that is moved to the interaction coordinates inside
Type declaration:
-
height: number
-
width: number
Private Readonly uploadedTextureMinimumPlateOverlap
• uploadedTextureMinimumPlateOverlap: number
Defined in src/util/SafeMargin.ts:50
How much percent of a texture must always be visible on the plate
Methods
Private _getBorderPoints
▸ _getBorderPoints(center: Vector3, size: object): any[]
Defined in src/util/SafeMargin.ts:104
Calculate corners given the center and size.
Parameters:
▪ center: Vector3
The center point
▪Default value size: object= this.size
(optional) The size of the object that should be placed.
| Name | Type |
|---|---|
height |
number |
width |
number |
Returns: any[]
Corners, based on size and center
Private _getFittingPosition
▸ _getFittingPosition(newPoint: Vector3, outline: any): Vector3
Defined in src/util/SafeMargin.ts:173
Try to find a position like the given point that will fit in the given outline
Parameters:
| Name | Type | Description |
|---|---|---|
newPoint |
Vector3 | the point around which the ornament should be centered |
outline |
any | the outline within which the ornament should fit |
Returns: Vector3
original given point if the ornament fits around it; last working position if we couldn't modify the point so that the ornament fits
Private _getOutline
▸ _getOutline(): Outline‹›
Defined in src/util/SafeMargin.ts:160
Get the outline of our currently assigned plate
Returns: Outline‹›
Private _moveToSafety
▸ _moveToSafety(point: Vector3, fixPropertyGetter: function, fixPropertySetter: function): Vector3
Defined in src/util/SafeMargin.ts:217
Move a given point to safety, using the given accessor functions to modify a property (i.e. x or y) that can alter the point to be in a safe position
Parameters:
▪ point: Vector3
the point to move
▪ fixPropertyGetter: function
a getter for the property
▸ (position: Vector3): number
Parameters:
| Name | Type |
|---|---|
position |
Vector3 |
▪ fixPropertySetter: function
a setter for the property
▸ (position: Vector3, newValue: number): void
Parameters:
| Name | Type |
|---|---|
position |
Vector3 |
newValue |
number |
Returns: Vector3
a version of the given point modified to be within _getOutline
Private _outlinesOverlap
▸ _outlinesOverlap(center: Vector3, size?: IDimensions2, points: Vector3[]): boolean
Defined in src/util/SafeMargin.ts:133
Tests if the plate's outline overlaps with this' object's outline. The center and optional points (eg center of a convex plate) are tested first. May return false even if they overlap (just point based tests).
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
center |
Vector3 | - | The center of this' object |
size? |
IDimensions2 | - | (optional) A new size for this' object |
points |
Vector3[] | [] | (optional) The points that must fit in the outline (ignoring z coordinate) |
Returns: boolean
If any one of the given points lies within the plates outline or any of the object's outline points lies within the plate's outline or any of the plate's outline points lies within the object's outline or
mapPoint
▸ mapPoint(point: Vector3): Vector3‹›
Defined in src/util/SafeMargin.ts:65
Parameters:
| Name | Type |
|---|---|
point |
Vector3 |
Returns: Vector3‹›
safe point in texture coordinates (mapped onto this.plate), returns old center if there is no fit.
setSize
▸ setSize(size: object, rotation?: number): void
Defined in src/util/SafeMargin.ts:91
Store the size of the object that is to be placed on plate
Parameters:
▪ size: object
The object size
| Name | Type |
|---|---|
height |
number |
width |
number |
▪Optional rotation: number
The objects rotation CW in radians
Returns: void
sizeFits
▸ sizeFits(size: object, position: Vector3‹›): boolean
Defined in src/util/SafeMargin.ts:81
Returns true iff the ornament still fits with the new given size.
Parameters:
▪Default value size: object= this.size
(optional) New size
| Name | Type |
|---|---|
height |
number |
width |
number |
▪Default value position: Vector3‹›= this.lastLocalPosition
(optional) New position
Returns: boolean
True iff the ornament still fits with the new given size.
Object literals
Private rotation
▪ rotation: object
Defined in src/util/SafeMargin.ts:19
Rotation of the object in radians CW around the center of the object
angle
• angle: number = 0
Defined in src/util/SafeMargin.ts:19
cos
• cos: number = 1
Defined in src/util/SafeMargin.ts:19
sin
• sin: number = 0
Defined in src/util/SafeMargin.ts:19