Repository: GraphiteEditor/Graphite
File: editor/src/messages/tool/tool_messages/path_tool.rs (Rust)

Code before:

	#[allow(clippy::too_many_arguments)]
	fn calculate_handle_angle(
		&mut self,
		shape_editor: &mut ShapeState,
		document: &DocumentMessageHandler,
		responses: &mut VecDeque<Message>,
		relative_vector: DVec2,
		handle_vector: DVec2,
		handle_id: ManipulatorPointId,
		lock_angle: bool,
		snap_angle: bool,
		tangent_to_neighboring_tangents: bool,
	) -> f64 {
		let current_angle = -handle_vector.angle_to(DVec2::X);

		if let Some((vector_data, layer)) = shape_editor
			.selected_shape_state
			.iter()
			.next()
			.and_then(|(layer, _)| document.network_interface.compute_modified_vector(*layer).map(|vector_data| (vector_data, layer)))
		{
			let adjacent_anchor = check_handle_over_adjacent_anchor(handle_id, &vector_data);
			let mut required_angle = None;

			// If the handle is dragged near its adjacent anchors while holding down the Ctrl key,compute the angle based on the tangent formed with the neighboring anchor points.
			if adjacent_anchor.is_some() && lock_angle && !self.angle_locked {
				let anchor = handle_id.get_anchor(&vector_data);
				let (angle, anchor_position) = calculate_adjacent_anchor_tangent(handle_id, anchor, adjacent_anchor, &vector_data);

				let layer_to_document = document.metadata().transform_to_document(*layer);

				self.adjacent_anchor_offset = handle_id
					.get_anchor_position(&vector_data)
					.and_then(|handle_anchor| anchor_position.map(|adjacent_anchor| layer_to_document.transform_point2(adjacent_anchor) - layer_to_document.transform_point2(handle_anchor)));

				required_angle = angle;
			}

			// If the handle is dragged near its adjacent anchors while holding down the Ctrl key, compute the angle using the tangent direction of neighboring segments.
			if relative_vector.length() < 25. && lock_angle && !self.angle_locked {
				required_angle = calculate_lock_angle(self, shape_editor, responses, document, &vector_data, handle_id, tangent_to_neighboring_tangents);
			}

			// Finalize and apply angle locking if a valid target angle was determined.
			if let Some(angle) = required_angle {
				self.angle = angle;
				self.angle_locked = true;
				return angle;
			}
		}

Review comment (suggestion):
```suggestion
			// If the handle is dragged over one of its adjacent anchors while holding down the Ctrl key, compute the angle based on the tangent formed with the neighboring anchor points.
```

Code after:

	#[allow(clippy::too_many_arguments)]
	fn calculate_handle_angle(
		&mut self,
		shape_editor: &mut ShapeState,
		document: &DocumentMessageHandler,
		responses: &mut VecDeque<Message>,
		relative_vector: DVec2,
		handle_vector: DVec2,
		handle_id: ManipulatorPointId,
		lock_angle: bool,
		snap_angle: bool,
		tangent_to_neighboring_tangents: bool,
	) -> f64 {
		let current_angle = -handle_vector.angle_to(DVec2::X);

		if let Some((vector_data, layer)) = shape_editor
			.selected_shape_state
			.iter()
			.next()
			.and_then(|(layer, _)| document.network_interface.compute_modified_vector(*layer).map(|vector_data| (vector_data, layer)))
		{
			let adjacent_anchor = check_handle_over_adjacent_anchor(handle_id, &vector_data);
			let mut required_angle = None;

			// If the handle is dragged over one of its adjacent anchors while holding down the Ctrl key, compute the angle based on the tangent formed with the neighboring anchor points.
			if adjacent_anchor.is_some() && lock_angle && !self.angle_locked {
				let anchor = handle_id.get_anchor(&vector_data);
				let (angle, anchor_position) = calculate_adjacent_anchor_tangent(handle_id, anchor, adjacent_anchor, &vector_data);

				let layer_to_document = document.metadata().transform_to_document(*layer);

				self.adjacent_anchor_offset = handle_id
					.get_anchor_position(&vector_data)
					.and_then(|handle_anchor| anchor_position.map(|adjacent_anchor| layer_to_document.transform_point2(adjacent_anchor) - layer_to_document.transform_point2(handle_anchor)));

				required_angle = angle;
			}

			// If the handle is dragged near its adjacent anchors while holding down the Ctrl key, compute the angle using the tangent direction of neighboring segments.
			if relative_vector.length() < 25. && lock_angle && !self.angle_locked {
				required_angle = calculate_lock_angle(self, shape_editor, responses, document, &vector_data, handle_id, tangent_to_neighboring_tangents);
			}

			// Finalize and apply angle locking if a valid target angle was determined.
			if let Some(angle) = required_angle {
				self.angle = angle;
				self.angle_locked = true;
				return angle;
			}
		}