new Indexer( [decimals])
Creates a new indexer.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
decimals |
number |
<optional> |
The number of decimal places to use when comparing coordinates (0 or more), defaults to 3. |
Members
-
:number
decimals
-
The number of decimal places to use when encoding vectors (0 or more).
Type
- number
-
:number
indexId
-
The current key value when using the
PD.Indexer#addByIdmethod.Type
- number
-
:object
map
-
An empty object storing the array index of each unique item.
Type
- object
-
:Array
unique
-
An array of unique items in the data stream.
Type
- Array
Methods
-
addById(obj)
-
Checks for an entry and adds it if it doesn't already exist.
This method adds a new
_indexIdproperty to each object and uses that as its unique key. It returns the numeric index of the object in the list.NOTE: If you use multiple indexers across shared objects, you will need to manually reset the
_indexIdproperty of all previously indexed objects back to zero.Parameters:
Name Type Description objobject | Array An object or array to stamp and index.
Returns:
Returns the index of the object within the list.
- Type
- number
-
addEntry(key, data)
-
Returns the index of an existing entry for a key, or adds a new entry.
Parameters:
Name Type Description keystring The map key to check for.
dataany The object or data to store if no existing entry.
Returns:
Returns the index of the key entry within the list.
- Type
- number
-
addObject(obj)
-
Adds the given object if it doesn't already exist and returns its numeric index in the list.
This method uses a JSON representation of the object as its unique key.
Parameters:
Name Type Description objobject An arbitrary object with a viable JSON representation.
Returns:
Returns the index of the object within the list.
- Type
- number
-
addVectorArray(vec)
-
Checks for a vector array and adds it if it doesn't already exist.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description vecArray.<number> A vector array in the form [x,y,z].
Returns:
Returns the index of the object within the list.
- Type
- number
-
addVectorObject(pnt)
-
Checks for a vector object and adds it if it doesn't already exist.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description pntobject An object with numeric
x,yandzproperties.Returns:
Returns the index of the object within the list.
- Type
- number
-
clear()
-
Clears all results from the indexer.
Returns:
Returns this indexer to support method chaining.
- Type
- PD.Indexer
-
getBRepVertex(brep, pnt)
-
Returns a unique vertex index for the given position.
Parameters:
Name Type Description brepPD.BRep The boundary representation to add new vertices to.
pntPD.Utils.VectorObject An {x,y,z} vector with the position to look for.
Returns:
Returns an existing vertex if the keys match, or adds a new vertex with its key.
- Type
- PD.Utils.VectorObject
-
getClipPtKey2D(clipPt)
-
Returns a key created from the given {X,Y} ClipperLib point object.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description clipPtobject An object with numeric
XandYproperties.Returns:
Returns the key for this 3D point.
- Type
- string
-
getEntry(key, data)
-
Returns the value of an existing entry for a key, or adds a new entry.
Parameters:
Name Type Description keystring The map key to check for.
dataany The object or data to store if no existing entry.
Returns:
Returns the data associated with of the key.
- Type
- any
-
getEntryIndex(key, data)
-
Returns the index of an existing entry for a key, or adds a new entry.
Parameters:
Name Type Description keystring The map key to check for.
dataany The object or data to store if no existing entry.
Returns:
Returns the index of the key entry within the list.
- Type
- number
-
getKey2D(X, Y)
-
Returns a key created from the given 2D x and y position.
This method uses the
decimalsproperty of the Indexer to generate a unique unique key for this position. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description Xnumber The 2D X-axis component.
Ynumber The 2D Y-axis component.
Returns:
Returns the key for XY position.
- Type
- string
-
getMeshVertexIndex(mesh, pnt)
-
Returns a unique mesh vertex index for the given position.
Parameters:
Name Type Description meshPD.PolyMesh The mesh to add new vertices to.
pntPD.Utils.VectorObject An {x,y,z} vector with the position to look for.
Returns:
Returns the index of an existing vertex if the keys match, or adds a new vertex with the key and returns its index.
- Type
- number
-
getMeshVertexIndexXY(mesh, vec)
-
Returns the index of an existing entry for a key, or adds a new entry.
Parameters:
Name Type Description meshPD.PolyMesh The dynamic mesh to add new vertices to.
vecArray A vector array in the form [x,y,z] with the position to look for.
Returns:
Returns the index of a matching mesh vertex or -1 if the given vector array is not valid.
- Type
- number
-
getShellVertex(shell, pnt)
-
Returns a unique vertex index for the given position.
Parameters:
Name Type Description shellPD.Shell The shell to add new vertices to.
pntPD.Utils.VectorObject An {x,y,z} vector with the position to look for.
Returns:
Returns an existing vertex if the keys match, or adds a new vertex with its key.
- Type
- PD.Utils.VectorObject
-
getUniqueEntry(key, obj)
-
Returns a matching vector array in the XY plane or adds it.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description keystring The map key to check for.
objany The object or data to store if no existing entry.
Returns:
Returns an existing or new entry matching the key.
- Type
- any
-
getUniqueVectorArray(vec)
-
Returns a matching vector array or adds it if not found.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description vecArray.<number> A vector array in the form [x,y,z].
Returns:
Returns a matching vector array from the list.
- Type
- Array
-
getUniqueVectorObject(pnt)
-
Returns a matching vector object or adds it if not found.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description pntobject An object with numeric
x,yandzproperties.Returns:
Returns a matching vector object within the list.
- Type
- object
-
getVectorArrayKey2D(vec)
-
Returns a key created from the given [x,y] vector array.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description vecArray A vector array in the form [x,y].
Returns:
Returns the key for this 2D vector.
- Type
- string
-
getVectorArrayKey3D(vec)
-
Returns a key created from the given [x,y,z] vector array.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description vecArray A vector array in the form [x,y[,z]].
Returns:
Returns the key for this 2D vector.
- Type
- string
-
getVectorKey2D(pnt)
-
Returns a key created from the given {x,y} point object.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description pntobject An object with numeric
xandyproperties.Returns:
Returns the key for this 2D point.
- Type
- string
-
getVectorKey3D(pnt)
-
Returns a key created from the given {x,y,z} point object.
This method uses the
decimalsproperty of the Indexer to generate each item's unique key. This defaults to 3 decimal places which should typically be fine as all dimensions are assumed to be in millimetres, so this means accuracy is down to the micrometre.You can set the decimal places to 0 if you want objects to share coordinates that are within one millimeter of each other.
Parameters:
Name Type Description pntobject An object with numeric
x,yandzproperties.Returns:
Returns the key for this 3D point.
- Type
- string