mxcad_2d API 文档 / 2d / McGeDoubleArray
Class: McGeDoubleArray
2d.McGeDoubleArray
McGeDoubleArray 表示一组双精度浮点数的数组容器。
Description
该类用于存储和处理浮点数集合,常见于数值采样、坐标值缓存、 变换参数和其他需要连续浮点数数据的场景。
Example
ts
import { McGeDoubleArray } from "mxcad";
const values = new McGeDoubleArray();
values.append(1.2);
values.append(3.4);
values.append(5.6);
console.log(values.at(1));//获取第一个索引位置的值;
console.log(values.length());//获取数组长度;Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new McGeDoubleArray(imp?, isDestroyImp?)
构造函数。
Parameters
| Name | Type | Description |
|---|---|---|
imp? | object | 内部实现对象 |
isDestroyImp? | boolean | - |
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): McGeDoubleArray
复制对象的值
Parameters
| Name | Type | Description |
|---|---|---|
val | McGeDoubleArray | 双精度浮点数数组 |
Returns
Example
ts
import { McGeDoubleArray } from "mxcad"
// array1 表示一个双精度浮点数数组
const array2 = new McGeDoubleArray();
array2.copy(array1);
// 现在array2与array1具有相同的值forEach
▸ forEach(call): void
遍历数组
Parameters
| Name | Type | Description |
|---|---|---|
call | (val: number, index: number) => void | 回调函数 |
Returns
void
Example
ts
import { McGeDoubleArray } from "mxcad"
const array = new McGeDoubleArray();
array.append(3.14159);
array.forEach((val,index)=>{
console.log(`Value at index ${index}: ${value}`);
})length
▸ length(): number
返回数组长度
Returns
number
数组长度
setAt
▸ setAt(index, val): void
通过数组索引设置数据元素的值
Parameters
| Name | Type | Description |
|---|---|---|
index | number | - |
val | number | 双精度浮点数 |
Returns
void
Example
ts
import { McGeDoubleArray } from "mxcad"
const array = new McGeDoubleArray();
array.setAt(1, 3.14159); // 将索引为1的位置的值设置为3.14159