mirror of https://gitee.com/cf-fz/WebCAD.git
commit
2a1d70b99e
@ -0,0 +1,243 @@
|
|||||||
|
import { CADFile } from '../../src/DatabaseServices/CADFile';
|
||||||
|
import { Polyline } from '../../src/DatabaseServices/Polyline';
|
||||||
|
import { GetPointAtCurveDir } from '../../src/Common/CurveUtils';
|
||||||
|
import { Vector3, Vector2 } from 'three';
|
||||||
|
import { Factory } from '../../src/DatabaseServices/CADFactory';
|
||||||
|
|
||||||
|
Factory(Polyline);
|
||||||
|
test('2个大圆中间', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 17, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 3, [108.37693694676932, 28.257776463252547], 0.4472440944881872, [108.37693694676932, 17.68555707305448], 3.5940684866260213, [111.70676982557188, 14.089337563947739], 0.5086040192926764, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, new Vector3(110.19, 17.4));
|
||||||
|
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
let p = new Vector3().fromArray([84.89024786541306, 11.031154321671167, 0]);
|
||||||
|
|
||||||
|
isR = GetPointAtCurveDir(pl, p);
|
||||||
|
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('点在端点且端点平行', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 16, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 43.1743189069092, -3.552713678800501e-15, 0, 1], 2, 3, [35.26780526232293, 5.878508963172803], -0.8898689681740283, [35.26780526232293, 13.326990467988661], 0, [35.26780526232293, 23.770222268555234], 0, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let p = new Vector3(81.8, 12.06);
|
||||||
|
let isR = GetPointAtCurveDir(pl, p);
|
||||||
|
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('点在和端点平行', () =>
|
||||||
|
{
|
||||||
|
let pl = new Polyline();
|
||||||
|
pl.AddVertexAt(0, new Vector2(0, 0));
|
||||||
|
pl.AddVertexAt(1, new Vector2(0, 5));
|
||||||
|
pl.AddVertexAt(2, new Vector2(0, 10));
|
||||||
|
|
||||||
|
let p = new Vector3(5, 5, 0);
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, p);
|
||||||
|
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('点在端点上且点在圆心上', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 31, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [17.513342658829444, 9.06588623278316], 0, [19.513342658829444, 9.06588623278316], 0.9999999999999999, [19.513342658829444, 7.06588623278316], -0.9999999999999999, [19.513342658829444, 5.06588623278316], 0, [17.513342658829444, 5.06588623278316], 0, true]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let p = new Vector3(19.48, 8.1097);
|
||||||
|
let isR = GetPointAtCurveDir(pl, p);
|
||||||
|
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('存在精度误差,并且点在圆内', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [0, 0], 0, [2, 0], 1, [2, 2], -1, [2, 4], 0, [0, 4], 0, true]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let p = new Vector3().fromArray([2, 3.8, 0]);
|
||||||
|
|
||||||
|
for (let i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
p.x -= 0.01;
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, p);
|
||||||
|
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
}
|
||||||
|
|
||||||
|
pl.Reverse();
|
||||||
|
|
||||||
|
for (let i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
p.x += 0.01;
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, p);
|
||||||
|
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('大于1凸度的圆', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 46, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [0, 0], 0, [1, 0], 3.7050811739160006, [1, 1.7149500468022372], 0, [0, 1.7149500468022374], 0, true]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let pt = new Vector3().fromArray([1.5998555184265881, 0.9127879590514852, 0]);
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('盲区计算', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 65, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 3, [0, 0], 0, [1, 0], 0.6998085535161632, [1, -1], -1.9959956751332304, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let pt = new Vector3().fromArray([1.3789363811285338, -0.34949587695820905, 0]);
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
pl.Reverse();
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('参数点在终点上', () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 38, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 9, [26.388805509867886, 5.284389892538414], 0, [28.388805509867886, 5.284389892538414], 0.9999999999999999, [28.388805509867886, 7.284389892538414], -0.9999999999999999, [28.388805509867886, 9.284389892538414], 0, [24.129449189553043, 9.284389892538414], 0, [24.129449189553043, 13.772242014802323], 0, [33.10581078647962, 13.772242014802321], 0, [33.10581078647962, 0.368763303745288], 0, [27.762738407356657, 0.36876330374528865], 0, true]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
let pt = new Vector3().fromArray([24.40481807693597, 4.679455426066854, 0]);
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
pt = new Vector3().fromArray([30.314368267468268, 10.71117601112483, 0]);
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
|
||||||
|
pl.Reverse();
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
pt = new Vector3().fromArray([24.40481807693597, 4.679455426066854, 0]);
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('点在小角内', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 27, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -47.5997122622927, 10.897558314909338, 0, 1], 2, 4, [-0.906131771640112, 6.969061295372345], 3.7897716494829594, [4.660056657223795, 6.487252124645892], 0, [20.106696883852685, 18.393201133144473], 0, [9.169563739376775, 22.583048158640217], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
let pt = new Vector3().fromArray([-45.25245903106504, 20.057300217471017, 0]);
|
||||||
|
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
pl.Reverse();
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('首尾点相等', () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 264, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [0, 0], 0, [5, 0], 0.9999999999999999, [5, 5], -0.9999999999999999, [5, 10], 0, [0, 10], 0, [0, 0], 0, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let pt = new Vector3().fromArray([-0.4662687082606203, -0.5388413229688394, 0]);
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
|
||||||
|
pl.Reverse();
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test('点在圆弧的弦中心上', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 264, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [0, 0], 0, [5, 0], 0.9999999999999999, [5, 5], -0.9999999999999999, [5, 10], 0, [0, 10], 0, [0, 0], 0, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let pt = new Vector3().fromArray([4.999999999999999, 2.5, 0]);
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
pt = new Vector3().fromArray([5, 9.5, 0]);
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
pt = new Vector3().fromArray([5, 5.5, 0]);
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
|
||||||
|
pt = new Vector3().fromArray([6, 10, 0]);
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('圆弧过大导致直线小角错误', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.028011204481791063, 0.028011204481792618, 0, 1], 2, 4, [-2241.358078364921, -214.80916327845875], -1.1401903887488165, [-2190.503423306555, -220.10318099746846], -1.1044015866963386, [-2231.667025600985, -212.01859443849355], 0, [-2241.358078364921, -214.80916327845875], 0, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let pt = new Vector3().fromArray([-2246.7733894227954, -220.1844621837422, 0]);
|
||||||
|
let isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
|
||||||
|
pt = new Vector3().fromArray([-2184.668414731696, -221.35723534211996, 0]);
|
||||||
|
|
||||||
|
//[1,["Circle",1,1,4,false,7,-1,[1,0,0,0,0,1,0,0,0,0,1,0,-2184,-221.357,0,1],1,1]]
|
||||||
|
isR = GetPointAtCurveDir(pl, pt);
|
||||||
|
expect(isR).toBeFalsy();
|
||||||
|
});
|
@ -0,0 +1,147 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`IKKGK圆与直线补圆弧 1`] = `1`;
|
||||||
|
|
||||||
|
exports[`IKKGK圆与直线补圆弧 2`] = `44.998097679646904`;
|
||||||
|
|
||||||
|
exports[`IKKGK圆与直线补圆弧 3`] = `1`;
|
||||||
|
|
||||||
|
exports[`IKKGK圆与直线补圆弧 4`] = `44.998097679647046`;
|
||||||
|
|
||||||
|
exports[`IKKGK圆与直线补圆弧 5`] = `1`;
|
||||||
|
|
||||||
|
exports[`IKKGK圆与直线补圆弧 6`] = `52.52605376818708`;
|
||||||
|
|
||||||
|
exports[`中间区域需要圆裁剪 1`] = `1`;
|
||||||
|
|
||||||
|
exports[`中间区域需要圆裁剪 2`] = `24.711300177428036`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 1`] = `4148.643109243218`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 2`] = `4425.268216257021`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 3`] = `4021.8883370297244`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 4`] = `4581.211434067452`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 5`] = `3900.596094685299`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 6`] = `4757.455448859379`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 7`] = `3783.7370117939813`;
|
||||||
|
|
||||||
|
exports[`圆求交错误导致的线丢失 8`] = `4971.999047743294`;
|
||||||
|
|
||||||
|
exports[`拱门偏移 1`] = `1`;
|
||||||
|
|
||||||
|
exports[`拱门偏移 2`] = `4.314156035548454`;
|
||||||
|
|
||||||
|
exports[`拱门偏移 3`] = `1`;
|
||||||
|
|
||||||
|
exports[`拱门偏移 4`] = `6.827404319936081`;
|
||||||
|
|
||||||
|
exports[`简单图形因为点在线内算法错误导致的丢失 1`] = `8.675026988029915`;
|
||||||
|
|
||||||
|
exports[`简单图形因为点在线内算法错误导致的丢失 2`] = `8.252659494518674`;
|
||||||
|
|
||||||
|
exports[`简单图形因为点在线内算法错误导致的丢失 3`] = `6.802593049888034`;
|
||||||
|
|
||||||
|
exports[`简单图形因为点在线内算法错误导致的丢失 4`] = `6.045525633131274`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 1`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 2`] = `202.39234999237357`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 3`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 4`] = `202.97100463130596`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 5`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 6`] = `203.6334701054305`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 7`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 8`] = `204.40220678622498`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 9`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 10`] = `205.30911616294793`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 11`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 12`] = `206.4013429179738`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 13`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 14`] = `207.75214121305123`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 15`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 16`] = `209.48307101962268`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 17`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 18`] = `211.81505991717293`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 19`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 20`] = `215.20865129706962`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 21`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 22`] = `220.89085248936073`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 23`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 24`] = `243.05075247271324`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 25`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 26`] = `236.6991306483004`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 27`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 28`] = `236.69932095661932`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 29`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 30`] = `205.62990409788847`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 31`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 32`] = `198.55214618601138`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 33`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 34`] = `195.91344487061264`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 35`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 36`] = `194.55183899140644`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 37`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 38`] = `193.73991606924534`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 39`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 40`] = `193.2116315246781`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 41`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 42`] = `192.84670578048616`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 43`] = `1`;
|
||||||
|
|
||||||
|
exports[`补圆弧测试 补圆弧测试1 44`] = `192.58324938493251`;
|
||||||
|
|
||||||
|
exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 1`] = `54789.14760701891`;
|
||||||
|
|
||||||
|
exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 2`] = `54907.17933624483`;
|
||||||
|
|
||||||
|
exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 3`] = `55497.39792073307`;
|
||||||
|
|
||||||
|
exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 4`] = `56678.13326318633`;
|
||||||
|
|
||||||
|
exports[`闭合多段线判断精度和重复交点参数导致偏移丢失 5`] = `57859.26303559798`;
|
@ -0,0 +1,19 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`多段线 优化参数在端点上的时候 1`] = `
|
||||||
|
Vector3 {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0,
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`多段线 存在大圆弧的多段线面积 1`] = `-24.019436375469752`;
|
||||||
|
|
||||||
|
exports[`多段线 最近点精度 1`] = `
|
||||||
|
Vector3 {
|
||||||
|
"x": 1.987500976448074,
|
||||||
|
"y": 3.9999218841540816,
|
||||||
|
"z": 0,
|
||||||
|
}
|
||||||
|
`;
|
@ -0,0 +1,835 @@
|
|||||||
|
import { Factory } from "../../src/DatabaseServices/CADFactory";
|
||||||
|
import { CADFile } from "../../src/DatabaseServices/CADFile";
|
||||||
|
import { Curve } from "../../src/DatabaseServices/Curve";
|
||||||
|
import { Polyline } from "../../src/DatabaseServices/Polyline";
|
||||||
|
Factory(Polyline);
|
||||||
|
|
||||||
|
function loadFile(data)
|
||||||
|
{
|
||||||
|
let file = new CADFile();
|
||||||
|
file.Data = data;
|
||||||
|
let cus: Curve[] = [];
|
||||||
|
let count = file.Read();
|
||||||
|
for (let i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
cus.push(file.ReadObject(undefined) as Curve);
|
||||||
|
}
|
||||||
|
return cus;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EntityToMatchSnapshot(ens: Curve[])
|
||||||
|
{
|
||||||
|
expect(ens.length).toMatchSnapshot();
|
||||||
|
for (let c of ens)
|
||||||
|
{
|
||||||
|
expect(c.Length).toMatchSnapshot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test('IKKGK圆与直线补圆弧', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 5, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -47.808747539346534, 10.92028558763661, 0, 1], 2, 3, [-0.906131771640112, 6.969061295372345], 3.7897716494829594, [4.660056657223795, 6.487252124645892], 0, [18.466397865202012, 17.128892766521286], 0, false]]
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
//负1 左边. 禁止补圆弧
|
||||||
|
let cus = pl.GetOffsetCurves(-1);
|
||||||
|
|
||||||
|
EntityToMatchSnapshot(cus);
|
||||||
|
|
||||||
|
pl.GetOffsetCurves(-5.654208780429431);
|
||||||
|
//
|
||||||
|
|
||||||
|
//翻转曲线后测试
|
||||||
|
pl.Reverse();
|
||||||
|
cus = pl.GetOffsetCurves(1);
|
||||||
|
|
||||||
|
EntityToMatchSnapshot(cus);
|
||||||
|
|
||||||
|
//圆丢失的问题
|
||||||
|
cus = pl.GetOffsetCurves(-1.926388985025112);
|
||||||
|
EntityToMatchSnapshot(cus);
|
||||||
|
});
|
||||||
|
describe("闭合多段线", () =>
|
||||||
|
{
|
||||||
|
|
||||||
|
test('闭合多段线偏移测试1', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [6.059716713881022, 3.983456090651555], 1.1217395195062214, [6.383002832861191, 4.064022662889515], 0, [4.929178470254959, 8.399433427762037], 1.2642365052895204, [5.750708215297452, 4.050991501416427], 0.7171789779484218, true]]
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 1; i < 10; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = -0.5; i < -0.15; i += 0.05)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 2; i < 10; i += 2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试2', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 734, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [8.176442643449754, 4.003694129881114], 0.6482011490054378, [8.554554536583165, 4.090460859042256], 0, [7.7292787370841225, 8.733182129315965], 0, [7.8227800907745895, 4.037582052934876], 1.223388515290821, true]]
|
||||||
|
|
||||||
|
let cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(-0.1799).length).toBe(2);
|
||||||
|
|
||||||
|
for (let i = 0.2; i < 10; i += 2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = -0.17; i < 0; i += 0.03)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = -0.2; i > -0.34; i -= 0.02)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 0.35; i < 0.5; i += 0.05)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试3', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 1172, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [12.52535684411379, 4.512623511896158], 0.39558516940595195, [13.121416971132648, 4.487590129452889], 0, [12.414545456418505, 8.796498405316765], 0, [12.015990240675425, 8.743859037199755], 0, [12.015990240675425, 4.4951100391838885], 0.8508932598252141, true]]
|
||||||
|
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 0.5; i < 10; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 0.1; i <= 0.5; i += 0.01)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 0.51; i <= 1; i += 0.1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试4', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 1453, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [17.138593827490823, 4.9429359111242475], 0.6262511063576436, [18.12066066115083, 4.8347623552068075], 0, [18.12066066115083, 10.450468898178228], 0, [16.250318720818097, 10.450468898178228], 0, [16.250318720818097, 4.952028938447833], 0.8739221457690426, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 1; i < 10; i += 2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 0.4; i <= 0.6; i += 0.02)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 1; i <= 2; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(0);
|
||||||
|
}
|
||||||
|
//变换曲线顺序
|
||||||
|
data = [1, ["Polyline", 1, 1, 1891, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [22.178278439318607, -1.9155229050126357], 0, [22.83746943877066, -1.800164480108526], 0, [23.79329638797614, -6.11786552651948], -0.871731137783436, [23.348342463346004, -6.282663276382493], -0.7430788314178012, [22.903388538715866, -6.267501883395095], 0, true]];
|
||||||
|
cus = loadFile(data);
|
||||||
|
for (let i = 0.01; i <= 0.33; i += 0.03)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 0.34; i <= 1; i += 0.1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试5', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 264, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [0, 0], 0, [5, 0], 0.9999999999999999, [5, 5], -0.9999999999999999, [5, 10], 0, [0, 10], 0, [0, 0], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 0.5; i < 10; i += 1.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(-1.3).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(-1.2).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(-2).length).toBe(1);
|
||||||
|
|
||||||
|
for (let i = 2; i <= 2.8; i += 0.1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 2.9; i <= 6; i += 0.5)
|
||||||
|
{
|
||||||
|
let len = cus[0].GetOffsetCurves(-i).length;
|
||||||
|
expect(len).toBe(0);
|
||||||
|
}
|
||||||
|
//反转曲线
|
||||||
|
cus[0].Reverse();
|
||||||
|
for (let i = 0.5; i < 10; i += 1.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(1.3).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(1.2).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(2).length).toBe(1);
|
||||||
|
|
||||||
|
for (let i = 2; i <= 2.8; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 2.9; i <= 6; i += 1)
|
||||||
|
{
|
||||||
|
let len = cus[0].GetOffsetCurves(i).length;
|
||||||
|
expect(len).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试6', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 11080, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2.007355593658339, -15.226898894860806, 0, 1], 2, 6, [0.06393073988345588, -13.474722415885717], 0, [0.06393073988345643, -4.4950563800695225], 0, [6.069811270331949, -4.495056380069524], -0.9999999999999999, [6.0698112703319484, -9.101508437403805], 0.8261854469247998, [6.069811270331948, -13.53303193559881], 0, [0.06393073988345588, -13.474722415885717], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 0.5; i < 10; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 0.1; i <= 2.9; i += 0.1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 3; i <= 6; i += 0.1)
|
||||||
|
{
|
||||||
|
let len = cus[0].GetOffsetCurves(i).length;
|
||||||
|
expect(len).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试7', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 3103, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [7.068575921553821, 19.385189367549113], 0, [17.866251977281493, 27.179961431447197], -0.7242773730087224, [27.449988121418478, 20.215779833374317], -0.5496546648274403, [21.06083069199382, 18.554598901723907], 0.7351204491094537, [17.802360402987244, 16.70174324719076], -1.609719383557213, [7.068575921553821, 19.385189367549113], 0, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移
|
||||||
|
for (let i = 0.5; i < 5.5; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
//内偏移
|
||||||
|
for (let i = 3.6; i > 0; i -= 0.6)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 3.7; i <= 4.7; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(5).length).toBe(1);
|
||||||
|
for (let i = 6.1; i < 10; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试8', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 8895, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 9, [-35.77751476623335, 275.4953263952156], 0, [220.87993293360785, 358.6317790975911], 0, [317.8724610863793, 154.43698298649332], 0, [128.26300755464567, 91.72000989522755], 0, [202.6482547094027, 193.81740795077644], 0, [96.90452100901277, 149.33211308371583], 0, [167.64343251892882, 238.30270281783706], 0, [-5.9221441755043855, 147.87357882577945], 0, [115.1361992332179, 265.2855865896607], 0, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 20; i < 200; i += 100)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
//内偏移+
|
||||||
|
expect(cus[0].GetOffsetCurves(15).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(17.8).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(19).length).toBe(3);
|
||||||
|
for (let i = 20; i <= 40; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(3);
|
||||||
|
}
|
||||||
|
for (let i = 41.3; i <= 44.3; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(45).length).toBe(1);
|
||||||
|
for (let i = 50; i <= 250; i += 100)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试9', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 12283, false, 2, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2494.1602062139054, -154.37421492307953, 0, 1], 2, 4, [-835.9056689963722, -81.71614968554674], -1.404257507243489, [-2.5205246091134654, -224.3682931983378], -0.7704346688180675, [-677.9527382520764, -55.635630094036955], 0, [-835.9056689963722, -81.71614968554674], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
//内偏移+
|
||||||
|
for (let i = -350; i <= 350; i += 100)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 360; i <= 460; i += 50)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
cus[0].Reverse();
|
||||||
|
for (let i = -350; i <= 350; i += 100)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 360; i <= 460; i += 50)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试10', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 4133, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -38.7066882611841, -36.73336766355714, 0, 1], 2, 10, [57.916496677407835, -1.0361149153581897], 0, [57.916496677407835, 9.149866136686853], 0, [63.00948720343037, 6.40233177396418], 0, [67.96845166297861, 11.696361399698116], 0, [67.96845166297861, 5.866227508067071], 0, [76.41209385085804, 8.144670638129776], -0.6438035714487224, [82.13500688930966, 1.215523001409662], -0.16133386709235895, [73.7315725213725, -7.388950466238915], -0.24328993833238707, [62.473382937533245, -7.388950466238914], 0.16864648307761998, [53.5472469103464, -6.102300228085856], -1.9523252757782097, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 5; i < 20; i += 5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//内偏移+
|
||||||
|
expect(cus[0].GetOffsetCurves(2.3).length).toBe(1);
|
||||||
|
for (let i = 2.5; i < 4; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
for (let i = 4.2; i <= 7.2; i += 0.8)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 7.5; i <= 17.5; i += 5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试11', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 109, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 9, [8.533519553072624, 3.044692737430166], 0, [8.198324022346368, 5.782122905027932], 0, [9.483240223463685, 4.594972067039105], 0, [10.293296089385473, 4.958100558659217], 0, [11.298882681564244, 3.50558659217877], 0, [11.648044692737429, 3.1424581005586587], 0, [9.525139664804467, 2.3324022346368705], 0, [9.748603351955305, 3.589385474860334], 0, [8.519553072625698, 1.3268156424580995], 0, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 0.1; i <= 0.3; i += 0.1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//内偏移+
|
||||||
|
expect(cus[0].GetOffsetCurves(0.15).length).toBe(1);
|
||||||
|
|
||||||
|
for (let i = 0.2; i <= 0.7; i += 0.1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
for (let i = 0.8; i <= 3.8; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试12', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 4132, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 12, [13.549363225511495, 3.33570646745377], 0, [14.34284463241268, 4.996139781895137], 0, [14.523074259257426, 3.9557232996550056], 0, [15.838887129162556, 4.9814356943054605], 0, [15.943612070431213, 3.9627476292376005], 0, [17.33950450111622, 4.461280640196535], 0, [18.123624596131165, 2.7156799524846913], 0, [17.99903152781382, 1.6177035379380693], 0, [16.03466125512531, 2.900960499995888], 0, [15.014220997727234, 1.7794865537465168], 0, [14.332835411729478, 2.6268506799232134], 0, [13.549363225511495, 3.33570646745377], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 0.5; i <= 2; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//内偏移+
|
||||||
|
expect(cus[0].GetOffsetCurves(0.3).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(0.4).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(0.46).length).toBe(3);
|
||||||
|
expect(cus[0].GetOffsetCurves(0.5).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(0.9).length).toBe(1);
|
||||||
|
|
||||||
|
for (let i = 0.55; i <= 0.85; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
for (let i = 1; i <= 2; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试13', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 2689, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 13.053732578466253, -1.845982384833612, 0, 1], 2, 12, [10.73237450059647, 5.925995426719515], 0, [14.934000173256667, 9.279899014962986], 0, [15.443475259425389, 6.338838290261696], 0, [16.902963217271246, 7.476549375511614], 0, [17.07910144494388, 5.7632047972414195], 0, [18.04054823840169, 6.106578652047782], 0, [19.469515702452366, 2.925424892792106], 0, [19.064111106000592, -0.6472031134391991], 0, [17.253277279358528, 2.956832838161076], 0, [14.95258895308757, 3.1324290048358128], 0, [13.37431523183268, 1.7225442000746034], 0, [10.73237450059647, 5.925995426719515], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 0.5; i <= 2; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
//内偏移+
|
||||||
|
expect(cus[0].GetOffsetCurves(1).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(1.2).length).toBe(3);
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试14', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 1625, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 14, [340.820007357324, -3.870032999900914], 0, [431.6163856609081, 116.2815653567217], 0, [485.54806901416487, 54.84040710617603], 0, [533.3356365423672, 67.81131829240235], 0, [624.1320148459513, 40.504136847715344], 0, [656.9006325795757, 23.43714844478601], -0.783383849320176, [633.0068488154745, -74.86870475608706], 0.4462700081240285, [605.0169878346704, -106.27196341747704], -0.8416099256631104, [529.9222388617812, -128.11770857322662], 0, [510.1245323143834, -22.98506001118185], 0, [430.251026588674, -129.48306764546098], 0, [430.251026588674, -65.99387078656383], 0, [351.74287993519897, -145.86737651227318], 0, [303.2726328708796, -87.83961594231337], 0, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 10; i <= 90; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
//内偏移+
|
||||||
|
for (let i = 5; i <= 25; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(26.5).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(36).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(36.1).length).toBe(3);
|
||||||
|
expect(cus[0].GetOffsetCurves(45).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(60).length).toBe(1);
|
||||||
|
for (let i = 71; i <= 101; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试15', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 394, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 8, [-3.096429035694039, 1.977370035127478], 0, [2.646251476487261, 5.186031066288948], -0.5113280232193118, [8.158566581303122, 2.619102241359773], 0.23700604598013766, [11.103952861189804, -1.2148363240793185], -1.4842976346055852, [7.994019861756378, -4.028585228328609], 0.5402454464135219, [3.1398916351274853, -2.8932128634560885], -1.0879771453350477, [1.4615150957507161, -0.803469525212464], -0.082022192610066, [-3.096429035694039, 1.977370035127478], 0, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
for (let i = 0.5; i <= 5.5; i += 1)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
//内偏移+
|
||||||
|
for (let i = 0.1; i <= 1.8; i += 0.3)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1.9; i <= 2.2; i += 0.05)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
for (let i = 2.3; i <= 3.7; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 3.9; i <= 6.9; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test('闭合多段线偏移测试16', () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 4, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [-6.203966005665723, -0.056657223796033884], 0, [-1.8834846458923415, -0.923353563739375], -1.4125691360015384, [-1.9069913201133035, -1.5932937790368253], 0, [-6.189801699716714, -2.2096317280453257], -2.3881275241710798, [-6.203966005665723, -0.056657223796033884], 0, true]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
//外偏移 -
|
||||||
|
//内偏移+
|
||||||
|
for (let i = -1.5; i <= 1.5; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(1.6).length).toBe(0);
|
||||||
|
for (let i = 1.6; i <= 4.6; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
describe("补圆弧测试", () =>
|
||||||
|
{
|
||||||
|
test("补圆弧测试1", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 8815, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [-99.60068327971061, 80.69599512140186], 0, [-48.362234971168355, 80.69599512140186], -0.9874208089640422, [-14.972250883848176, 88.46675505445091], -1.1745224194600496, [18.29631507951812, 78.51046889023182], 0, [89.44733571649859, 78.5104688902318], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
// 向上-
|
||||||
|
// 向下+
|
||||||
|
expect(cus[0].GetOffsetCurves(17.45).length).toBe(2);
|
||||||
|
for (let i = -55; i <= 55; i += 5)
|
||||||
|
{
|
||||||
|
if (i === 0) continue;
|
||||||
|
EntityToMatchSnapshot(cus[0].GetOffsetCurves(i));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test("补圆弧测试2", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 12266, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [-869.4193524531552, -50.92359793870933], 0, [-609.861025770732, -50.92359793870939], -0.8167984427288847, [-480.7149315189898, -23.068558002059024], -1.4042575072434897, [-317.9835774160859, -50.92359793870939], 0, [-92.77019349218811, -50.92359793870939], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
// 向上-
|
||||||
|
// 向下+
|
||||||
|
expect(cus[0].GetOffsetCurves(83.24).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(86.46).length).toBe(2);
|
||||||
|
for (let i = 364; i <= 395; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test("补圆弧测试3", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 12272, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [-894.3165541673695, -331.80629190023], 0, [-671.3300245231958, -331.80629190023], -1.0058680701224356, [-535.7124860261546, -329.1982623137485], 0, [-214.92484688892245, -329.1982623137485], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
// 向上-
|
||||||
|
// 向下+
|
||||||
|
expect(cus[0].GetOffsetCurves(-1200).length).toBe(1);
|
||||||
|
for (let i = 63; i <= 94; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test("补圆弧测试3", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 195, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 23, [-25.572010711696727, -62.383195892823124], 0, [-10.312959798454724, -40.55427583637971], 0, [0.28360333574111785, -55.81332674962171], 0, [9.820510156517361, -48.18380129300071], 0, [18.721623189241864, -65.13830230771404], 0, [29.530117586121616, -60.47581452866788], 0, [39.06702440689787, -79.97349069558823], 0, [51.78290016793288, -70.64851513749588], -0.6227891115113805, [70.85671380948538, -80.60928448363998], 0.3759603135798005, [86.75155851077912, -99.68309812519247], -1.1383492019405204, [81.45327694368122, -117.6972554533254], 0.6271394112393051, [57.2931129977147, -138.2545879336653], -1.2933960333754264, [21.68866086681669, -138.2545879336653], -0.8106183277649434, [-17.73055399239181, -132.9563063665674], 0, [-43.37423677714574, -105.82910474302606], 0, [-51.003762233766736, -83.5763221612148], 0, [-48.67251834424364, -64.07864599429448], 0, [-62.65998168138215, -50.09118265715597], 0, [-86.39628310198083, -65.35023357039795], 0, [-86.39628310198083, -33.13668164244262], 0, [-73.68040734094582, -13.639005475522275], 0, [-43.16230551446182, -13.639005475522275], 0, [-33.62539869368556, -11.307761585999202], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
// 向外-
|
||||||
|
// 向内+
|
||||||
|
expect(cus[0].GetOffsetCurves(18).length).toBe(3);
|
||||||
|
for (let i = 50; i <= 80; i += 5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
//需要删除一个无效的线段 ref #IKO6L
|
||||||
|
expect(cus[0].GetOffsetCurves(27.3).length).toBe(1);
|
||||||
|
})
|
||||||
|
test("补圆弧测试3", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 10, [-5.637393767705383, -1.586402266288952], 0, [-0.84985835694051, 1.954674220963173], -0.5207626681247078, [1.728045325779038, 1.0906515580736542], -1.2136457904456304, [4.060938624362605, 1.3838754084985838], -1.0694858869096764, [6.891142200566573, -0.047681051558073895], -1.4716493502287318, [9.178341602266286, -2.976612659490083], -1.5003222663355726, [8.09233325325779, -7.040916632294616], -0.9628743606456998, [4.53257790368272, -7.478753541076488], -1.076087427994497, [2.3229461756373926, -7.478753541076488], 0, [-5.39660056657224, -7.478753541076487], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
// 向外-
|
||||||
|
// 向内+
|
||||||
|
expect(cus[0].GetOffsetCurves(1.88).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(2.12).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(3.2).length).toBe(1);
|
||||||
|
for (let i = 0.5; i <= 3.5; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 3.3; i <= 5.3; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(0);
|
||||||
|
}
|
||||||
|
for (let i = 2.33; i <= 3.2; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("不规则不闭合多段线测试", () =>
|
||||||
|
{
|
||||||
|
test("test1", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 3135, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [16.034190840579708, -16.545186318840567], 0, [36.985943188405784, -16.545186318840567], 0, [31.311510260869554, -12.507609043478254], 0, [48.334809043478245, -12.507609043478254], 0, [43.969860637681144, -16.6543100289855], 0, [56.84645843478259, -16.654310028985503], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 1.27; i <= 2.96; i += 0.2)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(9.16).length).toBe(2);
|
||||||
|
for (let i = 0.5; i <= 7.5; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
test("test2-共线线段", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 8814, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 7, [15.642409533480423, -31.01626057276902], 0, [38.129771973149346, -31.016260572769028], 0, [32.85929640135194, -26.50707591689791], 0, [47.440945483324754, -26.50707591689791], 0, [45.33685543194063, -31.016260572769028], 0, [61.52187596164093, -31.016260572769035], 0, [70.31099992504923, -35.88209931313313], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = 1.82; i <= 3.37; i += 0.3)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(18).length).toBe(2);
|
||||||
|
for (let i = 1; i <= 27; i += 5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
cus[0].Reverse();
|
||||||
|
expect(cus[0].GetOffsetCurves(-18).length).toBe(2);
|
||||||
|
data = [1, ["Polyline", 1, 1, 22696, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 7, [21.944751443449043, -31.01626057276902], 0, [38.129771973149346, -31.016260572769028], 0, [32.85929640135194, -26.50707591689791], 0, [47.440945483324754, -26.50707591689791], 0, [45.33685543194063, -31.016260572769028], 0, [61.52187596164093, -31.016260572769035], 0, [70.31099992504923, -35.88209931313313], 0, false]];
|
||||||
|
cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(11.4).length).toBe(1);
|
||||||
|
data = [1, ["Polyline", 1, 1, 24383, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -56.21146708819905, -48.62279820279199, 0, 1], 2, 7, [26.333787338902418, -31.01626057276902], 0, [35.05226039203026, -31.016260572769013], 0, [32.85929640135194, -26.50707591689791], 0, [47.440945483324754, -26.50707591689791], 0, [41.54871106124796, -31.016260572769013], 0, [61.52187596164093, -31.016260572769035], 0, [70.31099992504923, -35.88209931313313], 0, false]]
|
||||||
|
cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(5.2).length).toBe(1);
|
||||||
|
|
||||||
|
data = [1, ["Polyline", 1, 1, 4, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 6, [-3.158640226628895, -0.9915014164305944], 0, [-1.0906515580736538, -0.991501416430595], 0, [-1.983002832861189, 0.18413597733711037], 0, [1.0906515580736549, 0.3966005665722377], 0, [0.2974504249291776, -0.9915014164305944], 0, [3.966005665722378, -0.9915014164305953], 0, false]];
|
||||||
|
cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(2.01133).length).toBe(1);
|
||||||
|
})
|
||||||
|
test("test3", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 4308, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 5, [-41.52354973772388, -163.989590203395], 0, [-41.5235497377239, -231.3399374277236], 0, [21.016058399152634, -231.3399374277236], 0, [21.016058399152623, -294.68133541250876], 1.378670046466899, [261.5530127717545, -216.10593031745873], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = -100; i <= 181; i += 30)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
expect(cus[0].GetOffsetCurves(-122.6).length).toBe(2);
|
||||||
|
})
|
||||||
|
test("test4", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 14565, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -131.50093441946296, -806.1569163328921, 0, 1], 2, 24, [256.5228611988947, -38.705370748164505], 0, [372.1955588024039, 31.844231195771492], 0, [372.1955588024039, -31.54297461172431], 0, [450.9819163032461, 37.57414810492366], 0, [423.0485713711294, -54.10452244151095], 0, [589.216161736542, 52.97329979827009], 0, [611.0614699526845, -2.177150452319474], 0, [672.6580767260702, 61.21005535517633], 0, [678.0298738284004, 13.938240854670997], 0, [735.329042919922, 21.100636991111184], 0, [684.1179105443746, -21.515620020708024], 0, [730.6734854312358, -32.61733403219032], 0, [815.1897598412304, 38.29038771856768], 0, [835.6025888300849, -8.981426781937659], 0, [862.1034545349137, 74.4604882075907], 0, [943.4539498526012, 74.46048820759069], 0, [986.972668777612, -29.064785548515978], 0, [924.5022496755805, -66.26627108118637], 0, [1001.0109652050348, -106.27541589934134], 0, [965.9152241364777, -128.73669018321777], 0, [1006.6262837760039, -176.46689803645526], 0, [904.1467198558175, -189.8032796425069], 0, [981.3573502066429, -242.44689124534239], 0, [1004.5205393118904, -256.48518767276516], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(-100).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(46.8).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(49.6).length).toBe(3);
|
||||||
|
expect(cus[0].GetOffsetCurves(86.6).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(102.3).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(110).length).toBe(1);
|
||||||
|
|
||||||
|
})
|
||||||
|
test("test5", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 18, [-3.895184135977337, 0.7648725212464592], 0, [0.8215297450424939, 0.7648725212464592], 0, [-2.1246458923512743, -2.1388101983002827], 0, [5.311614730878187, -2.1388101983002827], 0, [1.89801699716714, 3.4844192634560907], 0, [6.671388101983003, 3.4844192634560907], 0, [6.671388101983002, -3.4985835694051], 0, [10.6657223796034, -0.11331444759206824], 0, [8.810198300283286, 1.161473087818697], 0, [14.674220963172807, 3.30028328611898], 0, [16.713881019830033, -2.521246458923512], 0, [11.55807365439094, -5.773371104815864], 0, [3.8441926345609083, -5.773371104815863], 0, [2.3569405099150167, -8.787535410764873], 0, [-1.5297450424929169, -6.090651558073655], 0, [-6.586402266288951, -12.674220963172807], 0, [-8.113314447592067, -8.767705382436262], 0, [-10.929178470254957, -12.436260623229463], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(0.755).length).toBe(3);
|
||||||
|
expect(cus[0].GetOffsetCurves(1.915).length).toBe(4);
|
||||||
|
expect(cus[0].GetOffsetCurves(2.36).length).toBe(4);
|
||||||
|
expect(cus[0].GetOffsetCurves(2.892).length).toBe(2);
|
||||||
|
expect(cus[0].GetOffsetCurves(3.6850).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(-1).length).toBe(3);
|
||||||
|
for (let i = 2; i <= 4; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
test("test6", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 2781, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -38.54242746474825, 6.4891615215880964, 0, 1], 2, 3, [18.466397865202012, 17.128892766521286], 0, [4.660056657223795, 6.487252124645892], -3.7897716494829594, [-0.906131771640112, 6.969061295372345], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
|
||||||
|
for (let i = -2.766; i <= 4.57; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 2.9; i <= 5.3; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(2);
|
||||||
|
}
|
||||||
|
for (let i = 6.14; i <= 8; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
cus[0].Reverse();
|
||||||
|
for (let i = -2.766; i <= 4.57; i++)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 2.9; i <= 5.3; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(2);
|
||||||
|
}
|
||||||
|
for (let i = 6.14; i <= 8; i += 0.5)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test("test7", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 2347, false, 1, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -86.54515219838936, -34.782221464287886, 0, 1], 2, 5, [-51.274354719855246, 28.573003242461496], 0, [-13.931531095689206, 15.255196629685734], 3.7897716494829594, [-8.365342666825299, 14.77338745895928], 0, [5.4409985411529185, 25.415028100834675], 0.37399715496699776, [29.033295173881022, 23.38858533792915], 0, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(-3.133).length).toBe(2);
|
||||||
|
for (let i = 10; i <= 60; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 5.9; i <= 43.3; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
cus[0].Reverse();
|
||||||
|
expect(cus[0].GetOffsetCurves(3.133).length).toBe(2);
|
||||||
|
for (let i = 10; i <= 60; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(-i).length).toBe(1);
|
||||||
|
}
|
||||||
|
for (let i = 5.9; i <= 43.3; i += 10)
|
||||||
|
{
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test("test8", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 395, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 8, [14.442408344729744, 12.584578126613017], 0, [14.442408344729742, 4.502438174603963], 0, [20.086360825183, 4.502438174603963], 0, [20.086360825183, -0.9157562066311582], 0, [26.226981123916133, -0.9157562066311598], 0.4633692494967541, [33.496391918739924, 7.663051563657783], -0.673355221273594, [51.96340443478295, 18.996108144407916], 0.32851266965536, [64.10919017271836, 18.996108144407913], -1.9784627492130062, false]];
|
||||||
|
let cus = loadFile(data);
|
||||||
|
for (let i = -15; i <= 15; i += 5)
|
||||||
|
{
|
||||||
|
if (i === 0) continue;
|
||||||
|
expect(cus[0].GetOffsetCurves(i).length).toBe(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
test("test9-2圆弧没交点", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 23321, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 3, [-245.7800398731897, -124.83507012637789], 0.47532901948537815, [-247.69480466441718, -117.62074637472406], 0.12615539092932912, [-193.96898890583213, -126.5297489543612], 0, false]]
|
||||||
|
let cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(11.22).length).toBe(1);
|
||||||
|
expect(cus[0].GetOffsetCurves(-11.22).length).toBe(1);
|
||||||
|
})
|
||||||
|
test("test10-共线部分错误裁剪", () =>
|
||||||
|
{
|
||||||
|
let data =
|
||||||
|
[1, ["Polyline", 1, 1, 151, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 13, [37846.488077851434, 5711.914029035103], 0, [28152.473806690192, 5711.914029035104], 0, [31338.416239942802, 10002.31650581529], 0, [39750.51284565329, 10002.316505815288], 0, [39750.51284565329, 17632.65706309083], 0, [45109.026777541825, 17632.65706309083], 0, [45109.02677754183, 10002.31650581529], 0, [54643.39210261924, 10002.31650581529], -0.8704734266845496, [55266.30970531861, 5526.15551510335], 0, [45201.90603450778, 5526.155515103216], 0, [45201.90603450778, 249.9945243911434], 0, [37846.488077851434, 435.75303832303064], 0, [37846.488077851434, 5711.914029035103], 0, false]]
|
||||||
|
let cus = loadFile(data);
|
||||||
|
expect(cus[0].GetOffsetCurves(2700).length).toBe(1);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test('提前丢失所有的线段', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 12, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -17.386067452264705, 17.11283965241085, 0, 1], 2, 3, [108.37693694676932, 28.257776463252547], 0.4472440944881872, [108.37693694676932, 17.68555707305448], 3.5940684866260213, [111.70676982557188, 14.089337563947739], 0.5086040192926764, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let cus = pl.GetOffsetCurves(-7.155086190577401);
|
||||||
|
|
||||||
|
expect(cus.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('中间区域需要圆裁剪', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 2628, false, 1, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -1325.2800870006804, -703.3564533406019, 0, 1], 2, 5, [-51.274354719855246, 28.573003242461496], 0, [-13.931531095689206, 15.255196629685734], 3.7897716494829594, [-8.365342666825299, 14.77338745895928], 0, [5.4409985411529185, 25.415028100834675], 0.37399715496699776, [29.033295173881022, 23.38858533792915], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let cus = pl.GetOffsetCurves(-35.6);
|
||||||
|
|
||||||
|
EntityToMatchSnapshot(cus);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('拱门偏移', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 6, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 4, [0, 0], 0, [0, 2], -1, [1, 2], 0, [1, 0], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
let cus = pl.GetOffsetCurves(0.4);
|
||||||
|
EntityToMatchSnapshot(cus);
|
||||||
|
|
||||||
|
cus = pl.GetOffsetCurves(-0.4);
|
||||||
|
EntityToMatchSnapshot(cus);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('土偏移因为点在圆弧切线上错误导致的丢失', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -9159.663865546216, 8361.344537815126, 0, 1], 2, 17, [28900.928792569663, -4648.336577340973], -0.9999999999999999, [28900.928792569663, 580.3540867812549], 0, [37687.5122530782, 580.3540867812552], 0, [37687.5122530782, 5568.3816889128875], 0, [27851.140930176796, 5568.381688912888], 0, [31251.043800494088, 10146.917554273516], 0, [39591.53702088006, 10146.917554273514], 0, [39591.53702088006, 17633.191417258837], -0.9999999999999999, [45238.18434134903, 17633.191417258837], 0, [45238.184341349035, 10146.917554273516], 0, [54628.482972136226, 10146.917554273516], -0.8741669928857767, [55271.13672581777, 5382.623174980927], 0, [45331.063598314984, 5382.623174981001], 0, [45331.063598314984, 1648.4655418896164], 0, [53885.44891640867, 1648.4655418896143], -0.6803347640614656, [56371.20555398866, -4648.336577340822], 0, [28900.928792569663, -4648.336577340976], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
let cus = pl.GetOffsetCurves(-801);
|
||||||
|
|
||||||
|
expect(cus.length).toBe(1);
|
||||||
|
cus = pl.GetOffsetCurves(801);
|
||||||
|
expect(cus.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
//ISSUE #IKSMH
|
||||||
|
test('闭合多段线判断精度和重复交点参数导致偏移丢失', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0.042016806722689815, 0.028011204481792618, 0, 1], 2, 11, [15758.920914649752, -1642.832074394305], 1.1432358165627696, [15758.920914649756, -3551.5797508523133], 0.010240353549940432, [20850.68748853413, -2761.478041111637], 0.39873042440013945, [23564.17781148077, 901.7338948663096], 0.029927117999965277, [22452.27083112051, 6973.8467189556395], 0, [31778.947378692996, 6973.846718955635], 0, [31327.636369627562, 7575.594679533537], 0, [31646.066893308867, 7787.881806674935], 0, [20955.832135358123, 7787.881806674936], 0, [21703.795934364476, 5637.485884531684], -0.559029831351755, [15758.920914649752, -1642.832074394304], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
for (let d of [40, 50, 100, 200, 300])
|
||||||
|
{
|
||||||
|
let cus = pl.GetOffsetCurves(d);
|
||||||
|
|
||||||
|
expect(cus.length).toBe(1);
|
||||||
|
expect(cus[0].Length).toMatchSnapshot();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//ISSUE #IKSMH
|
||||||
|
test('简单图形因为点在线内算法错误导致的丢失', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 3, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -0.01400560224089542, 0.37815126050420145, 0, 1], 2, 7, [2.075848303393214, 0.09193367302761479], -3.109533447960064, [2.8332320619106284, 1.1077844311377247], 0, [3.542914171656688, 1.1077844311377247], 0, [3.542914171656688, -0.4890219560878247], 0, [2.0758483033932134, -0.4890219560878247], 0, [2.0758483033932134, -0.4890219560878247], 0, [2.0758483033932134, 0.09193367302761501], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
for (let d of [0.2, 0.3, 0.4, 0.5])
|
||||||
|
{
|
||||||
|
let cus = pl.GetOffsetCurves(d);
|
||||||
|
|
||||||
|
expect(cus.length).toBe(1);
|
||||||
|
expect(cus[0].Length).toMatchSnapshot();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('圆求交错误导致的线丢失', () =>
|
||||||
|
{
|
||||||
|
let f = new CADFile();
|
||||||
|
f.Data =
|
||||||
|
[1, ["Polyline", 1, 1, 1077, false, 7, -1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2, 8, [245.62964413684085, 1116.1391538309313], -0.6953179171905909, [357.14209871457234, 1741.1251588427203], -0.6821635222887411, [892.2042303620135, 1596.040230558597], 0.37526047823909664, [1317.3934365017694, 1221.2756098839004], 0.14384173346393453, [1715.0964405621776, 1096.7424042631346], 0.026448384140957723, [1793.2064027435729, 1099.4889679050386], -0.1912121824403452, [733.4339688924879, 1000.3133228797258], -0.3304377553967397, [245.62964413684108, 1116.139153830931], 0, false]]
|
||||||
|
|
||||||
|
f.Read();
|
||||||
|
let pl = f.ReadObject() as Polyline;
|
||||||
|
|
||||||
|
for (let d of [10, 20, 30, 40])
|
||||||
|
{
|
||||||
|
let cus = pl.GetOffsetCurves(d);
|
||||||
|
|
||||||
|
expect(cus.length).toBe(1);
|
||||||
|
expect(cus[0].Length).toMatchSnapshot();
|
||||||
|
|
||||||
|
cus = pl.GetOffsetCurves(-d);
|
||||||
|
expect(cus.length).toBe(1);
|
||||||
|
expect(cus[0].Length).toMatchSnapshot();
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,14 @@
|
|||||||
|
import { app } from "../ApplicationServices/Application";
|
||||||
|
import { copyTextToClipboard } from "../Common/Utils";
|
||||||
|
import { PromptStatus } from "../Editor/PromptResult";
|
||||||
|
|
||||||
|
export class Command_CopyPoint
|
||||||
|
{
|
||||||
|
async exec()
|
||||||
|
{
|
||||||
|
let ptRes = await app.m_Editor.GetPoint();
|
||||||
|
|
||||||
|
if (ptRes.Status === PromptStatus.OK)
|
||||||
|
copyTextToClipboard(`new Vector3().fromArray(${JSON.stringify(ptRes.Value.toArray())});`);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
import { app } from "../ApplicationServices/Application";
|
||||||
|
import { copyTextToClipboard } from "../Common/Utils";
|
||||||
|
import { Polyline } from "../DatabaseServices/Polyline";
|
||||||
|
import { PromptStatus } from "../Editor/PromptResult";
|
||||||
|
|
||||||
|
export class Command_Lisp
|
||||||
|
{
|
||||||
|
async exec()
|
||||||
|
{
|
||||||
|
let ssRes = await app.m_Editor.GetEntity();
|
||||||
|
if (ssRes.Status != PromptStatus.OK) return;
|
||||||
|
|
||||||
|
let pl = ssRes.Entity as Polyline;
|
||||||
|
if (!pl) return;
|
||||||
|
|
||||||
|
let { pts, buls } = pl.PtsBuls;
|
||||||
|
|
||||||
|
let fun = `
|
||||||
|
(defun cx-make-pline (pts buls closeMark)
|
||||||
|
(entmakeX
|
||||||
|
(append
|
||||||
|
(list
|
||||||
|
'(0 . "LWPOLYLINE")
|
||||||
|
'(100 . "AcDbEntity")
|
||||||
|
'(100 . "AcDbPolyline")
|
||||||
|
(cons 90 (length pts))
|
||||||
|
(cons 70 closeMark)
|
||||||
|
)
|
||||||
|
(apply 'append(mapcar '(lambda (pt bul) (list (cons 10 pt) (cons 42 bul))) pts buls))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
let str = fun + "(cx-make-pline '(";
|
||||||
|
pts.forEach(p => str += `(${p.x} ${p.y})`)
|
||||||
|
str += ") '(";
|
||||||
|
buls.forEach(b => str += `${b} `);
|
||||||
|
str += `)`;
|
||||||
|
str += pl.CloseMark ? "1" : "0";
|
||||||
|
str += ")";
|
||||||
|
|
||||||
|
copyTextToClipboard(str);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
import { app } from "../ApplicationServices/Application";
|
||||||
|
import { Polyline } from "../DatabaseServices/Polyline";
|
||||||
|
import { Command } from "../Editor/CommandMachine";
|
||||||
|
import { PromptStatus } from "../Editor/PromptResult";
|
||||||
|
import { Vector3 } from "three";
|
||||||
|
|
||||||
|
//无限内偏移
|
||||||
|
export class OffsetX implements Command
|
||||||
|
{
|
||||||
|
offsetDis: number = 1;
|
||||||
|
async exec()
|
||||||
|
{
|
||||||
|
let ssRes = await app.m_Editor.GetEntity();
|
||||||
|
if (ssRes.Status != PromptStatus.OK) return;
|
||||||
|
let pl = ssRes.Entity as Polyline;
|
||||||
|
if (!pl) return;
|
||||||
|
|
||||||
|
let dis: number, step: number;
|
||||||
|
|
||||||
|
if (window["autoDis"])
|
||||||
|
{
|
||||||
|
this.offsetDis = 1.2 * Math.max(...pl.BoundingBox.getSize(new Vector3()).toArray());
|
||||||
|
dis = -this.offsetDis;
|
||||||
|
step = this.offsetDis / 20;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let disRes = await app.m_Editor.GetDistance({
|
||||||
|
Msg: "指定偏移距离:",
|
||||||
|
KeyWordList: [{ msg: "通过", key: "T" }],
|
||||||
|
Default: this.offsetDis
|
||||||
|
});
|
||||||
|
|
||||||
|
if (disRes.Status != PromptStatus.OK) return;
|
||||||
|
this.offsetDis = disRes.Value;
|
||||||
|
dis = -this.offsetDis;
|
||||||
|
if (pl.IsClockWise) dis = -dis;
|
||||||
|
|
||||||
|
let disRes1 = await app.m_Editor.GetDistance({
|
||||||
|
Msg: "步长:",
|
||||||
|
KeyWordList: [{ msg: "通过", key: "T" }],
|
||||||
|
Default: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
if (disRes1.Status != PromptStatus.OK) return;
|
||||||
|
step = disRes1.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// let step = 0.5;
|
||||||
|
let offRes: Polyline[] = [];
|
||||||
|
// offRes.push(...pl.GetOffsetCurves(dis) as Polyline[]);
|
||||||
|
|
||||||
|
// for (let i = 0; i < offRes.length; i++)
|
||||||
|
// {
|
||||||
|
// let offpl = offRes[i];
|
||||||
|
// if (offpl.IsClose)
|
||||||
|
// {
|
||||||
|
// offRes.push(...offpl.GetOffsetCurves(dis) as Polyline[]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
for (let i = 0; i <= Math.abs(dis); i += step)
|
||||||
|
{
|
||||||
|
offRes.push(...pl.GetOffsetCurves(i) as Polyline[]);
|
||||||
|
offRes.push(...pl.GetOffsetCurves(-i) as Polyline[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
offRes.forEach(c => app.m_Database.ModelSpace.Append(c));
|
||||||
|
}
|
||||||
|
}
|
@ -1,37 +0,0 @@
|
|||||||
import { app } from "../../ApplicationServices/Application";
|
|
||||||
import { Circle } from "../../DatabaseServices/Circle";
|
|
||||||
import { Curve } from "../../DatabaseServices/Curve";
|
|
||||||
import { Polyline } from "../../DatabaseServices/Polyline";
|
|
||||||
import { Command } from "../../Editor/CommandMachine";
|
|
||||||
import { PromptStatus } from "../../Editor/PromptResult";
|
|
||||||
import { isTargetCurInSourceCur } from "../../GraphicsSystem/BoolOperateUtils";
|
|
||||||
|
|
||||||
export class TestBoolOperationUtil implements Command
|
|
||||||
{
|
|
||||||
async exec()
|
|
||||||
{
|
|
||||||
let ssRes = await app.m_Editor.GetSelection(
|
|
||||||
{
|
|
||||||
Msg: "选择曲线"
|
|
||||||
},
|
|
||||||
);
|
|
||||||
let source = ssRes.SelectSet.SelectEntityList[0] as Polyline | Circle;
|
|
||||||
ssRes = await app.m_Editor.GetSelection(
|
|
||||||
{
|
|
||||||
Msg: "选择目标曲线"
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (ssRes.Status === PromptStatus.OK)
|
|
||||||
{
|
|
||||||
let target = ssRes.SelectSet.SelectEntityList as Curve[];
|
|
||||||
target.forEach(l =>
|
|
||||||
{
|
|
||||||
if (!isTargetCurInSourceCur(source, l))
|
|
||||||
{
|
|
||||||
l.ColorIndex = 1;
|
|
||||||
} else
|
|
||||||
l.ColorIndex = 2;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,130 @@
|
|||||||
|
import { Vector3 } from "three";
|
||||||
|
import { app } from "../../ApplicationServices/Application";
|
||||||
|
import { arrayLast, arrayRemoveIf, arraySortByNumber } from "../../Common/ArrayExt";
|
||||||
|
import { Circle } from "../../DatabaseServices/Circle";
|
||||||
|
import { Contour } from "../../DatabaseServices/Contour";
|
||||||
|
import { Curve } from "../../DatabaseServices/Curve";
|
||||||
|
import { Polyline } from "../../DatabaseServices/Polyline";
|
||||||
|
import { Command } from "../../Editor/CommandMachine";
|
||||||
|
import { PromptStatus } from "../../Editor/PromptResult";
|
||||||
|
import { equaln } from "../../Geometry/GeUtils";
|
||||||
|
import { IsPtsAllOutOrOnReg } from "../../GraphicsSystem/BoolOperateUtils";
|
||||||
|
|
||||||
|
export class TestTargeOnCurve implements Command
|
||||||
|
{
|
||||||
|
async exec()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
let ssRes = await app.m_Editor.GetSelection(
|
||||||
|
{
|
||||||
|
Msg: "选择曲线"
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let source = ssRes.SelectSet.SelectEntityList[0] as Polyline | Circle;
|
||||||
|
ssRes = await app.m_Editor.GetSelection(
|
||||||
|
{
|
||||||
|
Msg: "选择目标曲线"
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ssRes.Status === PromptStatus.OK && source.Length)
|
||||||
|
{
|
||||||
|
let target = ssRes.SelectSet.SelectEntityList[0] as Curve;
|
||||||
|
|
||||||
|
// let con1 = Contour.CreateContour([source]);
|
||||||
|
// let con2 = Contour.CreateContour([target]);
|
||||||
|
// let res = con1.getOperatedCurves(con2);
|
||||||
|
// testCurve(res.unionList, 1);
|
||||||
|
// testCurve(res.intersectionList, 2);
|
||||||
|
// testCurve(res.subtractList, 3);
|
||||||
|
// this.testClip(source as Polyline, target).forEach((c, i) =>
|
||||||
|
// {
|
||||||
|
// c.ColorIndex = i + 1;
|
||||||
|
// app.m_Database.ModelSpace.Append(c);
|
||||||
|
// })
|
||||||
|
this.testPtIn(source as Polyline, target);
|
||||||
|
// target.Erase();
|
||||||
|
// source.Erase();
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (err)
|
||||||
|
{
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testClip(outline: Polyline, l: Curve)
|
||||||
|
{
|
||||||
|
let tmpCus = [];
|
||||||
|
//交点参数列表
|
||||||
|
let iParams = l.IntersectWith(outline, 0)
|
||||||
|
.map(p => l.GetParamAtPoint(p));
|
||||||
|
arraySortByNumber(iParams);
|
||||||
|
|
||||||
|
//需要计算的点列表
|
||||||
|
let needCaclPts: Vector3[] = [];
|
||||||
|
for (let i = 0; i < iParams.length - 1; i++)
|
||||||
|
{
|
||||||
|
needCaclPts.push(l.GetPointAtParam((iParams[i] + iParams[i + 1]) / 2));
|
||||||
|
}
|
||||||
|
//如果交点不是首尾点,就加入首尾点
|
||||||
|
if (!equaln(iParams[0], 0, 1e-6))
|
||||||
|
needCaclPts.unshift(l.StartPoint);
|
||||||
|
if (!equaln(arrayLast(iParams), 1, 1e-6))
|
||||||
|
needCaclPts.push(l.EndPoint);
|
||||||
|
|
||||||
|
//切割曲线,缓存切割后曲线包围盒
|
||||||
|
if (IsPtsAllOutOrOnReg(outline, needCaclPts))
|
||||||
|
{
|
||||||
|
tmpCus.push(l);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let cus = l.GetSplitCurves(iParams);
|
||||||
|
|
||||||
|
//移除0长度线和在轮廓内的线.
|
||||||
|
arrayRemoveIf(cus, cu => equaln(cu.Length, 0, 1e-6)
|
||||||
|
|| outline.PtInCurve(cu.GetPointAtParam(0.5))
|
||||||
|
);
|
||||||
|
tmpCus.push(...cus);
|
||||||
|
}
|
||||||
|
return tmpCus;
|
||||||
|
}
|
||||||
|
testPtIn(outline: Polyline, l: Curve)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (outline.PtInCurve(l.EndPoint))
|
||||||
|
{
|
||||||
|
l.ColorIndex = 3
|
||||||
|
} else
|
||||||
|
l.ColorIndex = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function testPts(pts: Vector3[], color = 2)
|
||||||
|
{
|
||||||
|
pts.forEach(p =>
|
||||||
|
{
|
||||||
|
let cir = new Circle(p, 0.5);
|
||||||
|
cir.ColorIndex = color;
|
||||||
|
app.m_Database.ModelSpace.Append(cir);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function testContours(cons: Contour[], color = 2)
|
||||||
|
{
|
||||||
|
cons.forEach(c =>
|
||||||
|
{
|
||||||
|
c.Outline.ColorIndex = color;
|
||||||
|
app.m_Database.ModelSpace.Append(c.Outline);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function testCurve(cons: Curve[], color: number = 2)
|
||||||
|
{
|
||||||
|
cons.forEach(c =>
|
||||||
|
{
|
||||||
|
c.ColorIndex = color;
|
||||||
|
app.m_Database.ModelSpace.Append(c);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
|||||||
|
import { Box3, Vector3 } from "three";
|
||||||
|
import { Curve } from "../DatabaseServices/Curve";
|
||||||
|
import { IntersectOption } from "../GraphicsSystem/IntersectWith";
|
||||||
|
import { greater } from "./GeUtils";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 简化优化版本的曲线求交, 优化版本可以参考(算法导论33.2 确定任意一对线段是否相交 p599)
|
||||||
|
*
|
||||||
|
* @class CurveIntersection
|
||||||
|
*/
|
||||||
|
export class CurveIntersection
|
||||||
|
{
|
||||||
|
//用来缓存的曲线包围盒
|
||||||
|
private boxMap: Map<Curve, Box3> = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交点数据集,key 为曲线 value 为和它相交的(曲线和交点的Map)
|
||||||
|
*
|
||||||
|
* @type {Map<Curve, Map<Curve, Vector3[]>>}
|
||||||
|
* @memberof CurveIntersection
|
||||||
|
*/
|
||||||
|
intersect: Map<Curve, Map<Curve, Vector3[]>> = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Curve[]} cus 请注意数组的顺序会被更改,如果你在意数组的顺序,请拷贝数组后传进来
|
||||||
|
* @memberof CurveIntersection
|
||||||
|
*/
|
||||||
|
constructor(cus: Curve[])
|
||||||
|
{
|
||||||
|
this.genBox(cus);
|
||||||
|
//按x排序
|
||||||
|
this.sortCurve(cus);
|
||||||
|
|
||||||
|
let count = cus.length;
|
||||||
|
for (let i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
let c1 = cus[i];
|
||||||
|
let c1d = this.GetIntersect(c1);
|
||||||
|
|
||||||
|
let c1b = this.boxMap.get(c1);
|
||||||
|
for (let j = i + 1; j < count; j++)
|
||||||
|
{
|
||||||
|
let c2 = cus[j];
|
||||||
|
|
||||||
|
//过滤掉不需要计算的曲线
|
||||||
|
let c2b = this.boxMap.get(c2);
|
||||||
|
|
||||||
|
if (greater(c2b.min.x, c1b.max.x, 1e-6))
|
||||||
|
break;
|
||||||
|
if (greater(c2b.min.y, c1b.max.y, 1e-6))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
let pts = c1.IntersectWith(c2, IntersectOption.OnBothOperands);
|
||||||
|
if (pts.length > 0)
|
||||||
|
{
|
||||||
|
c1d.set(c2, pts);
|
||||||
|
this.GetIntersect(c2).set(c1, pts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private genBox(cus: Curve[])
|
||||||
|
{
|
||||||
|
cus.forEach(c =>
|
||||||
|
{
|
||||||
|
this.boxMap.set(c, c.BoundingBox);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private sortCurve(cus: Curve[])
|
||||||
|
{
|
||||||
|
cus.sort((c1, c2) =>
|
||||||
|
{
|
||||||
|
return this.boxMap.get(c1).min.x - this.boxMap.get(c2).min.x;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
GetIntersect(cu: Curve): Map<Curve, Vector3[]>
|
||||||
|
{
|
||||||
|
if (this.intersect.has(cu))
|
||||||
|
return this.intersect.get(cu);
|
||||||
|
|
||||||
|
let m = new Map();
|
||||||
|
this.intersect.set(cu, m);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
import { Box3 } from "three";
|
||||||
|
import { equaln } from "./GeUtils";
|
||||||
|
|
||||||
|
export interface EBox
|
||||||
|
{
|
||||||
|
BoundingBox: Box3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据盒子x排序盒子
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @param {EBox[]} arr
|
||||||
|
*/
|
||||||
|
export function SortEntityByBox(arr: EBox[], sort: boolean = true)
|
||||||
|
{
|
||||||
|
let boxMap: Map<EBox, Box3> = new Map();
|
||||||
|
arr.forEach(e => boxMap.set(e, e.BoundingBox));
|
||||||
|
|
||||||
|
if (sort)
|
||||||
|
arr.sort((e1, e2) =>
|
||||||
|
{
|
||||||
|
let b1 = boxMap.get(e1);
|
||||||
|
let b2 = boxMap.get(e2);
|
||||||
|
if (!equaln(b1.min.x, b2.min.x))
|
||||||
|
return b1.min.x - b2.min.x;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return b2.min.y - b1.min.y;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return boxMap;
|
||||||
|
}
|
@ -0,0 +1,293 @@
|
|||||||
|
import { Vector3 } from "three";
|
||||||
|
import { Curve } from "../DatabaseServices/Curve";
|
||||||
|
import { CurveIntersection } from "../Geometry/CurveIntersection";
|
||||||
|
import { CurveMap } from "../Geometry/CurveMap";
|
||||||
|
import { equal, equaln } from "../Geometry/GeUtils";
|
||||||
|
import { Stand } from "../Geometry/RegionParse";
|
||||||
|
|
||||||
|
export class LinkSelf
|
||||||
|
{
|
||||||
|
private curveUseData: WeakMap<Curve, boolean> = new WeakMap();
|
||||||
|
private curveIndexData: WeakMap<Curve, number> = new WeakMap();
|
||||||
|
sealCus: Set<Curve>[] = [];
|
||||||
|
noSealCus: Curve[][] = [];
|
||||||
|
private m_Count;
|
||||||
|
private cuMap: CurveMap;
|
||||||
|
constructor(cus: Curve[])
|
||||||
|
{
|
||||||
|
this.m_Count = cus.length;
|
||||||
|
//打断曲线
|
||||||
|
let breakCus: Curve[] = this.BreakCurve(cus);
|
||||||
|
// breakCus.forEach(c =>
|
||||||
|
// {
|
||||||
|
// c.ColorIndex = 3;
|
||||||
|
// app.m_Database.ModelSpace.Append(c);
|
||||||
|
// })
|
||||||
|
|
||||||
|
//曲线图 用来快速搜索求交
|
||||||
|
this.cuMap = this.GenerateCurveMap(breakCus);
|
||||||
|
|
||||||
|
//自交曲线表
|
||||||
|
this.CalCloseCurve(breakCus, this.cuMap);
|
||||||
|
|
||||||
|
//非自交曲线连接表
|
||||||
|
this.CalOrderLink(breakCus, this.cuMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
//打断曲线 并且保存了曲线的索引
|
||||||
|
private BreakCurve(cus: Curve[]): Curve[]
|
||||||
|
{
|
||||||
|
let insMap = new CurveIntersection(cus.concat());
|
||||||
|
//打断后存储的曲线列表
|
||||||
|
let breakCus: Curve[] = [];
|
||||||
|
// let count = cus.length;
|
||||||
|
for (let i = 0; i < this.m_Count; i++)
|
||||||
|
{
|
||||||
|
let cu = cus[i];
|
||||||
|
//交点数据
|
||||||
|
let insData = insMap.GetIntersect(cu);
|
||||||
|
let insPts: Vector3[] = [];
|
||||||
|
for (let [, pts] of insData)
|
||||||
|
{
|
||||||
|
insPts.push(...pts);
|
||||||
|
}
|
||||||
|
|
||||||
|
let params = insPts.map(p => cu.GetParamAtPoint(p));
|
||||||
|
let spCus = cu.GetSplitCurves(params);
|
||||||
|
if (spCus.length === 0)
|
||||||
|
{
|
||||||
|
this.SetCurveIndex(cu, i);
|
||||||
|
breakCus.push(cu);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (let c of spCus)
|
||||||
|
{
|
||||||
|
if (!equaln(c.Length, 0, 1e-6))
|
||||||
|
{
|
||||||
|
this.SetCurveIndex(c, i);
|
||||||
|
breakCus.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return breakCus;
|
||||||
|
}
|
||||||
|
|
||||||
|
//计算闭合的区域
|
||||||
|
private CalCloseCurve(breakCus: Curve[], cuMap: CurveMap)
|
||||||
|
{
|
||||||
|
let breakCount = breakCus.length;
|
||||||
|
|
||||||
|
//搜索闭合自交
|
||||||
|
for (let i = 0; i < breakCount; i++)
|
||||||
|
{
|
||||||
|
let cu = breakCus[i];
|
||||||
|
if (this.GetCurveUse(cu)) continue;
|
||||||
|
let cuIndex = this.GetCurveIndex(cu);
|
||||||
|
let stand = cuMap.GetStand(cu.EndPoint);
|
||||||
|
|
||||||
|
let routeCus = new Set<Curve>();
|
||||||
|
|
||||||
|
for (let route of stand.routes)
|
||||||
|
{
|
||||||
|
//缓存走过的节点
|
||||||
|
let ways: Stand[] = [];
|
||||||
|
ways.push(cuMap.GetStand(cu.StartPoint));
|
||||||
|
|
||||||
|
if (equal(route.curve.EndPoint, stand.position))
|
||||||
|
continue; //如果方向相反,那么退出计算 (不符合)
|
||||||
|
|
||||||
|
let routeIndex = this.GetCurveIndex(route.curve);
|
||||||
|
if (routeIndex === cuIndex)
|
||||||
|
continue;//自己不和自己计算
|
||||||
|
if (routeIndex < cuIndex)
|
||||||
|
continue;//不和小于自己索引的计算
|
||||||
|
|
||||||
|
//如果存在闭合区域
|
||||||
|
if (this.FindCloseCurve(route.to, cuIndex, ways, routeCus, cuMap))
|
||||||
|
{
|
||||||
|
routeCus.add(route.curve);
|
||||||
|
routeCus.add(cu);
|
||||||
|
//提取闭合区域
|
||||||
|
for (let c of routeCus)
|
||||||
|
{
|
||||||
|
this.SetCurveUse(c);
|
||||||
|
}
|
||||||
|
this.sealCus.push(routeCus);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//顺序连接.
|
||||||
|
private CalOrderLink(breakCus: Curve[], cuMap: CurveMap)
|
||||||
|
{
|
||||||
|
let breakCount = breakCus.length;
|
||||||
|
//剩下没有被自交
|
||||||
|
for (let i = 0; i < breakCount; i++)
|
||||||
|
{
|
||||||
|
let cu = breakCus[i];
|
||||||
|
if (this.GetCurveUse(cu)) continue;
|
||||||
|
// let cuIndex = this.GetCurveIndex(cu);
|
||||||
|
this.SetCurveUse(cu);
|
||||||
|
let cs = [cu];
|
||||||
|
//顺序连接
|
||||||
|
this.linkCurve(cu, cuMap, cs);
|
||||||
|
//拿出第一条进行倒序连接
|
||||||
|
cu = cs[0];
|
||||||
|
this.linkCurve(cu, cuMap, cs, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linkCurve(originCu: Curve, cuMap: CurveMap, cs: Curve[], isInv: boolean = false)
|
||||||
|
{
|
||||||
|
//FIXME:两线共线时连接有问题
|
||||||
|
let cuIndex = this.GetCurveIndex(originCu);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
let oldCount = cs.length;
|
||||||
|
let routes = cuMap.GetStand(isInv ? originCu.StartPoint : originCu.EndPoint).routes;
|
||||||
|
|
||||||
|
//把索引相等的站点最后遍历
|
||||||
|
for (let i = 0; i < routes.length; i++)
|
||||||
|
{
|
||||||
|
let index = this.GetCurveIndex(routes[i].curve);
|
||||||
|
if (index === cuIndex)
|
||||||
|
{
|
||||||
|
routes.unshift(routes.splice(i, 1)[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let j = routes.length; j--;) //按照索引从小到大搜索
|
||||||
|
{
|
||||||
|
let cu2 = routes[j].curve;
|
||||||
|
if (this.GetCurveUse(cu2)) continue;
|
||||||
|
|
||||||
|
//能够连接
|
||||||
|
let isLink = isInv ? equal(cu2.EndPoint, originCu.StartPoint) : equal(cu2.StartPoint, originCu.EndPoint);
|
||||||
|
if (isLink)
|
||||||
|
{
|
||||||
|
this.SetCurveUse(cu2);
|
||||||
|
isInv ? cs.unshift(cu2) : cs.push(cu2);
|
||||||
|
originCu = cu2;
|
||||||
|
cuIndex = this.GetCurveIndex(cu2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果没找到 则退出循环
|
||||||
|
if (oldCount === cs.length)
|
||||||
|
{
|
||||||
|
!isInv && this.noSealCus.push(cs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//寻找最小索引的路线
|
||||||
|
private FindMinRoute(nowStand: Stand, nowIndex: number, cs: Curve[], routes: Curve[]): { minIndex: number, routes: Curve[] }
|
||||||
|
{
|
||||||
|
//和当前索引一样的 搜索结果
|
||||||
|
let curIndex: { minIndex: number, routes: Curve[] } = undefined;
|
||||||
|
for (let j = nowStand.routes.length; j--;) //按照索引从小到大搜索
|
||||||
|
{
|
||||||
|
let cu = nowStand.routes[j].curve;
|
||||||
|
let cuIndex = this.GetCurveIndex(cu);
|
||||||
|
if (this.GetCurveUse(cu)) continue;
|
||||||
|
if (!equal(cu.StartPoint, nowStand.position)) continue;
|
||||||
|
if (nowIndex === cuIndex)
|
||||||
|
{
|
||||||
|
let routes2 = routes.concat();//复制数组保证函数有唯一结果
|
||||||
|
routes2.push(cu);
|
||||||
|
curIndex = this.FindMinRoute(this.cuMap.GetStand(cu.EndPoint), nowIndex, cs, routes2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cuIndex < nowIndex) //小于 回归自身
|
||||||
|
if (cs.findIndex((c) => this.GetCurveIndex(c) === cuIndex) === -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (curIndex && curIndex.minIndex < cuIndex)
|
||||||
|
return curIndex;
|
||||||
|
|
||||||
|
//这里不复制数组,因为数组不会再被改变
|
||||||
|
routes.push(cu);
|
||||||
|
return { minIndex: cuIndex, routes };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { minIndex: Infinity, routes };
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCurveUse(curve: Curve): boolean
|
||||||
|
{
|
||||||
|
return this.curveUseData.get(curve);
|
||||||
|
}
|
||||||
|
SetCurveUse(curve: Curve, use: boolean = true)
|
||||||
|
{
|
||||||
|
this.curveUseData.set(curve, use);
|
||||||
|
}
|
||||||
|
GetCurveIndex(curve: Curve): number
|
||||||
|
{
|
||||||
|
return this.curveIndexData.get(curve);
|
||||||
|
}
|
||||||
|
SetCurveIndex(curve: Curve, index: number)
|
||||||
|
{
|
||||||
|
this.curveIndexData.set(curve, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
//搜索闭合的区域
|
||||||
|
private FindCloseCurve(nowStand: Stand, cuIndex: number, ways: Stand[], routes: Set<Curve>, cuMap: CurveMap)
|
||||||
|
{
|
||||||
|
for (let route of nowStand.routes)
|
||||||
|
{
|
||||||
|
if (equal(route.curve.EndPoint, nowStand.position))
|
||||||
|
continue; //如果方向相反,那么退出计算 (不符合)
|
||||||
|
|
||||||
|
if (this.GetCurveUse(route.curve)) continue;
|
||||||
|
|
||||||
|
let routeIndex = this.GetCurveIndex(route.curve);
|
||||||
|
if (routeIndex === cuIndex)
|
||||||
|
continue;//自己不和自己计算
|
||||||
|
if (routeIndex < cuIndex)
|
||||||
|
continue;//不和小于自己索引的计算
|
||||||
|
|
||||||
|
//验证通过,可以连接.
|
||||||
|
let toStand = route.to;
|
||||||
|
|
||||||
|
routes.add(route.curve);
|
||||||
|
if (ways[0] === toStand)//自交闭合
|
||||||
|
return true;
|
||||||
|
else if (ways.indexOf(toStand) !== -1)//中途回路
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ways.push(toStand);
|
||||||
|
if (this.FindCloseCurve(toStand, routeIndex, ways, routes, cuMap))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
routes.delete(route.curve);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerateCurveMap(breakCus: Curve[])
|
||||||
|
{
|
||||||
|
let cuMap = new CurveMap();
|
||||||
|
breakCus.forEach(c => cuMap.addCurveToMap(c));
|
||||||
|
//所有的站点 逆序排序.
|
||||||
|
for (let [, stand] of cuMap.m_NodeMap)
|
||||||
|
{
|
||||||
|
stand.routes.sort((r1, r2) =>
|
||||||
|
{
|
||||||
|
return this.GetCurveIndex(r2.curve) - this.GetCurveIndex(r1.curve); //从大到小
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cuMap;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue