mxcad_2d API 文档 / 2d / McGeLongArray
Class: McGeLongArray
2d.McGeLongArray
McGeLongArray 表示一组整数值的数组容器。
Description
该类用于存储和操作一组整数数据,常用于 CAD 内部的数值缓存、 对象 ID 集合、颜色通道数据等场景。它提供了追加、读取、修改和遍历等常用能力。
Example
ts
import { McGeLongArray } from "mxcad";
const values = new McGeLongArray();
values.append(10);
values.append(20);
values.append(30);
console.log(values.length())//获取数组长度;
console.log(values.at(1))//获取索引为1的元素值;Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new McGeLongArray(imp?)
构造函数。
Parameters
| Name | Type | Description |
|---|---|---|
imp? | object | 内部实现对象 |
Properties
imp
• imp: any
内部实现对象
Methods
append
▸ append(val): void
向数组中添加一个值
Parameters
| Name | Type | Description |
|---|---|---|
val | number | 整数值 |
Returns
void
at
▸ at(index): number
根据数组索引得到数据元素的值
Parameters
| Name | Type | Description |
|---|---|---|
index | number | 数组索引 |
Returns
number
返回元素值
clear
▸ clear(): void
清空数组
Returns
void
copy
▸ copy(val): McGeLongArray
复制对象的值
Parameters
| Name | Type | Description |
|---|---|---|
val | McGeLongArray | 整数数组 |
Returns
Example
ts
import { McGeLongArray } from "mxcad"
const array1 = new McGeLongArray();
const array2 = new McGeLongArray();
array2.append(10);
array2.append(20);
// 复制 array2 的值到 array1
array1.copy(array2);copyFormAryId
▸ copyFormAryId(aryId): McGeLongArray
从 McObjectId 数组中复制值
Parameters
| Name | Type | Description |
|---|---|---|
aryId | McObjectId[] | McObjectId 数组 |
Returns
forEach
▸ forEach(call): void
遍历数组
Parameters
| Name | Type | Description |
|---|---|---|
call | (val: number, index: number) => void | 回调函数 |
Returns
void
Example
ts
import { McGeLongArray } from "mxcad"
const array = new McGeLongArray();
array.append(5);
array.append(10);
array.forEach((val, index) => {
console.log(`Index ${index}: Value ${val}`);
});
// 输出:
// Index 0: Value 5
// Index 1: Value 10length
▸ length(): number
返回数组长度
Returns
number
数组长度
setAt
▸ setAt(index, val): void
通过数组索引设置数据元素的值
Parameters
| Name | Type | Description |
|---|---|---|
index | number | 数组索引值 |
val | number | 整数数值 |
Returns
void
