add sin cos tan to stdlib and make sure you cant redeclare a stdlib fn (#497)

more tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2023-09-13 15:09:07 -07:00
committed by GitHub
parent f8ed830b60
commit 0466f04d82
5 changed files with 307 additions and 2 deletions

View File

@ -1,6 +1,7 @@
//! Functions implemented for language execution.
pub mod extrude;
pub mod math;
pub mod segment;
pub mod sketch;
pub mod utils;
@ -61,6 +62,10 @@ impl StdLib {
Box::new(crate::std::sketch::Close),
Box::new(crate::std::sketch::Arc),
Box::new(crate::std::sketch::BezierCurve),
Box::new(crate::std::math::Cos),
Box::new(crate::std::math::Sin),
Box::new(crate::std::math::Tan),
Box::new(crate::std::math::Pi),
];
let mut fns = HashMap::new();
@ -122,6 +127,21 @@ impl<'a> Args<'a> {
)?))
}
fn get_number(&self) -> Result<f64, KclError> {
let first_value = self
.args
.first()
.ok_or_else(|| {
KclError::Type(KclErrorDetails {
message: format!("Expected a number as the first argument, found `{:?}`", self.args),
source_ranges: vec![self.source_range],
})
})?
.get_json_value()?;
parse_json_number_as_f64(&first_value, self.source_range)
}
fn get_number_array(&self) -> Result<Vec<f64>, KclError> {
let mut numbers: Vec<f64> = Vec::new();
for arg in &self.args {