添加坐标节点 - AddCoordinateNode
函数简介
向现有图添加或更新一个坐标节点,可按阈值将新节点连接到现有节点,并可选择使用欧几里得距离作为权重。
接口名称
AddCoordinateNode
DLL调用
int32_t AddCoordinateNode(int64_t instance, int64_t graphPtr, char* name,
double x, double y, bool connectToExisting,
double maxDistance, bool useEuclideanDistance);
参数说明
参数名 | 类型 | 说明 |
---|---|---|
instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
graphPtr | 长整数型 | 图的指针,由 CreateGraph 或 CreateGraphFromCoordinates 返回。 |
name | 字符串 | 节点名称,若已存在则更新其坐标。 |
x | 双精度型 | X 坐标。 |
y | 双精度型 | Y 坐标。 |
connectToExisting | 布尔型 | 是否连接到现有节点,默认 true。 |
maxDistance | 双精度型 | 最大连接距离阈值,默认无穷大。 |
useEuclideanDistance | 布尔型 | 是否使用欧几里得距离作为边权重,默认 true。 |
示例
// 创建OLA实例
int64_t instance = CreateCOLAPlugInterFace();
// 先创建一张图
int64_t graphPtr = CreateGraphFromCoordinates(instance,
"[{\"name\":\"A\",\"x\":0,\"y\":0},{\"name\":\"B\",\"x\":3,\"y\":4}]",
true, 10.0, true);
// 添加新节点C,并自动连接到距离小于5的节点
int32_t ok = AddCoordinateNode(instance, graphPtr, "C", 1.0, 1.0, true, 5.0, true);
printf("AddCoordinateNode: %d\n", ok);
// 释放
DeleteGraph(instance, graphPtr);
DestroyCOLAPlugInterFace(instance);
返回值
成功返回1,失败返回0。
注意事项
- 确保 graphPtr 是有效的图指针。
- 如果节点名称已存在,会更新坐标信息。
- connectToExisting 为 true 时,新节点会连接到距离小于 maxDistance 的现有节点。