Skip to content

Commit

Permalink
fix(all): various fixes to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JAG committed Jun 4, 2024
1 parent e23a5ab commit 5cb1d64
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/io/x3d-deserializer/src/objects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { poly2 } from '@jscad/modeling'
import { area, poly2 } from '@jscad/modeling'

export const x3dTypes = {
X3D: 0,
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions packages/io/x3d-deserializer/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 }
}
24 changes: 12 additions & 12 deletions packages/io/x3d-deserializer/tests/instantiate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
10 changes: 4 additions & 6 deletions packages/io/x3d-deserializer/tests/translate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/geometries/geom3/fromPointsConvex.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
1 change: 1 addition & 0 deletions packages/modeling/src/maths/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 5cb1d64

Please sign in to comment.