pub fn smooth_by(smoothness: usize, line: &Line2) -> Line2 {
  let length = line.len();
  line
    .clone()
    .iter()
    .enumerate()
    .map(|(i, _pt)| {
      let min = if i < smoothness { 0 } else { i - smoothness };
      let max = if i + smoothness > length - 1 {
        length - 1
      } else {
        i + smoothness
      };
      // if i > length - 4 || i < smoothness {
      //   return pt.clone();
      // }
      let range = min..max;
      // let magnitude: f32 = range.magnitude().into();
      let magnitude = range.clone().count() as f32;
      let x = &line[range.clone()].iter().map(|p| p.x).sum::<f32>() / magnitude;
      let y = &line[range].iter().map(|p| p.y).sum::<f32>() / magnitude;
      pt2(x, y)
    })
    .collect()
}
// basic line-smoothing algorithm
// TODO: investigate other smoothing algorithms, not sure this is very efficient/good
basic line-smoothing algorithm
TODO: investigate other smoothing algorithms, not sure this is very efficient/good
basic line - smoothing algorithm TODO : investigate other smoothing algorithms not sure this is very efficient / good
pub fn smooth_by(smoothness: usize, line: &Line2) -> Line2 {
  let length = line.len();
  line
    .clone()
    .iter()
    .enumerate()
    .map(|(i, _pt)| {
      let min = if i < smoothness { 0 } else { i - smoothness };
      let max = if i + smoothness > length - 1 {
        length - 1
      } else {
        i + smoothness
      };
      // if i > length - 4 || i < smoothness {
      //   return pt.clone();
      // }
      let range = min..max;
      // let magnitude: f32 = range.magnitude().into();
      let magnitude = range.clone().count() as f32;
      let x = &line[range.clone()].iter().map(|p| p.x).sum::<f32>() / magnitude;
      let y = &line[range].iter().map(|p| p.y).sum::<f32>() / magnitude;
      pt2(x, y)
    })
    .collect()
}
pub fn smooth_by ( smoothness : usize , line : & Line2 ) -> Line2 { let length = line . len ( ) ; line . clone ( ) . iter ( ) . enumerate ( ) . map ( | ( i , _pt ) | { let min = if i < smoothness { 0 } else { i - smoothness } ; let max = if i + smoothness > length - 1 { length - 1 } else { i + smoothness } ; // if i > length - 4 || i < smoothness { //   return pt.clone(); // } let range = min .. max ; // let magnitude: f32 = range.magnitude().into(); let magnitude = range . clone ( ) . count ( ) as f32 ; let x = & line [ range . clone ( ) ] . iter ( ) . map ( | p | p . x ) . sum :: < f32 > ( ) / magnitude ; let y = & line [ range ] . iter ( ) . map ( | p | p . y ) . sum :: < f32 > ( ) / magnitude ; pt2 ( x , y ) } ) . collect ( ) }
basic line-smoothing algorithm
TODO: investigate other smoothing algorithms, not sure this is very efficient/good
basic line - smoothing algorithm TODO : investigate other smoothing algorithms not sure this is very efficient / good
smoothness
usize
line
&Line2