[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGePoint3dArray
Class: McGePoint3dArray
2d.McGePoint3dArray
McGePoint3dArray represents an array container of three-dimensional points.
Description
This class is used for batch management of multiple 3D points, commonly used for constructing polylines, polylines, boundaries, path point sets, and geometric calculations. It allows for easy tracking, reading, setting, and traversing of point sets.
Example
import { McGePoint3d, McGePoint3dArray } from "mxcad";
const points = new McGePoint3dArray();
points.append(new McGePoint3d(0, 0, 0));
points.append(new McGePoint3d(10, 0, 0));
points.append(new McGePoint3d(10, 10, 0));
const first = points.at(0); //Get the first point object
console.log(first.x, first.y, first.z);Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new McGePoint3dArray(imp?, isDestroyImp?)
Constructor.
Parameters
| Name | Type | Description |
|---|---|---|
imp? | ` Object | Internal implementation object |
isDestroyImp? | boolean | - |
Example
import { McGePoint3dArray, McGePoint3d } from "mxcad";
//Create a new instance of McGePoint3dArray
const myArray = new McGePoint3dArray();
//Initialize McGePoint3dArray by passing in an object
const initialValues = [
new McGePoint3d({ x: 1, y: 2, z: 3 }),
new McGePoint3d({ x: 4, y: 5, z: 6 }),
];
const myArray2 = new McGePoint3dArray(initialValues);Properties
imp
• imp: any
Internal implementation object
Methods
append
▸ append(val): void
Add a value
Parameters
| Name | Type | Description |
|---|---|---|
| Val | [McGePoint3d] (2d. McGePoint3d. md) | 3D point object |
Returns
void
at
▸ at(index): McGePoint3d
Obtain the value of a data element based on the array index value
Parameters
| Name | Type | Description |
|---|---|---|
| Index | number | array index |
Returns
Example
import { McGePoint3dArray, McGePoint3d } from "mxcad"
const array = new McGePoint3dArray();
array.append(new McGePoint3d({ x: 1, y: 2, z: 3 }));
array.append(new McGePoint3d({ x: 4, y: 5, z: 6 }));
const point = array.at(0);
console.log(point); // Output: McGePoint3d { x: 1, y: 2, z: 3 }clear
▸ clear(): void
Clear the array
Returns
void
copy
▸ copy(val): McGePoint3dArray
Copy the value of the object
Parameters
| Name | Type | Description |
|---|---|---|
| Val | [McGePoint3dArray] (2d. McGePoint3dArray. md) \ | [McGePoint3d] (2d. McGePoint3d. md) [] |
Returns
Example
import { McGePoint3d, McGePoint3dArray } from "mxcad"
const array1 = new McGePoint3dArray();
const array2 = new McGePoint3dArray();
array2.append(new McGePoint3d({ x: 1, y: 2, z: 3 }));
array2.append(new McGePoint3d({ x: 4, y: 5, z: 6 }));
//Copy the value of array2 to array1
array1.copy(array2);forEach
▸ forEach(call): void
Traverse the array
Parameters
| Name | Type | Description |
|---|---|---|
| Call | (val: [McGePoint3d] (2d. McGePoint3d. md), index: number=>void | callback function |
Returns
void
Example
import { McGePoint3dArray, McGePoint3d } from "mxcad"
const array = new McGePoint3dArray();
array.append(new McGePoint3d({ x: 1, y: 2, z: 3 }));
array.append(new McGePoint3d({ x: 4, y: 5, z: 6 }));
array.forEach((point, index) => {
console.log(`Index ${index}: Point ${point}`);
});
//Output:
// Index 0: Point McGePoint3d { x: 1, y: 2, z: 3 }
// Index 1: Point McGePoint3d { x: 4, y: 5, z: 6 }isEmpty
▸ isEmpty(): boolean
Return an empty array
Returns
boolean
Boolean value
length
▸ length(): number
Return the length of the array
Returns
number
Array length
setAt
▸ setAt(index, val): void
Set the value of data elements through array indexing
Parameters
| Name | Type | Description |
|---|---|---|
| Index | number | array index |
| Val | [McGePoint3d] (2d. McGePoint3d. md) | 3D point object |
Returns
void
Example
import { McGePoint3dArray, McGePoint3d } from "mxcad"
const array = new McGePoint3dArray();
array.append(new McGePoint3d({ x: 1, y: 2, z: 3 }));
array.append(new McGePoint3d({ x: 4, y: 5, z: 6 }));
array.setAt(0, new McGePoint3d({ x: 7, y: 8, z: 9 }));
console.log(array.at(0)); // Output: McGePoint3d { x: 7, y: 8, z: 9 }