Skip to content

editorGlobalsPaperPathUtils

Class: PaperPathUtils

Hierarchy

  • PaperPathUtils

Index

Properties

Methods

Properties

Static Private circleDifferenceThreshold

circleDifferenceThreshold: number = 0.05

Defined in src/util/PaperPathUtils.ts:27

Defines the threshold for the difference between the analyzed path and a perfect circle for it to still be recognized as a circle.


Static Private Readonly circleSampledPointDistance

circleSampledPointDistance: 1 = 1

Defined in src/util/PaperPathUtils.ts:22

The distance of the points to be sampled when checking for a circle It therefore affects the precision of the circle detection


Static Private Readonly simplificationTolerance

simplificationTolerance: 1 = 1

Defined in src/util/PaperPathUtils.ts:17

Methods

Static Private _getSimilarCircle

_getSimilarCircle(points: Vector3[], path: any): any

Defined in src/util/PaperPathUtils.ts:227

Checks if the given path is similar to a circle, meaning that all sampled points have about the same distance to the center

Parameters:

Name Type Description
points Vector3[] vertices of the polygon represented in the path
path any the paper.js path to be compared to a circle

Returns: any

a perfect circle similar to the given shape. If there is none, it just returns a smoothed version of the original path.


Static Private _setupPaperScope

_setupPaperScope(): void

Defined in src/util/PaperPathUtils.ts:215

sets up a scope that is needed for Paper.js to create paper objects

Returns: void


Static complexPolygonToPaperPath

complexPolygonToPaperPath(outline: Vector3[], holes: Vector3[][]): any

Defined in src/util/PaperPathUtils.ts:59

Converts a complex polygon (with holes) given as outline and holes to a paper.js Compound Path

Parameters:

Name Type Description
outline Vector3[] vertices of the outline polygon, they should already be converted to 2d coordinates and therefore have a z-coordinate of 0
holes Vector3[][] array of vertices of the hole polygons, they should already be converted to 2d coordinates and therefore have a z-coordinate of 0

Returns: any

a paper.js CompoundPath


Static discretisePath

discretisePath(path: any, pointDistance: number): Vector3[]

Defined in src/util/PaperPathUtils.ts:114

Takes a paper.js Path and converts it into a sequence of points

Parameters:

Name Type Default Description
path any - the paper.js Path to discretise
pointDistance number 0.25 the distance of the sampled points to be sampled on the given path

Returns: Vector3[]

the vertices of the polygon as an array of Vector3


Static getOrthogonalVector

getOrthogonalVector(vector: Vector2): Vector2

Defined in src/util/PaperPathUtils.ts:140

Returns a 2D vector orthogonal to the input 2D vector. This is calculated by rotating the vector by 90 degrees and normalizing it.

Parameters:

Name Type
vector Vector2

Returns: Vector2


Static hasPathDisconnectedParts

hasPathDisconnectedParts(path: any): boolean

Defined in src/util/PaperPathUtils.ts:85

Checks if the compound path or path only contains one outline and holes if a hole is not touching the outline the compound path consists of disconnected polygons

Parameters:

Name Type Description
path any -

Returns: boolean


Static paperPathToComplexPolygon

paperPathToComplexPolygon(path: any): object

Defined in src/util/PaperPathUtils.ts:73

Converts a paper.js Compound Path or Path to a complex polygon (it can have holes)

Parameters:

Name Type
path any

Returns: object

an object that contains the outline and holes of the polygon

  • holes: Vector3[][]

  • outline: Vector3[]


Static paperPathToPolygon

paperPathToPolygon(path: any): Vector3[]

Defined in src/util/PaperPathUtils.ts:49

Converts a paper.js Path to a simple polygon

Parameters:

Name Type Description
path any - returns a polygon

Returns: Vector3[]


Static polygonToPaperPath

polygonToPaperPath(outline: Vector3[], closed: boolean): any

Defined in src/util/PaperPathUtils.ts:35

Converts a given simple polygon to a paper.js Path

Parameters:

Name Type Default Description
outline Vector3[] - vertices of the polygon, they should already be converted to 2d coordinates and therefore have a z-coordinate of 0
closed boolean true indicates if the outline is closed or not

Returns: any

a paper.js Path


Static smooth

smooth(points: Vector3[], findCircle: boolean): Vector3[]

Defined in src/util/PaperPathUtils.ts:97

Make the outline of a polygon smoother

Parameters:

Name Type Default Description
points Vector3[] - vertices of the polygon, they should already be converted to 2d coordinates and therefore have a z-coordinate of 0
findCircle boolean true if set to true, the method generates a perfect circle if the polygon is already similar to one

Returns: Vector3[]


Static splitPolygon

splitPolygon(points: Vector3[], splitPlaneOrigin: Vector3, splitPlaneNormal: Vector3): Vector3[][]

Defined in src/util/PaperPathUtils.ts:152

Splits a polygon along a given plane by subtracting / intersecting a polygon on one side of the split plane that covers all vertices on that side. All inputs must have already been transformed to 2D.

Parameters:

Name Type Description
points Vector3[] vertices of the input polygon (on 2D plane)
splitPlaneOrigin Vector3 a point located on both the split plane and the polygon (on 2D plane)
splitPlaneNormal Vector3 the normal of the split plane which is orthogonal to the split line (on 2D plane)

Returns: Vector3[][]

the resulting 2D polygons after performing the split