2022-12-25 21:14:43 +11:00
|
|
|
import { abstractSyntaxTree } from './abstractSyntaxTree'
|
|
|
|
import { lexer } from './tokeniser'
|
2023-06-22 16:43:33 +10:00
|
|
|
import { SketchGroup, ExtrudeGroup } from './executor'
|
2023-02-21 09:42:41 +11:00
|
|
|
import { initPromise } from './rust'
|
2023-07-10 15:15:07 +10:00
|
|
|
import { enginelessExecutor, executor } 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-07-10 15:15:07 +10:00
|
|
|
// |> rx(45, %)
|
2022-12-25 21:14:43 +11:00
|
|
|
show(mySketch001)`
|
2023-07-10 15:15:07 +10:00
|
|
|
const programMemory = await enginelessExecutor(
|
|
|
|
abstractSyntaxTree(lexer(code))
|
|
|
|
)
|
|
|
|
const shown = programMemory?.return?.map(
|
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-01-08 16:37:31 +11:00
|
|
|
type: 'sketchGroup',
|
2023-03-17 08:27:40 +11:00
|
|
|
start: {
|
|
|
|
type: 'base',
|
|
|
|
to: [0, 0],
|
|
|
|
from: [0, 0],
|
|
|
|
__geoMeta: {
|
2023-06-22 16:43:33 +10:00
|
|
|
id: '66366561-6465-4734-a463-366330356563',
|
2023-03-17 08:27:40 +11:00
|
|
|
sourceRange: [21, 42],
|
|
|
|
pathToNode: [],
|
|
|
|
},
|
|
|
|
},
|
2023-01-08 16:37:31 +11:00
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'toPoint',
|
|
|
|
to: [-1.59, -1.54],
|
|
|
|
from: [0, 0],
|
|
|
|
__geoMeta: {
|
2023-02-12 10:56:45 +11:00
|
|
|
sourceRange: [48, 73],
|
2023-06-22 16:43:33 +10:00
|
|
|
id: '30366338-6462-4330-a364-303935626163',
|
2023-01-08 16:37:31 +11:00
|
|
|
pathToNode: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'toPoint',
|
|
|
|
to: [0.46, -5.82],
|
|
|
|
from: [-1.59, -1.54],
|
|
|
|
__geoMeta: {
|
2023-02-12 10:56:45 +11:00
|
|
|
sourceRange: [79, 103],
|
2023-06-22 16:43:33 +10:00
|
|
|
id: '32653334-6331-4231-b162-663334363535',
|
2023-01-08 16:37:31 +11:00
|
|
|
pathToNode: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
position: [0, 0, 0],
|
2023-07-10 15:15:07 +10:00
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
id: '39643164-6130-4734-b432-623638393262',
|
|
|
|
__meta: [{ sourceRange: [21, 42], pathToNode: [] }],
|
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-07-10 15:15:07 +10:00
|
|
|
const programMemory = await enginelessExecutor(
|
|
|
|
abstractSyntaxTree(lexer(code))
|
|
|
|
)
|
|
|
|
const shown = programMemory?.return?.map(
|
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
|
|
|
{
|
|
|
|
type: 'extrudeGroup',
|
2023-07-10 15:15:07 +10:00
|
|
|
id: '31616631-3438-4664-a464-393034663561',
|
|
|
|
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-01-08 16:37:31 +11:00
|
|
|
__meta: [
|
2023-07-10 15:15:07 +10:00
|
|
|
{ sourceRange: [127, 140], pathToNode: [] },
|
2023-02-12 10:56:45 +11:00
|
|
|
{ sourceRange: [21, 42], pathToNode: [] },
|
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, %)
|
|
|
|
|
|
|
|
|
|
|
|
show(theExtrude, sk2)`
|
2023-07-10 15:15:07 +10:00
|
|
|
const programMemory = await enginelessExecutor(
|
|
|
|
abstractSyntaxTree(lexer(code))
|
|
|
|
)
|
2023-01-09 08:52:48 +11:00
|
|
|
const geos = programMemory?.return?.map(
|
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
|
|
|
{
|
|
|
|
type: 'extrudeGroup',
|
2023-07-10 15:15:07 +10:00
|
|
|
id: '35623732-3138-4137-a163-626336313834',
|
|
|
|
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-01-09 08:52:48 +11:00
|
|
|
__meta: [
|
2023-07-10 15:15:07 +10:00
|
|
|
{ sourceRange: [212, 227], pathToNode: [] },
|
2023-02-12 10:56:45 +11:00
|
|
|
{ sourceRange: [13, 34], pathToNode: [] },
|
2023-01-09 08:52:48 +11:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'extrudeGroup',
|
2023-07-10 15:15:07 +10:00
|
|
|
id: '64303137-3930-4039-a334-333164373166',
|
|
|
|
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-01-09 08:52:48 +11:00
|
|
|
__meta: [
|
2023-07-10 15:15:07 +10:00
|
|
|
{ sourceRange: [453, 466], pathToNode: [] },
|
|
|
|
{ sourceRange: [302, 323], pathToNode: [] },
|
2023-01-09 08:52:48 +11:00
|
|
|
],
|
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
2022-12-25 21:14:43 +11:00
|
|
|
})
|