More propagation of numeric types (#6177)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -503,19 +503,19 @@ impl Args {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn make_user_val_from_point(&self, p: [f64; 2]) -> Result<KclValue, KclError> {
|
||||
pub(crate) fn make_user_val_from_point(&self, p: [TyF64; 2]) -> Result<KclValue, KclError> {
|
||||
let meta = Metadata {
|
||||
source_range: self.source_range,
|
||||
};
|
||||
let x = KclValue::Number {
|
||||
value: p[0],
|
||||
value: p[0].n,
|
||||
meta: vec![meta],
|
||||
ty: NumericType::Unknown,
|
||||
ty: p[0].ty.clone(),
|
||||
};
|
||||
let y = KclValue::Number {
|
||||
value: p[1],
|
||||
value: p[1].n,
|
||||
meta: vec![meta],
|
||||
ty: NumericType::Unknown,
|
||||
ty: p[1].ty.clone(),
|
||||
};
|
||||
Ok(KclValue::MixedArray {
|
||||
value: vec![x, y],
|
||||
@ -696,10 +696,9 @@ impl Args {
|
||||
FromArgs::from_args(self, 0)
|
||||
}
|
||||
|
||||
pub(crate) fn get_data_and_optional_tag<'a, T>(&'a self) -> Result<(T, Option<FaceTag>), KclError>
|
||||
where
|
||||
T: serde::de::DeserializeOwned + FromKclValue<'a> + Sized,
|
||||
{
|
||||
pub(crate) fn get_sketch_data_and_optional_tag(
|
||||
&self,
|
||||
) -> Result<(super::sketch::SketchData, Option<FaceTag>), KclError> {
|
||||
FromArgs::from_args(self, 0)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use kcl_derive_docs::stdlib;
|
||||
use super::args::FromArgs;
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::{ExecState, KclValue},
|
||||
execution::{types::NumericType, ExecState, KclValue},
|
||||
std::args::{Args, TyF64},
|
||||
};
|
||||
|
||||
@ -67,7 +67,7 @@ pub async fn tan(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
|
||||
pub async fn pi(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_pi()?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::count(result)))
|
||||
}
|
||||
|
||||
/// Return the value of `pi`. Archimedes’ constant (π).
|
||||
@ -96,7 +96,7 @@ pub async fn sqrt(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
let num = args.get_number()?;
|
||||
let result = inner_sqrt(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::Unknown)))
|
||||
}
|
||||
|
||||
/// Compute the square root of a number.
|
||||
@ -123,10 +123,10 @@ fn inner_sqrt(num: f64) -> Result<f64, KclError> {
|
||||
|
||||
/// Compute the absolute value of a number.
|
||||
pub async fn abs(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let num = args.get_number()?;
|
||||
let result = inner_abs(num)?;
|
||||
let num = args.get_number_with_type()?;
|
||||
let result = inner_abs(num.n)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(num.map_value(result)))
|
||||
}
|
||||
|
||||
/// Compute the absolute value of a number.
|
||||
@ -160,10 +160,10 @@ fn inner_abs(num: f64) -> Result<f64, KclError> {
|
||||
|
||||
/// Round a number to the nearest integer.
|
||||
pub async fn round(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let num = args.get_number()?;
|
||||
let result = inner_round(num)?;
|
||||
let num = args.get_number_with_type()?;
|
||||
let result = inner_round(num.n)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(num.map_value(result)))
|
||||
}
|
||||
|
||||
/// Round a number to the nearest integer.
|
||||
@ -188,10 +188,10 @@ fn inner_round(num: f64) -> Result<f64, KclError> {
|
||||
|
||||
/// Compute the largest integer less than or equal to a number.
|
||||
pub async fn floor(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let num = args.get_number()?;
|
||||
let result = inner_floor(num)?;
|
||||
let num = args.get_number_with_type()?;
|
||||
let result = inner_floor(num.n)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(num.map_value(result)))
|
||||
}
|
||||
|
||||
/// Compute the largest integer less than or equal to a number.
|
||||
@ -216,10 +216,10 @@ fn inner_floor(num: f64) -> Result<f64, KclError> {
|
||||
|
||||
/// Compute the smallest integer greater than or equal to a number.
|
||||
pub async fn ceil(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let num = args.get_number()?;
|
||||
let result = inner_ceil(num)?;
|
||||
let num = args.get_number_with_type()?;
|
||||
let result = inner_ceil(num.n)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(num.map_value(result)))
|
||||
}
|
||||
|
||||
/// Compute the smallest integer greater than or equal to a number.
|
||||
@ -335,7 +335,7 @@ pub async fn pow(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
|
||||
|
||||
let result = inner_pow(nums[0], nums[1])?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::Unknown)))
|
||||
}
|
||||
|
||||
/// Compute the number to a power.
|
||||
@ -365,7 +365,7 @@ pub async fn acos(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
let num = args.get_number()?;
|
||||
let result = inner_acos(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
|
||||
}
|
||||
|
||||
/// Compute the arccosine of a number (in radians).
|
||||
@ -396,7 +396,7 @@ pub async fn asin(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
let num = args.get_number()?;
|
||||
let result = inner_asin(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
|
||||
}
|
||||
|
||||
/// Compute the arcsine of a number (in radians).
|
||||
@ -426,7 +426,7 @@ pub async fn atan(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
let num = args.get_number()?;
|
||||
let result = inner_atan(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
|
||||
}
|
||||
|
||||
/// Compute the arctangent of a number (in radians).
|
||||
@ -456,7 +456,7 @@ pub async fn atan2(_exec_state: &mut ExecState, args: Args) -> Result<KclValue,
|
||||
let (y, x) = FromArgs::from_args(&args, 0)?;
|
||||
let result = inner_atan2(y, x)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
|
||||
}
|
||||
|
||||
/// Compute the four quadrant arctangent of Y and X (in radians).
|
||||
@ -503,7 +503,7 @@ pub async fn log(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
|
||||
}
|
||||
let result = inner_log(nums[0], nums[1])?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::Unknown)))
|
||||
}
|
||||
|
||||
/// Compute the logarithm of the number with respect to an arbitrary base.
|
||||
@ -535,7 +535,7 @@ pub async fn log2(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, K
|
||||
let num = args.get_number()?;
|
||||
let result = inner_log2(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::Unknown)))
|
||||
}
|
||||
|
||||
/// Compute the base 2 logarithm of the number.
|
||||
@ -563,7 +563,7 @@ pub async fn log10(_exec_state: &mut ExecState, args: Args) -> Result<KclValue,
|
||||
let num = args.get_number()?;
|
||||
let result = inner_log10(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::Unknown)))
|
||||
}
|
||||
|
||||
/// Compute the base 10 logarithm of the number.
|
||||
@ -591,7 +591,7 @@ pub async fn ln(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
|
||||
let num = args.get_number()?;
|
||||
let result = inner_ln(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::Unknown)))
|
||||
}
|
||||
|
||||
/// Compute the natural logarithm of the number.
|
||||
@ -618,7 +618,7 @@ fn inner_ln(num: f64) -> Result<f64, KclError> {
|
||||
pub async fn e(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_e()?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::count())))
|
||||
}
|
||||
|
||||
/// Return the value of Euler’s number `e`.
|
||||
@ -650,7 +650,7 @@ fn inner_e() -> Result<f64, KclError> {
|
||||
pub async fn tau(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_tau()?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::count())))
|
||||
}
|
||||
|
||||
/// Return the value of `tau`. The full circle constant (τ). Equal to 2π.
|
||||
@ -683,7 +683,7 @@ pub async fn to_radians(_exec_state: &mut ExecState, args: Args) -> Result<KclVa
|
||||
let num = args.get_number()?;
|
||||
let result = inner_to_radians(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::radians())))
|
||||
}
|
||||
|
||||
/// Converts a number from degrees to radians.
|
||||
@ -713,7 +713,7 @@ pub async fn to_degrees(_exec_state: &mut ExecState, args: Args) -> Result<KclVa
|
||||
let num = args.get_number()?;
|
||||
let result = inner_to_degrees(num)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::degrees())))
|
||||
}
|
||||
|
||||
/// Converts a number from radians to degrees.
|
||||
|
@ -7,10 +7,10 @@ use kittycad_modeling_cmds::shared::Angle;
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::{
|
||||
types::{PrimitiveType, RuntimeType},
|
||||
types::{NumericType, PrimitiveType, RuntimeType},
|
||||
ExecState, KclValue, Point2d, Sketch, TagIdentifier,
|
||||
},
|
||||
std::{utils::between, Args},
|
||||
std::{args::TyF64, utils::between, Args},
|
||||
};
|
||||
|
||||
/// Returns the point at the end of the given segment.
|
||||
@ -54,7 +54,7 @@ pub async fn segment_end(exec_state: &mut ExecState, args: Args) -> Result<KclVa
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_end(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<[f64; 2], KclError> {
|
||||
fn inner_segment_end(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<[TyF64; 2], KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -63,7 +63,7 @@ fn inner_segment_end(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(path.get_base().to)
|
||||
Ok(path.get_to().clone())
|
||||
}
|
||||
|
||||
/// Returns the segment end of x.
|
||||
@ -71,7 +71,7 @@ pub async fn segment_end_x(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
let result = inner_segment_end_x(&tag, exec_state, args.clone())?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Compute the ending point of the provided line segment along the 'x' axis.
|
||||
@ -95,7 +95,7 @@ pub async fn segment_end_x(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_end_x(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_segment_end_x(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<TyF64, KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -104,7 +104,7 @@ fn inner_segment_end_x(tag: &TagIdentifier, exec_state: &mut ExecState, args: Ar
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(path.get_base().to[0])
|
||||
Ok(TyF64::new(path.get_base().to[0], path.get_base().units.into()))
|
||||
}
|
||||
|
||||
/// Returns the segment end of y.
|
||||
@ -112,7 +112,7 @@ pub async fn segment_end_y(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
let result = inner_segment_end_y(&tag, exec_state, args.clone())?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Compute the ending point of the provided line segment along the 'y' axis.
|
||||
@ -137,7 +137,7 @@ pub async fn segment_end_y(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_end_y(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_segment_end_y(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<TyF64, KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -146,7 +146,7 @@ fn inner_segment_end_y(tag: &TagIdentifier, exec_state: &mut ExecState, args: Ar
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(path.get_to()[1])
|
||||
Ok(path.get_to()[1].clone())
|
||||
}
|
||||
|
||||
/// Returns the point at the start of the given segment.
|
||||
@ -190,7 +190,7 @@ pub async fn segment_start(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_start(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<[f64; 2], KclError> {
|
||||
fn inner_segment_start(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<[TyF64; 2], KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -207,7 +207,7 @@ pub async fn segment_start_x(exec_state: &mut ExecState, args: Args) -> Result<K
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
let result = inner_segment_start_x(&tag, exec_state, args.clone())?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Compute the starting point of the provided line segment along the 'x' axis.
|
||||
@ -231,7 +231,7 @@ pub async fn segment_start_x(exec_state: &mut ExecState, args: Args) -> Result<K
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_start_x(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_segment_start_x(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<TyF64, KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -240,7 +240,7 @@ fn inner_segment_start_x(tag: &TagIdentifier, exec_state: &mut ExecState, args:
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(path.get_from()[0])
|
||||
Ok(path.get_from()[0].clone())
|
||||
}
|
||||
|
||||
/// Returns the segment start of y.
|
||||
@ -248,7 +248,7 @@ pub async fn segment_start_y(exec_state: &mut ExecState, args: Args) -> Result<K
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
let result = inner_segment_start_y(&tag, exec_state, args.clone())?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Compute the starting point of the provided line segment along the 'y' axis.
|
||||
@ -273,7 +273,7 @@ pub async fn segment_start_y(exec_state: &mut ExecState, args: Args) -> Result<K
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_start_y(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_segment_start_y(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<TyF64, KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -282,7 +282,7 @@ fn inner_segment_start_y(tag: &TagIdentifier, exec_state: &mut ExecState, args:
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(path.get_from()[1])
|
||||
Ok(path.get_from()[1].clone())
|
||||
}
|
||||
/// Returns the last segment of x.
|
||||
pub async fn last_segment_x(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
@ -290,7 +290,7 @@ pub async fn last_segment_x(exec_state: &mut ExecState, args: Args) -> Result<Kc
|
||||
args.get_unlabeled_kw_arg_typed("sketch", &RuntimeType::Primitive(PrimitiveType::Sketch), exec_state)?;
|
||||
let result = inner_last_segment_x(sketch, args.clone())?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Extract the 'x' axis value of the last line segment in the provided 2-d
|
||||
@ -315,7 +315,7 @@ pub async fn last_segment_x(exec_state: &mut ExecState, args: Args) -> Result<Kc
|
||||
sketch = { docs = "The sketch whose line segment is being queried"},
|
||||
}
|
||||
}]
|
||||
fn inner_last_segment_x(sketch: Sketch, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_last_segment_x(sketch: Sketch, args: Args) -> Result<TyF64, KclError> {
|
||||
let last_line = sketch
|
||||
.paths
|
||||
.last()
|
||||
@ -327,7 +327,7 @@ fn inner_last_segment_x(sketch: Sketch, args: Args) -> Result<f64, KclError> {
|
||||
})?
|
||||
.get_base();
|
||||
|
||||
Ok(last_line.to[0])
|
||||
Ok(TyF64::new(last_line.to[0], last_line.units.into()))
|
||||
}
|
||||
|
||||
/// Returns the last segment of y.
|
||||
@ -336,7 +336,7 @@ pub async fn last_segment_y(exec_state: &mut ExecState, args: Args) -> Result<Kc
|
||||
args.get_unlabeled_kw_arg_typed("sketch", &RuntimeType::Primitive(PrimitiveType::Sketch), exec_state)?;
|
||||
let result = inner_last_segment_y(sketch, args.clone())?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Extract the 'y' axis value of the last line segment in the provided 2-d
|
||||
@ -361,7 +361,7 @@ pub async fn last_segment_y(exec_state: &mut ExecState, args: Args) -> Result<Kc
|
||||
sketch = { docs = "The sketch whose line segment is being queried"},
|
||||
}
|
||||
}]
|
||||
fn inner_last_segment_y(sketch: Sketch, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_last_segment_y(sketch: Sketch, args: Args) -> Result<TyF64, KclError> {
|
||||
let last_line = sketch
|
||||
.paths
|
||||
.last()
|
||||
@ -373,14 +373,14 @@ fn inner_last_segment_y(sketch: Sketch, args: Args) -> Result<f64, KclError> {
|
||||
})?
|
||||
.get_base();
|
||||
|
||||
Ok(last_line.to[1])
|
||||
Ok(TyF64::new(last_line.to[1], last_line.units.into()))
|
||||
}
|
||||
|
||||
/// Returns the length of the segment.
|
||||
pub async fn segment_length(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
let result = inner_segment_length(&tag, exec_state, args.clone())?;
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(result))
|
||||
}
|
||||
|
||||
/// Compute the length of the provided line segment.
|
||||
@ -412,7 +412,7 @@ pub async fn segment_length(exec_state: &mut ExecState, args: Args) -> Result<Kc
|
||||
tag = { docs = "The line segment being queried by its tag"},
|
||||
}
|
||||
}]
|
||||
fn inner_segment_length(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<f64, KclError> {
|
||||
fn inner_segment_length(tag: &TagIdentifier, exec_state: &mut ExecState, args: Args) -> Result<TyF64, KclError> {
|
||||
let line = args.get_tag_engine_info(exec_state, tag)?;
|
||||
let path = line.path.clone().ok_or_else(|| {
|
||||
KclError::Type(KclErrorDetails {
|
||||
@ -421,9 +421,7 @@ fn inner_segment_length(tag: &TagIdentifier, exec_state: &mut ExecState, args: A
|
||||
})
|
||||
})?;
|
||||
|
||||
let result = path.length();
|
||||
|
||||
Ok(result)
|
||||
Ok(path.length())
|
||||
}
|
||||
|
||||
/// Returns the angle of the segment.
|
||||
@ -431,7 +429,7 @@ pub async fn segment_angle(exec_state: &mut ExecState, args: Args) -> Result<Kcl
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
|
||||
let result = inner_segment_angle(&tag, exec_state, args.clone())?;
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::degrees())))
|
||||
}
|
||||
|
||||
/// Compute the angle (in degrees) of the provided line segment.
|
||||
@ -476,7 +474,7 @@ pub async fn tangent_to_end(exec_state: &mut ExecState, args: Args) -> Result<Kc
|
||||
let tag: TagIdentifier = args.get_unlabeled_kw_arg("tag")?;
|
||||
|
||||
let result = inner_tangent_to_end(&tag, exec_state, args.clone()).await?;
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::degrees())))
|
||||
}
|
||||
|
||||
/// Returns the angle coming out of the end of the segment in degrees.
|
||||
@ -586,7 +584,7 @@ async fn inner_tangent_to_end(tag: &TagIdentifier, exec_state: &mut ExecState, a
|
||||
pub async fn angle_to_match_length_x(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (tag, to, sketch) = args.get_tag_to_number_sketch()?;
|
||||
let result = inner_angle_to_match_length_x(&tag, to, sketch, exec_state, args.clone())?;
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::degrees())))
|
||||
}
|
||||
|
||||
/// Returns the angle to match the given length for x.
|
||||
@ -621,7 +619,7 @@ fn inner_angle_to_match_length_x(
|
||||
})
|
||||
})?;
|
||||
|
||||
let length = path.length();
|
||||
let length = path.length().n;
|
||||
|
||||
let last_line = sketch
|
||||
.paths
|
||||
@ -634,6 +632,7 @@ fn inner_angle_to_match_length_x(
|
||||
})?
|
||||
.get_base();
|
||||
|
||||
// TODO assumption about the units of to
|
||||
let diff = (to - last_line.to[0]).abs();
|
||||
|
||||
let angle_r = (diff / length).acos();
|
||||
@ -649,7 +648,7 @@ fn inner_angle_to_match_length_x(
|
||||
pub async fn angle_to_match_length_y(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (tag, to, sketch) = args.get_tag_to_number_sketch()?;
|
||||
let result = inner_angle_to_match_length_y(&tag, to, sketch, exec_state, args.clone())?;
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::degrees())))
|
||||
}
|
||||
|
||||
/// Returns the angle to match the given length for y.
|
||||
@ -685,7 +684,7 @@ fn inner_angle_to_match_length_y(
|
||||
})
|
||||
})?;
|
||||
|
||||
let length = path.length();
|
||||
let length = path.length().n;
|
||||
|
||||
let last_line = sketch
|
||||
.paths
|
||||
@ -698,6 +697,7 @@ fn inner_angle_to_match_length_y(
|
||||
})?
|
||||
.get_base();
|
||||
|
||||
// TODO assumption about the units of to
|
||||
let diff = (to - last_line.to[1]).abs();
|
||||
|
||||
let angle_r = (diff / length).asin();
|
||||
|
@ -25,7 +25,7 @@ use crate::{
|
||||
};
|
||||
|
||||
/// A sketch surface or a sketch.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(untagged)]
|
||||
pub enum SketchOrSurface {
|
||||
|
@ -840,7 +840,7 @@ async fn inner_angled_line_that_intersects(
|
||||
|
||||
/// Data for start sketch on.
|
||||
/// You can start a sketch on a plane or an solid.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase", untagged)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
@ -892,7 +892,7 @@ pub enum PlaneData {
|
||||
|
||||
/// Start a sketch on a specific plane or face.
|
||||
pub async fn start_sketch_on(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (data, tag): (SketchData, Option<FaceTag>) = args.get_data_and_optional_tag()?;
|
||||
let (data, tag) = args.get_sketch_data_and_optional_tag()?;
|
||||
|
||||
match inner_start_sketch_on(data, tag, exec_state, &args).await? {
|
||||
SketchSurface::Plane(value) => Ok(KclValue::Plane { value }),
|
||||
|
@ -5,7 +5,7 @@ use kcl_derive_docs::stdlib;
|
||||
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd};
|
||||
use kittycad_modeling_cmds::{self as kcmc};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::DEFAULT_TOLERANCE;
|
||||
use crate::{
|
||||
@ -16,7 +16,7 @@ use crate::{
|
||||
};
|
||||
|
||||
/// A path to sweep along.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(untagged)]
|
||||
pub enum SweepPath {
|
||||
|
@ -6,14 +6,14 @@ use kcl_derive_docs::stdlib;
|
||||
use crate::{
|
||||
errors::KclError,
|
||||
execution::{types::UnitLen, ExecState, KclValue},
|
||||
std::Args,
|
||||
std::{args::TyF64, Args},
|
||||
};
|
||||
|
||||
/// Millimeters conversion factor for current projects units.
|
||||
pub async fn mm(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_mm(exec_state)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units())))
|
||||
}
|
||||
|
||||
/// Millimeters conversion factor for current projects units.
|
||||
@ -54,7 +54,7 @@ fn inner_mm(exec_state: &ExecState) -> Result<f64, KclError> {
|
||||
pub async fn inch(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_inch(exec_state)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units())))
|
||||
}
|
||||
|
||||
/// Inches conversion factor for current projects units.
|
||||
@ -95,7 +95,7 @@ fn inner_inch(exec_state: &ExecState) -> Result<f64, KclError> {
|
||||
pub async fn ft(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_ft(exec_state)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units())))
|
||||
}
|
||||
|
||||
/// Feet conversion factor for current projects units.
|
||||
@ -137,7 +137,7 @@ fn inner_ft(exec_state: &ExecState) -> Result<f64, KclError> {
|
||||
pub async fn m(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_m(exec_state)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units())))
|
||||
}
|
||||
|
||||
/// Meters conversion factor for current projects units.
|
||||
@ -179,7 +179,7 @@ fn inner_m(exec_state: &ExecState) -> Result<f64, KclError> {
|
||||
pub async fn cm(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_cm(exec_state)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units())))
|
||||
}
|
||||
|
||||
/// Centimeters conversion factor for current projects units.
|
||||
@ -221,7 +221,7 @@ fn inner_cm(exec_state: &ExecState) -> Result<f64, KclError> {
|
||||
pub async fn yd(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let result = inner_yd(exec_state)?;
|
||||
|
||||
Ok(args.make_user_val_from_f64(result))
|
||||
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, exec_state.current_default_units())))
|
||||
}
|
||||
|
||||
/// Yards conversion factor for current projects units.
|
||||
|
Reference in New Issue
Block a user