fn calculate_snap<R>(&mut self, targets: R, responses: &mut VecDeque<Message>) -> DVec2
	where
		R: Iterator<Item = DVec2> + Clone,
	{
		let empty = Vec::new();
		let snap_points = self.snap_x && self.snap_y;

		let axis = self.bound_targets.as_ref().unwrap_or(&empty);
		let points = if snap_points { self.point_targets.as_ref().unwrap_or(&empty) } else { &empty };

		let x_axis = if self.snap_x { axis } else { &empty }
			.iter()
			.flat_map(|&pos| targets.clone().map(move |goal| (pos, goal, (pos - goal).x)));
		let y_axis = if self.snap_y { axis } else { &empty }
			.iter()
			.flat_map(|&pos| targets.clone().map(move |goal| (pos, goal, (pos - goal).y)));
		let points = points.iter().flat_map(|&pos| targets.clone().map(move |goal| (pos, pos - goal, (pos - goal).length())));

		let min_x = x_axis.clone().min_by(|a, b| a.2.abs().partial_cmp(&b.2.abs()).expect("Could not compare position."));
		let min_y = y_axis.clone().min_by(|a, b| a.2.abs().partial_cmp(&b.2.abs()).expect("Could not compare position."));
		let min_points = points.clone().min_by(|a, b| a.2.abs().partial_cmp(&b.2.abs()).expect("Could not compare position."));

		// Snap to a point if possible
		let clamped_closest_distance = if let Some(min_points) = min_points.filter(|&(_, _, dist)| dist <= SNAP_POINT_TOLERANCE) {
			min_points.1
		} else {
			// Do not move if over snap tolerance
			let closest_distance = DVec2::new(min_x.unwrap_or_default().2, min_y.unwrap_or_default().2);
			DVec2::new(
				if closest_distance.x.abs() > SNAP_AXIS_TOLERANCE { 0. } else { closest_distance.x },
				if closest_distance.y.abs() > SNAP_AXIS_TOLERANCE { 0. } else { closest_distance.y },
			)
		};

		self.snap_overlays.update_overlays(responses, (x_axis, y_axis, points), clamped_closest_distance);

		clamped_closest_distance
	}
/// Computes the necessary translation to the layer to snap it (as well as updating necessary overlays)
Computes the necessary translation to the layer to snap it (as well as updating necessary overlays)
Computes the necessary translation to the layer to snap it ( as well as updating necessary overlays )
fn calculate_snap<R>(&mut self, targets: R, responses: &mut VecDeque<Message>) -> DVec2
	where
		R: Iterator<Item = DVec2> + Clone,
	{
		let empty = Vec::new();
		let snap_points = self.snap_x && self.snap_y;
		let axis = self.bound_targets.as_ref().unwrap_or(&empty);
		let points = if snap_points { self.point_targets.as_ref().unwrap_or(&empty) } else { &empty };
		let x_axis = if self.snap_x { axis } else { &empty }
			.iter()
			.flat_map(|&pos| targets.clone().map(move |goal| (pos, goal, (pos - goal).x)));
		let y_axis = if self.snap_y { axis } else { &empty }
			.iter()
			.flat_map(|&pos| targets.clone().map(move |goal| (pos, goal, (pos - goal).y)));
		let points = points.iter().flat_map(|&pos| targets.clone().map(move |goal| (pos, pos - goal, (pos - goal).length())));
		let min_x = x_axis.clone().min_by(|a, b| a.2.abs().partial_cmp(&b.2.abs()).expect("Could not compare position."));
		let min_y = y_axis.clone().min_by(|a, b| a.2.abs().partial_cmp(&b.2.abs()).expect("Could not compare position."));
		let min_points = points.clone().min_by(|a, b| a.2.abs().partial_cmp(&b.2.abs()).expect("Could not compare position."));
		// Snap to a point if possible
		let clamped_closest_distance = if let Some(min_points) = min_points.filter(|&(_, _, dist)| dist <= SNAP_POINT_TOLERANCE) {
			min_points.1
		} else {
			// Do not move if over snap tolerance
			let closest_distance = DVec2::new(min_x.unwrap_or_default().2, min_y.unwrap_or_default().2);
			DVec2::new(
				if closest_distance.x.abs() > SNAP_AXIS_TOLERANCE { 0. } else { closest_distance.x },
				if closest_distance.y.abs() > SNAP_AXIS_TOLERANCE { 0. } else { closest_distance.y },
			)
		};
		self.snap_overlays.update_overlays(responses, (x_axis, y_axis, points), clamped_closest_distance);
		clamped_closest_distance
	}
fn calculate_snap < R > ( & mut self , targets : R , responses : & mut VecDeque < Message > ) -> DVec2 where R : Iterator < Item = DVec2 > + Clone , { let empty = Vec :: new ( ) ; let snap_points = self . snap_x && self . snap_y ; let axis = self . bound_targets . as_ref ( ) . unwrap_or ( & empty ) ; let points = if snap_points { self . point_targets . as_ref ( ) . unwrap_or ( & empty ) } else { & empty } ; let x_axis = if self . snap_x { axis } else { & empty } . iter ( ) . flat_map ( | & pos | targets . clone ( ) . map ( move | goal | ( pos , goal , ( pos - goal ) . x ) ) ) ; let y_axis = if self . snap_y { axis } else { & empty } . iter ( ) . flat_map ( | & pos | targets . clone ( ) . map ( move | goal | ( pos , goal , ( pos - goal ) . y ) ) ) ; let points = points . iter ( ) . flat_map ( | & pos | targets . clone ( ) . map ( move | goal | ( pos , pos - goal , ( pos - goal ) . length ( ) ) ) ) ; let min_x = x_axis . clone ( ) . min_by ( | a , b | a . 2 . abs ( ) . partial_cmp ( & b . 2 . abs ( ) ) . expect ( " " ) ) ; let min_y = y_axis . clone ( ) . min_by ( | a , b | a . 2 . abs ( ) . partial_cmp ( & b . 2 . abs ( ) ) . expect ( " " ) ) ; let min_points = points . clone ( ) . min_by ( | a , b | a . 2 . abs ( ) . partial_cmp ( & b . 2 . abs ( ) ) . expect ( " " ) ) ; // Snap to a point if possible let clamped_closest_distance = if let Some ( min_points ) = min_points . filter ( | & ( _ , _ , dist ) | dist <= SNAP_POINT_TOLERANCE ) { min_points . 1 } else { // Do not move if over snap tolerance let closest_distance = DVec2 :: new ( min_x . unwrap_or_default ( ) . 2 , min_y . unwrap_or_default ( ) . 2 ) ; DVec2 :: new ( if closest_distance . x . abs ( ) > SNAP_AXIS_TOLERANCE { 0. } else { closest_distance . x } , if closest_distance . y . abs ( ) > SNAP_AXIS_TOLERANCE { 0. } else { closest_distance . y } , ) } ; self . snap_overlays . update_overlays ( responses , ( x_axis , y_axis , points ) , clamped_closest_distance ) ; clamped_closest_distance }
Computes the necessary translation to the layer to snap it (as well as updating necessary overlays)
Computes the necessary translation to the layer to snap it ( as well as updating necessary overlays )
&mut self
targets
R
responses
&mut VecDeque<Message>
&mut self
targets
R
responses
&mut VecDeque<Message>