diff --git a/__test__/Polyline/split.test.ts b/__test__/Polyline/split.test.ts index 484cd2255..a39bab0bc 100644 --- a/__test__/Polyline/split.test.ts +++ b/__test__/Polyline/split.test.ts @@ -113,7 +113,7 @@ function createTestPolyline(): Polyline test('切割点在尾部', () => { let pl = new Polyline(); - pl.Create2Pt(new Vector3(), new Vector3(100, 100)); + pl.Rectangle(100, 100); let cus = pl.GetSplitCurves([1, 4]); expect(cus.length).toBe(2); diff --git a/src/Add-on/BoardEditor/Board2Regions.ts b/src/Add-on/BoardEditor/Board2Regions.ts index 4ca1c0a30..5a153461b 100644 --- a/src/Add-on/BoardEditor/Board2Regions.ts +++ b/src/Add-on/BoardEditor/Board2Regions.ts @@ -35,7 +35,7 @@ export function Board2Regions(br: Board): Region[] for (let l of lines) { - let rectPl = new Polyline().Create2Pt(ZeroVec, new Vector3(l.Length, br.Thickness)); + let rectPl = new Polyline().Rectangle(l.Length, br.Thickness); let reg = Region.CreateFromCurves([rectPl]); let p = l.StartPoint.applyMatrix4(ocs); diff --git a/src/Add-on/DrawRect.ts b/src/Add-on/DrawRect.ts index b635e8ead..3ad2c536f 100644 --- a/src/Add-on/DrawRect.ts +++ b/src/Add-on/DrawRect.ts @@ -12,7 +12,7 @@ export class DrawRect implements Command if (rectRes.Status === PromptStatus.OK) { let rec = new Polyline(); - rec.Create2Pt(rectRes.Point1UCS, rectRes.Point2UCS); + rec.RectangleFrom2Pt(rectRes.Point1UCS, rectRes.Point2UCS); rec.ApplyMatrix(app.Editor.UCSMatrix); app.Database.ModelSpace.Append(rec); diff --git a/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts b/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts index 64d1289dc..24377850b 100644 --- a/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts +++ b/src/Add-on/DrawWineRack/DrawObliqueWineRackTool.ts @@ -73,7 +73,7 @@ export class DrawObliqueWineRackTool extends DrawWineRackTool break; } - let rectPl = new Polyline().Create2Pt(new Vector3(), new Vector3(spaceWidth, spaceHeight)); + let rectPl = new Polyline().Rectangle(spaceWidth, spaceHeight); let gripWidth = config.boardThick + config.gripWidth; let retPls: Polyline[] = []; @@ -652,8 +652,7 @@ export class DrawObliqueWineRackTool extends DrawWineRackTool { const size = this.space.Size; let pl = new Polyline(); - pl.Create2Pt(new Vector3(), new Vector3(size.y, len)); - pl.CloseMark = true; + pl.Rectangle(size.y, len); const config = this.Config; let addWidth = config.grooveWidthAdd; diff --git a/src/DatabaseServices/Entity/Extrude.ts b/src/DatabaseServices/Entity/Extrude.ts index 380c9fb06..24cec29d1 100644 --- a/src/DatabaseServices/Entity/Extrude.ts +++ b/src/DatabaseServices/Entity/Extrude.ts @@ -248,7 +248,7 @@ export class ExtrudeSolid extends Entity if (!this.contourCurve || !(this.contourCurve instanceof Polyline)) this.contourCurve = new Polyline(); - this.contourCurve.Create2Pt(new Vector3(), new Vector3(this.width, this.height)); + this.contourCurve.Rectangle(this.width, this.height); } /** diff --git a/src/DatabaseServices/Entity/Polyline.ts b/src/DatabaseServices/Entity/Polyline.ts index b1e891670..32aff8f90 100644 --- a/src/DatabaseServices/Entity/Polyline.ts +++ b/src/DatabaseServices/Entity/Polyline.ts @@ -258,7 +258,17 @@ export class Polyline extends Curve { return this._LineData[index].bul; } - Create2Pt(p1: Vector3, p2: Vector3) + Rectangle(length: number, height: number): this + { + this.LineData = [ + { pt: new Vector2(), bul: 0 }, + { pt: new Vector2(length), bul: 0 }, + { pt: new Vector2(length, height), bul: 0 }, + { pt: new Vector2(0, height), bul: 0 }]; + this.CloseMark = true; + return this; + } + RectangleFrom2Pt(p1: Vector3, p2: Vector3): this { let box = new Box3(); box.setFromPoints([p2, p1].map((p: Vector3) => p.clone().applyMatrix4(this.OCSInv))); @@ -1436,3 +1446,5 @@ export class Polyline extends Curve file.Write(this._ClosedMark); } } + +export const TempPolyline = new Polyline(); diff --git a/src/GraphicsSystem/CalcEdgeSealing.ts b/src/GraphicsSystem/CalcEdgeSealing.ts index 6934ff8b4..83f162d74 100644 --- a/src/GraphicsSystem/CalcEdgeSealing.ts +++ b/src/GraphicsSystem/CalcEdgeSealing.ts @@ -5,7 +5,7 @@ import { Board } from "../DatabaseServices/Entity/Board"; import { Circle } from "../DatabaseServices/Entity/Circle"; import { Curve } from "../DatabaseServices/Entity/Curve"; import { Line } from "../DatabaseServices/Entity/Line"; -import { Polyline } from "../DatabaseServices/Entity/Polyline"; +import { Polyline, TempPolyline } from "../DatabaseServices/Entity/Polyline"; import { angle, equaln, equalv3, isParallelTo, SelectNearP } from "../Geometry/GeUtils"; import { IntersectOption } from "./IntersectWith"; @@ -187,8 +187,7 @@ export function GetBoardSealingCurves(br: Board) } else { - let cu = new Polyline().Create2Pt(new Vector3(), new Vector3(br.Width, br.Height)) - cus = cu.Explode(); + cus = TempPolyline.Rectangle(br.Width, br.Height).Explode(); } return cus; } diff --git a/src/GraphicsSystem/ToolPath/FeedingToolPath.ts b/src/GraphicsSystem/ToolPath/FeedingToolPath.ts index bbc623a5c..78bf559d2 100644 --- a/src/GraphicsSystem/ToolPath/FeedingToolPath.ts +++ b/src/GraphicsSystem/ToolPath/FeedingToolPath.ts @@ -235,7 +235,7 @@ export class FeedingToolPath extends Singleton box.max.add(new Vector3(0, addLen / 2)); box.min.add(new Vector3(0, -addLen / 2)); } - let pl = new Polyline().Create2Pt(box.min, box.max).ApplyMatrix(curveData.OCS); + let pl = new Polyline().RectangleFrom2Pt(box.min, box.max).ApplyMatrix(curveData.OCS); pl.ColorIndex = shape.Outline.Curve.ColorIndex; shape.Outline = Contour.CreateContour(pl); } diff --git a/src/Production/Product.ts b/src/Production/Product.ts index a48cfbe5d..539bfcd08 100644 --- a/src/Production/Product.ts +++ b/src/Production/Product.ts @@ -1,5 +1,4 @@ import { Matrix4, Vector2, Vector3 } from "three"; -import { arrayLast } from "../Common/ArrayExt"; import { EBoardKeyList } from "../Common/BoardKeyList"; import { Vector2ApplyMatrix4 } from "../Common/Matrix4Utils"; import { GangDrill, GangDrillType } from "../DatabaseServices/3DSolid/GangDrill";