Skip to content

Commit 97fe5fe

Browse files
authored
[add] bezier curve close (#64)
1 parent 4d6c054 commit 97fe5fe

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/chili/src/commands/create/bezier.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import {
88
GeometryNode,
99
I18n,
1010
LineType,
11+
Precision,
1112
ShapeMeshData,
1213
VisualConfig,
1314
XYZ,
1415
command,
1516
} from "chili-core";
16-
import { Dimension, PointSnapData } from "../../snap";
17+
import { Dimension, PointSnapData, SnapResult } from "../../snap";
1718
import { IStep, PointStep } from "../../step";
1819
import { CreateCommand } from "../createCommand";
1920

@@ -39,9 +40,20 @@ export class BezierCommand extends CreateCommand {
3940
return this.controller.result?.status === "success";
4041
}
4142
this.stepDatas.push(data);
43+
if (this.isClose(data)) {
44+
return true;
45+
}
4246
}
4347
}
4448

49+
private isClose(data: SnapResult) {
50+
console.log(this.stepDatas[0].point!.distanceTo(data.point!));
51+
return (
52+
this.stepDatas.length > 1 &&
53+
this.stepDatas[0].point!.distanceTo(data.point!) <= Precision.Distance
54+
);
55+
}
56+
4557
protected override getSteps(): IStep[] {
4658
let firstStep = new PointStep("operate.pickFistPoint");
4759
let secondStep = new PointStep("operate.pickNextPoint", this.getNextData);
@@ -54,6 +66,13 @@ export class BezierCommand extends CreateCommand {
5466
dimension: Dimension.D1D2D3,
5567
validator: this.validator,
5668
preview: this.preview,
69+
featurePoints: [
70+
{
71+
point: this.stepDatas.at(0)!.point!,
72+
prompt: I18n.translate("prompt.polygon.close"),
73+
when: () => this.stepDatas.length > 2,
74+
},
75+
],
5776
};
5877
};
5978

0 commit comments

Comments
 (0)