Class: Polygon
Describes a Polygon used for clipping operations
Hierarchy
- Polygon
Index
Constructors
Properties
Methods
- _applyMatrixToPointArray
- _clonePoints
- _isOutlineSelfIntersecting
- _resetCache
- _signedDistanceToOutline
- addCutLinesIfNecessary
- applyMatrix
- cleanse
- clearCutLines
- clone
- constrainCutLinesToAABB
- contains
- couldIntersect
- doesPointLieOnOutline
- getAABB
- getAllOutlines
- getAllOutlinesRef
- getArea
- getAsJstsPolygon
- getCenterOfMass
- getCutLines
- getDescription
- getHoles
- getHolesRef
- getOutline
- getOutlineArea
- getOutlineRef
- getOutlines
- getPolygons
- getPolygonsRef
- getSerializedLength
- isEmpty
- isSelfIntersecting
- normalize
- overlappingArea
- rotate
- round
- roundOutline
- scale
- scaleAroundCenter
- setCutLines
- setDescription
- setHoles
- setOutline
- signedDistanceToPoint
- subtractPolygon
- toArray
- toGeoJson
- toNestingSvg
- toSvg
- translate
- unionWithPolygon
- _fromJstsPolygon
- fromArray
- fromJSTSUnion
- getDuplicatePoints
- polygonFromRasterizedOutlineWithHoles
- polygonsFromArray
- polygonsToArray
Constructors
constructor
+ new Polygon(outline: ArrayPoint2[], holes: ArrayPoint2[][], cutLines: ArrayLine2[], description?: string): Polygon
Defined in src/util/polygon/Polygon.ts:208
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
outline |
ArrayPoint2[] | [] | the outline as an array of points as arrays ([x, y]) |
holes |
ArrayPoint2[][] | [] | the outlines of holes inside the polygon, each one described as an array of points as arrays |
cutLines |
ArrayLine2[] | [] | the cutLines as arrays of arrays of points as arrays ([x, y]) |
description? |
string | - | optional description of the Polygon |
Returns: Polygon
Properties
Private cachedAABB
• cachedAABB: AABB | null = null
Defined in src/util/polygon/Polygon.ts:206
Private cutLines
• cutLines: ArrayLine2[] = []
Defined in src/util/polygon/Polygon.ts:203
Private description
• description: string | null = null
Defined in src/util/polygon/Polygon.ts:204
Private holes
• holes: ArrayPoint2[][] = []
Defined in src/util/polygon/Polygon.ts:202
Readonly isMultiPolygon
• isMultiPolygon: false = false
Defined in src/util/polygon/Polygon.ts:199
Private outline
• outline: ArrayPoint2[] = []
Defined in src/util/polygon/Polygon.ts:201
Private reducer
• reducer: any = new jsts.precision.GeometryPrecisionReducer()
Defined in src/util/polygon/Polygon.ts:208
Methods
Private _applyMatrixToPointArray
▸ _applyMatrixToPointArray(points: ArrayPoint2[], matrix: Matrix4): void
Defined in src/util/polygon/Polygon.ts:1035
Parameters:
| Name | Type |
|---|---|
points |
ArrayPoint2[] |
matrix |
Matrix4 |
Returns: void
Private _clonePoints
▸ _clonePoints(pointsAsArrays: ArrayPoint2[]): ArrayPoint2[]
Defined in src/util/polygon/Polygon.ts:1120
Parameters:
| Name | Type |
|---|---|
pointsAsArrays |
ArrayPoint2[] |
Returns: ArrayPoint2[]
Private _isOutlineSelfIntersecting
▸ _isOutlineSelfIntersecting(outline: ArrayPoint2[], maxDistanceToPoint: number): boolean
Defined in src/util/polygon/Polygon.ts:1078
Parameters:
| Name | Type |
|---|---|
outline |
ArrayPoint2[] |
maxDistanceToPoint |
number |
Returns: boolean
Private _resetCache
▸ _resetCache(): void
Defined in src/util/polygon/Polygon.ts:1074
Returns: void
Private _signedDistanceToOutline
▸ _signedDistanceToOutline(outline: ArrayPoint2[], point: ReadonlyVector3): number
Defined in src/util/polygon/Polygon.ts:1045
Parameters:
| Name | Type |
|---|---|
outline |
ArrayPoint2[] |
point |
ReadonlyVector3 |
Returns: number
addCutLinesIfNecessary
▸ addCutLinesIfNecessary(newCutlines: ArrayLine2[]): void
Defined in src/util/polygon/Polygon.ts:520
Adds the passed cutlines to this Polygon, if they intersect the polygon's AABB. For more on cutLines, see Polygon.setCutLines.
Parameters:
| Name | Type |
|---|---|
newCutlines |
ArrayLine2[] |
Returns: void
applyMatrix
▸ applyMatrix(matrix: Matrix4): this
Defined in src/util/polygon/Polygon.ts:648
Parameters:
| Name | Type |
|---|---|
matrix |
Matrix4 |
Returns: this
cleanse
▸ cleanse(epsilon: number, __namedParameters: object): boolean
Defined in src/util/polygon/Polygon.ts:788
Removes duplicate and collinear points from the outline and holes. Alters this polygon.
Parameters:
▪Default value epsilon: number= 0.001
points with a mutual distance below epsilon are considered the same
▪Default value __namedParameters: object= {}
| Name | Type | Default |
|---|---|---|
area |
boolean | true |
collinearPoints |
boolean | true |
duplicatePoints |
boolean | true |
Returns: boolean
Whether this polygon has a degenerated outline
clearCutLines
▸ clearCutLines(): ArrayLine2[]
Defined in src/util/polygon/Polygon.ts:552
Clears all cutLines and returns the current cutLines
Returns: ArrayLine2[]
the original cutLines array
clone
▸ clone(): Polygon
Defined in src/util/polygon/Polygon.ts:949
Returns: Polygon
constrainCutLinesToAABB
▸ constrainCutLinesToAABB(clamp: boolean): void
Defined in src/util/polygon/Polygon.ts:577
Constrains the CutLines to the AABB of this Polygon. Lines that do not intersect the AABB or are not contained, are discarded.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
clamp |
boolean | false | - If set to false (default), cutLines that solely intersect the AABB are kept, but not clamped If set to true, all cutLines are clamped to the AABB |
Returns: void
contains
▸ contains(point: ReadonlyVector3, epsilon: number): boolean
Defined in src/util/polygon/Polygon.ts:965
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
point |
ReadonlyVector3 | - | a 2D point |
epsilon |
number | 0 | - The epsilon accuracy to check for "insideness", defaults to 0. Notice: leaving the default to 0 will use a raycast algorithm, which is fast but unstable for points exactly on the outline / hole's outlines |
Returns: boolean
whether the point is inside the polygon (and not in a hole).
couldIntersect
▸ couldIntersect(otherPolygon: Polygon | MultiPolygon): boolean
Defined in src/util/polygon/Polygon.ts:669
Tests whether this polygon could intersect the other polygon by comparing both AABB's for intersection
Parameters:
| Name | Type |
|---|---|
otherPolygon |
Polygon | MultiPolygon |
Returns: boolean
doesPointLieOnOutline
▸ doesPointLieOnOutline(point: ReadonlyVector3, epsilon: any): boolean
Defined in src/util/polygon/Polygon.ts:986
Parameters:
| Name | Type | Default |
|---|---|---|
point |
ReadonlyVector3 | - |
epsilon |
any | Config.get("modelLimits.maximumPositionEqualityDistance") |
Returns: boolean
getAABB
▸ getAABB(): AABB | null
Defined in src/util/polygon/Polygon.ts:613
Returns: AABB | null
the min/max coordinates of this polygon's AABB
getAllOutlines
▸ getAllOutlines(): ArrayPoint2[][]
Defined in src/util/polygon/Polygon.ts:468
Returns: ArrayPoint2[][]
all outlines of this polygon. The outline is at index 0, followed by the holes.
getAllOutlinesRef
▸ getAllOutlinesRef(): ArrayPoint2[][]
Defined in src/util/polygon/Polygon.ts:475
Returns: ArrayPoint2[][]
references to all outlines of this polygon. The outline is at index 0, followed by the holes.
getArea
▸ getArea(): number
Defined in src/util/polygon/Polygon.ts:748
Returns: number
the (always positive) area of the outline, including area loss due to cutouts
getAsJstsPolygon
▸ getAsJstsPolygon(geomFactory: jsts.geom.GeometryFactory, displacement: number): jsts.geom.Polygon
Defined in src/util/polygon/Polygon.ts:247
Parameters:
| Name | Type | Default |
|---|---|---|
geomFactory |
jsts.geom.GeometryFactory | - |
displacement |
number | 0 |
Returns: jsts.geom.Polygon
getCenterOfMass
▸ getCenterOfMass(): ArrayPoint2
Defined in src/util/polygon/Polygon.ts:761
Returns: ArrayPoint2
the center of mass (calculated using this formular: https://de.wikipedia.org/wiki/Geometrischer_Schwerpunkt#Polygon)
getCutLines
▸ getCutLines(): ArrayLine2[]
Defined in src/util/polygon/Polygon.ts:538
Returns: ArrayLine2[]
copy of all cutLines
getDescription
▸ getDescription(): string
Defined in src/util/polygon/Polygon.ts:566
Returns: string
getHoles
▸ getHoles(): ArrayPoint2[][]
Defined in src/util/polygon/Polygon.ts:494
Returns: ArrayPoint2[][]
a copy of all holes (CW direction)
getHolesRef
▸ getHolesRef(): ArrayPoint2[][]
Defined in src/util/polygon/Polygon.ts:501
Returns: ArrayPoint2[][]
a reference to the array of holes (CW direction)out (only for read access)
getOutline
▸ getOutline(): ArrayPoint2[]
Defined in src/util/polygon/Polygon.ts:440
Returns: ArrayPoint2[]
a copy of the outline (CCW direction)
getOutlineArea
▸ getOutlineArea(): number
Defined in src/util/polygon/Polygon.ts:741
Returns: number
the (always positive) area of the outline, ignoring area loss due to cutouts
getOutlineRef
▸ getOutlineRef(): ArrayPoint2[]
Defined in src/util/polygon/Polygon.ts:461
Returns: ArrayPoint2[]
a reference to the outline (CCW direction) (only for read access)
getOutlines
▸ getOutlines(): ArrayPoint2[][]
Defined in src/util/polygon/Polygon.ts:447
For compatibility with MultiPolygon
Returns: ArrayPoint2[][]
getPolygons
▸ getPolygons(): Polygon[]
Defined in src/util/polygon/Polygon.ts:433
to adhere to MultiPolygon.getPolygons()
Returns: Polygon[]
getPolygonsRef
▸ getPolygonsRef(): Polygon[]
Defined in src/util/polygon/Polygon.ts:454
For compatibility with MultiPolygon
Returns: Polygon[]
getSerializedLength
▸ getSerializedLength(): number
Defined in src/util/polygon/Polygon.ts:723
Returns: number
isEmpty
▸ isEmpty(): boolean
Defined in src/util/polygon/Polygon.ts:1031
Returns: boolean
isSelfIntersecting
▸ isSelfIntersecting(maxDistanceToPoint: number): boolean
Defined in src/util/polygon/Polygon.ts:1017
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
maxDistanceToPoint |
number | 0.01 | - If an intersection point is nearly equal to one of the polygon's points (within distance), the polygon is assumed to be self-touching and not intersecting |
Returns: boolean
true, if two sections of the outline or of one of the holes intersect. If the intersection is near the end of a section, it might be a self-touching polygon, so a self-touching case is assumed and false returned - beware, it could also be self-intersecting nevertheless!
normalize
▸ normalize(): this
Defined in src/util/polygon/Polygon.ts:624
Returns: this
overlappingArea
▸ overlappingArea(otherPolygon: Polygon): number
Defined in src/util/polygon/Polygon.ts:276
Parameters:
| Name | Type |
|---|---|
otherPolygon |
Polygon |
Returns: number
rotate
▸ rotate(quaternion: ReadonlyQuaternion): this
Defined in src/util/polygon/Polygon.ts:633
Parameters:
| Name | Type |
|---|---|
quaternion |
ReadonlyQuaternion |
Returns: this
round
▸ round(precision: number): void
Defined in src/util/polygon/Polygon.ts:829
Rounds all points in the outline and holes using Math.round().
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
precision |
number | 1 | the desired rounding precision (e.g. 1.0, 0.1, 0.001) |
Returns: void
roundOutline
▸ roundOutline(radius: number): void
Defined in src/util/polygon/Polygon.ts:312
Creates roundings on all corners of this polygon. Taken from https://riptutorial.com/html5-canvas/example/18766/render-a-rounded-polygon-
Parameters:
| Name | Type | Description |
|---|---|---|
radius |
number | the radius used to round this polygon |
Returns: void
scale
▸ scale(scale: ReadonlyVector3): this
Defined in src/util/polygon/Polygon.ts:637
Parameters:
| Name | Type |
|---|---|
scale |
ReadonlyVector3 |
Returns: this
scaleAroundCenter
▸ scaleAroundCenter(scale: ReadonlyVector3): this
Defined in src/util/polygon/Polygon.ts:641
Parameters:
| Name | Type |
|---|---|
scale |
ReadonlyVector3 |
Returns: this
setCutLines
▸ setCutLines(newCutLines: ArrayLine2[]): void
Defined in src/util/polygon/Polygon.ts:512
Sets the cutLines of this polygon. CutLines are cuts that are made into the polygon independent of the cutouts. Each line is a straight line from the first point in the array to the second point. They have zero surface and are therefore treated differently than cutouts. E.g. the slits that are cut into wood to make it bendable.
Parameters:
| Name | Type | Description |
|---|---|---|
newCutLines |
ArrayLine2[] | an array of two-element arrays of points |
Returns: void
setDescription
▸ setDescription(description?: string): void
Defined in src/util/polygon/Polygon.ts:562
Sets the description of this polygon. The description can be used to identify this polygon.
Parameters:
| Name | Type | Description |
|---|---|---|
description? |
string | The new description. May be null or undefined to remove the description. |
Returns: void
setHoles
▸ setHoles(newHoles: ArrayPoint2[][]): void
Defined in src/util/polygon/Polygon.ts:479
Parameters:
| Name | Type |
|---|---|
newHoles |
ArrayPoint2[][] |
Returns: void
setOutline
▸ setOutline(newOutline: ArrayPoint2[]): void
Defined in src/util/polygon/Polygon.ts:228
Parameters:
| Name | Type |
|---|---|
newOutline |
ArrayPoint2[] |
Returns: void
signedDistanceToPoint
▸ signedDistanceToPoint(point: ReadonlyVector3): number
Defined in src/util/polygon/Polygon.ts:846
Computes the minimum distance of this point to the polygon, including holes
Parameters:
| Name | Type |
|---|---|
point |
ReadonlyVector3 |
Returns: number
subtractPolygon
▸ subtractPolygon(otherPolygon: Polygon): Polygon
Defined in src/util/polygon/Polygon.ts:297
Parameters:
| Name | Type |
|---|---|
otherPolygon |
Polygon |
Returns: Polygon
toArray
▸ toArray(backingArray?: Float32Array, offset: number): Float32Array
Defined in src/util/polygon/Polygon.ts:678
Returns this polygon in serialized form with all points stored in a single array, with a header at the beginning. The format is the following: [numberOfPointsInOutline, numberOfHoles, numberOfPointsInFirstHole, numberOfPointsInSecondHole, …, numberOfCutlines, x1, y1, …]
Parameters:
| Name | Type | Default |
|---|---|---|
backingArray? |
Float32Array | - |
offset |
number | 0 |
Returns: Float32Array
toGeoJson
▸ toGeoJson(): ArrayPoint2[][]
Defined in src/util/polygon/Polygon.ts:928
Returns: ArrayPoint2[][]
toNestingSvg
▸ toNestingSvg(): string
Defined in src/util/polygon/Polygon.ts:234
Returns: string
toSvg
▸ toSvg(__namedParameters: object): string
Defined in src/util/polygon/Polygon.ts:862
Parameters:
▪Default value __namedParameters: object= {}
| Name | Type | Default | Description |
|---|---|---|---|
asDataUrl |
boolean | false | - |
fill |
string | "rgba(0, 0, 0, 0.5)" | the fill color, defaults to 'rgba(0, 0, 0, 0.5)' |
includeSvgDescription |
boolean | false | - |
round |
boolean | true | - |
stroke |
string | "red" | the stroke color, defaults to 'red' |
strokeWidth |
string | "0.3px" | - |
Returns: string
A SVG
translate
▸ translate(offset: ReadonlyVector3): this
Defined in src/util/polygon/Polygon.ts:629
Parameters:
| Name | Type |
|---|---|
offset |
ReadonlyVector3 |
Returns: this
unionWithPolygon
▸ unionWithPolygon(otherPolygon: Polygon): Polygon
Defined in src/util/polygon/Polygon.ts:286
Parameters:
| Name | Type |
|---|---|
otherPolygon |
Polygon |
Returns: Polygon
Static Private _fromJstsPolygon
▸ _fromJstsPolygon(unionJstsPolygon: any): Polygon‹›
Defined in src/util/polygon/Polygon.ts:186
Parameters:
| Name | Type |
|---|---|
unionJstsPolygon |
any |
Returns: Polygon‹›
Static fromArray
▸ fromArray(array: Float32Array | number[], offset: number): Polygon
Defined in src/util/polygon/Polygon.ts:83
Parameters:
| Name | Type | Default |
|---|---|---|
array |
Float32Array | number[] | - |
offset |
number | 0 |
Returns: Polygon
Static fromJSTSUnion
▸ fromJSTSUnion(jstsUnion: any): Polygon
Defined in src/util/polygon/Polygon.ts:173
Parameters:
| Name | Type |
|---|---|
jstsUnion |
any |
Returns: Polygon
Static getDuplicatePoints
▸ getDuplicatePoints(pointArray: ArrayPoint2[], epsilon: number): number[][]
Defined in src/util/polygon/Polygon.ts:47
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
pointArray |
ArrayPoint2[] | - | a polygon outline, either the outline itself or a hole |
epsilon |
number | Config.get("modelLimits.maximumPositionPrecision", 0) / 2 | - |
Returns: number[][]
arrays of point indices (positions) that are duplicate (= used multiple times in the outline -- self touching polygon)
Static polygonFromRasterizedOutlineWithHoles
▸ polygonFromRasterizedOutlineWithHoles(rasterizedOutlineWithHoles: RasterizedOutlineWithHoles, nesting: boolean): Polygon
Defined in src/util/polygon/Polygon.ts:148
Parameters:
| Name | Type | Default |
|---|---|---|
rasterizedOutlineWithHoles |
RasterizedOutlineWithHoles | - |
nesting |
boolean | true |
Returns: Polygon
Static polygonsFromArray
▸ polygonsFromArray(array: Float32Array | number[], offset: number): Polygon[]
Defined in src/util/polygon/Polygon.ts:137
Parameters:
| Name | Type | Default |
|---|---|---|
array |
Float32Array | number[] | - |
offset |
number | 0 |
Returns: Polygon[]
Static polygonsToArray
▸ polygonsToArray(...polygons: Array‹Polygon | MultiPolygon›): Float32Array
Defined in src/util/polygon/Polygon.ts:121
Parameters:
| Name | Type |
|---|---|
...polygons |
Array‹Polygon | MultiPolygon› |
Returns: Float32Array