Merge branch 'main' into pierremtb/issue1349

This commit is contained in:
Pierre Jacquier
2024-03-27 05:20:27 -04:00
parent d7e2abad20
commit d03a641d6f
208 changed files with 10097 additions and 276 deletions

View File

@ -1,3 +1,3 @@
[codespell]
ignore-words-list: crate,everytime,inout,co-ordinate,ot,nwo,absolutey
skip: **/target,node_modules,build,**/Cargo.lock,./src-tauri/gen/schemas
skip: **/target,node_modules,build,**/Cargo.lock,./docs/kcl/*.md,./src-tauri/gen/schemas

View File

@ -12,6 +12,10 @@ Computes the absolute value of a number.
abs(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the arccosine of a number (in radians).
acos(num: number) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Computes the arcsine of a number (in radians).
asin(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the arctangent of a number (in radians).
atan(num: number) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Computes the smallest integer greater than or equal to a number.
ceil(num: number) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Computes the sine of a number (in radians).
cos(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Return the value of Eulers number `e`.
e() -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Computes the largest integer less than or equal to a number.
floor(num: number) -> number
```
### Tags
* `math`
### Examples
```js

180
docs/kcl/getEdge.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

308
docs/kcl/helix.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -30,10 +30,12 @@ layout: manual
* [`extrude`](kcl/extrude)
* [`fillet`](kcl/fillet)
* [`floor`](kcl/floor)
* [`getEdge`](kcl/getEdge)
* [`getExtrudeWallTransform`](kcl/getExtrudeWallTransform)
* [`getNextAdjacentEdge`](kcl/getNextAdjacentEdge)
* [`getOppositeEdge`](kcl/getOppositeEdge)
* [`getPreviousAdjacentEdge`](kcl/getPreviousAdjacentEdge)
* [`helix`](kcl/helix)
* [`hole`](kcl/hole)
* [`import`](kcl/import)
* [`lastSegX`](kcl/lastSegX)
@ -55,6 +57,7 @@ layout: manual
* [`patternLinear3d`](kcl/patternLinear3d)
* [`pi`](kcl/pi)
* [`pow`](kcl/pow)
* [`revolve`](kcl/revolve)
* [`segAng`](kcl/segAng)
* [`segEndX`](kcl/segEndX)
* [`segEndY`](kcl/segEndY)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Returns the angle of the given leg for x.
legAngX(hypotenuse: number, leg: number) -> number
```
### Tags
* `utilities`
### Examples
```js

View File

@ -12,6 +12,10 @@ Returns the angle of the given leg for y.
legAngY(hypotenuse: number, leg: number) -> number
```
### Tags
* `utilities`
### Examples
```js

View File

@ -12,6 +12,10 @@ Returns the length of the given leg.
legLen(hypotenuse: number, leg: number) -> number
```
### Tags
* `utilities`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Computes the natural logarithm of the number.
ln(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ The result might not be correctly rounded owing to implementation details; `log2
log(num: number, base: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the base 10 logarithm of the number.
log10(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the base 2 logarithm of the number.
log2(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the maximum of the given arguments.
max(args: [number]) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the minimum of the given arguments.
min(args: [number]) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Return the value of `pi`. Archimedes constant (π).
pi() -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the number to a power.
pow(num: number, pow: number) -> number
```
### Tags
* `math`
### Examples
```js

412
docs/kcl/revolve.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Computes the sine of a number (in radians).
sin(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Computes the square root of a number.
sqrt(num: number) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,10 @@ Computes the tangent of a number (in radians).
tan(num: number) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,10 @@ Return the value of `tau`. The full circle constant (τ). Equal to 2π.
tau() -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Converts a number from radians to degrees.
toDegrees(num: number) -> number
```
### Tags
* `math`
### Examples
```js

View File

@ -12,6 +12,10 @@ Converts a number from degrees to radians.
toRadians(num: number) -> number
```
### Tags
* `math`
### Examples
```js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -1,6 +1,6 @@
{
"name": "untitled-app",
"version": "0.16.0",
"version": "0.17.0",
"private": true,
"dependencies": {
"@codemirror/autocomplete": "^6.15.0",
@ -10,7 +10,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.18",
"@headlessui/tailwindcss": "^0.2.0",
"@kittycad/lib": "^0.1.0",
"@kittycad/lib": "^0.0.56",
"@lezer/javascript": "^1.4.9",
"@open-rpc/client-js": "^1.8.1",
"@react-hook/resize-observer": "^1.2.6",

View File

@ -56,8 +56,11 @@
"identifier": "http:default",
"allow": [
"https://dev.kittycad.io/*",
"https://dev.zoo.dev/*",
"https://kittycad.io/*",
"https://api.dev.kittycad.io/*"
"https://zoo.dev/*",
"https://api.dev.kittycad.io/*",
"https://api.dev.zoo.dev/*"
]
},
"os:allow-platform",

View File

@ -48,12 +48,12 @@
"shortDescription": "",
"targets": "all"
},
"identifier": "io.kittycad.modeling-app",
"identifier": "dev.zoo.modeling-app",
"plugins": {
"shell": {
"open": true
}
},
"productName": "zoo-modeling-app",
"version": "0.16.0"
"version": "0.17.0"
}

View File

@ -242,7 +242,6 @@ export const ModelingMachineProvider = ({
}
exportFromEngine({
source_unit: baseUnit,
format: format as Models['OutputFormat_type'],
}).catch((e) => toast.error('Error while exporting', e)) // TODO I think we need to throw the error from engineCommandManager
},

View File

@ -1289,40 +1289,14 @@ export class EngineCommandManager {
this.callbacksEngineStateConnection.push(callback)
}
endSession() {
// TODO: instead of sending a single command with `object_ids: Object.keys(this.artifactMap)`
// we need to loop over them each individually because if the engine doesn't recognise a single
// id the whole command fails.
const artifactsToDelete: any = {}
Object.entries(this.artifactMap).forEach(([id, artifact]) => {
const artifactTypesToDelete: ArtifactMap[string]['commandType'][] = [
// 'start_path' creates a new scene object for the path, which is why it needs to be deleted,
// however all of the segments in the path are its children so there don't need to be deleted.
// this fact is very opaque in the api and docs (as to what should can be deleted).
// Using an array is the list is likely to grow.
'start_path',
'entity_linear_pattern',
'entity_circular_pattern',
]
if (artifactTypesToDelete.includes(artifact.commandType)) {
artifactsToDelete[id] = artifact
}
if (artifact.commandType === 'import_files') {
// TODO why is this handled differently from other artifacts, i.e. why does it not use the id from the
// modeling command? We're having to do special clean up for this one special object.
artifactsToDelete[(artifact as any)?.data?.data?.object_id] = artifact
}
})
Object.keys(artifactsToDelete).forEach((id) => {
const deleteCmd: EngineCommand = {
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'remove_scene_objects',
object_ids: [id],
},
}
this.engineConnection?.send(deleteCmd)
})
const deleteCmd: EngineCommand = {
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'scene_clear_all',
},
}
this.engineConnection?.send(deleteCmd)
}
addCommandLog(message: CommandLog) {
if (this._commandLogs.length > 500) {

View File

@ -127,13 +127,15 @@ export interface ProgramMemory {
export const executor = async (
node: Program,
programMemory: ProgramMemory = { root: {}, return: null },
engineCommandManager: EngineCommandManager
engineCommandManager: EngineCommandManager,
isMock: boolean = false
): Promise<ProgramMemory> => {
engineCommandManager.startNewSession()
const _programMemory = await _executor(
node,
programMemory,
engineCommandManager
engineCommandManager,
isMock
)
await engineCommandManager.waitForAllCommands()
@ -148,7 +150,8 @@ const getSettingsState = import('components/SettingsAuthProvider').then(
export const _executor = async (
node: Program,
programMemory: ProgramMemory = { root: {}, return: null },
engineCommandManager: EngineCommandManager
engineCommandManager: EngineCommandManager,
isMock: boolean
): Promise<ProgramMemory> => {
try {
const baseUnit = (await getSettingsState)()?.baseUnit || 'mm'
@ -157,7 +160,8 @@ export const _executor = async (
JSON.stringify(programMemory),
baseUnit,
engineCommandManager,
fileSystemManager
fileSystemManager,
isMock
)
return memory
} catch (e: any) {

View File

@ -5,10 +5,8 @@ import { v4 as uuidv4 } from 'uuid'
// Isolating a function to call the engine to export the current scene.
// Because it has given us trouble in automated testing environments.
export function exportFromEngine({
source_unit,
format,
}: {
source_unit: Models['UnitLength_type']
format: Models['OutputFormat_type']
}) {
return engineCommandManager.sendSceneCommand({
@ -20,7 +18,6 @@ export function exportFromEngine({
// in the scene to export. In that case, you'd pass the IDs thru here.
entity_ids: [],
format,
source_unit,
},
cmd_id: uuidv4(),
})

View File

@ -66,7 +66,7 @@ export async function enginelessExecutor(
}) as any as EngineCommandManager
await mockEngineCommandManager.waitForReady
mockEngineCommandManager.startNewSession()
const programMemory = await _executor(ast, pm, mockEngineCommandManager)
const programMemory = await _executor(ast, pm, mockEngineCommandManager, true)
await mockEngineCommandManager.waitForAllCommands()
return programMemory
}
@ -86,7 +86,7 @@ export async function executor(
})
await engineCommandManager.waitForReady
engineCommandManager.startNewSession()
const programMemory = await _executor(ast, pm, engineCommandManager)
const programMemory = await _executor(ast, pm, engineCommandManager, false)
await engineCommandManager.waitForAllCommands()
return programMemory
}

View File

@ -263,7 +263,7 @@ export async function executeAst({
}
const programMemory = await (useFakeExecutor
? enginelessExecutor(ast, programMemoryOverride || programMemoryInit())
: _executor(ast, programMemoryInit(), engineCommandManager))
: _executor(ast, programMemoryInit(), engineCommandManager, false))
await engineCommandManager.waitForAllCommands()
return {

View File

@ -322,6 +322,12 @@ version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]]
name = "base64"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"
[[package]]
name = "base64ct"
version = "1.6.0"
@ -1843,9 +1849,11 @@ dependencies = [
"approx 0.5.1",
"async-recursion",
"async-trait",
"base64 0.22.0",
"bson",
"chrono",
"clap",
"convert_case",
"criterion",
"dashmap",
"databake",
@ -1853,6 +1861,7 @@ dependencies = [
"expectorate",
"futures",
"gltf-json",
"image",
"insta",
"itertools 0.12.1",
"js-sys",
@ -1874,6 +1883,7 @@ dependencies = [
"tokio-tungstenite",
"tower-lsp",
"ts-rs",
"twenty-twenty",
"uuid",
"wasm-bindgen",
"wasm-bindgen-futures",
@ -1896,9 +1906,9 @@ dependencies = [
[[package]]
name = "kittycad"
version = "0.2.62"
version = "0.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bb6a3e37a902c099f3f077f1e75814339bf5d548151a675544366841a882377"
checksum = "93a332250e08fd715ad3d5826e04d36da1c5bb42d0c1b1ff1f0598278b9ebf3c"
dependencies = [
"anyhow",
"async-trait",

View File

@ -59,7 +59,7 @@ members = [
]
[workspace.dependencies]
kittycad = { version = "0.2.62", default-features = false, features = ["js", "requests"] }
kittycad = { version = "0.2.63", default-features = false, features = ["js", "requests"] }
kittycad-execution-plan = { git = "https://github.com/KittyCAD/modeling-api", branch = "main" }
kittycad-execution-plan-macros = { git = "https://github.com/KittyCAD/modeling-api", branch = "main" }
kittycad-execution-plan-traits = { git = "https://github.com/KittyCAD/modeling-api", branch = "main" }

View File

@ -201,7 +201,7 @@ fn do_stdlib_inner(
.code_blocks
.iter()
.enumerate()
.map(|(index, code_block)| generate_code_block_test(&fn_name_str, code_block, index))
.map(|(index, code_block)| generate_code_block_test(&fn_name_str, code_block, index, &metadata.tags))
.collect::<Vec<_>>();
let tags = metadata
@ -731,12 +731,18 @@ fn parse_array_type(type_name: &str) -> Option<(&str, usize)> {
// For each kcl code block, we want to generate a test that checks that the
// code block is valid kcl code and compiles and executes.
fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> proc_macro2::TokenStream {
fn generate_code_block_test(
fn_name: &str,
code_block: &str,
index: usize,
tags: &[String],
) -> proc_macro2::TokenStream {
let test_name = format_ident!("serial_test_example_{}{}", fn_name, index);
let test_name_str = format!("serial_test_example_{}{}", fn_name, index);
// TODO: We ignore import for now, because the files don't exist and we just want
// to show easy imports.
let ignored = if fn_name == "import" {
let ignored = if tags.contains(&"norun".to_string()) {
quote! { #[ignore] }
} else {
quote! {}
@ -778,14 +784,58 @@ fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> pr
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(crate::engine::conn::EngineConnection::new(ws).await.unwrap())),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone()).await.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx).await.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D { x: 0.0, y: 0.0, z: 0.0 },
up: kittycad::types::Point3D { x: 0.0, y: 0.0, z: 1.0 },
vantage: kittycad::types::Point3D { x: 0.0, y: -x, z: y },
sequence: None,
},
)
.await.unwrap();
// Send a snapshot request to the engine.
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await.unwrap();
// Create a temporary file to write the output to.
let output_file = std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
// Save the snapshot locally.
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
// Read the output file.
let actual = image::io::Reader::open(output_file).unwrap().decode().unwrap();
twenty_twenty::assert_image(&format!("tests/outputs/{}.png", #test_name_str), &actual, 1.0);
}
}
}

View File

@ -345,6 +345,7 @@ fn test_stdlib_doc_comment_with_code_on_ignored_function() {
let (item, errors) = do_stdlib(
quote! {
name = "import",
tags = ["norun"]
},
quote! {
/// This is some function.

View File

@ -29,19 +29,72 @@ mod test_examples_show {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"),
&actual,
1.0,
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
@ -73,19 +126,72 @@ mod test_examples_show {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show1"),
&actual,
1.0,
);
}
}

View File

@ -29,19 +29,72 @@ mod test_examples_show {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"),
&actual,
1.0,
);
}
}

View File

@ -29,19 +29,72 @@ mod test_examples_my_func {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_my_func0"),
&actual,
1.0,
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
@ -73,19 +126,72 @@ mod test_examples_my_func {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_my_func1"),
&actual,
1.0,
);
}
}

View File

@ -30,19 +30,72 @@ mod test_examples_import {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"),
&actual,
1.0,
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
@ -75,19 +128,72 @@ mod test_examples_import {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import1"),
&actual,
1.0,
);
}
}
@ -126,7 +232,7 @@ impl crate::docs::StdLibFn for Import {
}
fn tags(&self) -> Vec<String> {
vec![]
vec!["norun".to_string()]
}
fn args(&self) -> Vec<crate::docs::StdLibFnArg> {

View File

@ -29,19 +29,72 @@ mod test_examples_line_to {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_line_to0"),
&actual,
1.0,
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
@ -73,19 +126,72 @@ mod test_examples_line_to {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_line_to1"),
&actual,
1.0,
);
}
}

View File

@ -29,19 +29,72 @@ mod test_examples_min {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_min0"),
&actual,
1.0,
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
@ -73,19 +126,72 @@ mod test_examples_min {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_min1"),
&actual,
1.0,
);
}
}

View File

@ -29,19 +29,72 @@ mod test_examples_show {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"),
&actual,
1.0,
);
}
}

View File

@ -1,7 +1,6 @@
#[cfg(test)]
mod test_examples_import {
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
#[ignore]
async fn serial_test_example_import0() {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
@ -30,19 +29,72 @@ mod test_examples_import {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"),
&actual,
1.0,
);
}
}

View File

@ -1,7 +1,6 @@
#[cfg(test)]
mod test_examples_import {
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
#[ignore]
async fn serial_test_example_import0() {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
@ -30,19 +29,72 @@ mod test_examples_import {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"),
&actual,
1.0,
);
}
}

View File

@ -1,7 +1,6 @@
#[cfg(test)]
mod test_examples_import {
#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
#[ignore]
async fn serial_test_example_import0() {
let user_agent = concat!(env!("CARGO_PKG_NAME"), ".rs/", env!("CARGO_PKG_VERSION"),);
let http_client = reqwest::Client::builder()
@ -30,19 +29,72 @@ mod test_examples_import {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_import0"),
&actual,
1.0,
);
}
}

View File

@ -29,19 +29,72 @@ mod test_examples_show {
let parser = crate::parser::Parser::new(tokens);
let program = parser.ast().unwrap();
let mut mem: crate::executor::ProgramMemory = Default::default();
let ctx = crate::executor::ExecutorContext {
engine: std::sync::Arc::new(Box::new(
crate::engine::conn::EngineConnection::new(ws)
.await
.unwrap(),
)),
fs: crate::fs::FileManager::new(),
stdlib: std::sync::Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
};
let units = kittycad::types::UnitLength::Mm;
let ctx = crate::executor::ExecutorContext::new(ws, units.clone())
.await
.unwrap();
crate::executor::execute(program, &mut mem, crate::executor::BodyType::Root, &ctx)
.await
.unwrap();
let (x, y) = crate::std::utils::get_camera_zoom_magnitude_per_unit_length(units);
ctx.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::DefaultCameraLookAt {
center: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 0.0,
},
up: kittycad::types::Point3D {
x: 0.0,
y: 0.0,
z: 1.0,
},
vantage: kittycad::types::Point3D {
x: 0.0,
y: -x,
z: y,
},
sequence: None,
},
)
.await
.unwrap();
let resp = ctx
.engine
.send_modeling_cmd(
false,
uuid::Uuid::new_v4(),
crate::executor::SourceRange::default(),
kittycad::types::ModelingCmd::TakeSnapshot {
format: kittycad::types::ImageFormat::Png,
},
)
.await
.unwrap();
let output_file =
std::env::temp_dir().join(format!("kcl_output_{}.png", uuid::Uuid::new_v4()));
if let kittycad::types::OkWebSocketResponseData::Modeling {
modeling_response: kittycad::types::OkModelingCmdResponse::TakeSnapshot { data },
} = &resp
{
std::fs::write(&output_file, &data.contents.0).unwrap();
} else {
panic!("Unexpected response from engine: {:?}", resp);
}
let actual = image::io::Reader::open(output_file)
.unwrap()
.decode()
.unwrap();
twenty_twenty::assert_image(
&format!("tests/outputs/{}.png", "serial_test_example_show0"),
&actual,
1.0,
);
}
}

View File

@ -67,12 +67,16 @@ debug = true
debug = true # Flamegraphs of benchmarks require accurate debug symbols
[dev-dependencies]
base64 = "0.22.0"
convert_case = "0.6.0"
criterion = "0.5.1"
expectorate = "1.1.0"
image = "0.24.9"
insta = { version = "1.36.1", features = ["json"] }
itertools = "0.12.1"
pretty_assertions = "1.4.0"
tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros", "time"] }
twenty-twenty = "0.7.0"
[[bench]]
name = "compiler_benchmark"

View File

@ -134,6 +134,11 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
pub fn is_cmd_with_return_values(cmd: &kittycad::types::ModelingCmd) -> bool {
let (kittycad::types::ModelingCmd::Export { .. }
| kittycad::types::ModelingCmd::Extrude { .. }
| kittycad::types::ModelingCmd::DefaultCameraLookAt { .. }
| kittycad::types::ModelingCmd::DefaultCameraFocusOn { .. }
| kittycad::types::ModelingCmd::DefaultCameraGetSettings { .. }
| kittycad::types::ModelingCmd::DefaultCameraPerspectiveSettings { .. }
| kittycad::types::ModelingCmd::DefaultCameraZoom { .. }
| kittycad::types::ModelingCmd::SketchModeDisable { .. }
| kittycad::types::ModelingCmd::ObjectBringToFront { .. }
| kittycad::types::ModelingCmd::SelectWithPoint { .. }
@ -144,8 +149,6 @@ pub fn is_cmd_with_return_values(cmd: &kittycad::types::ModelingCmd) -> bool {
| kittycad::types::ModelingCmd::EntityGetAllChildUuids { .. }
| kittycad::types::ModelingCmd::CameraDragMove { .. }
| kittycad::types::ModelingCmd::CameraDragEnd { .. }
| kittycad::types::ModelingCmd::DefaultCameraGetSettings { .. }
| kittycad::types::ModelingCmd::DefaultCameraZoom { .. }
| kittycad::types::ModelingCmd::SelectGet { .. }
| kittycad::types::ModelingCmd::Solid3DGetAllEdgeFaces { .. }
| kittycad::types::ModelingCmd::Solid3DGetAllOppositeEdges { .. }

View File

@ -983,11 +983,13 @@ pub struct ExecutorContext {
pub fs: FileManager,
pub stdlib: Arc<StdLib>,
pub units: kittycad::types::UnitLength,
/// Mock mode is only for the modeling app when they just want to mock engine calls and not
/// actually make them.
pub is_mock: bool,
}
impl ExecutorContext {
/// Create a new default executor context.
#[cfg(not(test))]
#[cfg(not(target_arch = "wasm32"))]
pub async fn new(ws: reqwest::Upgraded, units: kittycad::types::UnitLength) -> Result<Self> {
Ok(Self {
@ -995,6 +997,7 @@ impl ExecutorContext {
fs: FileManager::new(),
stdlib: Arc::new(StdLib::new()),
units,
is_mock: false,
})
}
}
@ -1302,6 +1305,7 @@ mod tests {
fs: crate::fs::FileManager::new(),
stdlib: Arc::new(crate::std::StdLib::new()),
units: kittycad::types::UnitLength::Mm,
is_mock: false,
};
let memory = execute(program, &mut mem, BodyType::Root, &ctx).await?;

Some files were not shown because too many files have changed in this diff Show More