Skip to content

mxcad_2d API 文档 / 2d / McGePoint3dArray

Class: McGePoint3dArray

2d.McGePoint3dArray

McGePoint3dArray 表示一组三维点的数组容器。

Description

该类用于批量管理多个三维点,常用于构造折线、多段线、边界、路径点集及几何计算。 通过它可以方便地追加点、读取点、设置点和遍历点集合。

Example

ts
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);// 获取第一个点对象
console.log(first.x, first.y, first.z);

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new McGePoint3dArray(imp?, isDestroyImp?)

构造函数。

Parameters

NameTypeDescription
imp?object内部实现对象
isDestroyImp?boolean-

Example

ts
import { McGePoint3dArray, McGePoint3d } from "mxcad";

  // 创建一个新的 McGePoint3dArray 实例
  const myArray = new McGePoint3dArray();

  // 通过传入一个对象初始化 McGePoint3dArray
  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

内部实现对象

Methods

append

append(val): void

添加一个值

Parameters

NameTypeDescription
valMcGePoint3d三维点对象

Returns

void


at

at(index): McGePoint3d

根据数组索引值得到数据元素的值

Parameters

NameTypeDescription
indexnumber数组索引

Returns

McGePoint3d

Example

ts
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); // 输出: McGePoint3d { x: 1, y: 2, z: 3 }

clear

clear(): void

清空数组

Returns

void


copy

copy(val): McGePoint3dArray

复制对象的值

Parameters

NameTypeDescription
valMcGePoint3dArray | McGePoint3d[]三维点的数组

Returns

McGePoint3dArray

Example

ts
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 }));

  // 复制 array2 的值到 array1
  array1.copy(array2);

forEach

forEach(call): void

遍历数组

Parameters

NameTypeDescription
call(val: McGePoint3d, index: number) => void回调函数

Returns

void

Example

ts
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}`);
  });
  // 输出:
  // Index 0: Point McGePoint3d { x: 1, y: 2, z: 3 }
  // Index 1: Point McGePoint3d { x: 4, y: 5, z: 6 }

isEmpty

isEmpty(): boolean

返回数组为空

Returns

boolean

布尔值


length

length(): number

返回数组长度

Returns

number

数组长度


setAt

setAt(index, val): void

通过数组索引设置数据元素的值

Parameters

NameTypeDescription
indexnumber数组索引
valMcGePoint3d三维点对象

Returns

void

Example

ts
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)); // 输出: McGePoint3d { x: 7, y: 8, z: 9 }