From 5cb1d648d3af1a4448d2c9a6a6acc701d38f36d3 Mon Sep 17 00:00:00 2001 From: JAG Date: Tue, 4 Jun 2024 15:16:20 +0900 Subject: [PATCH] fix(all): various fixes to pass tests --- packages/io/x3d-deserializer/src/objects.js | 4 ++-- packages/io/x3d-deserializer/src/parse.js | 6 ++--- .../tests/instantiate.test.js | 24 +++++++++---------- .../x3d-deserializer/tests/translate.test.js | 10 ++++---- .../src/geometries/geom3/fromPointsConvex.js | 2 +- .../geometries/geom3/fromPointsConvex.test.js | 6 ++--- packages/modeling/src/maths/index.js | 1 + 7 files changed, 25 insertions(+), 28 deletions(-) diff --git a/packages/io/x3d-deserializer/src/objects.js b/packages/io/x3d-deserializer/src/objects.js index f80c64bbf..de973b6a7 100644 --- a/packages/io/x3d-deserializer/src/objects.js +++ b/packages/io/x3d-deserializer/src/objects.js @@ -1,4 +1,4 @@ -import { poly2 } from '@jscad/modeling' +import { area, poly2 } from '@jscad/modeling' export const x3dTypes = { X3D: 0, @@ -224,7 +224,7 @@ export const x3dExtrusion = (element) => { const vi = i * 2 points.push([values[vi], values[vi + 1]]) } - obj.ccw = (maths.utils.area(points) < 0) // WHAT!!!! X3D IS SICK!!! + obj.ccw = (area(points) < 0) // WHAT!!!! X3D IS SICK!!! obj.crossSection = points } if (element.orientation) { diff --git a/packages/io/x3d-deserializer/src/parse.js b/packages/io/x3d-deserializer/src/parse.js index deb966e8c..b6788522b 100644 --- a/packages/io/x3d-deserializer/src/parse.js +++ b/packages/io/x3d-deserializer/src/parse.js @@ -92,7 +92,7 @@ const nodeToObjectMap = { let objectId = 1 const getObjectId = () => ('0000' + objectId++).slice(-4) -const createX3DParser = (src) => { +export const parse = (src) => { // create a parser for the XML const parser = new saxes.SaxesParser() @@ -331,10 +331,8 @@ const createX3DParser = (src) => { // start the parser parser.write(src).close() -} -export const parse = (src) => { - createX3DParser(src) + // return the results // console.log(JSON.stringify(x3dObj)) return { x3dObj, x3dMaterials, x3dTextures } } diff --git a/packages/io/x3d-deserializer/tests/instantiate.test.js b/packages/io/x3d-deserializer/tests/instantiate.test.js index 8a7e147be..118c8fa03 100644 --- a/packages/io/x3d-deserializer/tests/instantiate.test.js +++ b/packages/io/x3d-deserializer/tests/instantiate.test.js @@ -95,13 +95,13 @@ test('deserialize X3D 3D triangle sets with comma delimiters to JSCAD geometry', const inputPath = path.resolve(samplesPath, 'tests/TriangleSets_CommaMF.x3d') const inputFile = fs.readFileSync(inputPath) - const observed = deserializer.deserialize({ output: 'geometry', addMetaData: false }, inputFile) + const observed = deserialize({ output: 'geometry', addMetaData: false }, inputFile) t.true(Array.isArray(observed)) t.is(observed.length, 4) - t.true(geometries.geom3.isA(observed[0])) - t.true(geometries.geom3.isA(observed[1])) - t.true(geometries.geom3.isA(observed[2])) - t.true(geometries.geom3.isA(observed[3])) + t.true(geom3.isA(observed[0])) + t.true(geom3.isA(observed[1])) + t.true(geom3.isA(observed[2])) + t.true(geom3.isA(observed[3])) }) test('deserialize X3D 3D transforms to JSCAD geometry', (t) => { @@ -136,15 +136,15 @@ test('deserialize X3D 3D indexed triangle sets with comma delimiters to JSCAD ge const inputPath = path.resolve(samplesPath, 'tests/IndexedTriangleSets_CommaMF.x3d') const inputFile = fs.readFileSync(inputPath) - const observed = deserializer.deserialize({ output: 'geometry', addMetaData: false }, inputFile) + const observed = deserialize({ output: 'geometry', addMetaData: false }, inputFile) t.true(Array.isArray(observed)) t.is(observed.length, 6) - t.true(geometries.geom3.isA(observed[0])) - t.true(geometries.geom3.isA(observed[1])) - t.true(geometries.geom3.isA(observed[2])) - t.true(geometries.geom3.isA(observed[3])) - t.true(geometries.geom3.isA(observed[4])) - t.true(geometries.geom3.isA(observed[5])) + t.true(geom3.isA(observed[0])) + t.true(geom3.isA(observed[1])) + t.true(geom3.isA(observed[2])) + t.true(geom3.isA(observed[3])) + t.true(geom3.isA(observed[4])) + t.true(geom3.isA(observed[5])) }) test('deserialize X3D 3D groups to JSCAD geometry', (t) => { diff --git a/packages/io/x3d-deserializer/tests/translate.test.js b/packages/io/x3d-deserializer/tests/translate.test.js index 24b9de8db..327232d74 100644 --- a/packages/io/x3d-deserializer/tests/translate.test.js +++ b/packages/io/x3d-deserializer/tests/translate.test.js @@ -89,13 +89,12 @@ test('deserialize X3D 3D triangle sets with comma delimiters to JSCAD script', ( const inputPath = path.resolve(samplesPath, 'tests/TriangleSets_CommaMF.x3d') const inputFile = fs.readFileSync(inputPath) - const observed = deserializer.deserialize({ output: 'script', addMetaData: false }, inputFile) + const observed = deserialize({ output: 'script', addMetaData: false }, inputFile) t.is(countOf('createObjects', observed), 18) t.is(countOf('points', observed), 12) t.is(countOf('faces', observed), 12) t.is(countOf('orientation', observed), 8) - t.is(countOf('primitives.polyhedron', observed), 4) - t.is(countOf('applyTransform', observed), 1) + t.is(countOf('polyhedron', observed), 4) }) test('deserialize X3D 3D transforms to JSCAD script', (t) => { @@ -126,13 +125,12 @@ test('deserialize X3D 3D indexed triangle sets with comma delimiters to JSCAD sc const inputPath = path.resolve(samplesPath, 'tests/IndexedTriangleSets_CommaMF.x3d') const inputFile = fs.readFileSync(inputPath) - const observed = deserializer.deserialize({ output: 'script', addMetaData: false }, inputFile) + const observed = deserialize({ output: 'script', addMetaData: false }, inputFile) t.is(countOf('createObjects', observed), 24) t.is(countOf('points', observed), 18) t.is(countOf('faces', observed), 20) t.is(countOf('orientation', observed), 12) - t.is(countOf('primitives.polyhedron', observed), 6) - t.is(countOf('applyTransform', observed), 1) + t.is(countOf('polyhedron', observed), 6) }) test('deserialize X3D 3D groups to JSCAD script', (t) => { diff --git a/packages/modeling/src/geometries/geom3/fromPointsConvex.js b/packages/modeling/src/geometries/geom3/fromPointsConvex.js index 883cd0a0c..dc153c3f9 100644 --- a/packages/modeling/src/geometries/geom3/fromPointsConvex.js +++ b/packages/modeling/src/geometries/geom3/fromPointsConvex.js @@ -1,4 +1,4 @@ -import { runner } from '../../quickhull/index.js' +import { runner } from '../../operations/hulls/quickhull/index.js' import { create } from './create.js' import * as poly3 from '../poly3/index.js' diff --git a/packages/modeling/src/geometries/geom3/fromPointsConvex.test.js b/packages/modeling/src/geometries/geom3/fromPointsConvex.test.js index f7837055b..546289977 100644 --- a/packages/modeling/src/geometries/geom3/fromPointsConvex.test.js +++ b/packages/modeling/src/geometries/geom3/fromPointsConvex.test.js @@ -4,9 +4,9 @@ import { fromPointsConvex, validate } from './index.js' test('fromPointsConvex (uniquePoints)', (t) => { let out = [] - for(x=-9;x<=9;++x) - for(y=-9;y<=9;++y) - for(z=-9;z<=9;++z) + for(let x=-9;x<=9;++x) + for(let y=-9;y<=9;++y) + for(let z=-9;z<=9;++z) if (x*x+y*y+z*z <= 96) out.push([x,y,z]) diff --git a/packages/modeling/src/maths/index.js b/packages/modeling/src/maths/index.js index a42e3f632..38419a5a1 100644 --- a/packages/modeling/src/maths/index.js +++ b/packages/modeling/src/maths/index.js @@ -15,3 +15,4 @@ export * as vec2 from './vec2/index.js' export * as vec3 from './vec3/index.js' export * as vec4 from './vec4/index.js' export { cos, sin } from './utils/trigonometry.js' +export { area } from './utils/area.js'