KCL: Add planeOf function to stdlib (#7643)
Gets the plane a face lies on, if any. Closes #7642
This commit is contained in:
@ -226,10 +226,7 @@ impl From<&KclValue> for OpKclValue {
|
||||
match value {
|
||||
KclValue::Uuid { value, .. } => Self::Uuid { value: *value },
|
||||
KclValue::Bool { value, .. } => Self::Bool { value: *value },
|
||||
KclValue::Number { value, ty, .. } => Self::Number {
|
||||
value: *value,
|
||||
ty: ty.clone(),
|
||||
},
|
||||
KclValue::Number { value, ty, .. } => Self::Number { value: *value, ty: *ty },
|
||||
KclValue::String { value, .. } => Self::String { value: value.clone() },
|
||||
KclValue::Tuple { value, .. } | KclValue::HomArray { value, .. } => {
|
||||
let value = value.iter().map(Self::from).collect();
|
||||
|
@ -1297,7 +1297,7 @@ impl Node<UnaryExpression> {
|
||||
Ok(KclValue::Number {
|
||||
value: -value,
|
||||
meta,
|
||||
ty: ty.clone(),
|
||||
ty: *ty,
|
||||
})
|
||||
}
|
||||
KclValue::Plane { value } => {
|
||||
@ -1329,7 +1329,7 @@ impl Node<UnaryExpression> {
|
||||
.map(|v| match v {
|
||||
KclValue::Number { value, ty, meta } => Ok(KclValue::Number {
|
||||
value: *value * -1.0,
|
||||
ty: ty.clone(),
|
||||
ty: *ty,
|
||||
meta: meta.clone(),
|
||||
}),
|
||||
_ => Err(err()),
|
||||
@ -1350,7 +1350,7 @@ impl Node<UnaryExpression> {
|
||||
.map(|v| match v {
|
||||
KclValue::Number { value, ty, meta } => Ok(KclValue::Number {
|
||||
value: *value * -1.0,
|
||||
ty: ty.clone(),
|
||||
ty: *ty,
|
||||
meta: meta.clone(),
|
||||
}),
|
||||
_ => Err(err()),
|
||||
@ -1544,7 +1544,7 @@ impl Node<ArrayRangeExpression> {
|
||||
.into_iter()
|
||||
.map(|num| KclValue::Number {
|
||||
value: num as f64,
|
||||
ty: start_ty.clone(),
|
||||
ty: start_ty,
|
||||
meta: meta.clone(),
|
||||
})
|
||||
.collect(),
|
||||
|
@ -939,6 +939,7 @@ impl From<Point3d> for Point3D {
|
||||
Self { x: p.x, y: p.y, z: p.z }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Point3d> for kittycad_modeling_cmds::shared::Point3d<LengthUnit> {
|
||||
fn from(p: Point3d) -> Self {
|
||||
Self {
|
||||
@ -1004,12 +1005,12 @@ pub struct BasePath {
|
||||
impl BasePath {
|
||||
pub fn get_to(&self) -> [TyF64; 2] {
|
||||
let ty: NumericType = self.units.into();
|
||||
[TyF64::new(self.to[0], ty.clone()), TyF64::new(self.to[1], ty)]
|
||||
[TyF64::new(self.to[0], ty), TyF64::new(self.to[1], ty)]
|
||||
}
|
||||
|
||||
pub fn get_from(&self) -> [TyF64; 2] {
|
||||
let ty: NumericType = self.units.into();
|
||||
[TyF64::new(self.from[0], ty.clone()), TyF64::new(self.from[1], ty)]
|
||||
[TyF64::new(self.from[0], ty), TyF64::new(self.from[1], ty)]
|
||||
}
|
||||
}
|
||||
|
||||
@ -1225,14 +1226,14 @@ impl Path {
|
||||
pub fn get_from(&self) -> [TyF64; 2] {
|
||||
let p = &self.get_base().from;
|
||||
let ty: NumericType = self.get_base().units.into();
|
||||
[TyF64::new(p[0], ty.clone()), TyF64::new(p[1], ty)]
|
||||
[TyF64::new(p[0], ty), TyF64::new(p[1], ty)]
|
||||
}
|
||||
|
||||
/// Where does this path segment end?
|
||||
pub fn get_to(&self) -> [TyF64; 2] {
|
||||
let p = &self.get_base().to;
|
||||
let ty: NumericType = self.get_base().units.into();
|
||||
[TyF64::new(p[0], ty.clone()), TyF64::new(p[1], ty)]
|
||||
[TyF64::new(p[0], ty), TyF64::new(p[1], ty)]
|
||||
}
|
||||
|
||||
/// The path segment start point and its type.
|
||||
|
@ -415,15 +415,41 @@ impl KclValue {
|
||||
|
||||
/// Put the point into a KCL value.
|
||||
pub fn from_point2d(p: [f64; 2], ty: NumericType, meta: Vec<Metadata>) -> Self {
|
||||
let [x, y] = p;
|
||||
Self::Tuple {
|
||||
value: vec![
|
||||
Self::Number {
|
||||
value: p[0],
|
||||
value: x,
|
||||
meta: meta.clone(),
|
||||
ty: ty.clone(),
|
||||
ty,
|
||||
},
|
||||
Self::Number {
|
||||
value: p[1],
|
||||
value: y,
|
||||
meta: meta.clone(),
|
||||
ty,
|
||||
},
|
||||
],
|
||||
meta,
|
||||
}
|
||||
}
|
||||
|
||||
/// Put the point into a KCL value.
|
||||
pub fn from_point3d(p: [f64; 3], ty: NumericType, meta: Vec<Metadata>) -> Self {
|
||||
let [x, y, z] = p;
|
||||
Self::Tuple {
|
||||
value: vec![
|
||||
Self::Number {
|
||||
value: x,
|
||||
meta: meta.clone(),
|
||||
ty,
|
||||
},
|
||||
Self::Number {
|
||||
value: y,
|
||||
meta: meta.clone(),
|
||||
ty,
|
||||
},
|
||||
Self::Number {
|
||||
value: z,
|
||||
meta: meta.clone(),
|
||||
ty,
|
||||
},
|
||||
@ -448,7 +474,7 @@ impl KclValue {
|
||||
|
||||
pub fn as_int_with_ty(&self) -> Option<(i64, NumericType)> {
|
||||
match self {
|
||||
KclValue::Number { value, ty, .. } => crate::try_f64_to_i64(*value).map(|i| (i, ty.clone())),
|
||||
KclValue::Number { value, ty, .. } => crate::try_f64_to_i64(*value).map(|i| (i, *ty)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -562,7 +588,7 @@ impl KclValue {
|
||||
|
||||
pub fn as_ty_f64(&self) -> Option<TyF64> {
|
||||
match self {
|
||||
KclValue::Number { value, ty, .. } => Some(TyF64::new(*value, ty.clone())),
|
||||
KclValue::Number { value, ty, .. } => Some(TyF64::new(*value, *ty)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ impl fmt::Display for PrimitiveType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum NumericType {
|
||||
@ -575,7 +575,7 @@ impl NumericType {
|
||||
match (&ty, &i.ty) {
|
||||
(Any, Default { .. }) if i.n == 0.0 => {}
|
||||
(Any, t) => {
|
||||
ty = t.clone();
|
||||
ty = *t;
|
||||
}
|
||||
(_, Unknown) | (Default { .. }, Default { .. }) => return (result, Unknown),
|
||||
|
||||
@ -598,7 +598,7 @@ impl NumericType {
|
||||
}
|
||||
|
||||
if ty == Any && !input.is_empty() {
|
||||
ty = input[0].ty.clone();
|
||||
ty = input[0].ty;
|
||||
}
|
||||
|
||||
(result, ty)
|
||||
@ -722,7 +722,7 @@ impl NumericType {
|
||||
if ty.subtype(self) {
|
||||
return Ok(KclValue::Number {
|
||||
value: *value,
|
||||
ty: ty.clone(),
|
||||
ty: *ty,
|
||||
meta: meta.clone(),
|
||||
});
|
||||
}
|
||||
@ -736,7 +736,7 @@ impl NumericType {
|
||||
|
||||
(Any, _) => Ok(KclValue::Number {
|
||||
value: *value,
|
||||
ty: self.clone(),
|
||||
ty: *self,
|
||||
meta: meta.clone(),
|
||||
}),
|
||||
|
||||
@ -744,7 +744,7 @@ impl NumericType {
|
||||
// means accept any number rather than force the current default.
|
||||
(_, Default { .. }) => Ok(KclValue::Number {
|
||||
value: *value,
|
||||
ty: ty.clone(),
|
||||
ty: *ty,
|
||||
meta: meta.clone(),
|
||||
}),
|
||||
|
||||
@ -1491,7 +1491,7 @@ impl KclValue {
|
||||
pub fn principal_type(&self) -> Option<RuntimeType> {
|
||||
match self {
|
||||
KclValue::Bool { .. } => Some(RuntimeType::Primitive(PrimitiveType::Boolean)),
|
||||
KclValue::Number { ty, .. } => Some(RuntimeType::Primitive(PrimitiveType::Number(ty.clone()))),
|
||||
KclValue::Number { ty, .. } => Some(RuntimeType::Primitive(PrimitiveType::Number(*ty))),
|
||||
KclValue::String { .. } => Some(RuntimeType::Primitive(PrimitiveType::String)),
|
||||
KclValue::Object { value, .. } => {
|
||||
let properties = value
|
||||
|
Reference in New Issue
Block a user