fn contour_line(&self, threshold: f32) -> Option<Deque2> {
    // If all points are above or all are below, then there are no intersections
    let below: Vec<Point3> = self
      .vertices
      .iter()
      .filter(|v| v.z < threshold)
      .cloned()
      .collect();
    let above: Vec<Point3> = self
      .vertices
      .iter()
      .filter(|v| v.z >= threshold)
      .cloned()
      .collect();

    // no intersections
    if above.is_empty() || below.is_empty() {
      return None;
    }

    // We have a contour line, let's find it
    let minority = if above.len() < below.len() {
      above.clone()
    } else {
      below.clone()
    };
    let majority = if above.len() > below.len() {
      above.clone()
    } else {
      below.clone()
    };

    let mut contour_points = VecDeque::with_capacity(2);
    let crossed_edges = vec![(minority[0], majority[0]), (minority[0], majority[1])];
    for (vertex1, vertex2) in crossed_edges {
      // the percentage of the distance along the edge at which the point crosses
      let how_far = (threshold - vertex2.z) / (vertex1.z - vertex2.z);
      let crossing_point = pt2(
        how_far * vertex1.x + (1.0 - how_far) * vertex2.x,
        how_far * vertex1.y + (1.0 - how_far) * vertex2.y,
      );
      contour_points.push_back(crossing_point);
    }
    Some(contour_points)
  }
/// Returns a optional line segment that traces the contour path across the triangle
/// for the given threshold (elevation).
/// If no line exists across this triangle for the given threshold,
/// return None.
/// If a line exists, return Some(line)
/// where `line` is two points, each sitting on one edge of the triangle.
Returns a optional line segment that traces the contour path across the triangle
for the given threshold (elevation).
If no line exists across this triangle for the given threshold,
return None.
If a line exists, return Some(line)
where `line` is two points, each sitting on one edge of the triangle.
Returns a optional line segment that traces the contour path across the triangle for the given threshold ( elevation ) . If no line exists across this triangle for the given threshold return None . If a line exists return Some ( line ) where ` line ` is two points each sitting on one edge of the triangle .
fn contour_line(&self, threshold: f32) -> Option<Deque2> {
    // If all points are above or all are below, then there are no intersections
    let below: Vec<Point3> = self
      .vertices
      .iter()
      .filter(|v| v.z < threshold)
      .cloned()
      .collect();
    let above: Vec<Point3> = self
      .vertices
      .iter()
      .filter(|v| v.z >= threshold)
      .cloned()
      .collect();
    // no intersections
    if above.is_empty() || below.is_empty() {
      return None;
    }
    // We have a contour line, let's find it
    let minority = if above.len() < below.len() {
      above.clone()
    } else {
      below.clone()
    };
    let majority = if above.len() > below.len() {
      above.clone()
    } else {
      below.clone()
    };
    let mut contour_points = VecDeque::with_capacity(2);
    let crossed_edges = vec![(minority[0], majority[0]), (minority[0], majority[1])];
    for (vertex1, vertex2) in crossed_edges {
      // the percentage of the distance along the edge at which the point crosses
      let how_far = (threshold - vertex2.z) / (vertex1.z - vertex2.z);
      let crossing_point = pt2(
        how_far * vertex1.x + (1.0 - how_far) * vertex2.x,
        how_far * vertex1.y + (1.0 - how_far) * vertex2.y,
      );
      contour_points.push_back(crossing_point);
    }
    Some(contour_points)
  }
fn contour_line ( & self , threshold : f32 ) -> Option < Deque2 > { // If all points are above or all are below, then there are no intersections let below : Vec < Point3 > = self . vertices . iter ( ) . filter ( | v | v . z < threshold ) . cloned ( ) . collect ( ) ; let above : Vec < Point3 > = self . vertices . iter ( ) . filter ( | v | v . z >= threshold ) . cloned ( ) . collect ( ) ; // no intersections if above . is_empty ( ) || below . is_empty ( ) { return None ; } // We have a contour line, let's find it let minority = if above . len ( ) < below . len ( ) { above . clone ( ) } else { below . clone ( ) } ; let majority = if above . len ( ) > below . len ( ) { above . clone ( ) } else { below . clone ( ) } ; let mut contour_points = VecDeque :: with_capacity ( 2 ) ; let crossed_edges = vec ! [ ( minority [ 0 ] majority [ 0 ] ) ( minority [ 0 ] majority [ 1 ] ) ] ; for ( vertex1 , vertex2 ) in crossed_edges { // the percentage of the distance along the edge at which the point crosses let how_far = ( threshold - vertex2 . z ) / ( vertex1 . z - vertex2 . z ) ; let crossing_point = pt2 ( how_far * vertex1 . x + ( 1.0 - how_far ) * vertex2 . x , how_far * vertex1 . y + ( 1.0 - how_far ) * vertex2 . y , ) ; contour_points . push_back ( crossing_point ) ; } Some ( contour_points ) }
Returns a optional line segment that traces the contour path across the triangle
for the given threshold (elevation).
Returns a optional line segment that traces the contour path across the triangle for the given threshold ( elevation ) .
&self
threshold
f32