diff --git a/__test__/Polyline/__snapshots__/polylineArea.test.ts.snap b/__test__/Polyline/__snapshots__/polylineArea.test.ts.snap new file mode 100644 index 000000000..c196660b7 --- /dev/null +++ b/__test__/Polyline/__snapshots__/polylineArea.test.ts.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`多段线面积 1`] = `"0.00000"`; + +exports[`多段线面积 2`] = `"105946.37829"`; + +exports[`多段线面积 3`] = `"183539.66828"`; + +exports[`多段线面积 4`] = `"11783.91238"`; + +exports[`多段线面积 5`] = `"0.00000"`; + +exports[`多段线面积 6`] = `"117468.55553"`; diff --git a/__test__/Polyline/polylineArea.test.ts b/__test__/Polyline/polylineArea.test.ts new file mode 100644 index 000000000..605666842 --- /dev/null +++ b/__test__/Polyline/polylineArea.test.ts @@ -0,0 +1,16 @@ +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; +import { Polyline } from "../../src/DatabaseServices/Entity/Polyline"; +import "../Utils/jest.util"; + +test('多段线面积', () => +{ + let d = + { "file": [6, "Polyline", 5, 2, 101, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 2, [9.569377990430496, 149.52153110047848], 0, [441.3875598086124, 373.2057416267944], 0, false, "Polyline", 5, 2, 102, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 3, [612.4401913875597, 147.12918660287082], 0, [1139.952153110048, 383.9712918660287], 0, [1203.349282296651, 160.28708133971296], 0, false, "Polyline", 5, 2, 103, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 3, [1493.5406698564593, 8.612440191387606], 0, [2302.3923444976076, 372.0095693779905], 0, [2302.3923444976076, -81.81818181818187], 0, true, "Polyline", 5, 2, 104, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 3, [2601.818181818182, 136.88995215311004], 0, [3033.2057416267944, 495.59808612440185], -1.4100385033366523, [3122.2966507177034, 256.4593301435407], 0, false, "Polyline", 5, 2, 105, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 2, [3438.803827751196, -13.157894736842092], -0.37911328762272817, [3745.933014354067, -285.11961722488024], 0, false, "Polyline", 5, 2, 106, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 2, 3, [4261.253588516746, -110.68899521531104], 0, [5012.899521531101, 99.37799043062196], -0.5470946737007636, [4261.253588516747, -110.68899521531102], 0, false], "basePt": { "x": 9.569377990430496, "y": -285.1196172248802, "z": 0 } } + + let pls = LoadEntityFromFileData(d) as Polyline[]; + + for (let pl of pls) + { + expect(pl.Area).toMatchNumberSnapshot(); + } +}); diff --git a/src/Add-on/testEntity/DrawShapeManage.ts b/src/Add-on/testEntity/DrawShapeManage.ts index d2948628f..239092c01 100644 --- a/src/Add-on/testEntity/DrawShapeManage.ts +++ b/src/Add-on/testEntity/DrawShapeManage.ts @@ -1,6 +1,7 @@ import { ShapeManager } from "../../DatabaseServices/ShapeManager"; import { Region } from "../../DatabaseServices/Entity/Region"; import { app } from "../../ApplicationServices/Application"; +import { Shape } from "../../DatabaseServices/Shape"; export function DrawShapeManage(sm: ShapeManager) { @@ -11,3 +12,13 @@ export function DrawShapeManage(sm: ShapeManager) app.Database.ModelSpace.Append(reg1); } + +export function DrawShape(sp: Shape) +{ + let reg1 = new Region(); + //@ts-ignore + reg1.m_ShapeManager = new ShapeManager().AppendShapeList(sp); + reg1 = reg1.Clone(); + + app.Database.ModelSpace.Append(reg1); +} diff --git a/src/DatabaseServices/Entity/Polyline.ts b/src/DatabaseServices/Entity/Polyline.ts index 05ffb03f7..8d6645cc9 100644 --- a/src/DatabaseServices/Entity/Polyline.ts +++ b/src/DatabaseServices/Entity/Polyline.ts @@ -360,7 +360,7 @@ export class Polyline extends Curve } get Area2() { - if (this.NumberOfVertices < 3 && this.GetBuilgeAt(0) === 0) + if (this.EndParam < 2) return 0; let { pts, buls } = this.PtsBuls; diff --git a/src/DatabaseServices/ShapeManager.ts b/src/DatabaseServices/ShapeManager.ts index 7ed35ffb5..2d92976eb 100644 --- a/src/DatabaseServices/ShapeManager.ts +++ b/src/DatabaseServices/ShapeManager.ts @@ -22,6 +22,7 @@ export class ShapeManager AppendShapeList(shapes: Shape | Shape[]) { Array.isArray(shapes) ? this.m_ShapeList.push(...shapes) : this.m_ShapeList.push(shapes); + return this; } Clear() {