修复:干涉检查错误

auto-ime
ChenX 2 years ago
parent 8238cfccc1
commit e0cfa70451

@ -1,12 +1,13 @@
import { LoadCurvesFromFileData } from "../Utils/LoadEntity.util";
import { PolylineSpliteRect } from "../../src/Common/CurveUtils"; import { PolylineSpliteRect } from "../../src/Common/CurveUtils";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline"; import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { LoadCurvesFromFileData } from "../Utils/LoadEntity.util";
describe("封闭多段线分割矩形测试", () => describe("封闭多段线分割矩形测试", () =>
{ {
test("轮廓1", () => test("轮廓1", () =>
{ {
let data = { "file": [1, "Polyline", 8, 2, 176, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 9, [8387.713348727397, 1084.5343505247351], 0, [7226.765061171589, 1084.5343505247351], 0, [7226.765061171589, 829.0146317325472], 0, [4632.684437781331, 829.0146317325472], 0, [4632.684437781331, 1078.9795740292527], 0, [5965.830796697095, 1078.9795740292527], 0, [5965.830796697095, 1301.1706338485465], 0, [8387.713348727397, 1301.1706338485465], 0, [8387.713348727397, 1084.5343505247351], 0, false], "basePt": { "x": 4632.684437781331, "y": 829.0146317325472, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; let data =
{ "file": [1, "Polyline", 8, 2, 176, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 9, [8387.713348727397, 1084.5343505247351], 0, [7226.765061171589, 1084.5343505247351], 0, [7226.765061171589, 829.0146317325472], 0, [4632.684437781331, 829.0146317325472], 0, [4632.684437781331, 1078.9795740292527], 0, [5965.830796697095, 1078.9795740292527], 0, [5965.830796697095, 1301.1706338485465], 0, [8387.713348727397, 1301.1706338485465], 0, [8387.713348727397, 1084.5343505247351], 0, false], "basePt": { "x": 4632.684437781331, "y": 829.0146317325472, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[]; let pl = LoadCurvesFromFileData(data) as Polyline[];
@ -20,7 +21,8 @@ describe("封闭多段线分割矩形测试", () =>
}); });
test("轮廓2", () => test("轮廓2", () =>
{ {
let data = { "file": [1, "Polyline", 8, 2, 209, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5376.119285317616, -2438.550333164698, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 17, [0, 0], 0, [0, -2396.493624880947], 0, [774.4127870794337, -2396.493624880947], 0, [774.4127870794337, -805.8079000691391], 0, [1852.3116663926985, -805.8079000691391], 0, [1852.3116663926985, -1789.521440413283], 0, [2972.0706963589055, -1789.521440413283], 0, [2972.0706963589055, -1088.3639169765001], 0, [4029.0395003456997, -1088.3639169765001], 0, [4029.0395003456997, -2155.797758626529], 0, [4719.731986119246, -2155.797758626529], 0, [4719.731986119246, -1517.4304611691587], 0, [7095.295535673724, -1517.4304611691587], 0, [7095.295535673724, -690.6924857735476], 0, [4426.7109315486505, -690.6924857735476], 0, [4426.7109315486505, 0], 0, [0, 0], 0, false], "basePt": { "x": 5376.119285317616, "y": -4835.043958045645, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; let data =
{ "file": [1, "Polyline", 8, 2, 209, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5376.119285317616, -2438.550333164698, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 17, [0, 0], 0, [0, -2396.493624880947], 0, [774.4127870794337, -2396.493624880947], 0, [774.4127870794337, -805.8079000691391], 0, [1852.3116663926985, -805.8079000691391], 0, [1852.3116663926985, -1789.521440413283], 0, [2972.0706963589055, -1789.521440413283], 0, [2972.0706963589055, -1088.3639169765001], 0, [4029.0395003456997, -1088.3639169765001], 0, [4029.0395003456997, -2155.797758626529], 0, [4719.731986119246, -2155.797758626529], 0, [4719.731986119246, -1517.4304611691587], 0, [7095.295535673724, -1517.4304611691587], 0, [7095.295535673724, -690.6924857735476], 0, [4426.7109315486505, -690.6924857735476], 0, [4426.7109315486505, 0], 0, [0, 0], 0, false], "basePt": { "x": 5376.119285317616, "y": -4835.043958045645, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[]; let pl = LoadCurvesFromFileData(data) as Polyline[];
@ -34,7 +36,8 @@ describe("封闭多段线分割矩形测试", () =>
}); });
test("轮廓3", () => test("轮廓3", () =>
{ {
let data = { "file": [1, "Polyline", 8, 2, 204, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 13, [6757.27535177342, -889.6497705352106], 0, [8091.75010660756, -889.6497705352106], 0, [8091.75010660756, -490.4058330764652], 0, [6922.134064474898, -490.4058330764652], 0, [6922.134064474898, -259.85651707916213], 0, [5668.170711611516, -259.85651707916213], 0, [5668.170711611516, -479.1595249790362], 0, [4577.27882616086, -479.1595249790362], 0, [4577.27882616086, -889.6497705352106], 0, [5898.729096631669, -889.6497705352106], 0, [5898.729096631669, -658.1101316379868], 0, [6757.27535177342, -658.1101316379868], 0, [6757.27535177342, -889.6497705352106], 0, false], "basePt": { "x": 4577.27882616086, "y": -889.6497705352106, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; let data =
{ "file": [1, "Polyline", 8, 2, 204, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 13, [6757.27535177342, -889.6497705352106], 0, [8091.75010660756, -889.6497705352106], 0, [8091.75010660756, -490.4058330764652], 0, [6922.134064474898, -490.4058330764652], 0, [6922.134064474898, -259.85651707916213], 0, [5668.170711611516, -259.85651707916213], 0, [5668.170711611516, -479.1595249790362], 0, [4577.27882616086, -479.1595249790362], 0, [4577.27882616086, -889.6497705352106], 0, [5898.729096631669, -889.6497705352106], 0, [5898.729096631669, -658.1101316379868], 0, [6757.27535177342, -658.1101316379868], 0, [6757.27535177342, -889.6497705352106], 0, false], "basePt": { "x": 4577.27882616086, "y": -889.6497705352106, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(data) as Polyline[]; let pl = LoadCurvesFromFileData(data) as Polyline[];
@ -88,4 +91,17 @@ describe("封闭多段线分割矩形测试", () =>
expect(c.Area).toMatchSnapshot(); expect(c.Area).toMatchSnapshot();
}); });
test('交点参数为负数?', () =>
{
let d =
{ "file": [1, "Polyline", 8, 2, 102, false, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 5, [753.4709588432369, 2025.012386886011], 0, [735.4710123919904, 2025.0123894054675], 0, [735.4710123919904, 863.0123868860028], 0, [753.4710123919904, 863.0123868860028], 0, [753.4710123919904, 863.0132159650564], 0, true], "basePt": { "x": 735.4710123919904, "y": 863.0123868860028, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadCurvesFromFileData(d)[0] as Polyline;
let cons = PolylineSpliteRect(pl);
for (let c of cons)
expect(c.Area).toMatchSnapshot();
});
}); });

@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`封闭多段线分割矩形测试 交点参数为负数? 1`] = `20916.000000000233`;
exports[`封闭多段线分割矩形测试 轮廓1 1`] = `333239.8526794412`; exports[`封闭多段线分割矩形测试 轮廓1 1`] = `333239.8526794412`;
exports[`封闭多段线分割矩形测试 轮廓1 2`] = `595357.6812453549`; exports[`封闭多段线分割矩形测试 轮廓1 2`] = `595357.6812453549`;

@ -15,7 +15,7 @@ import { Orbit } from '../Geometry/Orbit';
import { PlaneExt } from '../Geometry/Plane'; import { PlaneExt } from '../Geometry/Plane';
import { IntersectOption, IntersectResult } from '../GraphicsSystem/IntersectWith'; import { IntersectOption, IntersectResult } from '../GraphicsSystem/IntersectWith';
import { OffsetPolyline } from '../GraphicsSystem/OffsetPolyline'; import { OffsetPolyline } from '../GraphicsSystem/OffsetPolyline';
import { arrayLast, changeArrayStartIndex, equalArray } from './ArrayExt'; import { arrayLast, arrayRemoveDuplicateBySort, changeArrayStartIndex, equalArray } from './ArrayExt';
import { Status } from './Status'; import { Status } from './Status';
import { FixIndex, LINK_FUZZ } from './Utils'; import { FixIndex, LINK_FUZZ } from './Utils';
@ -821,7 +821,8 @@ export function PolylineSpliteRect(outline: Polyline): Polyline[]
return [outline]; return [outline];
let firstDerv = outline.GetFistDeriv(0).normalize(); let firstDerv = outline.GetFistDeriv(0).normalize();
if (!isParallelTo(firstDerv, XAxis, PolylineSpliteRectFuzz) && !isParallelTo(firstDerv, YAxis, PolylineSpliteRectFuzz)) return [outline]; if (!isParallelTo(firstDerv, XAxis, PolylineSpliteRectFuzz) && !isParallelTo(firstDerv, YAxis, PolylineSpliteRectFuzz))
return [outline];
let cus = outline.Explode(); let cus = outline.Explode();
let yCus: Curve[] = []; let yCus: Curve[] = [];
@ -841,8 +842,8 @@ export function PolylineSpliteRect(outline: Polyline): Polyline[]
yCus.sort((c1, c2) => c1.StartPoint.x - c2.StartPoint.x); yCus.sort((c1, c2) => c1.StartPoint.x - c2.StartPoint.x);
let rects: Polyline[] = []; let rects: Polyline[] = [];
let endParam = outline.EndParam;
for (let i = 0; i < yCus.length - 1; i++) for (let i = 0; i < yCus.length - 1; i++)
{ {
@ -858,11 +859,21 @@ export function PolylineSpliteRect(outline: Polyline): Polyline[]
let y2: number; let y2: number;
let res = c1.IntersectWith2(outline, IntersectOption.ExtendThis); let res = c1.IntersectWith2(outline, IntersectOption.ExtendThis);
let res2 = c2.IntersectWith2(outline, IntersectOption.ExtendThis); let res2 = c2.IntersectWith2(outline, IntersectOption.ExtendThis);
let pars = [...res.map(r => Math.floor(r.argParam)), ...res2.map(r => Math.floor(r.argParam))]; let pars: number[] = [];
pars = [...new Set(pars)]; for (let i of res) pars.push(i.argParam);
for (let i of res2) pars.push(i.argParam);
for (let i = 0; i < pars.length; i++)
{
let p = pars[i];
if (p < 0) p = 0;//请参照测试用例
else if (p > endParam) p = endParam;//请参照测试用例
else p = Math.floor(p);
pars[i] = p;
}
pars.sort((a, b) => a - b); pars.sort((a, b) => a - b);
arrayRemoveDuplicateBySort(pars);
let ys: number[] = []; let ys: number[] = [];
for (let par of pars) for (let par of pars)

Loading…
Cancel
Save