run rust benchmarks and compare on prs (#5734)
* run benchmarks and compare on prs Signed-off-by: Jess Frazelle <github@jessfraz.com> * run benchmarks and compare on prs Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * benchmark kcl-samples Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
52
.github/workflows/cargo-bench.yml
vendored
Normal file
52
.github/workflows/cargo-bench.yml
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- '**.rs'
|
||||
- '**/Cargo.toml'
|
||||
- '**/Cargo.lock'
|
||||
- '**/rust-toolchain.toml'
|
||||
- .github/workflows/cargo-bench.yml
|
||||
pull_request:
|
||||
paths:
|
||||
- '**.rs'
|
||||
- '**/Cargo.toml'
|
||||
- '**/Cargo.lock'
|
||||
- '**/rust-toolchain.toml'
|
||||
- .github/workflows/cargo-bench.yml
|
||||
workflow_dispatch:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
name: cargo bench
|
||||
jobs:
|
||||
cargo-bench:
|
||||
name: cargo bench
|
||||
runs-on: ubuntu-latest-8-cores
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use correct Rust toolchain
|
||||
shell: bash
|
||||
run: |
|
||||
[ -e rust-toolchain.toml ] || cp rust/rust-toolchain.toml ./
|
||||
- name: Install rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
cache: rust
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cargo install cargo-criterion
|
||||
sudo apt update
|
||||
sudo apt install -y valgrind
|
||||
- uses: boa-dev/criterion-compare-action@v3
|
||||
with:
|
||||
cwd: "rust"
|
||||
defaultFeatures: true
|
||||
# Needed. The name of the branch to compare with. This default uses the branch which is being pulled against
|
||||
branchName: ${{ github.base_ref }}
|
||||
env:
|
||||
KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}}
|
2
rust/Cargo.lock
generated
2
rust/Cargo.lock
generated
@ -1813,7 +1813,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kcl-directory-test-macro"
|
||||
version = "0.1.46"
|
||||
version = "0.1.47"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -54,6 +54,7 @@ bump-kcl-crate-versions bump='patch':
|
||||
publish-kcl version:
|
||||
git tag kcl-{{version}}
|
||||
cargo publish -p kcl-derive-docs
|
||||
cargo publish -p kcl-directory-test-macro
|
||||
cargo publish -p kcl-lib
|
||||
cargo publish -p kcl-test-server
|
||||
# We push the tag at the end of publish since pushing the tag
|
||||
|
@ -9,6 +9,11 @@ description = "Bumps versions in Cargo.toml"
|
||||
publish = false
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[[bin]]
|
||||
name = "kcl-bumper"
|
||||
path = "src/main.rs"
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
clap = { workspace = true, features = ["derive"] }
|
||||
|
@ -9,6 +9,7 @@ repository = "https://github.com/KittyCAD/modeling-app"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
Inflector = "0.11.4"
|
||||
|
@ -1,14 +1,14 @@
|
||||
[package]
|
||||
name = "kcl-directory-test-macro"
|
||||
description = "A tool for generating tests from a directory of kcl files"
|
||||
version = "0.1.46"
|
||||
version = "0.1.47"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/KittyCAD/modeling-app"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1"
|
||||
|
@ -6,6 +6,11 @@ authors = ["KittyCAD Inc <kcl@kittycad.io>"]
|
||||
publish = false
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[[bin]]
|
||||
name = "kcl-language-server-release"
|
||||
path = "src/main.rs"
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
clap = { workspace = true, features = ["cargo", "derive", "env", "unicode"] }
|
||||
|
@ -10,6 +10,7 @@ license = "MIT"
|
||||
[[bin]]
|
||||
name = "kcl-language-server"
|
||||
path = "src/main.rs"
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
|
@ -11,6 +11,14 @@ keywords = ["kcl", "KittyCAD", "CAD"]
|
||||
exclude = ["tests/*", "benches/*", "examples/*", "e2e/*", "bindings/*", "fuzz/*"]
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "kcl-lib-bin"
|
||||
path = "src/main.rs"
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true, features = ["backtrace"] }
|
||||
async-recursion = "1.1.1"
|
||||
@ -33,7 +41,7 @@ http = { workspace = true }
|
||||
image = { version = "0.25.5", default-features = false, features = ["png"] }
|
||||
indexmap = { workspace = true, features = ["serde"] }
|
||||
itertools = "0.13.0"
|
||||
kcl-derive-docs = { path = "../kcl-derive-docs" }
|
||||
kcl-derive-docs = { version = "0.1", path = "../kcl-derive-docs" }
|
||||
kittycad = { workspace = true }
|
||||
kittycad-modeling-cmds = { workspace = true }
|
||||
lazy_static = { workspace = true }
|
||||
@ -114,7 +122,7 @@ expectorate = "1.1.0"
|
||||
handlebars = "6.3.0"
|
||||
image = { version = "0.25.5", default-features = false, features = ["png"] }
|
||||
insta = { version = "1.41.1", features = ["json", "filters", "redactions"] }
|
||||
kcl-directory-test-macro = { path = "../kcl-directory-test-macro" }
|
||||
kcl-directory-test-macro = { version = "0.1", path = "../kcl-directory-test-macro" }
|
||||
miette = { version = "7.5.0", features = ["fancy"] }
|
||||
pretty_assertions = "1.4.1"
|
||||
tokio = { version = "1.41.1", features = ["rt-multi-thread", "macros", "time"] }
|
||||
@ -140,6 +148,10 @@ required-features = ["lsp-test-util"]
|
||||
name = "executor_benchmark_criterion"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "benchmark_kcl_samples"
|
||||
harness = false
|
||||
|
||||
[[test]]
|
||||
name = "executor"
|
||||
path = "e2e/executor/main.rs"
|
||||
|
95
rust/kcl-lib/benches/benchmark_kcl_samples.rs
Normal file
95
rust/kcl-lib/benches/benchmark_kcl_samples.rs
Normal file
@ -0,0 +1,95 @@
|
||||
use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
const IGNORE_DIRS: [&str; 2] = ["step", "screenshots"];
|
||||
|
||||
fn discover_benchmark_dirs(base_path: &Path) -> Vec<PathBuf> {
|
||||
let mut benchmark_dirs = Vec::new();
|
||||
|
||||
if let Ok(entries) = fs::read_dir(base_path) {
|
||||
for entry in entries.filter_map(Result::ok) {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
let dir_name = path.file_name().unwrap().to_string_lossy();
|
||||
if !IGNORE_DIRS.iter().any(|&x| x == dir_name) {
|
||||
benchmark_dirs.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
benchmark_dirs
|
||||
}
|
||||
|
||||
fn find_main_kcl_file(dir_path: &Path) -> PathBuf {
|
||||
let file_path = dir_path.join("main.kcl");
|
||||
|
||||
if !file_path.exists() || !file_path.is_file() {
|
||||
panic!("Required main.kcl file not found in directory: {}", dir_path.display());
|
||||
}
|
||||
|
||||
file_path
|
||||
}
|
||||
|
||||
fn run_benchmarks(c: &mut Criterion) {
|
||||
// Specify the base directory containing benchmark subdirectories
|
||||
let base_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../public/kcl-samples");
|
||||
|
||||
if !base_dir.exists() || !base_dir.is_dir() {
|
||||
panic!("Invalid base directory: {}", base_dir.display());
|
||||
}
|
||||
|
||||
let benchmark_dirs = discover_benchmark_dirs(&base_dir);
|
||||
|
||||
let rt = Runtime::new().unwrap();
|
||||
|
||||
for dir in benchmark_dirs {
|
||||
let dir_name = dir.file_name().unwrap().to_string_lossy().to_string();
|
||||
|
||||
// Change the current directory to the benchmark directory.
|
||||
// This is necessary for the kcl-lib to correctly resolve relative paths.
|
||||
std::env::set_current_dir(&dir).unwrap();
|
||||
|
||||
// Find main.kcl file (will panic if not found)
|
||||
let input_file = find_main_kcl_file(&dir);
|
||||
|
||||
// Read the file content (panic on failure)
|
||||
let input_content = fs::read_to_string(&input_file)
|
||||
.unwrap_or_else(|e| panic!("Failed to read main.kcl in directory {}: {}", dir_name, e));
|
||||
|
||||
// Create a benchmark group for this directory
|
||||
let mut group = c.benchmark_group(&dir_name);
|
||||
group
|
||||
.sample_size(10)
|
||||
.measurement_time(std::time::Duration::from_secs(1)); // Short measurement time to keep it from running in parallel
|
||||
|
||||
let program = kcl_lib::Program::parse_no_errs(&input_content).unwrap();
|
||||
|
||||
group.bench_function("parse", |b| {
|
||||
b.iter(|| kcl_lib::Program::parse_no_errs(black_box(&input_content)).unwrap())
|
||||
});
|
||||
|
||||
group.bench_function("execute", |b| {
|
||||
b.iter(|| {
|
||||
rt.block_on(async {
|
||||
let ctx = kcl_lib::ExecutorContext::new_with_default_client(Default::default())
|
||||
.await
|
||||
.unwrap();
|
||||
let mut exec_state = kcl_lib::ExecState::new(&ctx.settings);
|
||||
ctx.run(black_box(&program), &mut exec_state).await.unwrap();
|
||||
ctx.close().await;
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
group.finish();
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(benches, run_benchmarks);
|
||||
criterion_main!(benches);
|
@ -13,7 +13,14 @@ pub fn bench_execute(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("executor");
|
||||
// Configure Criterion.rs to detect smaller differences and increase sample size to improve
|
||||
// precision and counteract the resulting noise.
|
||||
group.sample_size(10);
|
||||
group
|
||||
.sample_size(10)
|
||||
.measurement_time(std::time::Duration::from_secs(1)); // Short
|
||||
// measurement
|
||||
// time to keep
|
||||
// it from
|
||||
// running in
|
||||
// parallel
|
||||
group.bench_with_input(BenchmarkId::new("execute", name), &code, |b, &s| {
|
||||
let rt = Runtime::new().unwrap();
|
||||
// Spawn a future onto the runtime
|
||||
|
@ -8,6 +8,7 @@ repository = "https://github.com/kittycad/modeling-app"
|
||||
[lib]
|
||||
name = "kcl"
|
||||
crate-type = ["cdylib"]
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
|
@ -1,50 +0,0 @@
|
||||
// Antenna
|
||||
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
|
||||
// import constants
|
||||
import height, width, antennaBaseWidth, antennaBaseHeight, antennaTopWidth, antennaTopHeight from "globals.kcl"
|
||||
|
||||
// Calculate the origin
|
||||
origin = [-width / 2 + .45, -0.10]
|
||||
|
||||
// Create the antenna
|
||||
antennaX = origin[0]
|
||||
antennaY = origin[1]
|
||||
|
||||
antennaPlane = {
|
||||
plane = {
|
||||
origin = { x = 0, y = 0, z = height / 2 },
|
||||
xAxis = { x = 1, y = 0, z = 0 },
|
||||
yAxis = { x = 0, y = 1, z = 0 },
|
||||
zAxis = { x = 0, y = 0, z = 1 }
|
||||
}
|
||||
}
|
||||
|
||||
// Create the antenna base sketch
|
||||
sketch001 = startSketchOn(antennaPlane)
|
||||
|> startProfileAt([origin[0], origin[1]], %)
|
||||
|> line(end = [antennaBaseWidth, 0])
|
||||
|> line(end = [0, -antennaBaseHeight])
|
||||
|> line(end = [-antennaBaseWidth, 0])
|
||||
|> close()
|
||||
|
||||
// Create the antenna top sketch
|
||||
loftPlane = offsetPlane('XY', offset = height / 2 + 3)
|
||||
|
||||
sketch002 = startSketchOn(loftPlane)
|
||||
|> startProfileAt([
|
||||
origin[0] + (antennaBaseWidth - antennaTopWidth) / 2,
|
||||
origin[1] - ((antennaBaseHeight - antennaTopHeight) / 2)
|
||||
], %)
|
||||
|> xLine(length = antennaTopWidth)
|
||||
|> yLine(length = -antennaTopHeight)
|
||||
|> xLine(length = -antennaTopWidth)
|
||||
|> close()
|
||||
|
||||
// Create the antenna using a loft
|
||||
loft([sketch001, sketch002])
|
||||
|> appearance(color = "#000000")
|
@ -1,80 +0,0 @@
|
||||
// Walkie talkie body
|
||||
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
|
||||
// Import constants
|
||||
import height, width, thickness, chamferLength, offset, screenWidth, screenHeight, screenYPosition, screenDepth, speakerBoxWidth, speakerBoxHeight from "globals.kcl"
|
||||
|
||||
bodySketch = startSketchOn('XZ')
|
||||
|> startProfileAt([-width / 2, height / 2], %)
|
||||
|> xLine(length = width, tag = $chamfer1)
|
||||
|> yLine(length = -height, tag = $chamfer2)
|
||||
|> xLine(length = -width, tag = $chamfer3)
|
||||
|> close(tag = $chamfer4)
|
||||
bodyExtrude = extrude(bodySketch, length = thickness)
|
||||
|> chamfer(
|
||||
length = chamferLength,
|
||||
tags = [
|
||||
getNextAdjacentEdge(chamfer1),
|
||||
getNextAdjacentEdge(chamfer2),
|
||||
getNextAdjacentEdge(chamfer3),
|
||||
getNextAdjacentEdge(chamfer4)
|
||||
]
|
||||
)
|
||||
|
||||
// Define the offset for the indentation
|
||||
sketch002 = startSketchOn(bodyExtrude, 'END')
|
||||
|> startProfileAt([
|
||||
-width / 2 + offset,
|
||||
height / 2 - (chamferLength + offset / 2 * cos(toRadians(45)))
|
||||
], %)
|
||||
|> angledLineToY({ angle = 45, to = height / 2 - offset }, %)
|
||||
|> line(endAbsolute = [
|
||||
width / 2 - (chamferLength + offset / 2 * cos(toRadians(45))),
|
||||
height / 2 - offset
|
||||
])
|
||||
|> angledLineToX({ angle = -45, to = width / 2 - offset }, %)
|
||||
|> line(endAbsolute = [
|
||||
width / 2 - offset,
|
||||
-(height / 2 - (chamferLength + offset / 2 * cos(toRadians(45))))
|
||||
])
|
||||
|> angledLineToY({
|
||||
angle = -135,
|
||||
to = -height / 2 + offset
|
||||
}, %)
|
||||
|> line(endAbsolute = [
|
||||
-(width / 2 - (chamferLength + offset / 2 * cos(toRadians(45)))),
|
||||
-height / 2 + offset
|
||||
])
|
||||
|> angledLineToX({
|
||||
angle = -225,
|
||||
to = -width / 2 + offset
|
||||
}, %)
|
||||
|> close()
|
||||
extrude002 = extrude(sketch002, length = -0.0625)
|
||||
|
||||
// Create the pocket for the screen
|
||||
sketch003 = startSketchOn(extrude002, 'start')
|
||||
|> startProfileAt([-screenWidth / 2, screenYPosition], %)
|
||||
|> xLine(length = screenWidth, tag = $seg01)
|
||||
|> yLine(length = -screenHeight)
|
||||
|> xLine(length = -segLen(seg01))
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude003 = extrude(sketch003, length = screenDepth)
|
||||
|
||||
// Create the speaker box
|
||||
sketch004 = startSketchOn(extrude002, 'start')
|
||||
|> startProfileAt([-1.25 / 2, -.125], %)
|
||||
|> xLine(length = speakerBoxWidth)
|
||||
|> yLine(length = -speakerBoxHeight)
|
||||
|> xLine(length = -speakerBoxWidth)
|
||||
|> close()
|
||||
extrude(sketch004, length = -.5)
|
||||
|> appearance(
|
||||
color = "#277bb0",
|
||||
)
|
||||
|
@ -1,38 +0,0 @@
|
||||
// Walkie Talkie button
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
// Import constants
|
||||
import screenHeight, buttonWidth, tolerance, buttonHeight, buttonThickness from 'globals.kcl'
|
||||
|
||||
|
||||
// Create a function for the button
|
||||
export fn button(origin, rotation, plane) {
|
||||
buttonSketch = startSketchOn(plane)
|
||||
|> startProfileAt([origin[0], origin[1]], %)
|
||||
|> angledLine({
|
||||
angle = 180 + rotation,
|
||||
length = buttonWidth
|
||||
}, %, $tag1)
|
||||
|> angledLine({
|
||||
angle = 270 + rotation,
|
||||
length = buttonHeight
|
||||
}, %, $tag2)
|
||||
|> angledLine({
|
||||
angle = 0 + rotation,
|
||||
length = buttonWidth
|
||||
}, %)
|
||||
|> close()
|
||||
buttonExtrude = extrude(buttonSketch, length = buttonThickness)
|
||||
|> chamfer(
|
||||
length = .050,
|
||||
tags = [
|
||||
getNextAdjacentEdge(tag1),
|
||||
getNextAdjacentEdge(tag2)
|
||||
]
|
||||
)
|
||||
|> appearance(color = "#ff0000")
|
||||
|
||||
return buttonExtrude
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
// Walkie talkie case
|
||||
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
|
||||
// Import constants and Zoo logo
|
||||
import width, height, chamferLength, offset, screenWidth, screenHeight, screenYPosition, screenDepth, speakerBoxWidth, speakerBoxHeight, squareHoleSideLength, caseTolerance from "globals.kcl"
|
||||
import zLogo, oLogo, oLogo2 from "zoo-logo.kcl"
|
||||
|
||||
plane = offsetPlane("XZ", offset = 1)
|
||||
|
||||
fn screenHole(sketchStart) {
|
||||
sketch006 = startSketchOn(sketchStart)
|
||||
|> startProfileAt([-screenWidth / 2, screenYPosition], %)
|
||||
|> xLine(length = screenWidth)
|
||||
|> yLine(length = -screenHeight)
|
||||
|> xLine(length = -screenWidth)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
return sketch006
|
||||
}
|
||||
|
||||
fn squareHolePattern(plane, x, y) {
|
||||
fn transformX(i) {
|
||||
return { translate = [.125 * i, 0] }
|
||||
}
|
||||
fn transformY(i) {
|
||||
return { translate = [0, -.125 * i] }
|
||||
}
|
||||
squareHolePatternSketch = startSketchOn(plane)
|
||||
|> startProfileAt([-x, -y], %)
|
||||
|> line(end = [squareHoleSideLength / 2, 0])
|
||||
|> line(end = [0, -squareHoleSideLength / 2])
|
||||
|> line(end = [-squareHoleSideLength / 2, 0])
|
||||
|> close()
|
||||
|> patternTransform2d(instances = 13, transform = transformX)
|
||||
|> patternTransform2d(instances = 11, transform = transformY)
|
||||
return squareHolePatternSketch
|
||||
}
|
||||
sketch005 = startSketchOn(offsetPlane("XZ", offset = 1))
|
||||
|> startProfileAt([
|
||||
-width / 2 + offset + caseTolerance,
|
||||
height / 2 - (chamferLength + (offset + caseTolerance) / 2 * cos(toRadians(45)))
|
||||
], %)
|
||||
|> angledLineToY({
|
||||
angle = 45,
|
||||
to = height / 2 - (offset + caseTolerance)
|
||||
}, %)
|
||||
|> line(endAbsolute = [
|
||||
width / 2 - (chamferLength + (offset + caseTolerance) / 2 * cos(toRadians(45))),
|
||||
height / 2 - (offset + caseTolerance)
|
||||
])
|
||||
|> angledLineToX({
|
||||
angle = -45,
|
||||
to = width / 2 - (offset + caseTolerance)
|
||||
}, %)
|
||||
|> line(endAbsolute = [
|
||||
width / 2 - (offset + caseTolerance),
|
||||
-(height / 2 - (chamferLength + (offset + caseTolerance) / 2 * cos(toRadians(45))))
|
||||
])
|
||||
|> angledLineToY({
|
||||
angle = -135,
|
||||
to = -height / 2 + offset + caseTolerance
|
||||
}, %)
|
||||
|> line(endAbsolute = [
|
||||
-(width / 2 - (chamferLength + (offset + caseTolerance) / 2 * cos(toRadians(45)))),
|
||||
-height / 2 + offset + caseTolerance
|
||||
])
|
||||
|> angledLineToX({
|
||||
angle = -225,
|
||||
to = -width / 2 + offset + caseTolerance
|
||||
}, %)
|
||||
|> close()
|
||||
|> hole(screenHole(plane), %)
|
||||
|> hole(squareHolePattern(plane, .75, .125), %)
|
||||
|> hole(zLogo(plane, [-.30, -1.825], .20), %)
|
||||
|> hole(oLogo(plane, [-.075, -1.825], .20), %)
|
||||
|> hole(oLogo2(plane, [-.075, -1.825], .20), %)
|
||||
|> hole(oLogo(plane, [.175, -1.825], .20), %)
|
||||
|> hole(oLogo2(plane, [.175, -1.825], .20), %)
|
||||
|
||||
extrude(sketch005, length = -0.0625)
|
||||
|> appearance(color = '#D0FF01', metalness = 0, roughness = 50)
|
@ -1,42 +0,0 @@
|
||||
// Global constants for the walkie talkie
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
// body
|
||||
export height = 4
|
||||
export width = 2.5
|
||||
export thickness = 1
|
||||
export chamferLength = .325
|
||||
export offset = .125
|
||||
export screenWidth = 1.75
|
||||
export screenHeight = 1
|
||||
export screenYPosition = height / 2 - 0.75
|
||||
export screenDepth = -.0625
|
||||
export speakerBoxWidth = 1.25
|
||||
export speakerBoxHeight = 1.25
|
||||
|
||||
// antenna
|
||||
export antennaBaseWidth = .5
|
||||
export antennaBaseHeight = .25
|
||||
export antennaTopWidth = .30
|
||||
export antennaTopHeight = .05
|
||||
|
||||
// button
|
||||
export buttonWidth = .15
|
||||
export tolerance = 0.020
|
||||
export buttonHeight = screenHeight / 2 - tolerance
|
||||
export buttonThickness = .040
|
||||
|
||||
// case
|
||||
export squareHoleSideLength = 0.0625
|
||||
export caseTolerance = 0.010
|
||||
|
||||
// knob
|
||||
export knobDiameter = .5
|
||||
export knobHeight = .25
|
||||
export knobRadius = 0.050
|
||||
|
||||
// talk-button
|
||||
export talkButtonSideLength = 0.5
|
||||
export talkButtonHeight = 0.050
|
@ -1,38 +0,0 @@
|
||||
// Walkie talkie knob
|
||||
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
|
||||
// Import constants
|
||||
import width, thickness, height, knobDiameter, knobHeight, knobRadius from "globals.kcl"
|
||||
|
||||
// Define the plane for the knob
|
||||
knobPlane = {
|
||||
plane = {
|
||||
origin = {
|
||||
x = width / 2 - 0.70,
|
||||
y = -thickness / 2,
|
||||
z = height / 2
|
||||
},
|
||||
xAxis = { x = 1, y = 0, z = 0 },
|
||||
yAxis = { x = 0, y = 0, z = 1 },
|
||||
zAxis = { x = 0, y = 1, z = 0 }
|
||||
}
|
||||
}
|
||||
|
||||
// Create the knob sketch and revolve
|
||||
startSketchOn(knobPlane)
|
||||
|> startProfileAt([0.0001, 0], %)
|
||||
|> xLine(length = knobDiameter / 2)
|
||||
|> yLine(length = knobHeight - 0.05)
|
||||
|> arc({
|
||||
angleStart = 0,
|
||||
angleEnd = 90,
|
||||
radius = .05
|
||||
}, %)
|
||||
|> xLine(endAbsolute = 0.0001)
|
||||
|> close()
|
||||
|> revolve({ axis = "Y" }, %)
|
||||
|> appearance(color = '#D0FF01', metalness = 90, roughness = 50)
|
@ -1,50 +0,0 @@
|
||||
// Walkie Talkie
|
||||
// A portable, handheld two-way radio device that allows users to communicate wirelessly over short to medium distances. It operates on specific radio frequencies and features a push-to-talk button for transmitting messages, making it ideal for quick and reliable communication in outdoor, work, or emergency settings.
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
// Import parts and constants
|
||||
import 'body.kcl'
|
||||
import 'antenna.kcl'
|
||||
import 'case.kcl'
|
||||
import 'talk-button.kcl' as talkButton
|
||||
import 'knob.kcl'
|
||||
import button from "button.kcl"
|
||||
import width, height, thickness, screenWidth, screenHeight, screenYPosition, tolerance from "globals.kcl"
|
||||
|
||||
// Import the body
|
||||
body
|
||||
|
||||
// Import the case
|
||||
case
|
||||
|
||||
// Import the antenna
|
||||
antenna
|
||||
|
||||
// Import the buttons
|
||||
button([
|
||||
-(screenWidth / 2 + tolerance),
|
||||
screenYPosition
|
||||
], 0, offsetPlane("XZ", offset = thickness))
|
||||
button([
|
||||
-(screenWidth / 2 + tolerance),
|
||||
screenYPosition - (screenHeight / 2)
|
||||
], 0, offsetPlane("XZ", offset = thickness))
|
||||
button([
|
||||
screenWidth / 2 + tolerance,
|
||||
screenYPosition - screenHeight
|
||||
], 180, offsetPlane("XZ", offset = thickness))
|
||||
button([
|
||||
screenWidth / 2 + tolerance,
|
||||
screenYPosition - (screenHeight / 2)
|
||||
], 180, offsetPlane("XZ", offset = thickness))
|
||||
|
||||
// Import the talk button
|
||||
talkButton
|
||||
|
||||
// Import the frequency knob
|
||||
knob
|
||||
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
// Walkie talkie talk button
|
||||
|
||||
|
||||
// Set units
|
||||
@settings(defaultLengthUnit = in)
|
||||
|
||||
|
||||
// Import constants
|
||||
import width, thickness, talkButtonSideLength, talkButtonHeight from "globals.kcl"
|
||||
|
||||
talkButtonPlane = {
|
||||
plane = {
|
||||
origin = {
|
||||
x = width / 2,
|
||||
y = -thickness / 2,
|
||||
z = .5
|
||||
},
|
||||
xAxis = { x = 0, y = 1, z = 0 },
|
||||
yAxis = { x = 0, y = 0, z = 1 },
|
||||
zAxis = { x = 1, y = 0, z = 0 }
|
||||
}
|
||||
}
|
||||
|
||||
// Create the talk button sketch
|
||||
talkButtonSketch = startSketchOn(talkButtonPlane)
|
||||
|> startProfileAt([
|
||||
-talkButtonSideLength / 2,
|
||||
talkButtonSideLength / 2
|
||||
], %)
|
||||
|> xLine(length = talkButtonSideLength, tag = $tag1)
|
||||
|> yLine(length = -talkButtonSideLength, tag = $tag2)
|
||||
|> xLine(length = -talkButtonSideLength, tag = $tag3)
|
||||
|> close(tag = $tag4)
|
||||
|
||||
// Create the talk button and apply fillets
|
||||
extrude(talkButtonSketch, length = talkButtonHeight)
|
||||
|> fillet(
|
||||
radius = 0.050,
|
||||
tags = [
|
||||
getNextAdjacentEdge(tag1),
|
||||
getNextAdjacentEdge(tag2),
|
||||
getNextAdjacentEdge(tag3),
|
||||
getNextAdjacentEdge(tag4)
|
||||
]
|
||||
)
|
||||
|> appearance(color = '#D0FF01', metalness = 90, roughness = 90)
|
@ -1,83 +0,0 @@
|
||||
// Zoo logo
|
||||
|
||||
// Define a function to draw the ZOO "Z"
|
||||
export fn zLogo(surface, origin, scale) {
|
||||
zSketch = surface
|
||||
|> startProfileAt([
|
||||
0 + origin[0],
|
||||
0.15 * scale + origin[1]
|
||||
], %)
|
||||
|> yLine(length = -0.15 * scale)
|
||||
|> xLine(length = 0.15 * scale)
|
||||
|> angledLineToX({
|
||||
angle = 47.15,
|
||||
to = 0.3 * scale + origin[0]
|
||||
}, %, $seg1)
|
||||
|> yLine(endAbsolute = 0 + origin[1], tag = $seg3)
|
||||
|> xLine(length = 0.63 * scale)
|
||||
|> yLine(length = 0.225 * scale)
|
||||
|> xLine(length = -0.57 * scale)
|
||||
|> angledLineToX({
|
||||
angle = 47.15,
|
||||
to = 0.93 * scale + origin[0]
|
||||
}, %)
|
||||
|> yLine(length = 0.15 * scale)
|
||||
|> xLine(length = -0.15 * scale)
|
||||
|> angledLine({
|
||||
angle = 47.15,
|
||||
length = -segLen(seg1)
|
||||
}, %, $seg2)
|
||||
|> yLine(length = segLen(seg3))
|
||||
|> xLine(endAbsolute = 0 + origin[0])
|
||||
|> yLine(length = -0.225 * scale)
|
||||
|> angledLineThatIntersects({
|
||||
angle = 0,
|
||||
intersectTag = seg2,
|
||||
offset = 0
|
||||
}, %)
|
||||
|> close()
|
||||
return zSketch
|
||||
}
|
||||
|
||||
// Define a function to draw the ZOO "O"
|
||||
export fn oLogo(surface, origin, scale) {
|
||||
oSketch001 = surface
|
||||
|> startProfileAt([
|
||||
.788 * scale + origin[0],
|
||||
.921 * scale + origin[1]
|
||||
], %)
|
||||
|> arc({
|
||||
angleStart = 47.15 + 6,
|
||||
angleEnd = 47.15 - 6 + 180,
|
||||
radius = .525 * scale
|
||||
}, %)
|
||||
|> angledLine({ angle = 47.15, length = .24 * scale }, %)
|
||||
|> arc({
|
||||
angleStart = 47.15 - 11 + 180,
|
||||
angleEnd = 47.15 + 11,
|
||||
radius = .288 * scale
|
||||
}, %)
|
||||
|> close()
|
||||
return oSketch001
|
||||
}
|
||||
|
||||
export fn oLogo2(surface, origin, scale) {
|
||||
oSketch002 = surface
|
||||
|> startProfileAt([
|
||||
.16 * scale + origin[0],
|
||||
.079 * scale + origin[1]
|
||||
], %)
|
||||
|> arc({
|
||||
angleStart = 47.15 + 6 - 180,
|
||||
angleEnd = 47.15 - 6,
|
||||
radius = .525 * scale
|
||||
}, %)
|
||||
|> angledLine({ angle = 47.15, length = -.24 * scale }, %)
|
||||
|> arc({
|
||||
angleStart = 47.15 - 11,
|
||||
angleEnd = 47.15 + 11 - 180,
|
||||
radius = .288 * scale
|
||||
}, %)
|
||||
|> close()
|
||||
return oSketch002
|
||||
}
|
@ -10,7 +10,15 @@ kcl_dir = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)), "..", "..", "kcl-lib"
|
||||
)
|
||||
lego_file = os.path.join(kcl_dir, "e2e", "executor", "inputs", "lego.kcl")
|
||||
walkie_talkie_dir = os.path.join(files_dir, "walkie-talkie")
|
||||
walkie_talkie_dir = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"public",
|
||||
"kcl-samples",
|
||||
"walkie-talkie",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -5,6 +5,9 @@ version = "0.1.47"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.95"
|
||||
hyper = { version = "0.14.29", features = ["http1", "server", "tcp"] }
|
||||
|
@ -8,10 +8,12 @@ repository = "https://github.com/KittyCAD/modeling-app"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "kcl-to-core"
|
||||
path = "src/tool.rs"
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
|
@ -8,6 +8,7 @@ publish = false
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
bench = false
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
bson = { version = "2.13.0", features = ["uuid-1", "chrono"] }
|
||||
|
Reference in New Issue
Block a user