mightyscape-1.2/extensions/fablabchemnitz/dxf_dwg_importer/node_modules/dxf/test/unit/toPolylines.test.js

188 lines
7.3 KiB
JavaScript

import fs from 'fs'
import { join } from 'path'
import expect from 'expect'
import { Box2 } from 'vecks'
import { parseString, toPolylines } from '../../src'
const dxfSquareAndCircle = fs.readFileSync(
join(__dirname, '/../resources/squareandcircle.dxf'),
'utf-8',
)
const dxfPolyfaceMesh = fs.readFileSync(
join(__dirname, '/../resources/polyfacemesh.dxf'),
'utf-8',
)
describe('DXF to coloured polylines', () => {
it('for square and circle', () => {
const parsed = parseString(dxfSquareAndCircle)
const { bbox, polylines } = toPolylines(parsed)
expect(bbox.equals(new Box2({ x: 0, y: 0 }, { x: 10, y: 10 }))).toEqual(
true,
)
expect(polylines).toEqual([
{
rgb: [0, 0, 255],
vertices: [
[10, 5],
[9.980973490458727, 5.435778713738291],
[9.92403876506104, 5.868240888334651],
[9.82962913144534, 6.294095225512604],
[9.698463103929543, 6.710100716628343],
[9.53153893518325, 7.113091308703497],
[9.330127018922195, 7.5],
[9.095760221444959, 7.86788218175523],
[8.83022221559489, 8.213938048432697],
[8.535533905932738, 8.535533905932738],
[8.213938048432697, 8.83022221559489],
[7.86788218175523, 9.095760221444959],
[7.5, 9.330127018922193],
[7.113091308703498, 9.53153893518325],
[6.710100716628345, 9.69846310392954],
[6.294095225512606, 9.82962913144534],
[5.868240888334654, 9.92403876506104],
[5.435778713738294, 9.980973490458727],
[5.0000000000000036, 10],
[4.564221286261713, 9.980973490458728],
[4.131759111665353, 9.924038765061042],
[3.705904774487401, 9.829629131445342],
[3.289899283371662, 9.698463103929544],
[2.8869086912965076, 9.531538935183253],
[2.500000000000005, 9.330127018922195],
[2.1321178182447746, 9.095760221444962],
[1.7860619515673082, 8.830222215594894],
[1.4644660940672671, 8.535533905932743],
[1.169777784405115, 8.213938048432702],
[0.9042397785550458, 7.8678821817552365],
[0.6698729810778108, 7.500000000000008],
[0.4684610648167542, 7.113091308703506],
[0.30153689607046097, 6.710100716628353],
[0.17037086855466121, 6.2940952255126135],
[0.07596123493896201, 5.868240888334663],
[0.019026509541273384, 5.435778713738302],
[0, 5.0000000000000115],
[0.019026509541271608, 4.564221286261722],
[0.07596123493895757, 4.131759111665361],
[0.170370868554655, 3.705904774487409],
[0.30153689607045386, 3.2898992833716694],
[0.46846106481674443, 2.886908691296516],
[0.6698729810777992, 2.500000000000013],
[0.9042397785550325, 2.132117818244782],
[1.1697777844050998, 1.7860619515673153],
[1.4644660940672507, 1.4644660940672738],
[1.7860619515672922, 1.1697777844051194],
[2.132117818244757, 0.9042397785550502],
[2.4999999999999867, 0.6698729810778143],
[2.886908691296488, 0.46846106481675687],
[3.2898992833716405, 0.30153689607046363],
[3.7059047744873794, 0.170370868554663],
[4.131759111665331, 0.0759612349389629],
[4.564221286261691, 0.019026509541274272],
[4.999999999999981, 0],
[5.435778713738272, 0.01902650954127072],
[5.868240888334633, 0.07596123493895579],
[6.294095225512584, 0.17037086855465322],
[6.710100716628324, 0.3015368960704512],
[7.113091308703478, 0.46846106481674177],
[7.499999999999981, 0.6698729810777957],
[7.8678821817552125, 0.904239778555028],
[8.213938048432679, 1.169777784405095],
[8.535533905932722, 1.4644660940672463],
[8.830222215594876, 1.7860619515672846],
[9.095760221444944, 2.1321178182447498],
[9.33012701892218, 2.4999999999999782],
[9.531538935183239, 2.8869086912964796],
[9.698463103929534, 3.289899283371632],
[9.829629131445333, 3.7059047744873705],
[9.924038765061034, 4.131759111665322],
[9.980973490458727, 4.564221286261682],
[10, 4.999999999999999],
],
},
{
rgb: [255, 0, 0],
vertices: [
[0, 0],
[10, 0],
[10, 10],
[0, 10],
[0, 0],
],
},
])
})
it('for polyface mesh', () => {
const parsed = parseString(dxfPolyfaceMesh)
const { bbox, polylines } = toPolylines(parsed)
expect(bbox).toEqual(
new Box2(
{ x: 0.5752088585545608, y: 1.403981252993389 },
{ x: 135.594208858553, y: 136.9879812529941 },
),
)
expect(polylines).toEqual([
{
rgb: [255, 255, 255],
vertices: [
[57.77920885855337, 1.403981252993389],
[134.3312088585548, 79.24098125299292],
[135.594208858553, 88.59198125299348],
[114.8762088585549, 130.7959812529932],
[111.845208858555, 129.1539812529934],
[108.3072088585536, 132.817981252994],
[103.2542088585546, 135.8509812529935],
[100.2232088585547, 136.6089812529933],
[96.30720885855362, 136.6089812529933],
[92.64320885855477, 135.8509812529935],
[88.34820885855378, 134.0819812529932],
[86.07420885855345, 136.9879812529941],
[0.5752088585545608, 68.22898125299412],
[37.7922088585533, 21.41698125299422],
[57.77920885855337, 1.403981252993389],
],
},
{
rgb: [255, 255, 255],
vertices: [
[32.20820885855346, 61.94798125299326],
[52.72220885855176, 35.73498125299352],
[54.96220885855336, 34.45498125299287],
[67.05220885855442, 47.32498125299366],
[64.32420885855345, 50.05698125299364],
[62.80120885855422, 48.53598125299299],
[58.4842088585533, 52.8569812529929],
[68.16720885855239, 62.5299812529936],
[72.56020885855332, 58.13298125299457],
[70.80120885855331, 56.37598125299314],
[73.68120885855431, 53.49398125299353],
[95.9302088585523, 75.72698125299371],
[92.08320885855437, 79.57598125299387],
[90.32220885855484, 77.81498125299345],
[86.32320885855324, 81.81598125299364],
[95.52420885855327, 91.01298125299377],
[99.76120885855426, 86.77398125299419],
[98.4022088585548, 85.41498125299383],
[101.5222088585546, 82.29498125299301],
[106.0022088585533, 86.7749812529944],
[107.7622088585544, 90.13498125299316],
[97.36220885855482, 111.4149812529938],
[91.76220885855263, 113.9749812529933],
[59.41720885855329, 89.74598125299394],
[62.81220885855464, 85.56298125299305],
[64.53820885855339, 86.96398125299287],
[67.83920885855377, 82.89798125299399],
[57.50720885855435, 74.50998125299316],
[54.86420885855341, 77.76598125299438],
[57.12220885855322, 79.5989812529931],
[51.7302088585534, 86.23898125299434],
[25.20220885855497, 64.69498125299447],
[29.19620885855375, 59.59098125299329],
[32.20820885855346, 61.94798125299326],
],
},
])
})
})