fn meander(model: &Model) -> Vec<Point2> {
  let start = pt2(model.x_start, model.y_start);
  let end = pt2(model.x_end, model.y_end);
  let mut points: Vec<Point2> = vec![start, end];

  for _recursion in 0..model.detail {
    let temp_points = points.clone();
    let iter_max = temp_points.len() - 1;

    for i in 0..iter_max {
      let one = temp_points[i];
      let two = temp_points[i + 1];
      let x_mid = (two.x + one.x) / 2.0;
      let y_mid = (two.y + one.y) / 2.0;
      let distance = one.distance(two);
      let orientation = ((two.y - one.y) / (two.x - one.x)).atan();
      let perpendicular = orientation + PI / 2.;

      let new = pt2(
        x_mid + perpendicular.cos() * (distance / 2. * random_f32()),
        y_mid + perpendicular.sin() * (distance / 2. * random_f32()),
      );
      points.insert(i * 2 + 1, new);
    }
  }

  points
}
// Finite subdivision rule algorithm to create a "fractal" line.
// Each subdivision diplaces the point by a random amount, perpendicular
// to the orientation of the line.
//
// The algorithm uses in-place mutation of an array -- my suspicion
// is that all the inserts are pretty inefficient. I would like to investigate
// using a linked list for this, or possibly another data structure
Finite subdivision rule algorithm to create a "fractal" line.
Each subdivision diplaces the point by a random amount, perpendicular
to the orientation of the line.

The algorithm uses in-place mutation of an array -- my suspicion
is that all the inserts are pretty inefficient. I would like to investigate
using a linked list for this, or possibly another data structure
Finite subdivision rule algorithm to create a " fractal " line . Each subdivision diplaces the point by a random amount perpendicular to the orientation of the line . The algorithm uses in - place mutation of an array -- my suspicion is that all the inserts are pretty inefficient . I would like to investigate using a linked list for this or possibly another data structure
fn meander(model: &Model) -> Vec<Point2> {
  let start = pt2(model.x_start, model.y_start);
  let end = pt2(model.x_end, model.y_end);
  let mut points: Vec<Point2> = vec![start, end];
  for _recursion in 0..model.detail {
    let temp_points = points.clone();
    let iter_max = temp_points.len() - 1;
    for i in 0..iter_max {
      let one = temp_points[i];
      let two = temp_points[i + 1];
      let x_mid = (two.x + one.x) / 2.0;
      let y_mid = (two.y + one.y) / 2.0;
      let distance = one.distance(two);
      let orientation = ((two.y - one.y) / (two.x - one.x)).atan();
      let perpendicular = orientation + PI / 2.;
      let new = pt2(
        x_mid + perpendicular.cos() * (distance / 2. * random_f32()),
        y_mid + perpendicular.sin() * (distance / 2. * random_f32()),
      );
      points.insert(i * 2 + 1, new);
    }
  }
  points
}
fn meander ( model : & Model ) -> Vec < Point2 > { let start = pt2 ( model . x_start , model . y_start ) ; let end = pt2 ( model . x_end , model . y_end ) ; let mut points : Vec < Point2 > = vec ! [ start end ] ; for _recursion in 0 .. model . detail { let temp_points = points . clone ( ) ; let iter_max = temp_points . len ( ) - 1 ; for i in 0 .. iter_max { let one = temp_points [ i ] ; let two = temp_points [ i + 1 ] ; let x_mid = ( two . x + one . x ) / 2.0 ; let y_mid = ( two . y + one . y ) / 2.0 ; let distance = one . distance ( two ) ; let orientation = ( ( two . y - one . y ) / ( two . x - one . x ) ) . atan ( ) ; let perpendicular = orientation + PI / 2. ; let new = pt2 ( x_mid + perpendicular . cos ( ) * ( distance / 2. * random_f32 ( ) ) , y_mid + perpendicular . sin ( ) * ( distance / 2. * random_f32 ( ) ) , ) ; points . insert ( i * 2 + 1 , new ) ; } } points }
Finite subdivision rule algorithm to create a "fractal" line.
Finite subdivision rule algorithm to create a " fractal " line .
model
&Model