Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
19f11fe55a | |||
f6f1574982 | |||
6dc4fbc808 | |||
8843d02380 | |||
3578ec07e6 | |||
db35f73e41 | |||
5cfc2b7941 | |||
318e4a0cc7 | |||
1e23be8f08 | |||
ef547e7db8 | |||
71b48bbd89 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -84,7 +84,7 @@ jobs:
|
||||
if: github.event_name == 'schedule'
|
||||
run: |
|
||||
VERSION=$(date +'%-y.%-m.%-d') yarn bump-jsons
|
||||
echo "$(jq --arg url 'https://dl.kittycad.io/releases/modeling-app/test/nightly/last_update.json' \
|
||||
echo "$(jq --arg url 'https://dl.kittycad.io/releases/modeling-app/nightly/last_update.json' \
|
||||
'.tauri.updater.endpoints[]=$url' src-tauri/tauri.conf.json --indent 2)" > src-tauri/tauri.conf.json
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
|
@ -3812,7 +3812,7 @@
|
||||
"args": [
|
||||
{
|
||||
"name": "data",
|
||||
"type": "AngeledLineThatIntersectsData",
|
||||
"type": "AngledLineThatIntersectsData",
|
||||
"schema": {
|
||||
"description": "Data for drawing an angled line that intersects with a given line.",
|
||||
"type": "object",
|
||||
|
@ -763,12 +763,12 @@ Draw an angled line that intersects with a given line.
|
||||
|
||||
|
||||
```
|
||||
angledLineThatIntersects(data: AngeledLineThatIntersectsData, sketch_group: SketchGroup) -> SketchGroup
|
||||
angledLineThatIntersects(data: AngledLineThatIntersectsData, sketch_group: SketchGroup) -> SketchGroup
|
||||
```
|
||||
|
||||
#### Arguments
|
||||
|
||||
* `data`: `AngeledLineThatIntersectsData` - Data for drawing an angled line that intersects with a given line.
|
||||
* `data`: `AngledLineThatIntersectsData` - Data for drawing an angled line that intersects with a given line.
|
||||
```
|
||||
{
|
||||
// The angle of the line.
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "untitled-app",
|
||||
"version": "0.11.0",
|
||||
"version": "0.11.1",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@codemirror/autocomplete": "^6.9.0",
|
||||
@ -10,7 +10,7 @@
|
||||
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||
"@headlessui/react": "^1.7.13",
|
||||
"@headlessui/tailwindcss": "^0.2.0",
|
||||
"@kittycad/lib": "^0.0.43",
|
||||
"@kittycad/lib": "^0.0.45",
|
||||
"@lezer/javascript": "^1.4.7",
|
||||
"@open-rpc/client-js": "^1.8.1",
|
||||
"@react-hook/resize-observer": "^1.2.6",
|
||||
|
43
src-tauri/Cargo.lock
generated
43
src-tauri/Cargo.lock
generated
@ -122,6 +122,12 @@ dependencies = [
|
||||
"system-deps 6.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@ -1658,9 +1664,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "kittycad"
|
||||
version = "0.2.33"
|
||||
version = "0.2.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d341a81a4dfef43460d395c87d86c17e24affb96db0e7f4a35e8688f0e092344"
|
||||
checksum = "633a728fb7209b398b7fa5b67460cb7f3cdb268c6b2a9e81967dda464cfbb5c1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@ -2833,9 +2839,9 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.20"
|
||||
version = "0.11.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1"
|
||||
checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
|
||||
dependencies = [
|
||||
"base64 0.21.2",
|
||||
"bytes",
|
||||
@ -2862,6 +2868,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"system-configuration",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tokio-rustls",
|
||||
@ -3011,9 +3018,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.37.19"
|
||||
version = "0.37.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
|
||||
checksum = "84f3f8f960ed3b5a59055428714943298bf3fa2d4a1d53135084e0544829d995"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"errno",
|
||||
@ -3600,6 +3607,27 @@ dependencies = [
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"core-foundation",
|
||||
"system-configuration-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-configuration-sys"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "5.0.0"
|
||||
@ -3927,7 +3955,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"redox_syscall 0.3.5",
|
||||
"rustix 0.37.19",
|
||||
"rustix 0.37.26",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
@ -4292,6 +4320,7 @@ version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2"
|
||||
dependencies = [
|
||||
"atomic",
|
||||
"getrandom 0.2.9",
|
||||
"serde",
|
||||
]
|
||||
|
@ -8,7 +8,7 @@
|
||||
},
|
||||
"package": {
|
||||
"productName": "kittycad-modeling",
|
||||
"version": "0.11.0"
|
||||
"version": "0.11.1"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
|
477
src/wasm-lib/Cargo.lock
generated
477
src/wasm-lib/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -11,21 +11,21 @@ crate-type = ["cdylib"]
|
||||
bson = { version = "2.7.0", features = ["uuid-1", "chrono"] }
|
||||
gloo-utils = "0.2.0"
|
||||
kcl-lib = { path = "kcl" }
|
||||
kittycad = { version = "0.2.33", default-features = false, features = ["js"] }
|
||||
kittycad = { workspace = true }
|
||||
serde_json = "1.0.107"
|
||||
uuid = { version = "1.4.1", features = ["v4", "js", "serde"] }
|
||||
uuid = { version = "1.5.0", features = ["v4", "js", "serde"] }
|
||||
wasm-bindgen = "0.2.87"
|
||||
wasm-bindgen-futures = "0.4.37"
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = "1"
|
||||
image = "0.24.7"
|
||||
kittycad = "0.2.33"
|
||||
kittycad = { workspace = true, default-features = true }
|
||||
pretty_assertions = "1.4.0"
|
||||
reqwest = { version = "0.11.22", default-features = false }
|
||||
tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros", "time"] }
|
||||
twenty-twenty = "0.6.1"
|
||||
uuid = { version = "1.4.1", features = ["v4", "js", "serde"] }
|
||||
uuid = { version = "1.5.0", features = ["v4", "js", "serde"] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
futures = "0.3.28"
|
||||
@ -53,6 +53,9 @@ members = [
|
||||
"kcl",
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
kittycad = { version = "0.2.41", default-features = false, features = ["js"] }
|
||||
|
||||
[[test]]
|
||||
name = "executor"
|
||||
path = "tests/executor/main.rs"
|
||||
|
@ -15,15 +15,15 @@ clap = { version = "4.4.6", features = ["cargo", "derive", "env", "unicode"], op
|
||||
dashmap = "5.5.3"
|
||||
derive-docs = { version = "0.1.4" }
|
||||
#derive-docs = { path = "../derive-docs" }
|
||||
kittycad = { version = "0.2.33", default-features = false, features = ["js"] }
|
||||
kittycad = { workspace = true }
|
||||
lazy_static = "1.4.0"
|
||||
parse-display = "0.8.2"
|
||||
schemars = { version = "0.8", features = ["impl_json_schema", "url", "uuid1"] }
|
||||
serde = { version = "1.0.189", features = ["derive"] }
|
||||
serde_json = "1.0.107"
|
||||
thiserror = "1.0.49"
|
||||
thiserror = "1.0.50"
|
||||
ts-rs = { version = "7", package = "ts-rs-json-value", features = ["serde-json-impl", "schemars-impl", "uuid-impl"] }
|
||||
uuid = { version = "1.4.1", features = ["v4", "js", "serde"] }
|
||||
uuid = { version = "1.5.0", features = ["v4", "js", "serde"] }
|
||||
winnow = "0.5.16"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
@ -136,7 +136,7 @@ pub async fn modify_ast_for_sketch(
|
||||
})?;
|
||||
|
||||
let mut additional_lines = Vec::new();
|
||||
let mut last_point = first_control_points.points[1].clone();
|
||||
let mut last_point = first_control_points.points[1];
|
||||
for control_point in control_points[1..].iter() {
|
||||
additional_lines.push([
|
||||
(control_point.points[1].x - last_point.x),
|
||||
|
@ -183,7 +183,7 @@ impl DefaultPlanes {
|
||||
SourceRange::default(),
|
||||
ModelingCmd::MakePlane {
|
||||
clobber: false,
|
||||
origin: default_origin.clone(),
|
||||
origin: default_origin,
|
||||
size: default_size,
|
||||
x_axis: Point3D { x: 1.0, y: 0.0, z: 0.0 },
|
||||
y_axis: Point3D { x: 0.0, y: 1.0, z: 0.0 },
|
||||
@ -216,7 +216,7 @@ impl DefaultPlanes {
|
||||
SourceRange::default(),
|
||||
ModelingCmd::MakePlane {
|
||||
clobber: false,
|
||||
origin: default_origin.clone(),
|
||||
origin: default_origin,
|
||||
size: default_size,
|
||||
x_axis: Point3D { x: 0.0, y: 1.0, z: 0.0 },
|
||||
y_axis: Point3D { x: 0.0, y: 0.0, z: 1.0 },
|
||||
|
@ -7,9 +7,11 @@ use schemars::JsonSchema;
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
executor::{MemoryItem, SketchGroup},
|
||||
std::{utils::Angle, Args},
|
||||
std::Args,
|
||||
};
|
||||
|
||||
use super::utils::between;
|
||||
|
||||
/// Returns the segment end of x.
|
||||
pub async fn segment_end_x(args: Args) -> Result<MemoryItem, KclError> {
|
||||
let (segment_name, sketch_group) = args.get_segment_name_sketch_group()?;
|
||||
@ -174,7 +176,7 @@ fn inner_segment_angle(segment_name: &str, sketch_group: Box<SketchGroup>, args:
|
||||
})?;
|
||||
let line = path.get_base();
|
||||
|
||||
let result = Angle::between(line.from.into(), line.to.into());
|
||||
let result = between(line.from.into(), line.to.into());
|
||||
|
||||
Ok(result.degrees())
|
||||
}
|
||||
|
@ -2,11 +2,10 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use derive_docs::stdlib;
|
||||
use kittycad::types::{ModelingCmd, Point3D};
|
||||
use kittycad::types::{Angle, ModelingCmd, Point3D};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::utils::Angle;
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
executor::{
|
||||
@ -334,6 +333,16 @@ pub enum AngledLineData {
|
||||
AngleAndLength([f64; 2]),
|
||||
}
|
||||
|
||||
impl AngledLineData {
|
||||
pub fn into_inner_line(self, to: [f64; 2]) -> LineData {
|
||||
if let AngledLineData::AngleWithTag { tag, .. } = self {
|
||||
LineData::PointWithTag { to, tag }
|
||||
} else {
|
||||
LineData::Point(to)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw an angled line.
|
||||
pub async fn angled_line(args: Args) -> Result<MemoryItem, KclError> {
|
||||
let (data, sketch_group): (AngledLineData, Box<SketchGroup>) = args.get_data_and_sketch_group()?;
|
||||
@ -429,16 +438,7 @@ async fn inner_angled_line_of_x_length(
|
||||
|
||||
let to = get_y_component(Angle::from_degrees(angle), length);
|
||||
|
||||
let new_sketch_group = inner_line(
|
||||
if let AngledLineData::AngleWithTag { tag, .. } = data {
|
||||
LineData::PointWithTag { to: to.into(), tag }
|
||||
} else {
|
||||
LineData::Point(to.into())
|
||||
},
|
||||
sketch_group,
|
||||
args,
|
||||
)
|
||||
.await?;
|
||||
let new_sketch_group = inner_line(data.into_inner_line(to.into()), sketch_group, args).await?;
|
||||
|
||||
Ok(new_sketch_group)
|
||||
}
|
||||
@ -461,6 +461,16 @@ pub enum AngledLineToData {
|
||||
AngleAndPoint([f64; 2]),
|
||||
}
|
||||
|
||||
impl AngledLineToData {
|
||||
pub fn into_inner_line(self, x_to: f64, y_to: f64) -> LineToData {
|
||||
if let AngledLineToData::AngleWithTag { tag, .. } = self {
|
||||
LineToData::PointWithTag { to: [x_to, y_to], tag }
|
||||
} else {
|
||||
LineToData::Point([x_to, y_to])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw an angled line to a given x coordinate.
|
||||
pub async fn angled_line_to_x(args: Args) -> Result<MemoryItem, KclError> {
|
||||
let (data, sketch_group): (AngledLineToData, Box<SketchGroup>) = args.get_data_and_sketch_group()?;
|
||||
@ -488,16 +498,7 @@ async fn inner_angled_line_to_x(
|
||||
let y_component = x_component * f64::tan(angle.to_radians());
|
||||
let y_to = from.y + y_component;
|
||||
|
||||
let new_sketch_group = inner_line_to(
|
||||
if let AngledLineToData::AngleWithTag { tag, .. } = data {
|
||||
LineToData::PointWithTag { to: [x_to, y_to], tag }
|
||||
} else {
|
||||
LineToData::Point([x_to, y_to])
|
||||
},
|
||||
sketch_group,
|
||||
args,
|
||||
)
|
||||
.await?;
|
||||
let new_sketch_group = inner_line_to(data.into_inner_line(x_to, y_to), sketch_group, args).await?;
|
||||
Ok(new_sketch_group)
|
||||
}
|
||||
|
||||
@ -526,16 +527,7 @@ async fn inner_angled_line_of_y_length(
|
||||
|
||||
let to = get_x_component(Angle::from_degrees(angle), length);
|
||||
|
||||
let new_sketch_group = inner_line(
|
||||
if let AngledLineData::AngleWithTag { tag, .. } = data {
|
||||
LineData::PointWithTag { to: to.into(), tag }
|
||||
} else {
|
||||
LineData::Point(to.into())
|
||||
},
|
||||
sketch_group,
|
||||
args,
|
||||
)
|
||||
.await?;
|
||||
let new_sketch_group = inner_line(data.into_inner_line(to.into()), sketch_group, args).await?;
|
||||
|
||||
Ok(new_sketch_group)
|
||||
}
|
||||
@ -567,16 +559,7 @@ async fn inner_angled_line_to_y(
|
||||
let x_component = y_component / f64::tan(angle.to_radians());
|
||||
let x_to = from.x + x_component;
|
||||
|
||||
let new_sketch_group = inner_line_to(
|
||||
if let AngledLineToData::AngleWithTag { tag, .. } = data {
|
||||
LineToData::PointWithTag { to: [x_to, y_to], tag }
|
||||
} else {
|
||||
LineToData::Point([x_to, y_to])
|
||||
},
|
||||
sketch_group,
|
||||
args,
|
||||
)
|
||||
.await?;
|
||||
let new_sketch_group = inner_line_to(data.into_inner_line(x_to, y_to), sketch_group, args).await?;
|
||||
Ok(new_sketch_group)
|
||||
}
|
||||
|
||||
@ -585,7 +568,7 @@ async fn inner_angled_line_to_y(
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
// TODO: make sure the docs on the args below are correct.
|
||||
pub struct AngeledLineThatIntersectsData {
|
||||
pub struct AngledLineThatIntersectsData {
|
||||
/// The angle of the line.
|
||||
pub angle: f64,
|
||||
/// The tag of the line to intersect with.
|
||||
@ -598,7 +581,7 @@ pub struct AngeledLineThatIntersectsData {
|
||||
|
||||
/// Draw an angled line that intersects with a given line.
|
||||
pub async fn angled_line_that_intersects(args: Args) -> Result<MemoryItem, KclError> {
|
||||
let (data, sketch_group): (AngeledLineThatIntersectsData, Box<SketchGroup>) = args.get_data_and_sketch_group()?;
|
||||
let (data, sketch_group): (AngledLineThatIntersectsData, Box<SketchGroup>) = args.get_data_and_sketch_group()?;
|
||||
let new_sketch_group = inner_angled_line_that_intersects(data, sketch_group, args).await?;
|
||||
Ok(MemoryItem::SketchGroup(new_sketch_group))
|
||||
}
|
||||
@ -608,7 +591,7 @@ pub async fn angled_line_that_intersects(args: Args) -> Result<MemoryItem, KclEr
|
||||
name = "angledLineThatIntersects",
|
||||
}]
|
||||
async fn inner_angled_line_that_intersects(
|
||||
data: AngeledLineThatIntersectsData,
|
||||
data: AngledLineThatIntersectsData,
|
||||
sketch_group: Box<SketchGroup>,
|
||||
args: Args,
|
||||
) -> Result<Box<SketchGroup>, KclError> {
|
||||
@ -1049,6 +1032,8 @@ async fn inner_arc(data: ArcData, sketch_group: Box<SketchGroup>, args: Args) ->
|
||||
segment: kittycad::types::PathSegment::Arc {
|
||||
angle_start: angle_start.degrees(),
|
||||
angle_end: angle_end.degrees(),
|
||||
start: Some(angle_start),
|
||||
end: Some(angle_end),
|
||||
center: center.into(),
|
||||
radius,
|
||||
relative: false,
|
||||
@ -1148,40 +1133,12 @@ async fn inner_tangential_arc(
|
||||
to.into()
|
||||
}
|
||||
TangentialArcData::PointWithTag { to, .. } => {
|
||||
args.send_modeling_cmd(
|
||||
id,
|
||||
ModelingCmd::ExtendPath {
|
||||
path: sketch_group.id,
|
||||
segment: kittycad::types::PathSegment::TangentialArcTo {
|
||||
angle_snap_increment: None,
|
||||
to: kittycad::types::Point3D {
|
||||
x: to[0],
|
||||
y: to[1],
|
||||
z: 0.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
args.send_modeling_cmd(id, tan_arc_to(&sketch_group, to)).await?;
|
||||
|
||||
*to
|
||||
}
|
||||
TangentialArcData::Point(to) => {
|
||||
args.send_modeling_cmd(
|
||||
id,
|
||||
ModelingCmd::ExtendPath {
|
||||
path: sketch_group.id,
|
||||
segment: kittycad::types::PathSegment::TangentialArcTo {
|
||||
angle_snap_increment: None,
|
||||
to: kittycad::types::Point3D {
|
||||
x: to[0],
|
||||
y: to[1],
|
||||
z: 0.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
args.send_modeling_cmd(id, tan_arc_to(&sketch_group, to)).await?;
|
||||
|
||||
*to
|
||||
}
|
||||
@ -1207,6 +1164,20 @@ async fn inner_tangential_arc(
|
||||
Ok(new_sketch_group)
|
||||
}
|
||||
|
||||
fn tan_arc_to(sketch_group: &SketchGroup, to: &[f64; 2]) -> ModelingCmd {
|
||||
ModelingCmd::ExtendPath {
|
||||
path: sketch_group.id,
|
||||
segment: kittycad::types::PathSegment::TangentialArcTo {
|
||||
angle_snap_increment: None,
|
||||
to: Point3D {
|
||||
x: to[0],
|
||||
y: to[1],
|
||||
z: 0.0,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Data to draw a tangential arc to a specific point.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, ts_rs::TS)]
|
||||
#[ts(export)]
|
||||
@ -1247,24 +1218,8 @@ async fn inner_tangential_arc_to(
|
||||
};
|
||||
|
||||
let delta = [to[0] - from.x, to[1] - from.y];
|
||||
|
||||
let id = uuid::Uuid::new_v4();
|
||||
|
||||
args.send_modeling_cmd(
|
||||
id,
|
||||
ModelingCmd::ExtendPath {
|
||||
path: sketch_group.id,
|
||||
segment: kittycad::types::PathSegment::TangentialArcTo {
|
||||
angle_snap_increment: None,
|
||||
to: kittycad::types::Point3D {
|
||||
x: delta[0],
|
||||
y: delta[1],
|
||||
z: 0.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
args.send_modeling_cmd(id, tan_arc_to(&sketch_group, &delta)).await?;
|
||||
|
||||
let current_path = Path::ToPoint {
|
||||
base: BasePath {
|
||||
|
@ -1,86 +1,57 @@
|
||||
use std::f64::consts::PI;
|
||||
|
||||
use kittycad::types::Angle;
|
||||
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
executor::{Point2d, SourceRange},
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialOrd, PartialEq, Debug)]
|
||||
pub struct Angle {
|
||||
degrees: f64,
|
||||
/// Get the angle between these points
|
||||
pub fn between(a: Point2d, b: Point2d) -> Angle {
|
||||
let x = b.x - a.x;
|
||||
let y = b.y - a.y;
|
||||
normalize(Angle::from_radians(y.atan2(x)))
|
||||
}
|
||||
|
||||
impl From<kittycad::types::Angle> for Angle {
|
||||
fn from(angle: kittycad::types::Angle) -> Self {
|
||||
match angle.unit {
|
||||
kittycad::types::UnitAngle::Degrees => Self::from_degrees(angle.value),
|
||||
kittycad::types::UnitAngle::Radians => Self::from_radians(angle.value),
|
||||
}
|
||||
}
|
||||
/// Normalize the angle
|
||||
pub fn normalize(angle: Angle) -> Angle {
|
||||
let deg = angle.degrees();
|
||||
let result = ((deg % 360.0) + 360.0) % 360.0;
|
||||
Angle::from_degrees(if result > 180.0 { result - 360.0 } else { result })
|
||||
}
|
||||
|
||||
impl Angle {
|
||||
const ZERO: Self = Self { degrees: 0.0 };
|
||||
/// Make an angle of the given degrees.
|
||||
pub fn from_degrees(degrees: f64) -> Self {
|
||||
Self { degrees }
|
||||
}
|
||||
/// Make an angle of the given radians.
|
||||
pub fn from_radians(radians: f64) -> Self {
|
||||
Self::from_degrees(radians.to_degrees())
|
||||
}
|
||||
/// Get the angle in degrees
|
||||
pub fn degrees(&self) -> f64 {
|
||||
self.degrees
|
||||
}
|
||||
/// Get the angle in radians
|
||||
pub fn radians(&self) -> f64 {
|
||||
self.degrees.to_radians()
|
||||
}
|
||||
/// Get the angle between these points
|
||||
pub fn between(a: Point2d, b: Point2d) -> Self {
|
||||
let x = b.x - a.x;
|
||||
let y = b.y - a.y;
|
||||
Self::from_radians(y.atan2(x)).normalize()
|
||||
}
|
||||
/// Normalize the angle
|
||||
pub fn normalize(self) -> Self {
|
||||
let angle = self.degrees();
|
||||
let result = ((angle % 360.0) + 360.0) % 360.0;
|
||||
Self::from_degrees(if result > 180.0 { result - 360.0 } else { result })
|
||||
}
|
||||
/// Gives the ▲-angle between from and to angles (shortest path), use radians.
|
||||
///
|
||||
/// Sign of the returned angle denotes direction, positive means counterClockwise 🔄
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::f64::consts::PI;
|
||||
///
|
||||
/// use kcl_lib::std::utils::Angle;
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Angle::delta(Angle::from_radians(PI / 8.0), Angle::from_radians(PI / 4.0)),
|
||||
/// Angle::from_radians(PI / 8.0)
|
||||
/// );
|
||||
/// ```
|
||||
#[allow(dead_code)]
|
||||
pub fn delta(from_angle: Self, to_angle: Self) -> Self {
|
||||
let norm_from_angle = normalize_rad(from_angle.radians());
|
||||
let norm_to_angle = normalize_rad(to_angle.radians());
|
||||
let provisional = norm_to_angle - norm_from_angle;
|
||||
/// Gives the ▲-angle between from and to angles (shortest path), use radians.
|
||||
///
|
||||
/// Sign of the returned angle denotes direction, positive means counterClockwise 🔄
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::f64::consts::PI;
|
||||
///
|
||||
/// use kcl_lib::std::utils::Angle;
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Angle::delta(Angle::from_radians(PI / 8.0), Angle::from_radians(PI / 4.0)),
|
||||
/// Angle::from_radians(PI / 8.0)
|
||||
/// );
|
||||
/// ```
|
||||
#[allow(dead_code)]
|
||||
pub fn delta(from_angle: Angle, to_angle: Angle) -> Angle {
|
||||
let norm_from_angle = normalize_rad(from_angle.radians());
|
||||
let norm_to_angle = normalize_rad(to_angle.radians());
|
||||
let provisional = norm_to_angle - norm_from_angle;
|
||||
|
||||
if provisional > -PI && provisional <= PI {
|
||||
return Angle::from_radians(provisional);
|
||||
}
|
||||
if provisional > PI {
|
||||
return Angle::from_radians(provisional - 2.0 * PI);
|
||||
}
|
||||
if provisional < -PI {
|
||||
return Angle::from_radians(provisional + 2.0 * PI);
|
||||
}
|
||||
Angle::ZERO
|
||||
if provisional > -PI && provisional <= PI {
|
||||
return Angle::from_radians(provisional);
|
||||
}
|
||||
if provisional > PI {
|
||||
return Angle::from_radians(provisional - 2.0 * PI);
|
||||
}
|
||||
if provisional < -PI {
|
||||
return Angle::from_radians(provisional + 2.0 * PI);
|
||||
}
|
||||
Angle::ZERO
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -1530,10 +1530,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.4.0.tgz#08d6c5e20cf7e4cc02fd181c4b0c225cd31dbb60"
|
||||
integrity sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==
|
||||
|
||||
"@kittycad/lib@^0.0.43":
|
||||
version "0.0.43"
|
||||
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.43.tgz#b93c0961200cf327f5ac6491be1ca01f9edc321c"
|
||||
integrity sha512-Pe/PQfZ8BWEDOm4dkY4tcPcuCSh2mQPe/W8RvJ6PQNTlB7bmjAj0234pVyG+8zrKKsJC9nq4ye7CZoaXEfUSTg==
|
||||
"@kittycad/lib@^0.0.45":
|
||||
version "0.0.45"
|
||||
resolved "https://registry.yarnpkg.com/@kittycad/lib/-/lib-0.0.45.tgz#42cd58df8e5712600d7ecf25713a2b67bc649bdc"
|
||||
integrity sha512-zfc42vg4BtZKklmz1nCJALdegdGE/lmCx3Cj0bE1ZTBEdxcra+Dpd77froglf0dzOzBGa4ONOHh5Ixh7/69aSQ==
|
||||
dependencies:
|
||||
node-fetch "3.3.2"
|
||||
openapi-types "^12.0.0"
|
||||
|
Reference in New Issue
Block a user