!1475 修复:简化多段线结果错误

pull/1475/MERGE
ChenX 4 years ago
parent 01afafa9b0
commit 18a7e5c1ec

@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`小恐龙简化 1`] = `723`;
exports[`小恐龙简化 1`] = `802`;
exports[`小恐龙简化 2`] = `671`;
exports[`小恐龙简化 2`] = `751`;
exports[`小恐龙简化 3`] = `"7392.79910"`;
exports[`小恐龙简化 3`] = `"7392.51664"`;
exports[`小恐龙简化 4`] = `"7397.08024"`;
exports[`小恐龙简化 4`] = `"7396.53311"`;
exports[`小恐龙简化 5`] = `5`;
@ -18,11 +18,11 @@ exports[`小恐龙简化 8`] = `"312.60195"`;
exports[`小恐龙简化 9`] = `35`;
exports[`小恐龙简化 10`] = `30`;
exports[`小恐龙简化 10`] = `28`;
exports[`小恐龙简化 11`] = `"1274.39343"`;
exports[`小恐龙简化 12`] = `"1275.37625"`;
exports[`小恐龙简化 12`] = `"1274.38489"`;
exports[`小恐龙简化 13`] = `12`;
@ -42,11 +42,11 @@ exports[`小恐龙简化 20`] = `"1976.92695"`;
exports[`小恐龙简化 21`] = `55`;
exports[`小恐龙简化 22`] = `47`;
exports[`小恐龙简化 22`] = `52`;
exports[`小恐龙简化 23`] = `"1220.90675"`;
exports[`小恐龙简化 24`] = `"1220.88609"`;
exports[`小恐龙简化 24`] = `"1220.91844"`;
exports[`小恐龙简化 25`] = `5`;
@ -72,13 +72,13 @@ exports[`小恐龙简化 35`] = `"1049.95998"`;
exports[`小恐龙简化 36`] = `"1049.95998"`;
exports[`小恐龙简化 37`] = `51`;
exports[`小恐龙简化 37`] = `49`;
exports[`小恐龙简化 38`] = `46`;
exports[`小恐龙简化 38`] = `49`;
exports[`小恐龙简化 39`] = `"1225.55997"`;
exports[`小恐龙简化 39`] = `"1225.38294"`;
exports[`小恐龙简化 40`] = `"1225.54790"`;
exports[`小恐龙简化 40`] = `"1225.40755"`;
exports[`小恐龙简化 41`] = `23`;
@ -96,21 +96,21 @@ exports[`小恐龙简化 47`] = `"1308.96068"`;
exports[`小恐龙简化 48`] = `"1308.92526"`;
exports[`小恐龙简化 49`] = `34`;
exports[`小恐龙简化 49`] = `36`;
exports[`小恐龙简化 50`] = `35`;
exports[`小恐龙简化 50`] = `41`;
exports[`小恐龙简化 51`] = `"646.03175"`;
exports[`小恐龙简化 52`] = `"645.95028"`;
exports[`小恐龙简化 52`] = `"645.91639"`;
exports[`小恐龙简化 53`] = `87`;
exports[`小恐龙简化 53`] = `89`;
exports[`小恐龙简化 54`] = `75`;
exports[`小恐龙简化 54`] = `79`;
exports[`小恐龙简化 55`] = `"949.48587"`;
exports[`小恐龙简化 55`] = `"949.50682"`;
exports[`小恐龙简化 56`] = `"948.69812"`;
exports[`小恐龙简化 56`] = `"948.61198"`;
exports[`小恐龙简化 57`] = `4`;
@ -120,7 +120,7 @@ exports[`小恐龙简化 59`] = `"341.03322"`;
exports[`小恐龙简化 60`] = `"341.03322"`;
exports[`小恐龙简化 61`] = `41`;
exports[`小恐龙简化 61`] = `49`;
exports[`小恐龙简化 62`] = `25`;
@ -136,7 +136,7 @@ exports[`小恐龙简化 67`] = `"158.44290"`;
exports[`小恐龙简化 68`] = `"158.44290"`;
exports[`简化多段线成为圆弧 1`] = `43`;
exports[`简化多段线成为圆弧 1`] = `45`;
exports[`简化多段线成为圆弧 2`] = `33`;
@ -144,7 +144,7 @@ exports[`简化多段线成为圆弧 3`] = `"1107.92600"`;
exports[`简化多段线成为圆弧 4`] = `"1107.90911"`;
exports[`简化多段线成为圆弧 5`] = `43`;
exports[`简化多段线成为圆弧 5`] = `45`;
exports[`简化多段线成为圆弧 6`] = `33`;
@ -152,7 +152,7 @@ exports[`简化多段线成为圆弧 7`] = `"1107.92600"`;
exports[`简化多段线成为圆弧 8`] = `"1107.90911"`;
exports[`简化多段线成为圆弧 9`] = `81`;
exports[`简化多段线成为圆弧 9`] = `83`;
exports[`简化多段线成为圆弧 10`] = `59`;
@ -160,7 +160,7 @@ exports[`简化多段线成为圆弧 11`] = `"2215.88135"`;
exports[`简化多段线成为圆弧 12`] = `"2215.85712"`;
exports[`简化多段线成为圆弧 13`] = `44`;
exports[`简化多段线成为圆弧 13`] = `46`;
exports[`简化多段线成为圆弧 14`] = `34`;
@ -168,7 +168,7 @@ exports[`简化多段线成为圆弧 15`] = `"1628.59895"`;
exports[`简化多段线成为圆弧 16`] = `"1628.58206"`;
exports[`简化多段线成为圆弧 17`] = `47`;
exports[`简化多段线成为圆弧 17`] = `49`;
exports[`简化多段线成为圆弧 18`] = `37`;
@ -178,24 +178,24 @@ exports[`简化多段线成为圆弧 20`] = `"1422.38721"`;
exports[`简化多段线成为圆弧 21`] = `6`;
exports[`简化多段线成为圆弧 22`] = `23`;
exports[`简化多段线成为圆弧 22`] = `21`;
exports[`简化多段线成为圆弧 23`] = `"2077.93854"`;
exports[`简化多段线成为圆弧 24`] = `"2078.01268"`;
exports[`简化多段线成为圆弧 24`] = `"2077.85312"`;
exports[`简化多段线成为圆弧 25`] = `9`;
exports[`简化多段线成为圆弧 26`] = `97`;
exports[`简化多段线成为圆弧 26`] = `89`;
exports[`简化多段线成为圆弧 27`] = `"2041.09919"`;
exports[`简化多段线成为圆弧 28`] = `"2041.97439"`;
exports[`简化多段线成为圆弧 28`] = `"2040.10773"`;
exports[`简化多段线成为圆弧 29`] = `2`;
exports[`简化多段线成为圆弧 30`] = `39`;
exports[`简化多段线成为圆弧 30`] = `37`;
exports[`简化多段线成为圆弧 31`] = `"705.34043"`;
exports[`简化多段线成为圆弧 32`] = `"705.83666"`;
exports[`简化多段线成为圆弧 32`] = `"704.78939"`;

