fn draw_alignment_lines(&mut self, is_horizontal: bool, distances: impl Iterator<Item = (DVec2, DVec2, f64)>, responses: &mut VecDeque<Message>, closest_distance: DVec2) {
		for (target, goal, distance) in distances.filter(|(_target, _pos, dist)| dist.abs() < SNAP_AXIS_OVERLAY_FADE_DISTANCE) {
			let offset = if is_horizontal { target.y } else { target.x }.round() - 0.5;
			let offset_other = if is_horizontal { target.x } else { target.y }.round() - 0.5;
			let goal_axis = if is_horizontal { goal.x } else { goal.y }.round() - 0.5;

			let scale = DVec2::new(offset_other - goal_axis, 1.);
			let angle = if is_horizontal { 0. } else { PI / 2. };
			let translation = if is_horizontal { DVec2::new(goal_axis, offset) } else { DVec2::new(offset, goal_axis) };

			let transform = DAffine2::from_scale_angle_translation(scale, angle, translation).to_cols_array();
			let closest = if is_horizontal { closest_distance.y } else { closest_distance.x };

			let opacity = if (closest - distance).abs() < 1. {
				1.
			} else {
				SNAP_AXIS_UNSNAPPED_OPACITY - distance.abs() / (SNAP_AXIS_OVERLAY_FADE_DISTANCE / SNAP_AXIS_UNSNAPPED_OPACITY)
			};

			// Add line
			Self::add_overlay(true, responses, transform, Some(opacity), self.axis_index, &mut self.axis_overlay_paths);
			self.axis_index += 1;

			let size = DVec2::splat(SNAP_POINT_SIZE);

			// Add point at target
			let transform = DAffine2::from_scale_angle_translation(size, 0., target - size / 2.).to_cols_array();
			Self::add_overlay(false, responses, transform, Some(opacity), self.point_index, &mut self.point_overlay_paths);
			self.point_index += 1;

			// Add point along line but towards goal
			let translation = if is_horizontal { DVec2::new(goal.x, target.y) } else { DVec2::new(target.x, goal.y) };
			let transform = DAffine2::from_scale_angle_translation(size, 0., translation - size / 2.).to_cols_array();
			Self::add_overlay(false, responses, transform, Some(opacity), self.point_index, &mut self.point_overlay_paths);
			self.point_index += 1
		}
	}
/// Draw the alignment lines for an axis
/// Note: horizontal refers to the overlay line being horizontal and the snap being along the Y axis
Draw the alignment lines for an axis
Note: horizontal refers to the overlay line being horizontal and the snap being along the Y axis
Draw the alignment lines for an axis Note : horizontal refers to the overlay line being horizontal and the snap being along the Y axis
fn draw_alignment_lines(&mut self, is_horizontal: bool, distances: impl Iterator<Item = (DVec2, DVec2, f64)>, responses: &mut VecDeque<Message>, closest_distance: DVec2) {
		for (target, goal, distance) in distances.filter(|(_target, _pos, dist)| dist.abs() < SNAP_AXIS_OVERLAY_FADE_DISTANCE) {
			let offset = if is_horizontal { target.y } else { target.x }.round() - 0.5;
			let offset_other = if is_horizontal { target.x } else { target.y }.round() - 0.5;
			let goal_axis = if is_horizontal { goal.x } else { goal.y }.round() - 0.5;
			let scale = DVec2::new(offset_other - goal_axis, 1.);
			let angle = if is_horizontal { 0. } else { PI / 2. };
			let translation = if is_horizontal { DVec2::new(goal_axis, offset) } else { DVec2::new(offset, goal_axis) };
			let transform = DAffine2::from_scale_angle_translation(scale, angle, translation).to_cols_array();
			let closest = if is_horizontal { closest_distance.y } else { closest_distance.x };
			let opacity = if (closest - distance).abs() < 1. {
				1.
			} else {
				SNAP_AXIS_UNSNAPPED_OPACITY - distance.abs() / (SNAP_AXIS_OVERLAY_FADE_DISTANCE / SNAP_AXIS_UNSNAPPED_OPACITY)
			};
			// Add line
			Self::add_overlay(true, responses, transform, Some(opacity), self.axis_index, &mut self.axis_overlay_paths);
			self.axis_index += 1;
			let size = DVec2::splat(SNAP_POINT_SIZE);
			// Add point at target
			let transform = DAffine2::from_scale_angle_translation(size, 0., target - size / 2.).to_cols_array();
			Self::add_overlay(false, responses, transform, Some(opacity), self.point_index, &mut self.point_overlay_paths);
			self.point_index += 1;
			// Add point along line but towards goal
			let translation = if is_horizontal { DVec2::new(goal.x, target.y) } else { DVec2::new(target.x, goal.y) };
			let transform = DAffine2::from_scale_angle_translation(size, 0., translation - size / 2.).to_cols_array();
			Self::add_overlay(false, responses, transform, Some(opacity), self.point_index, &mut self.point_overlay_paths);
			self.point_index += 1
		}
	}
