Skip to content

Commit fbcbb34

Browse files
authored
KCL: Add planeOf function to stdlib (#7643)
Gets the plane a face lies on, if any. Closes #7642
1 parent 4a080d1 commit fbcbb34

29 files changed

+1945
-44
lines changed

docs/kcl-std/functions/std-sketch-planeOf.md

Lines changed: 48 additions & 0 deletions
Large diffs are not rendered by default.

docs/kcl-std/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ layout: manual
6767
* [`patternCircular2d`](/docs/kcl-std/functions/std-sketch-patternCircular2d)
6868
* [`patternLinear2d`](/docs/kcl-std/functions/std-sketch-patternLinear2d)
6969
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
70+
* [`planeOf`](/docs/kcl-std/functions/std-sketch-planeOf)
7071
* [`polygon`](/docs/kcl-std/functions/std-sketch-polygon)
7172
* [`profileStart`](/docs/kcl-std/functions/std-sketch-profileStart)
7273
* [`profileStartX`](/docs/kcl-std/functions/std-sketch-profileStartX)

docs/kcl-std/modules/std-sketch.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This module contains functions for creating and manipulating sketches, and makin
3232
* [`patternCircular2d`](/docs/kcl-std/functions/std-sketch-patternCircular2d)
3333
* [`patternLinear2d`](/docs/kcl-std/functions/std-sketch-patternLinear2d)
3434
* [`patternTransform2d`](/docs/kcl-std/functions/std-sketch-patternTransform2d)
35+
* [`planeOf`](/docs/kcl-std/functions/std-sketch-planeOf)
3536
* [`polygon`](/docs/kcl-std/functions/std-sketch-polygon)
3637
* [`profileStart`](/docs/kcl-std/functions/std-sketch-profileStart)
3738
* [`profileStartX`](/docs/kcl-std/functions/std-sketch-profileStartX)

rust/justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ lint:
88
# Ensure we can build without extra feature flags.
99
cargo clippy -p kcl-lib --all-targets -- -D warnings
1010

11+
lint-fix:
12+
cargo clippy --workspace --all-targets --all-features --fix
13+
1114
# Run the stdlib docs generation
1215
redo-kcl-stdlib-docs-no-imgs:
1316
EXPECTORATE=overwrite {{cnr}} {{kcl_lib_flags}} docs::gen_std_tests::test_generate_stdlib

rust/kcl-derive-docs/src/example_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub const TEST_NAMES: &[&str] = &[
9797
"std-offsetPlane-2",
9898
"std-offsetPlane-3",
9999
"std-offsetPlane-4",
100+
"std-sketch-planeOf-0",
100101
"std-sketch-circle-0",
101102
"std-sketch-circle-1",
102103
"std-sketch-patternTransform2d-0",

rust/kcl-lib/src/execution/cad_op.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ impl From<&KclValue> for OpKclValue {
226226
match value {
227227
KclValue::Uuid { value, .. } => Self::Uuid { value: *value },
228228
KclValue::Bool { value, .. } => Self::Bool { value: *value },
229-
KclValue::Number { value, ty, .. } => Self::Number {
230-
value: *value,
231-
ty: ty.clone(),
232-
},
229+
KclValue::Number { value, ty, .. } => Self::Number { value: *value, ty: *ty },
233230
KclValue::String { value, .. } => Self::String { value: value.clone() },
234231
KclValue::Tuple { value, .. } | KclValue::HomArray { value, .. } => {
235232
let value = value.iter().map(Self::from).collect();

rust/kcl-lib/src/execution/exec_ast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ impl Node<UnaryExpression> {
12971297
Ok(KclValue::Number {
12981298
value: -value,
12991299
meta,
1300-
ty: ty.clone(),
1300+
ty: *ty,
13011301
})
13021302
}
13031303
KclValue::Plane { value } => {
@@ -1329,7 +1329,7 @@ impl Node<UnaryExpression> {
13291329
.map(|v| match v {
13301330
KclValue::Number { value, ty, meta } => Ok(KclValue::Number {
13311331
value: *value * -1.0,
1332-
ty: ty.clone(),
1332+
ty: *ty,
13331333
meta: meta.clone(),
13341334
}),
13351335
_ => Err(err()),
@@ -1350,7 +1350,7 @@ impl Node<UnaryExpression> {
13501350
.map(|v| match v {
13511351
KclValue::Number { value, ty, meta } => Ok(KclValue::Number {
13521352
value: *value * -1.0,
1353-
ty: ty.clone(),
1353+
ty: *ty,
13541354
meta: meta.clone(),
13551355
}),
13561356
_ => Err(err()),
@@ -1544,7 +1544,7 @@ impl Node<ArrayRangeExpression> {
15441544
.into_iter()
15451545
.map(|num| KclValue::Number {
15461546
value: num as f64,
1547-
ty: start_ty.clone(),
1547+
ty: start_ty,
15481548
meta: meta.clone(),
15491549
})
15501550
.collect(),

rust/kcl-lib/src/execution/geometry.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ impl From<Point3d> for Point3D {
939939
Self { x: p.x, y: p.y, z: p.z }
940940
}
941941
}
942+
942943
impl From<Point3d> for kittycad_modeling_cmds::shared::Point3d<LengthUnit> {
943944
fn from(p: Point3d) -> Self {
944945
Self {
@@ -1004,12 +1005,12 @@ pub struct BasePath {
10041005
impl BasePath {
10051006
pub fn get_to(&self) -> [TyF64; 2] {
10061007
let ty: NumericType = self.units.into();
1007-
[TyF64::new(self.to[0], ty.clone()), TyF64::new(self.to[1], ty)]
1008+
[TyF64::new(self.to[0], ty), TyF64::new(self.to[1], ty)]
10081009
}
10091010

10101011
pub fn get_from(&self) -> [TyF64; 2] {
10111012
let ty: NumericType = self.units.into();
1012-
[TyF64::new(self.from[0], ty.clone()), TyF64::new(self.from[1], ty)]
1013+
[TyF64::new(self.from[0], ty), TyF64::new(self.from[1], ty)]
10131014
}
10141015
}
10151016

@@ -1225,14 +1226,14 @@ impl Path {
12251226
pub fn get_from(&self) -> [TyF64; 2] {
12261227
let p = &self.get_base().from;
12271228
let ty: NumericType = self.get_base().units.into();
1228-
[TyF64::new(p[0], ty.clone()), TyF64::new(p[1], ty)]
1229+
[TyF64::new(p[0], ty), TyF64::new(p[1], ty)]
12291230
}
12301231

12311232
/// Where does this path segment end?
12321233
pub fn get_to(&self) -> [TyF64; 2] {
12331234
let p = &self.get_base().to;
12341235
let ty: NumericType = self.get_base().units.into();
1235-
[TyF64::new(p[0], ty.clone()), TyF64::new(p[1], ty)]
1236+
[TyF64::new(p[0], ty), TyF64::new(p[1], ty)]
12361237
}
12371238

12381239
/// The path segment start point and its type.

rust/kcl-lib/src/execution/kcl_value.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,41 @@ impl KclValue {
415415

416416
/// Put the point into a KCL value.
417417
pub fn from_point2d(p: [f64; 2], ty: NumericType, meta: Vec<Metadata>) -> Self {
418+
let [x, y] = p;
418419
Self::Tuple {
419420
value: vec![
420421
Self::Number {
421-
value: p[0],
422+
value: x,
422423
meta: meta.clone(),
423-
ty: ty.clone(),
424+
ty,
425+
},
426+
Self::Number {
427+
value: y,
428+
meta: meta.clone(),
429+
ty,
430+
},
431+
],
432+
meta,
433+
}
434+
}
435+
436+
/// Put the point into a KCL value.
437+
pub fn from_point3d(p: [f64; 3], ty: NumericType, meta: Vec<Metadata>) -> Self {
438+
let [x, y, z] = p;
439+
Self::Tuple {
440+
value: vec![
441+
Self::Number {
442+
value: x,
443+
meta: meta.clone(),
444+
ty,
445+
},
446+
Self::Number {
447+
value: y,
448+
meta: meta.clone(),
449+
ty,
424450
},
425451
Self::Number {
426-
value: p[1],
452+
value: z,
427453
meta: meta.clone(),
428454
ty,
429455
},
@@ -448,7 +474,7 @@ impl KclValue {
448474

449475
pub fn as_int_with_ty(&self) -> Option<(i64, NumericType)> {
450476
match self {
451-
KclValue::Number { value, ty, .. } => crate::try_f64_to_i64(*value).map(|i| (i, ty.clone())),
477+
KclValue::Number { value, ty, .. } => crate::try_f64_to_i64(*value).map(|i| (i, *ty)),
452478
_ => None,
453479
}
454480
}
@@ -562,7 +588,7 @@ impl KclValue {
562588

563589
pub fn as_ty_f64(&self) -> Option<TyF64> {
564590
match self {
565-
KclValue::Number { value, ty, .. } => Some(TyF64::new(*value, ty.clone())),
591+
KclValue::Number { value, ty, .. } => Some(TyF64::new(*value, *ty)),
566592
_ => None,
567593
}
568594
}

rust/kcl-lib/src/execution/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl fmt::Display for PrimitiveType {
460460
}
461461
}
462462

463-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ts_rs::TS, JsonSchema)]
463+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, ts_rs::TS, JsonSchema)]
464464
#[ts(export)]
465465
#[serde(tag = "type")]
466466
pub enum NumericType {
@@ -575,7 +575,7 @@ impl NumericType {
575575
match (&ty, &i.ty) {
576576
(Any, Default { .. }) if i.n == 0.0 => {}
577577
(Any, t) => {
578-
ty = t.clone();
578+
ty = *t;
579579
}
580580
(_, Unknown) | (Default { .. }, Default { .. }) => return (result, Unknown),
581581

@@ -598,7 +598,7 @@ impl NumericType {
598598
}
599599

600600
if ty == Any && !input.is_empty() {
601-
ty = input[0].ty.clone();
601+
ty = input[0].ty;
602602
}
603603

604604
(result, ty)
@@ -722,7 +722,7 @@ impl NumericType {
722722
if ty.subtype(self) {
723723
return Ok(KclValue::Number {
724724
value: *value,
725-
ty: ty.clone(),
725+
ty: *ty,
726726
meta: meta.clone(),
727727
});
728728
}
@@ -736,15 +736,15 @@ impl NumericType {
736736

737737
(Any, _) => Ok(KclValue::Number {
738738
value: *value,
739-
ty: self.clone(),
739+
ty: *self,
740740
meta: meta.clone(),
741741
}),
742742

743743
// If we're coercing to a default, we treat this as coercing to Any since leaving the numeric type unspecified in a coercion situation
744744
// means accept any number rather than force the current default.
745745
(_, Default { .. }) => Ok(KclValue::Number {
746746
value: *value,
747-
ty: ty.clone(),
747+
ty: *ty,
748748
meta: meta.clone(),
749749
}),
750750

@@ -1491,7 +1491,7 @@ impl KclValue {
14911491
pub fn principal_type(&self) -> Option<RuntimeType> {
14921492
match self {
14931493
KclValue::Bool { .. } => Some(RuntimeType::Primitive(PrimitiveType::Boolean)),
1494-
KclValue::Number { ty, .. } => Some(RuntimeType::Primitive(PrimitiveType::Number(ty.clone()))),
1494+
KclValue::Number { ty, .. } => Some(RuntimeType::Primitive(PrimitiveType::Number(*ty))),
14951495
KclValue::String { .. } => Some(RuntimeType::Primitive(PrimitiveType::String)),
14961496
KclValue::Object { value, .. } => {
14971497
let properties = value

0 commit comments

Comments
 (0)