2023-08-18 19:37:52 +10:00
|
|
|
import { parser_wasm } from './abstractSyntaxTree'
|
2023-02-21 09:42:41 +11:00
|
|
|
import { initPromise } from './rust'
|
2023-08-18 17:14:35 -05:00
|
|
|
import { enginelessExecutor } from '../lib/testHelpers'
|
2023-02-21 09:42:41 +11:00
|
|
|
|
|
|
|
beforeAll(() => initPromise)
|
2022-12-25 21:14:43 +11:00
|
|
|
|
2023-01-08 16:37:31 +11:00
|
|
|
describe('testing artifacts', () => {
|
2023-07-10 15:15:07 +10:00
|
|
|
// Enable rotations #152
|
2023-06-22 16:43:33 +10:00
|
|
|
test('sketch artifacts', async () => {
|
2022-12-25 21:14:43 +11:00
|
|
|
const code = `
|
2023-02-12 10:56:45 +11:00
|
|
|
const mySketch001 = startSketchAt([0, 0])
|
|
|
|
|> lineTo([-1.59, -1.54], %)
|
|
|
|
|> lineTo([0.46, -5.82], %)
|
2023-08-24 15:34:51 -07:00
|
|
|
// |> rx(45, %)
|
2022-12-25 21:14:43 +11:00
|
|
|
show(mySketch001)`
|
2023-08-18 19:37:52 +10:00
|
|
|
const programMemory = await enginelessExecutor(parser_wasm(code))
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2023-07-10 15:15:07 +10:00
|
|
|
const shown = programMemory?.return?.map(
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2023-01-08 16:37:31 +11:00
|
|
|
(a) => programMemory?.root?.[a.name]
|
|
|
|
)
|
2023-07-10 15:15:07 +10:00
|
|
|
expect(shown).toEqual([
|
2022-12-25 21:14:43 +11:00
|
|
|
{
|
2023-09-12 18:10:27 -07:00
|
|
|
type: 'SketchGroup',
|
2023-03-17 08:27:40 +11:00
|
|
|
start: {
|
|
|
|
to: [0, 0],
|
|
|
|
from: [0, 0],
|
2023-08-24 15:34:51 -07:00
|
|
|
name: '',
|
2023-03-17 08:27:40 +11:00
|
|
|
__geoMeta: {
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-03-17 08:27:40 +11:00
|
|
|
sourceRange: [21, 42],
|
|
|
|
},
|
|
|
|
},
|
2023-01-08 16:37:31 +11:00
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'toPoint',
|
2023-08-24 15:34:51 -07:00
|
|
|
name: '',
|
2023-01-08 16:37:31 +11:00
|
|
|
to: [-1.59, -1.54],
|
|
|
|
from: [0, 0],
|
|
|
|
__geoMeta: {
|
2023-02-12 10:56:45 +11:00
|
|
|
sourceRange: [48, 73],
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-01-08 16:37:31 +11:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'toPoint',
|
|
|
|
to: [0.46, -5.82],
|
|
|
|
from: [-1.59, -1.54],
|
2023-08-24 15:34:51 -07:00
|
|
|
name: '',
|
2023-01-08 16:37:31 +11:00
|
|
|
__geoMeta: {
|
2023-02-12 10:56:45 +11:00
|
|
|
sourceRange: [79, 103],
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-01-08 16:37:31 +11:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
position: [0, 0, 0],
|
2023-07-10 15:15:07 +10:00
|
|
|
rotation: [0, 0, 0, 1],
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
|
|
|
__meta: [{ sourceRange: [21, 42] }],
|
2023-01-08 16:37:31 +11:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
2023-06-22 16:43:33 +10:00
|
|
|
test('extrude artifacts', async () => {
|
2023-07-10 15:15:07 +10:00
|
|
|
// Enable rotations #152
|
2023-01-08 16:37:31 +11:00
|
|
|
const code = `
|
2023-02-12 10:56:45 +11:00
|
|
|
const mySketch001 = startSketchAt([0, 0])
|
|
|
|
|> lineTo([-1.59, -1.54], %)
|
|
|
|
|> lineTo([0.46, -5.82], %)
|
2023-07-10 15:15:07 +10:00
|
|
|
// |> rx(45, %)
|
2023-01-08 16:37:31 +11:00
|
|
|
|> extrude(2, %)
|
|
|
|
show(mySketch001)`
|
2023-08-18 19:37:52 +10:00
|
|
|
const programMemory = await enginelessExecutor(parser_wasm(code))
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2023-07-10 15:15:07 +10:00
|
|
|
const shown = programMemory?.return?.map(
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2023-01-08 16:37:31 +11:00
|
|
|
(a) => programMemory?.root?.[a.name]
|
|
|
|
)
|
2023-07-10 15:15:07 +10:00
|
|
|
expect(shown).toEqual([
|
2023-01-08 16:37:31 +11:00
|
|
|
{
|
2023-09-12 18:10:27 -07:00
|
|
|
type: 'ExtrudeGroup',
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-07-10 15:15:07 +10:00
|
|
|
value: [],
|
2023-01-08 16:37:31 +11:00
|
|
|
height: 2,
|
|
|
|
position: [0, 0, 0],
|
2023-07-10 15:15:07 +10:00
|
|
|
rotation: [0, 0, 0, 1],
|
2023-08-24 15:34:51 -07:00
|
|
|
__meta: [{ sourceRange: [21, 42] }],
|
2022-12-25 21:14:43 +11:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
2023-06-22 16:43:33 +10:00
|
|
|
test('sketch extrude and sketch on one of the faces', async () => {
|
2023-07-10 15:15:07 +10:00
|
|
|
// Enable rotations #152
|
|
|
|
// TODO #153 in order for getExtrudeWallTransform to work we need to query the engine for the location of a face.
|
2023-01-09 08:52:48 +11:00
|
|
|
const code = `
|
2023-02-12 10:56:45 +11:00
|
|
|
const sk1 = startSketchAt([0, 0])
|
|
|
|
|> lineTo([-2.5, 0], %)
|
|
|
|
|> lineTo({ to: [0, 10], tag: "p" }, %)
|
|
|
|
|> lineTo([2.5, 0], %)
|
2023-07-10 15:15:07 +10:00
|
|
|
// |> rx(45, %)
|
|
|
|
// |> translate([1,0,1], %)
|
|
|
|
// |> ry(5, %)
|
2023-01-09 08:52:48 +11:00
|
|
|
const theExtrude = extrude(2, sk1)
|
2023-07-10 15:15:07 +10:00
|
|
|
// const theTransf = getExtrudeWallTransform('p', theExtrude)
|
2023-02-12 10:56:45 +11:00
|
|
|
const sk2 = startSketchAt([0, 0])
|
|
|
|
|> lineTo([-2.5, 0], %)
|
|
|
|
|> lineTo({ to: [0, 3], tag: "p" }, %)
|
|
|
|
|> lineTo([2.5, 0], %)
|
2023-07-10 15:15:07 +10:00
|
|
|
// |> transform(theTransf, %)
|
2023-01-09 08:52:48 +11:00
|
|
|
|> extrude(2, %)
|
2023-08-24 15:34:51 -07:00
|
|
|
|
2023-01-09 08:52:48 +11:00
|
|
|
|
|
|
|
show(theExtrude, sk2)`
|
2023-08-18 19:37:52 +10:00
|
|
|
const programMemory = await enginelessExecutor(parser_wasm(code))
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2023-01-09 08:52:48 +11:00
|
|
|
const geos = programMemory?.return?.map(
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2023-07-10 15:15:07 +10:00
|
|
|
({ name }) => programMemory?.root?.[name]
|
2023-01-09 08:52:48 +11:00
|
|
|
)
|
2023-07-10 15:15:07 +10:00
|
|
|
expect(geos).toEqual([
|
2023-01-09 08:52:48 +11:00
|
|
|
{
|
2023-09-12 18:10:27 -07:00
|
|
|
type: 'ExtrudeGroup',
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-07-10 15:15:07 +10:00
|
|
|
value: [],
|
2023-01-09 08:52:48 +11:00
|
|
|
height: 2,
|
2023-07-10 15:15:07 +10:00
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
2023-08-24 15:34:51 -07:00
|
|
|
__meta: [{ sourceRange: [13, 34] }],
|
2023-01-09 08:52:48 +11:00
|
|
|
},
|
|
|
|
{
|
2023-09-12 18:10:27 -07:00
|
|
|
type: 'ExtrudeGroup',
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-07-10 15:15:07 +10:00
|
|
|
value: [],
|
2023-01-09 08:52:48 +11:00
|
|
|
height: 2,
|
2023-07-10 15:15:07 +10:00
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
2023-08-24 15:34:51 -07:00
|
|
|
__meta: [{ sourceRange: [302, 323] }],
|
2023-01-09 08:52:48 +11:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
2022-12-25 21:14:43 +11:00
|
|
|
})
|