@ -0,0 +1,26 @@
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { SmartPolylineSimply2Polyline } from "../../src/DatabaseServices/SplineConver2Polyline";
import { LoadEntityFromFileData } from "../Utils/LoadEntity.util";
test('意外少点1', () =>
{
let f = { "file": [1, "Polyline", 8, 2, 100, false, 1, 7, 0, [0.6230300783353291, -0.7821978787298477, 0, 0, 0.7821978787298479, 0.6230300783353292, 0, 0, 0, 0, 1, 0, 21.487109905020134, 31.954876619746756, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2459.345221004072, -1150.8130587261073, 0, 1], 0, 2, 9, [0, 0], 0, [1.903837092908816, 0], 0, [3.807674185817632, 1.7962520360015333e-10], 0, [10.202141908262547, 5.106812750454992e-10], 0, [16.596609630707803, 7.876224117353559e-10], 0, [22.991081471856432, 1.096395862987265e-9], 0, [29.385553313004834, 1.395164872519672e-9], 0, [31.985671722717257, 1.5143086784519255e-9], 0, [33.19239087621429, 1.5752448234707117e-9], 0, false], "basePt": { "x": 21.487109905020134, "y": 5.991858887381415, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(f)[0] as Polyline;
console.log(pl.EndParam);
let npl = SmartPolylineSimply2Polyline(pl);
expect(npl.EndParam).toBe(8);
});
test("意外少点2", () =>
{
let f = { "file": [1, "Polyline", 8, 2, 261, false, 1, 7, 0, [-0.9844191123786324, 0.1758380254201737, 0, 0, -0.1758380254201737, -0.9844191123786324, 0, 0, 0, 0, 1, 0, 2484.240620444994, 1120.666338127196, 0, 1], 0, 0, true, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 2, 9, [4.547473508864641e-13, 0], 0, [1.0068342808144735, -2.2737367544323206e-13], 0, [2.013668561628947, -9.913492249324918e-11], 0, [5.358291862453825, -2.710294211283326e-10], 0, [8.702915163278703, -4.2859937821049243e-10], 0, [12.047540609297357, -5.700258043361828e-10], 0, [15.392166055315101, -7.578364602522925e-10], 0, [16.76722763747739, -8.362803782802075e-10], 0, [17.405395938672882, -8.576535037718713e-10], 0, false], "basePt": { "x": 2467.106416024598, "y": 1120.666338127196, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pl = LoadEntityFromFileData(f)[0] as Polyline;
console.log(pl.EndParam);
let npl = SmartPolylineSimply2Polyline(pl);
expect(npl.EndParam).toBe(8);
});

@ -12,7 +12,7 @@ Factory(Region);
Factory(Board);
Factory(HardwareTopline);
export function LoadEntityFromFileData(data)
export function LoadEntityFromFileData(data: any)
{
if (!Array.isArray(data))
data = data.file;

@ -96,6 +96,7 @@ export function SplineConver2Polyline(spl: Spline, tolerance = 0.1): Polyline
//传入的一定是碎点,不是碎点,没有6个点请不要进来
function PointsSimplify2Polyline(pts: Vector3[], tolerance = 0.1): Polyline
{
let tolSq = tolerance * tolerance;
let cacheTange = new Map<number, Vector3>();
let ptsCount = pts.length;
@ -137,12 +138,15 @@ function PointsSimplify2Polyline(pts: Vector3[], tolerance = 0.1): Polyline
let index1 = GetIndexAtParam(param1);
let index2 = GetIndexAtParam(param2);
if ((index2 - index1) < 8)//当点个数等于4时,我们计算双圆弧插值必然成功.(但是也失去了意义)
if ((index2 - index1) < 4)//当点个数等于4时,我们计算双圆弧插值必然成功.(但是也失去了意义)
{
let lineD: PolylineProps[] = [];
for (let i = index1; i <= index2; i++)
lineD.push({ pt: AsVector2(pts[i]), bul: 0 });
curves.push(new Polyline(lineD));
if (index2 - index1 > 0)
{
let lineD: PolylineProps[] = [];
for (let i = index1; i <= index2; i++)
lineD.push({ pt: AsVector2(pts[i]), bul: 0 });
curves.push(new Polyline(lineD));
}
break;
}
@ -159,8 +163,8 @@ function PointsSimplify2Polyline(pts: Vector3[], tolerance = 0.1): Polyline
let [c1, c2] = ComputeBiarc(p1, p2, t1, t2);
if (
c1.GetClosestPointTo(midp1, false).distanceTo(midp1) < tolerance &&
c2.GetClosestPointTo(midp2, false).distanceTo(midp2) < tolerance
c1.GetClosestPointTo(midp1, false).distanceToSquared(midp1) < tolSq &&
c2.GetClosestPointTo(midp2, false).distanceToSquared(midp2) < tolSq
)
{
curves.push(c1, c2);
@ -254,7 +258,12 @@ export function PointsSimplify2PolylineAndParseArc(pts: Vector2[], buls: number[
start = to + 2;//闪烁到圆弧终点
if (start === next - 2) break;
if (start === next - 2)
{
retPolyline.Join(PointsSimplify2Polyline(pts.slice(start, next).map(AsVector3)));
start = next;
break;
};
}
else
retPolyline.Join(PointsSimplify2Polyline(pts.slice(start, next).map(AsVector3)));

Loading…
Cancel
Save