优化div代码

pull/738/MERGE
ChenX 5 years ago
parent e345f1d33d
commit 87af19c769

@ -11,7 +11,8 @@ export class CMD_Divide implements Command
let enRes = await app.Editor.GetEntity(
{
Msg: "请选择定数等分的对象",
KeyWordList: [{ key: "D", msg: "定数等分" }, { key: "S", msg: "定距等分" }]
KeyWordList: [{ key: "D", msg: "定数等分" }, { key: "S", msg: "定距等分" }],
Filter: { filterFunction: (obj, ent) => { return ent instanceof Curve; } }
});
switch (enRes.Status)
{
@ -42,29 +43,24 @@ export class CMD_Divide implements Command
}
async Divided(enRes: PromptEntityResult)//定数等分
{
let numRes = await app.Editor.GetDistance({ Msg: "请输入段数" });
let numRes = await app.Editor.GetDistance({ Msg: "请输入段数:", Default: 2 });
if (numRes.Status != PromptStatus.OK)
return;
let divCount = numRes.Distance;
if (divCount === 0)
if (divCount <= 1)
{
app.Editor.Prompt("您不能等分0");
app.Editor.Prompt("等分个数必须大于1!");
return;
}
if (enRes.Entity instanceof Curve)
{
let cu = enRes.Entity;
let len = cu.Length;
let divLen = len / numRes.Distance;
if (cu.IsClose) //闭合曲线分割点+1
{
divCount += 1;
}
for (let i = 0; i < divCount - 1; i++)
let divParam = cu.EndParam / divCount;
let i = cu.IsClose ? 0 : 1;
for (; i < divCount; i++)
{
let pt = cu.GetPointAtDistance(divLen * (i + 1));
let pt = cu.GetPointAtParam(divParam * i);
let ptEnt = new Point(pt);
app.Database.ModelSpace.Append(ptEnt);
}

Loading…
Cancel
Save