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

Code before:

		editor.left_mousedown(150.0, 100.0, ModifierKeys::empty()).await;
		editor
			.mouseup(
				EditorMouseState {
					editor_position: DVec2::new(150.0, 100.0),
					mouse_keys: MouseKeys::empty(),
					scroll_delta: ScrollDelta::default(),
				},
				ModifierKeys::empty(),
			)
			.await;

		editor.handle_message(SplineToolMessage::Confirm).await;
		editor.eval_graph().await;

		if let Some(points) = get_spline_points(&mut editor).await {
			assert!(points.len() >= 3, "Spline should have at least 3 points");
			let document = editor.active_document();
			let viewport_to_document = document.metadata().document_to_viewport.inverse();
			let expected_points = vec![
				viewport_to_document.transform_point2(DVec2::new(50.0, 50.0)),
				viewport_to_document.transform_point2(DVec2::new(100.0, 50.0)),
				viewport_to_document.transform_point2(DVec2::new(150.0, 100.0)),
			];
			for (i, (point, expected)) in points.iter().take(3).zip(expected_points.iter()).enumerate() {
				assert!(
					(*point - *expected).length() < 1.0,
					"Point {i} should be close to expected position. Got: {point:?}, expected: {expected:?}"
				);
			}
		} else {
			panic!("Could not get spline points");
		}
	}

	#[tokio::test]
	async fn test_spline_with_tilted_view() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;

		editor.handle_message(NavigationMessage::CanvasTiltSet { angle_radians: 45.0_f64.to_radians() }).await;
		editor.select_tool(ToolType::Spline).await;

		editor.left_mousedown(50.0, 50.0, ModifierKeys::empty()).await;
		editor
			.mouseup(
				EditorMouseState {
					editor_position: DVec2::new(50.0, 50.0),
					mouse_keys: MouseKeys::empty(),
					scroll_delta: ScrollDelta::default(),

Review comment (suggestion):
There is no need to use `.take()` since zip will end when either of the iterators ends. See: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.zip

Code after:
		// Finish the spline
		editor.handle_message(SplineToolMessage::Confirm).await;

		// Evaluate the graph to ensure everything is processed
		editor.eval_graph().await;

		// Get the layer and vector data
		let document = editor.active_document();
		let network_interface = &document.network_interface;
		let layer = network_interface
			.selected_nodes()
			.selected_visible_and_unlocked_layers(network_interface)
			.next()
			.expect("Should have a selected layer");
		let vector_data = network_interface.compute_modified_vector(layer).expect("Should have vector data");
		let layer_to_viewport = document.metadata().transform_to_viewport(layer);

		// Expected points in viewport coordinates
		let expected_points = vec![DVec2::new(50.0, 50.0), DVec2::new(100.0, 50.0), DVec2::new(150.0, 100.0)];

		// Assert all points are correctly positioned
		assert_point_positions(&vector_data, layer_to_viewport, &expected_points, 1e-10);
	}

	#[tokio::test]
	async fn test_spline_with_panned_view() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;

		let pan_amount = DVec2::new(200.0, 150.0);
		editor.handle_message(NavigationMessage::CanvasPan { delta: pan_amount }).await;

		editor.select_tool(ToolType::Spline).await;

		// Add points by clicking at different positions
		editor.click_tool(ToolType::Spline, MouseKeys::LEFT, DVec2::new(50.0, 50.0), ModifierKeys::empty()).await;
		editor.click_tool(ToolType::Spline, MouseKeys::LEFT, DVec2::new(100.0, 50.0), ModifierKeys::empty()).await;
		editor.click_tool(ToolType::Spline, MouseKeys::LEFT, DVec2::new(150.0, 100.0), ModifierKeys::empty()).await;

		editor.handle_message(SplineToolMessage::Confirm).await;

		// Evaluating the graph to ensure everything is processed
		editor.eval_graph().await;

		// Get the layer and vector data
		let document = editor.active_document();
		let network_interface = &document.network_interface;
		let layer = network_interface
			.selected_nodes()
			.selected_visible_and_unlocked_layers(network_interface)
			.next()