开发:优化代码

pull/1498/MERGE
ChenX 3 years ago
parent ce56cfc271
commit 3bee5afd9b

@ -4,7 +4,7 @@ import { app } from "../ApplicationServices/Application";
import { Entity } from "../DatabaseServices/Entity/Entity"; import { Entity } from "../DatabaseServices/Entity/Entity";
import { Command } from "../Editor/CommandMachine"; import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult"; import { PromptStatus } from "../Editor/PromptResult";
import { comparePoint } from '../Geometry/GeUtils'; import { comparePoint, GetBox } from '../Geometry/GeUtils';
import { HotCMD } from '../Hot/HotCommand'; import { HotCMD } from '../Hot/HotCommand';
@ -49,7 +49,7 @@ export class Command_PackageMove implements Command
for (let i = 0; i < ents.length; i++) for (let i = 0; i < ents.length; i++)
{ {
let en = ents[i]; let en = ents[i];
en.TempData = { i, b: en.BoundingBox, u: false }; en.TempData = { i, b: GetBox(en.DrawObject), u: false };
} }
let fb = new Flatbush(ents.length); let fb = new Flatbush(ents.length);
@ -65,13 +65,10 @@ export class Command_PackageMove implements Command
{ {
let arr = [ents.pop()]; let arr = [ents.pop()];
arr[0].TempData.u = true; arr[0].TempData.u = true;
let b = new Box3; let b = (arr[0].TempData.b as Box3).clone();
for (let i = 0; i < arr.length; i++) for (let i = 0; i < arr.length; i++)
{ {
let e = arr[i];
b.union(e.TempData.b);
let ids = fb.search(b.min.getComponent(i1) - i1d, b.min.getComponent(i2) - i2d, b.max.getComponent(i1) + i1d, b.max.getComponent(i2) + i2d, id => oents[id].TempData.u === false); let ids = fb.search(b.min.getComponent(i1) - i1d, b.min.getComponent(i2) - i2d, b.max.getComponent(i1) + i1d, b.max.getComponent(i2) + i2d, id => oents[id].TempData.u === false);
for (let id of ids) for (let id of ids)

@ -1,5 +1,5 @@
import { ClipType, PolyFillType } from "js-angusj-clipper/web"; import { ClipType, PolyFillType } from "js-angusj-clipper/web";
import { Vector2 } from "three"; import { Matrix4, Vector2, Vector3 } from "three";
import { app } from "../../ApplicationServices/Application"; import { app } from "../../ApplicationServices/Application";
import { Polyline } from "../../DatabaseServices/Entity/Polyline"; import { Polyline } from "../../DatabaseServices/Entity/Polyline";
import { Command } from "../../Editor/CommandMachine"; import { Command } from "../../Editor/CommandMachine";
@ -15,31 +15,18 @@ export class Test implements Command
{ {
async exec() async exec()
{ {
let promise = InitClipperCpp();
let plss = await app.Editor.GetSelection({ Filter: { filterTypes: [Polyline] } }); for (let e of app.Database.ModelSpace.Entitys)
if (plss.Status !== PromptStatus.OK) return; {
let box = e.BoundingBox;
let pls = plss.SelectSet.SelectEntityList as Polyline[];
let bin = pls.shift();
await promise;
let finalNfp = clipperCpp.lib.clipToPaths({
subjectInputs: [{ data: PathScale(bin.GetStretchPoints(), 1e4), closed: true }],
clipInputs: pls.map(pl => { return { data: PathScale(pl.GetStretchPoints(), 1e4) }; }),
clipType: ClipType.Difference,
subjectFillType: PolyFillType.NonZero
});
finalNfp = clipperCpp.lib.simplifyPolygons(finalNfp);
for (let nfp of finalNfp) if (isNaN(box.min.x))
{ {
let pl = Path2Polyline(nfp.map(p => new Vector2(p.x * 1e-4, p.y * 1e-4))); e.OCS = new Matrix4;
TestDraw(pl); e.Update();
app.Editor.SetSelection([e]);
return;
}
} }
} }
} }

Loading…
Cancel
Save