You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/__test__/Geometry/lir.test.ts

55 lines
6.6 KiB

import { LargestInteriorRectangle } from "../../src/Add-on/testEntity/LargestInteriorRectangle";
import { Polyline } from "../../src/DatabaseServices/Entity/Polyline";
import { AsVector2, equalv3 } from "../../src/Geometry/GeUtils";
import { LoadEntityFromFileData } from "../Utils/LoadEntity.util";
test('lir', () =>
{
let d =
{ "file": [6, "Polyline", 10, 2, 30486, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 21688.071880475363, -2641.585451102241, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10111.128053715596, -1330.0440361938563, 0, 1], 0, 0, 1, 2, 15, [0, -91.20902138697647], 0, [-99.27451926151298, -91.20902138697647], 0, [-99.27451926151298, -200.09655940165294], 0, [-218.3307782440097, -200.09655940165294], 0, [-218.3307782440097, -622.3626799614967], 0, [0, -622.3626799614967], 0, [0, -745.6835810795424], 0, [211.61290814419408, -745.6835810795424], 0, [211.61290814419408, -622.3626799614967], 0, [451.0569924161973, -622.3626799614967], 0, [451.0569924161973, -200.09655940165294], 0, [211.61290814419408, -200.09655940165294], 0, [211.61290814419408, 0], 0, [0, 0], 0, [0, -91.20902138697647], 0, false, "Polyline", 10, 2, 30487, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 11643.478317846675, -1064.2917826726493, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 11643.478317846675, -1064.2917826726493, 0, 1], 0, 0, 1, 2, 8, [11404.658586214457, -2178.3332612385607], 0, [11404.658586214457, -1330.8596015191276], 0, [11544.497767619087, -1330.8596015191276], 0, [11544.497767619087, -1458.6436810785299], 0, [11673.487357363012, -1458.6436810785299], 0, [11673.487357363012, -1573.1671486081832], 0, [11816.943069321209, -1573.1671486081832], 0, [11816.943069321209, -2178.3332612385607], 0, true, "Polyline", 10, 2, 30488, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 23720.604568827835, -2013.675435600278, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 7839.635766842221, -1733.9653511997813, 0, 1], 0, 0, 1, 2, 7, [764.4381757152514, -528.7843019985207], 0, [410.95736514015334, -528.7843019985207], 0, [410.95736514015334, 0], 0, [0, 0], 0, [0, -1503.01190187623], 0, [764.4381757152514, -1503.01190187623], 0, [764.4381757152514, -528.7843019985206], 0, false, "Polyline", 10, 2, 30489, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 25072.310317708012, -2434.1892907875726, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 11510.346173220109, -921.6709897391447, 0, 1], 0, 0, 1, 2, 9, [396.9987474480131, -364.5170317477214], 0, [0, -364.5170317477214], 0, [0, 0], 0, [-191.2812146794986, 369.9306510311035], 0, [-220.15385085754497, 398.803287209141], 0, [-433.08954267056106, 398.803287209141], 0, [-433.08954267056106, -1052.0466807372359], 0, [396.9987474480131, -1052.0466807372359], 0, [396.9987474480131, -364.5170317477214], 0, false, "Polyline", 10, 2, 30490, 0, 1, 7, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 14328.52642470492, -1135.02410656956, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 14328.52642470492, -1135.02410656956, 0, 1], 0, 0, 1, 2, 9, [11652.077020504916, -1169.4279001173695], 0, [11960.765451660282, -860.7394689621026], 0, [12049.398763576115, -1132.7520469107974], 0, [12510.903249758816, -1074.6819460003912], 0, [12572.02967176977, -1554.5243587863783], 0, [12706.507800193867, -2095.493193583319], 0, [12229.721708508428, -2315.5483128227534], 0, [12067.736690179401, -2630.349386179165], 0, [11755.991937923536, -2074.0989458794857], 0, true, "Polyline", 10, 2, 30485, 0, 1, 1, 0, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4219.473337791907, -173.97252646749985, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 4219.473337791907, -173.97252646749985, 0, 1], 0, 0, 1, 2, 16, [16114.89776987968, -3305.5912097645887], 0, [16114.89776987968, -2288.268620593054], 0, [16648.072861794884, -2288.268620593054], 0, [16648.072861794884, -2453.736752566737], 0, [16707.76395829206, -2453.736752566737], 0, [16721.001408849956, -2416.1080736660547], 0, [16748.57943084557, -2416.1080736660547], 0, [16748.57943084557, -2453.6141835800895], 0, [16782.776178120075, -2419.417436305495], 0, [16782.776178120075, -2480.089084695879], 0, [16861.097760587672, -2480.089084695879], 0, [16837.932222111358, -2536.3482495669314], 0, [16884.26329906399, -2604.7417441160537], 0, [16751.888793485043, -2631.2166452318434], 0, [16751.888793485043, -3117.6929532344725], 0, [16677.979694536796, -3296.3985357660504], 0, true], "basePt": { "x": 20334.371107671588, "y": -3765.373492748725, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pls = LoadEntityFromFileData(d.file) as Polyline[];
for (let pl of pls)
{
let pts = pl.GetStretchPoints();
if (equalv3(pts[0], pts[pts.length - 1]))
pts.pop();
let lir = new LargestInteriorRectangle;
let rects = lir.ParseLIR(pts.map(AsVector2));
expect(rects).toMatchSnapshot();
}
});
test('宽度优先的情况下 不再适合动态规划的内容', () =>
{
let d =
{ "file": [1, "Polyline", 10, 2, 931, 0, 1, 7, 71, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 0, 0, 1, 2, 27, [158.8731, 113.3827], 0, [258.06170000000003, 166.18730000000002], 0, [260.48, 166.18730000000002], 0, [262.7173, 167.1686], 0, [262.7173, 438.7912], 0, [294.1641, 429.9465], 0, [354.1641, 429.9465], 0, [354.1641, 646.8867], 0, [450.0488, 621.7620000000001], 0, [491.71130000000005, 586.4906], 0, [515.0884, 575.6342000000001], 0, [575.0884, 575.6342000000001], 0, [575.0884, 668.6566], 0, [1004.6024000000001, 668.6566], 0, [1004.6024000000001, 533.6516], 0, [888.0775, 533.6516], 0, [888.0775, 506.9855], 0, [887.9738000000001, 504.4506], 0, [887.9738000000001, 444.4506], 0, [1026.8447, 444.4506], 0, [1007.5792, 392.11100000000005], 0, [1007.5792, 332.111], 0, [1220, 332.111], 0, [1220, 1084.2889], 0, [0, 1084.2889], 0, [0, 0], 0, [60, 0], 0, true], "basePt": { "x": 0, "y": 0, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] };
let pls = LoadEntityFromFileData(d.file) as Polyline[];
for (let pl of pls)
{
let pts = pl.GetStretchPoints();
if (equalv3(pts[0], pts[pts.length - 1]))
pts.pop();
{
let lir = new LargestInteriorRectangle;
lir.GetMaxRectIndexFn = LargestInteriorRectangle.GetMaxWidthFn;
let rects = lir.ParseLIR(pts.map(AsVector2));
expect(rects).toMatchSnapshot();
}
{
let lir = new LargestInteriorRectangle;
lir.GetMaxRectIndexFn = LargestInteriorRectangle.GetMaxHeightFn;
let rects = lir.ParseLIR(pts.map(AsVector2));
expect(rects).toMatchSnapshot();
}
}
});