fn draw_alignment_lines ( & mut self , is_horizontal : bool , distances : impl Iterator < Item = ( DVec2 , DVec2 , f64 ) > , responses : & mut VecDeque < Message > , closest_distance : DVec2 ) { for ( target , goal , distance ) in distances . filter ( | ( _target , _pos , dist ) | dist . abs ( ) < SNAP_AXIS_OVERLAY_FADE_DISTANCE ) { let offset = if is_horizontal { target . y } else { target . x } . round ( ) - 0.5 ; let offset_other = if is_horizontal { target . x } else { target . y } . round ( ) - 0.5 ; let goal_axis = if is_horizontal { goal . x } else { goal . y } . round ( ) - 0.5 ; let scale = DVec2 :: new ( offset_other - goal_axis , 1. ) ; let angle = if is_horizontal { 0. } else { PI / 2. } ; let translation = if is_horizontal { DVec2 :: new ( goal_axis , offset ) } else { DVec2 :: new ( offset , goal_axis ) } ; let transform = DAffine2 :: from_scale_angle_translation ( scale , angle , translation ) . to_cols_array ( ) ; let closest = if is_horizontal { closest_distance . y } else { closest_distance . x } ; let opacity = if ( closest - distance ) . abs ( ) < 1. { 1. } else { SNAP_AXIS_UNSNAPPED_OPACITY - distance . abs ( ) / ( SNAP_AXIS_OVERLAY_FADE_DISTANCE / SNAP_AXIS_UNSNAPPED_OPACITY ) } ; // Add line Self :: add_overlay ( true , responses , transform , Some ( opacity ) , self . axis_index , & mut self . axis_overlay_paths ) ; self . axis_index += 1 ; let size = DVec2 :: splat ( SNAP_POINT_SIZE ) ; // Add point at target let transform = DAffine2 :: from_scale_angle_translation ( size , 0. , target - size / 2. ) . to_cols_array ( ) ; Self :: add_overlay ( false , responses , transform , Some ( opacity ) , self . point_index , & mut self . point_overlay_paths ) ; self . point_index += 1 ; // Add point along line but towards goal let translation = if is_horizontal { DVec2 :: new ( goal . x , target . y ) } else { DVec2 :: new ( target . x , goal . y ) } ; let transform = DAffine2 :: from_scale_angle_translation ( size , 0. , translation - size / 2. ) . to_cols_array ( ) ; Self :: add_overlay ( false , responses , transform , Some ( opacity ) , self . point_index , & mut self . point_overlay_paths ) ; self . point_index += 1 } }
Draw the alignment lines for an axis
Note: horizontal refers to the overlay line being horizontal and the snap being along the Y axis
Draw the alignment lines for an axis Note : horizontal refers to the overlay line being horizontal and the snap being along the Y axis
&mut self
is_horizontal
bool
distances
impl Iterator<Item = (DVec2, DVec2, f64)>
responses
&mut VecDeque<Message>
closest_distance
DVec2
&mut self
is_horizontal
bool
distances
impl Iterator<Item = (DVec2, DVec2, f64)>
responses
&mut VecDeque<Message>
closest_distance
DVec2