new Cache()
Methods
-
addIndexedPoint(X, Y)
-
Reuses a cached ClipperLib point or creates a new one.
Parameters:
Name Type Description Xnumber The 2D X-axis component.
Ynumber The 2D Y-axis component.
Returns:
Returns a {X,Y} ClipperLib point.
- Type
- object
-
addPoint()
-
Reuses a cached ClipperLib point or creates a new one.
Returns:
Returns a {X,Y} ClipperLib point.
- Type
- object
-
addPoint2D(X, Y)
-
Reuses a cached ClipperLib point or creates a new one.
Parameters:
Name Type Description Xnumber The 2D X-axis component.
Ynumber The 2D Y-axis component.
Returns:
Returns a {X,Y} ClipperLib point.
- Type
- object
-
addPointXY(pt3D)
-
Gets the next cached point and sets it to using X and Y axis components.
Parameters:
Name Type Description pt3DPD.Point The 3D {x,y,z} point to add to the cache.
Returns:
Returns a {X,Y} ClipperLib point.
- Type
- object
-
addPointXZ(pt3D)
-
Gets the next cached point and sets it to using X and Z axis components.
Parameters:
Name Type Description pt3DPD.Point The 3D {x,y,z} point to add to the cache.
Returns:
Returns a {X,Y} ClipperLib point.
- Type
- object
-
addPointYZ(pt3D)
-
Gets the next cached point and sets it to using Y and Z axis components.
Parameters:
Name Type Description pt3DPD.Point The 3D {x,y,z} point to add to the cache.
Returns:
Returns a {X,Y} ClipperLib point.
- Type
- object
-
clear()
-
Clears the cache and all its allocated memory.
Returns:
Returns this instance to support method chaining.
- Type
- PD.Clipper.Cache
-
createPathByAxisAndGetOrientation(vertices [, axis] [, clipPath])
-
Converts an array of points to a ClipperLib path.
This method uses the signed area to determine the orientation of the resulting 2D path. As this method returns the orientation, the path argument is required, and must be an array that will be filled with 2D points.
NOTE: This method only creates a 2D path and does not add it to the shape. To both create and add paths to the shape, use the
addBoundaryContour3D(),addHoleContour3D(), andaddPolyline3D()methods.Parameters:
Name Type Argument Description verticesArray.<PD.Point> An array of 3D
PD.Pointobjects.axisPD.AXIS <optional>
An optional axis to project 2D points onto, defaults to Z axis.
clipPathArray.<PD.ClipPt2D> <optional>
An array to receive the clipper points.
Returns:
Returns true if anti-clockwise oriented, false if clockwise.
- Type
- number
-
createPathFromPointsByAxis(vertices [, axis] [, clipPath])
-
Converts a polyline contour to a 2D
ClipperLib.Patharray.As ClipperLib works with 2D {X,Y} objects, the 3D polyline contour must be translated into a 2D cartesian plane. This method uses the given cartesian axis. If no axis is given, the X and Y components of the 3D points are used.
If an array to receive the new path is provided, it will be reset to contain the converted 2D points. If not, a new array will be created and returned.
NOTE: This method only creates a 2D path and does not add it to the shape. To both create and add paths to the shape, use the
addBoundaryContour3D(),addHoleContour3D(), andaddPolyline3D()methods.Parameters:
Name Type Argument Default Description verticesArray.<PD.Point> An array of 3D points.
axisPD.AXIS <optional>
0 An optional axis to project 2D points onto, defaults to Z axis.
clipPathArray.<PD.ClipPt2D> <optional>
An optional path to receive the 2D clip points.
Returns:
Returns the given path array filled with {X,Y} ClipperLib points, of a newly created array.
- Type
- Array
-
createPathFromPointsXY(vertices [, clipPath])
-
Converts 3D points to a 2D
ClipperLib.Patharray in the XY plane.This method uses the X and Y components of the given points to generate an array of 2D {X,Y} objects. If an array to receive the new path is provided, it will be reset to contain the converted 2D points. If not, a new array will be created and returned.
NOTE: This method only creates a 2D path and does not add it to the shape. To both create and add paths to the shape, use the
addBoundaryContour3D(),addHoleContour3D(), andaddPolyline3D()methods.Parameters:
Name Type Argument Description verticesArray.<PD.Point> An array of 3D points.
clipPathArray.<PD.ClipPt2D> <optional>
An optional path to receive the 2D points.
Returns:
Returns the given path array filled with {X,Y} ClipperLib points, of a newly created one.
- Type
- Array
-
createPathFromVectorArraysByAxis(vertices [, axis] [, clipPath])
-
Converts a contour of [x,y,z] vector arrays to a 2D
ClipperLib.Patharray.As ClipperLib works with 2D {X,Y} objects, the 3D polyline must be translated into a 2D cartesian plane. This method uses the given cartesian axis. If no axis is given, the X and Y components of the 3D [x,y,z] vector arrays are used.
If an array to receive the new path is provided, it will be reset to contain the converted 2D points. If not, a new array will be created and returned.
NOTE: This method only creates a 2D path and does not add it to the shape.
Parameters:
Name Type Argument Default Description verticesArray.<Array.<number>> An array of 3D [x,y,z] vector arrays.
axisPD.AXIS <optional>
0 An optional axis to project 2D points onto, defaults to Z axis.
clipPathArray.<PD.ClipPt2D> <optional>
An optional path to receive the 2D clip points.
Returns:
Returns the given path array filled with {X,Y} ClipperLib points, of a newly created array.
- Type
- Array
-
createPathsFromPolylineByAxis(polyline [, axis])
-
Converts a polyline into a series of 2D
ClipperLib.Patharrays.This method uses the polyline's axis of greatest surface exposure. If the polyline is also a polygon, the orientation of any holes in it will have the opposite orientation to the boundary.
NOTE: If calling this method from a
PD.Clipper.Shapeinstance, it is important to note that it only creates 2D paths and does not add them to the shape. To both create and add paths to the shape, use thePD.Clipper.Shape#addBoundaryContour3D,PD.Clipper.Shape#addHoleContour3Dand/orPD.Clipper.Shape#addPolyline3Dmethods.Parameters:
Name Type Argument Description polylinePD.Polyline The polyline to generate pats for.
axisPD.AXIS <optional>
The axis to use when converting, defaults to
polyline.axis.Returns:
Returns an array of one or more
ClipperLib.Patharrays, each containing {X,Y} Clipper points.- Type
- Array
-
getCacheSize()
-
Retrieves the number of entries in the point cache.
Returns:
Returns the point cache size.
- Type
- number
-
getNextPointIndex()
-
Retrieve the index of the next available point in the cache.
Returns:
Returns the current next point index.
- Type
- number
-
reuseEnd()
-
Finalises the shape.
This method must be called after you have first called
reuseStart()to reset the reusable index. Its role is to trim any excessive leftover data that has not been reused.Returns:
Returns this instance to support method chaining.
- Type
- PD.Clipper.Cache
-
reuseStart()
-
Resets the point cache to begin reusing them.
Returns:
Returns this instance to support method chaining.
- Type
- PD.Clipper.Cache
-
setCacheSize(new_size)
-
Sets the size of the point cache to the given number of entries.
Parameters:
Name Type Description new_sizenumber The new size of the cache.
Returns:
Returns this instance to support method chaining.
- Type
- PD.Clipper.Cache
-
setNextPointIndex(index)
-
Sets the index of the next available point in the cache.
This method is only for use when generating volatile clipping paths. This means that each new path is created, clipped and converted to something else all within the same function (or sub-functions), and not stored or referenced anywhere else at any other time.
To prevent the cache from persisting the points associated with these volatile shapes, you can use
PD.Clipper.Cache#getNextPointIndexto store the current index just before you create each new path and, once you have used it and it is no longer required, call this method with the stored value to reset the index.It is highly recommended that you store and reset indexes after processing individual paths as this will prevent the cache from growing excessively large. However, you need to be very careful when using this method as any cached points after the given index will be reused and their values overwritten.
Thus, if you create a volatile subject path and three volatile clip paths, and then subtract them, you cannot reset the index until the entire process is complete and all four paths are no longer needed or referenced. If you reset the index after creating each path, they will actually share the same points from the cache, and the last path created will set the values of points used by each of the other shapes as well as its own. As a result, any subtraction or other process will produce garbage values. In this case, you would store the index just before creating each of the paths, perform the subtraction, generate whatever geometry you need from the results, and then reset the index.
Parameters:
Name Type Description indexnumber The new index within the cache.
Returns:
Returns this instance to support method chaining.
- Type
- PD.Clipper.Cache
-
useIndexer( [decimals])
-
Instructs the cache to use an indexer to generate unique points at each coincident position.
After calling this method, any points added to the cache using the
addIndexedPoint()method will be stored by aPD.Indexerand any subsequent point with the same coordinates (within a tolerance given bydecimals) will be reused rather than creating a new point.This is useful for both reducing the number of points in the cache and for ensuring that the edges of paths line up exactly.
Parameters:
Name Type Argument Default Description decimalsnumber <optional>
1 The number of decimal places when comparing coordinates, defaults to 1 (0.1mm).
Returns:
Returns this instance to support method chaining.
- Type
- PD.Clipper.Cache