KCL stdlib reduce function (#3881)

Adds an `arrayReduce` function to KCL stdlib. Right now, it can only reduce SketchGroup values because my implementation of higher-order KCL functions sucks. But we will generalize it in the future to be able to reduce any type.

This simplifies sketching polygons, e.g.

```
fn decagon = (radius) => {
  let step = (1/10) * tau()
  let sketch = startSketchAt([
    (cos(0) * radius), 
    (sin(0) * radius),
  ])
  return arrayReduce([1..10], sketch, (i, sg) => {
      let x = cos(step * i) * radius
      let y = sin(step * i) * radius
      return lineTo([x, y], sg)
  })
}
```

Part of #3842
This commit is contained in:
Adam Chalmers
2024-09-14 00:10:17 -04:00
committed by GitHub
parent 3cd3e1af72
commit f235a950b0
9 changed files with 7651 additions and 2 deletions

View File

@ -1,6 +1,7 @@
//! Functions implemented for language execution.
pub mod args;
pub mod array;
pub mod assert;
pub mod chamfer;
pub mod convert;
@ -91,6 +92,7 @@ lazy_static! {
Box::new(crate::std::patterns::PatternCircular2D),
Box::new(crate::std::patterns::PatternCircular3D),
Box::new(crate::std::patterns::PatternTransform),
Box::new(crate::std::array::ArrayReduce),
Box::new(crate::std::chamfer::Chamfer),
Box::new(crate::std::fillet::Fillet),
Box::new(crate::std::fillet::GetOppositeEdge),