2023-09-29 11:11:01 -07:00
|
|
|
import { parse, initPromise } from './wasm'
|
2023-08-18 17:14:35 -05:00
|
|
|
import { enginelessExecutor } from '../lib/testHelpers'
|
2023-02-21 09:42:41 +11:00
|
|
|
|
2024-04-19 14:24:40 -07:00
|
|
|
beforeAll(async () => {
|
|
|
|
await 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-10-05 14:27:48 -07:00
|
|
|
const mySketch001 = startSketchOn('XY')
|
|
|
|
|> startProfileAt([0, 0], %)
|
2023-02-12 10:56:45 +11:00
|
|
|
|> lineTo([-1.59, -1.54], %)
|
|
|
|
|> lineTo([0.46, -5.82], %)
|
2024-03-01 17:16:18 -08:00
|
|
|
// |> rx(45, %)`
|
2023-09-29 11:11:01 -07:00
|
|
|
const programMemory = await enginelessExecutor(parse(code))
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2024-03-01 17:16:18 -08:00
|
|
|
const sketch001 = programMemory?.root?.mySketch001
|
|
|
|
expect(sketch001).toEqual({
|
|
|
|
type: 'SketchGroup',
|
|
|
|
on: expect.any(Object),
|
|
|
|
start: {
|
|
|
|
to: [0, 0],
|
|
|
|
from: [0, 0],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [46, 71],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
2023-08-24 15:34:51 -07:00
|
|
|
name: '',
|
2024-03-01 17:16:18 -08:00
|
|
|
to: [-1.59, -1.54],
|
|
|
|
from: [0, 0],
|
2023-03-17 08:27:40 +11:00
|
|
|
__geoMeta: {
|
2024-03-01 17:16:18 -08:00
|
|
|
sourceRange: [77, 102],
|
2023-08-24 15:34:51 -07:00
|
|
|
id: expect.any(String),
|
2023-03-17 08:27:40 +11:00
|
|
|
},
|
|
|
|
},
|
2024-03-01 17:16:18 -08:00
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
to: [0.46, -5.82],
|
|
|
|
from: [-1.59, -1.54],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
sourceRange: [108, 132],
|
|
|
|
id: expect.any(String),
|
2023-01-08 16:37:31 +11:00
|
|
|
},
|
2024-03-01 17:16:18 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
xAxis: { x: 1, y: 0, z: 0 },
|
|
|
|
yAxis: { x: 0, y: 1, z: 0 },
|
|
|
|
zAxis: { x: 0, y: 0, z: 1 },
|
|
|
|
id: expect.any(String),
|
|
|
|
entityId: expect.any(String),
|
|
|
|
__meta: [{ sourceRange: [46, 71] }],
|
|
|
|
})
|
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-10-05 14:27:48 -07:00
|
|
|
const mySketch001 = startSketchOn('XY')
|
|
|
|
|> startProfileAt([0, 0], %)
|
2023-02-12 10:56:45 +11:00
|
|
|
|> lineTo([-1.59, -1.54], %)
|
|
|
|
|> lineTo([0.46, -5.82], %)
|
2023-07-10 15:15:07 +10:00
|
|
|
// |> rx(45, %)
|
2024-03-01 17:16:18 -08:00
|
|
|
|> extrude(2, %)`
|
2023-09-29 11:11:01 -07:00
|
|
|
const programMemory = await enginelessExecutor(parse(code))
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2024-03-01 17:16:18 -08:00
|
|
|
const sketch001 = programMemory?.root?.mySketch001
|
|
|
|
expect(sketch001).toEqual({
|
|
|
|
type: 'ExtrudeGroup',
|
|
|
|
id: expect.any(String),
|
2024-03-22 10:23:04 +11:00
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: '',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [77, 102],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: '',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [108, 132],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
sketchGroupValues: [
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [0, 0],
|
|
|
|
to: [-1.59, -1.54],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [77, 102],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [-1.59, -1.54],
|
|
|
|
to: [0.46, -5.82],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [108, 132],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2024-03-01 17:16:18 -08:00
|
|
|
height: 2,
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
xAxis: { x: 1, y: 0, z: 0 },
|
|
|
|
yAxis: { x: 0, y: 1, z: 0 },
|
|
|
|
zAxis: { x: 0, y: 0, z: 1 },
|
2024-03-22 10:23:04 +11:00
|
|
|
startCapId: expect.any(String),
|
|
|
|
endCapId: expect.any(String),
|
2024-03-01 17:16:18 -08:00
|
|
|
__meta: [{ sourceRange: [46, 71] }],
|
|
|
|
})
|
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-10-05 14:27:48 -07:00
|
|
|
const sk1 = startSketchOn('XY')
|
|
|
|
|> startProfileAt([0, 0], %)
|
2023-02-12 10:56:45 +11:00
|
|
|
|> lineTo([-2.5, 0], %)
|
2024-03-15 17:03:42 -04:00
|
|
|
|> lineTo([0, 10], %, "p")
|
2023-02-12 10:56:45 +11:00
|
|
|
|> 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-10-05 14:27:48 -07:00
|
|
|
const sk2 = startSketchOn('XY')
|
|
|
|
|> startProfileAt([0, 0], %)
|
2023-02-12 10:56:45 +11:00
|
|
|
|> lineTo([-2.5, 0], %)
|
2024-03-15 17:03:42 -04:00
|
|
|
|> lineTo([0, 3], %, "p")
|
2023-02-12 10:56:45 +11:00
|
|
|
|> 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
|
|
|
|
2024-03-01 17:16:18 -08:00
|
|
|
`
|
2023-09-29 11:11:01 -07:00
|
|
|
const programMemory = await enginelessExecutor(parse(code))
|
2023-08-24 15:34:51 -07:00
|
|
|
// @ts-ignore
|
2024-03-01 17:16:18 -08:00
|
|
|
const geos = [programMemory?.root?.theExtrude, programMemory?.root?.sk2]
|
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),
|
2024-03-22 10:23:04 +11:00
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: '',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [69, 89],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: 'p',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [95, 118],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: '',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [124, 143],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
sketchGroupValues: [
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [0, 0],
|
|
|
|
to: [-2.5, 0],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [69, 89],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [-2.5, 0],
|
|
|
|
to: [0, 10],
|
|
|
|
name: 'p',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [95, 118],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [0, 10],
|
|
|
|
to: [2.5, 0],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [124, 143],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
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],
|
2024-02-12 18:08:42 -08:00
|
|
|
xAxis: { x: 1, y: 0, z: 0 },
|
|
|
|
yAxis: { x: 0, y: 1, z: 0 },
|
|
|
|
zAxis: { x: 0, y: 0, z: 1 },
|
2024-03-22 10:23:04 +11:00
|
|
|
startCapId: expect.any(String),
|
|
|
|
endCapId: expect.any(String),
|
2023-10-05 14:27:48 -07:00
|
|
|
__meta: [{ sourceRange: [38, 63] }],
|
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),
|
2024-03-22 10:23:04 +11:00
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: '',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [374, 394],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: 'p',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [400, 422],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'extrudePlane',
|
|
|
|
position: [0, 0, 0],
|
|
|
|
rotation: [0, 0, 0, 1],
|
|
|
|
faceId: expect.any(String),
|
|
|
|
name: '',
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [428, 447],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
sketchGroupValues: [
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [0, 0],
|
|
|
|
to: [-2.5, 0],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [374, 394],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [-2.5, 0],
|
|
|
|
to: [0, 3],
|
|
|
|
name: 'p',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [400, 422],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'ToPoint',
|
|
|
|
from: [0, 3],
|
|
|
|
to: [2.5, 0],
|
|
|
|
name: '',
|
|
|
|
__geoMeta: {
|
|
|
|
id: expect.any(String),
|
|
|
|
sourceRange: [428, 447],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
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],
|
2024-02-12 18:08:42 -08:00
|
|
|
xAxis: { x: 1, y: 0, z: 0 },
|
|
|
|
yAxis: { x: 0, y: 1, z: 0 },
|
|
|
|
zAxis: { x: 0, y: 0, z: 1 },
|
2024-03-22 10:23:04 +11:00
|
|
|
startCapId: expect.any(String),
|
|
|
|
endCapId: expect.any(String),
|
2024-03-15 17:03:42 -04:00
|
|
|
__meta: [{ sourceRange: [343, 368] }],
|
2023-01-09 08:52:48 +11:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
2022-12-25 21:14:43 +11:00
|
|
|
})
|