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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user