功能:移除多段线重复点

pull/2374/head
ChenX 1 year ago
parent ab8ddb35c7
commit aaca87d42a

@ -0,0 +1,33 @@
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { LoadEntityFromFileData } from "../Utils/LoadEntity.util";
import "../Utils/jest.util";
test('精简多段线', () =>
{
let d =
{ "file": [1, "Polyline", 10, 2, 182, 0, 1, 3, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1493.5460401813875, 698.3323670493448, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1493.5460401813875, 698.3323670493448, 0, 1], 0, 0, 1, 2, 7, [-529, -397.9970410676705], 0, [-2.9849800837673115, -1], 0, [-250, -1], -0.0006310150531804717, [-250.00252405719763, -0.999996814562558], 0.41569289652442754, [-529.0000031854374, -279.99747594280234], -0.000631015053187468, [-529, -280], 0, [-529, -397.9970410676705], 0, false], "basePt": { "x": 964.5451505016724, "y": 300.3353259816743, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
pl.RemoveRepeatPos();
expect(pl.EndParam).toMatchNumberSnapshot(0);
expect(pl.Length).toMatchNumberSnapshot(3);
});
//保留最后一个点?
test('精简多段线2', () =>
{
let d =
{ "file": [1, "Polyline", 10, 2, 183, 0, 1, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 7, [323.78480965026665, 1043.5675363800462], 0, [218.75605375536884, 744.9733873895931], 0, [400.1693593920104, 714.5931687423086], 0, [559.8825088520202, 935.9347617439527], 0, [757.7879331829016, 843.9260995550339], 0, [708.3115771001814, 1097.383923698093], 0, [323.7848611540741, 1043.5676220967764], 0, true], "basePt": { "x": 218.75605375536884, "y": 714.5931687423086, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(d)[0] as Polyline;
pl.CloseMark = false;
pl.RemoveRepeatPos();
expect(pl.EndParam).toMatchNumberSnapshot(0);
expect(pl.Length).toMatchNumberSnapshot(3);
pl = LoadEntityFromFileData(d)[0] as Polyline;
pl.CloseMark = true;
pl.RemoveRepeatPos();
expect(pl.EndParam).toMatchNumberSnapshot(0);
expect(pl.Length).toMatchNumberSnapshot(3);
});

@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`精简多段线 1`] = `"4"`;
exports[`精简多段线 2`] = `"1462.581"`;
exports[`精简多段线2 1`] = `"6"`;
exports[`精简多段线2 2`] = `"1638.178"`;
exports[`精简多段线2 3`] = `"6"`;
exports[`精简多段线2 4`] = `"1638.178"`;

@ -0,0 +1,20 @@
import { app } from "../ApplicationServices/Application";
import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
export class Command_RemovePolylineRepeatPos implements Command
{
async exec()
{
let ssRes = await app.Editor.GetSelection({
Msg: "选择多段线移除重复点:",
Filter: { filterTypes: [Polyline] }
});
if (ssRes.Status !== PromptStatus.OK) return;
let ents = ssRes.SelectSet.SelectEntityList as Polyline[];
for (let en of ents)
en.RemoveRepeatPos();
}
}

@ -456,6 +456,39 @@ export class Polyline extends Curve
}
}
/**
*
* @param [fuzz=0.1] =0.1
*/
RemoveRepeatPos(fuzz = 0.1)
{
let index = 0;
let pre = 0;
let writed = false;
for (let next = 1; next <= this._LineData.length; next++)
{
if ((!this._ClosedMark && next === this._LineData.length) ||//如果曲线没闭合 则总是保留最后一个点
!equalv2(this._LineData[pre].pt, this._LineData[FixIndex(next, this._LineData)].pt, fuzz))
{
if (!writed)
{
this.WriteAllObjectRecord();
writed = true;
}
this._LineData[index] = this._LineData[pre];
index++;
}
pre++;
}
if (equalv2(this._LineData[0].pt, this._LineData[index - 1].pt, fuzz))
this._LineData[index - 1].pt.copy(this._LineData[0].pt);
this._LineData.length = index;
this.Update();
}
get Length()
{
return this.Explode().reduce((l, cu) => l + cu.Length, 0);

@ -212,6 +212,7 @@ import { Command_GroovesModify } from "../Add-on/showModal/GroovesModify";
import { ShowEditorBBS } from "../Add-on/showModal/ShowModal";
// import { DrawFloor } from '../Add-on/DrawFloor';
// import { RevTarget, SaveTarget } from '../Add-on/RenderTarget';
import { Command_RemovePolylineRepeatPos } from "../Add-on/Cmd_RemovePolylineRepeatPos";
import { ParseHandle } from "../Add-on/DrawBoard/ParseHandle";
import { ParseHinge } from "../Add-on/DrawBoard/ParseHinge";
import { TestFb } from "../Add-on/TestFb";
@ -581,6 +582,7 @@ export function registerCommand()
commandMachine.RegisterCommand("TestDrawEdgeGeometry", new Command_TestDrawEdgeGeometry());
}
commandMachine.RegisterCommand(CommandNames.SimplifyPolyline, new Command_SimplifyPolyline());
commandMachine.RegisterCommand("RemovePolylineRepeatPos", new Command_RemovePolylineRepeatPos());
//用于测试包围盒
if (IsTest())

Loading…
Cancel
Save