fn drip(circles: &Vec<Circle>, drips: Vec<Point2>) -> Vec<Line2> {
  drips
    .iter()
    .map(|drip| {
      // set initial line conditions.
      // The line will always try to move in the "main_angle" direction,
      // but will by able to modify by it increments of "angle_adjustment"
      // in order to find a path that doesn't intersect a circle
      let main_angle = -PI / 2.; // straight down
      let mut x = drip.x;
      let mut y = drip.y;
      let mut angle_adjustment = 0.1;

      // create the actual line from 1200 segments
      let drip_line = (0..1200)
        .map(|_n| {
          let mut angle = main_angle;

          // if the "next point" would intersect any of the circles,
          // adjust the angle by small amounts until it no longer intersects.
          // TODO: avoid the possibility of infinite loops by breaking after a certain time
          while circles
            .iter()
            .any(|c| c.contains(pt2(x + angle.cos(), y + angle.sin())))
          {
            // if the angle is more than PI/2 away from the starting angle, then we've started to "go backwards".
            // In this case, we want to try going the opposite direction
            if angle >= main_angle + PI / 2. || angle <= main_angle - PI / 2. {
              angle = main_angle;
              angle_adjustment = angle_adjustment * -1.0;
            }
            angle += angle_adjustment;
          }

          // the angle is acceptable! Apply + create new point
          x += angle.cos();
          y += angle.sin();
          pt2(x, y)
        })
        .collect();

      // smooth the final line (looks much better)
      smooth_by(10, &drip_line)
    })
    .collect()
}
// drip initial points from top of view to bottom,
// while avoiding the "obstacles" of the circles.
drip initial points from top of view to bottom,
while avoiding the "obstacles" of the circles.
drip initial points from top of view to bottom while avoiding the " obstacles " of the circles .
fn drip(circles: &Vec<Circle>, drips: Vec<Point2>) -> Vec<Line2> {
  drips
    .iter()
    .map(|drip| {
      // set initial line conditions.
      // The line will always try to move in the "main_angle" direction,
      // but will by able to modify by it increments of "angle_adjustment"
      // in order to find a path that doesn't intersect a circle
      let main_angle = -PI / 2.; // straight down
      let mut x = drip.x;
      let mut y = drip.y;
      let mut angle_adjustment = 0.1;
      // create the actual line from 1200 segments
      let drip_line = (0..1200)
        .map(|_n| {
          let mut angle = main_angle;
          // if the "next point" would intersect any of the circles,
          // adjust the angle by small amounts until it no longer intersects.
          // TODO: avoid the possibility of infinite loops by breaking after a certain time
          while circles
            .iter()
            .any(|c| c.contains(pt2(x + angle.cos(), y + angle.sin())))
          {
            // if the angle is more than PI/2 away from the starting angle, then we've started to "go backwards".
            // In this case, we want to try going the opposite direction
            if angle >= main_angle + PI / 2. || angle <= main_angle - PI / 2. {
              angle = main_angle;
              angle_adjustment = angle_adjustment * -1.0;
            }
            angle += angle_adjustment;
          }
          // the angle is acceptable! Apply + create new point
          x += angle.cos();
          y += angle.sin();
          pt2(x, y)
        })
        .collect();
      // smooth the final line (looks much better)
      smooth_by(10, &drip_line)
    })
    .collect()
}
fn drip ( circles : & Vec < Circle > , drips : Vec < Point2 > ) -> Vec < Line2 > { drips . iter ( ) . map ( | drip | { // set initial line conditions. // The line will always try to move in the "main_angle" direction, // but will by able to modify by it increments of "angle_adjustment" // in order to find a path that doesn't intersect a circle let main_angle = - PI / 2. ; // straight down let mut x = drip . x ; let mut y = drip . y ; let mut angle_adjustment = 0.1 ; // create the actual line from 1200 segments let drip_line = ( 0 .. 1200 ) . map ( | _n | { let mut angle = main_angle ; // if the "next point" would intersect any of the circles, // adjust the angle by small amounts until it no longer intersects. // TODO: avoid the possibility of infinite loops by breaking after a certain time while circles . iter ( ) . any ( | c | c . contains ( pt2 ( x + angle . cos ( ) , y + angle . sin ( ) ) ) ) { // if the angle is more than PI/2 away from the starting angle, then we've started to "go backwards". // In this case, we want to try going the opposite direction if angle >= main_angle + PI / 2. || angle <= main_angle - PI / 2. { angle = main_angle ; angle_adjustment = angle_adjustment * - 1.0 ; } angle += angle_adjustment ; } // the angle is acceptable! Apply + create new point x += angle . cos ( ) ; y += angle . sin ( ) ; pt2 ( x , y ) } ) . collect ( ) ; // smooth the final line (looks much better) smooth_by ( 10 , & drip_line ) } ) . collect ( ) }
drip initial points from top of view to bottom,
while avoiding the "obstacles" of the circles.
drip initial points from top of view to bottom while avoiding the " obstacles " of the circles .
circles
&Vec<Circle>
drips
Vec<Point2>