@ -119,7 +119,7 @@ impl From<SolidOrSketchOrImportedGeometry> for crate::execution::KclValue {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| crate::execution::KclValue::Sketch { value: Box::new(s) })
|
.map(|s| crate::execution::KclValue::Sketch { value: Box::new(s) })
|
||||||
.collect(),
|
.collect(),
|
||||||
ty: crate::execution::PrimitiveType::Sketch,
|
ty: crate::execution::types::RuntimeType::sketch(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,10 @@ pub enum RuntimeType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RuntimeType {
|
impl RuntimeType {
|
||||||
|
pub fn sketch() -> Self {
|
||||||
|
RuntimeType::Primitive(PrimitiveType::Sketch)
|
||||||
|
}
|
||||||
|
|
||||||
/// `[Sketch; 1+]`
|
/// `[Sketch; 1+]`
|
||||||
pub fn sketches() -> Self {
|
pub fn sketches() -> Self {
|
||||||
RuntimeType::Array(
|
RuntimeType::Array(
|
||||||
@ -821,7 +825,7 @@ mod test {
|
|||||||
exec_state: &mut ExecState,
|
exec_state: &mut ExecState,
|
||||||
) {
|
) {
|
||||||
let is_subtype = value == expected_value;
|
let is_subtype = value == expected_value;
|
||||||
assert_eq!(&value.coerce(&super_type, exec_state).unwrap(), expected_value);
|
assert_eq!(&value.coerce(super_type, exec_state).unwrap(), expected_value);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
is_subtype,
|
is_subtype,
|
||||||
value.principal_type().is_some() && value.principal_type().unwrap().subtype(super_type),
|
value.principal_type().is_some() && value.principal_type().unwrap().subtype(super_type),
|
||||||
@ -1157,12 +1161,12 @@ mod test {
|
|||||||
RuntimeType::Primitive(PrimitiveType::Number(NumericType::Any)),
|
RuntimeType::Primitive(PrimitiveType::Number(NumericType::Any)),
|
||||||
RuntimeType::Primitive(PrimitiveType::Boolean),
|
RuntimeType::Primitive(PrimitiveType::Boolean),
|
||||||
]);
|
]);
|
||||||
// TODO implement covariance for homogenous arrays
|
// TODO implement covariance for homogeneous arrays
|
||||||
// assert_coerce_results(&hom_arr, &tyh, &hom_arr, &mut exec_state);
|
// assert_coerce_results(&hom_arr, &tyh, &hom_arr, &mut exec_state);
|
||||||
assert_coerce_results(&mixed1, &tym1, &mixed1, &mut exec_state);
|
assert_coerce_results(&mixed1, &tym1, &mixed1, &mut exec_state);
|
||||||
assert_coerce_results(&mixed2, &tym2, &mixed2, &mut exec_state);
|
assert_coerce_results(&mixed2, &tym2, &mixed2, &mut exec_state);
|
||||||
|
|
||||||
// Mixed to homogenous
|
// Mixed to homogeneous
|
||||||
let hom_arr_2 = KclValue::HomArray {
|
let hom_arr_2 = KclValue::HomArray {
|
||||||
value: vec![
|
value: vec![
|
||||||
KclValue::Number {
|
KclValue::Number {
|
||||||
|
|||||||
@ -189,8 +189,10 @@ impl Args {
|
|||||||
ty.human_friendly_type(),
|
ty.human_friendly_type(),
|
||||||
);
|
);
|
||||||
let suggestion = match (ty, actual_type_name) {
|
let suggestion = match (ty, actual_type_name) {
|
||||||
(RuntimeType::Primitive(PrimitiveType::Solid), "Sketch")
|
(RuntimeType::Primitive(PrimitiveType::Solid), "Sketch") => Some(
|
||||||
| (RuntimeType::Array(PrimitiveType::Solid, _), "Sketch") => Some(
|
"You can convert a sketch (2D) into a Solid (3D) by calling a function like `extrude` or `revolve`",
|
||||||
|
),
|
||||||
|
(RuntimeType::Array(t, _), "Sketch") if **t == RuntimeType::Primitive(PrimitiveType::Solid) => Some(
|
||||||
"You can convert a sketch (2D) into a Solid (3D) by calling a function like `extrude` or `revolve`",
|
"You can convert a sketch (2D) into a Solid (3D) by calling a function like `extrude` or `revolve`",
|
||||||
),
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
@ -5,20 +5,14 @@ use kcl_derive_docs::stdlib;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{
|
execution::{types::RuntimeType, ExecState, KclValue, Solid},
|
||||||
kcl_value::{ArrayLen, RuntimeType},
|
|
||||||
ExecState, KclValue, PrimitiveType, Solid,
|
|
||||||
},
|
|
||||||
std::Args,
|
std::Args,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Union two or more solids into a single solid.
|
/// Union two or more solids into a single solid.
|
||||||
pub async fn union(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
pub async fn union(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||||
let solids: Vec<Solid> = args.get_unlabeled_kw_arg_typed(
|
let solids: Vec<Solid> =
|
||||||
"objects",
|
args.get_unlabeled_kw_arg_typed("solids", &RuntimeType::Union(vec![RuntimeType::solids()]), exec_state)?;
|
||||||
&RuntimeType::Union(vec![RuntimeType::Array(PrimitiveType::Solid, ArrayLen::NonEmpty)]),
|
|
||||||
exec_state,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if solids.len() < 2 {
|
if solids.len() < 2 {
|
||||||
return Err(KclError::UndefinedValue(KclErrorDetails {
|
return Err(KclError::UndefinedValue(KclErrorDetails {
|
||||||
@ -74,11 +68,7 @@ async fn inner_union(solids: Vec<Solid>, exec_state: &mut ExecState, args: Args)
|
|||||||
/// Intersect returns the shared volume between multiple solids, preserving only
|
/// Intersect returns the shared volume between multiple solids, preserving only
|
||||||
/// overlapping regions.
|
/// overlapping regions.
|
||||||
pub async fn intersect(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
pub async fn intersect(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||||
let solids: Vec<Solid> = args.get_unlabeled_kw_arg_typed(
|
let solids: Vec<Solid> = args.get_unlabeled_kw_arg_typed("solids", &RuntimeType::solids(), exec_state)?;
|
||||||
"objects",
|
|
||||||
&RuntimeType::Union(vec![RuntimeType::Array(PrimitiveType::Solid, ArrayLen::NonEmpty)]),
|
|
||||||
exec_state,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if solids.len() < 2 {
|
if solids.len() < 2 {
|
||||||
return Err(KclError::UndefinedValue(KclErrorDetails {
|
return Err(KclError::UndefinedValue(KclErrorDetails {
|
||||||
@ -139,16 +129,8 @@ async fn inner_intersect(solids: Vec<Solid>, exec_state: &mut ExecState, args: A
|
|||||||
|
|
||||||
/// Subtract removes tool solids from base solids, leaving the remaining material.
|
/// Subtract removes tool solids from base solids, leaving the remaining material.
|
||||||
pub async fn subtract(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
pub async fn subtract(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||||
let solids: Vec<Solid> = args.get_unlabeled_kw_arg_typed(
|
let solids: Vec<Solid> = args.get_unlabeled_kw_arg_typed("solids", &RuntimeType::solids(), exec_state)?;
|
||||||
"objects",
|
let tools: Vec<Solid> = args.get_kw_arg_typed("tools", &RuntimeType::solids(), exec_state)?;
|
||||||
&RuntimeType::Union(vec![RuntimeType::Array(PrimitiveType::Solid, ArrayLen::NonEmpty)]),
|
|
||||||
exec_state,
|
|
||||||
)?;
|
|
||||||
let tools: Vec<Solid> = args.get_kw_arg_typed(
|
|
||||||
"tools",
|
|
||||||
&RuntimeType::Union(vec![RuntimeType::Array(PrimitiveType::Solid, ArrayLen::NonEmpty)]),
|
|
||||||
exec_state,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let solids = inner_subtract(solids, tools, exec_state, args).await?;
|
let solids = inner_subtract(solids, tools, exec_state, args).await?;
|
||||||
Ok(solids.into())
|
Ok(solids.into())
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use kittycad_modeling_cmds as kcmc;
|
|||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
|
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
|
||||||
|
parsing::ast::types::TagNode,
|
||||||
std::{extrude::do_post_extrude, fillet::default_tolerance, Args},
|
std::{extrude::do_post_extrude, fillet::default_tolerance, Args},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -7,21 +7,14 @@ use kittycad_modeling_cmds::{self as kcmc};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
execution::{
|
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
|
||||||
kcl_value::{ArrayLen, RuntimeType},
|
|
||||||
ExecState, KclValue, PrimitiveType, Sketch, Solid,
|
|
||||||
},
|
|
||||||
parsing::ast::types::TagNode,
|
parsing::ast::types::TagNode,
|
||||||
std::{axis_or_reference::Axis2dOrEdgeReference, extrude::do_post_extrude, fillet::default_tolerance, Args},
|
std::{axis_or_reference::Axis2dOrEdgeReference, extrude::do_post_extrude, fillet::default_tolerance, Args},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Revolve a sketch or set of sketches around an axis.
|
/// Revolve a sketch or set of sketches around an axis.
|
||||||
pub async fn revolve(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
pub async fn revolve(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||||
let sketches = args.get_unlabeled_kw_arg_typed(
|
let sketches = args.get_unlabeled_kw_arg_typed("sketches", &RuntimeType::sketches(), exec_state)?;
|
||||||
"sketches",
|
|
||||||
&RuntimeType::Array(PrimitiveType::Sketch, ArrayLen::NonEmpty),
|
|
||||||
exec_state,
|
|
||||||
)?;
|
|
||||||
let axis: Axis2dOrEdgeReference = args.get_kw_arg("axis")?;
|
let axis: Axis2dOrEdgeReference = args.get_kw_arg("axis")?;
|
||||||
let angle = args.get_kw_arg_opt("angle")?;
|
let angle = args.get_kw_arg_opt("angle")?;
|
||||||
let tolerance = args.get_kw_arg_opt("tolerance")?;
|
let tolerance = args.get_kw_arg_opt("tolerance")?;
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
errors::KclError,
|
errors::KclError,
|
||||||
execution::{types::RuntimeType, ExecState, Helix, KclValue, Sketch, Solid},
|
execution::{types::RuntimeType, ExecState, Helix, KclValue, Sketch, Solid},
|
||||||
|
parsing::ast::types::TagNode,
|
||||||
std::{extrude::do_post_extrude, fillet::default_tolerance, Args},
|
std::{extrude::do_post_extrude, fillet::default_tolerance, Args},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user