Repository: GraphiteEditor/Graphite
File: editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs (Rust)

Code before:
		let after_rotate_transform = get_layer_transform(&mut editor, layer).await.unwrap();

		editor.handle_message(TransformLayerMessage::BeginScale).await;

		editor.move_mouse(150.0, 150.0, ModifierKeys::empty(), MouseKeys::NONE).await;
		editor
			.handle_message(TransformLayerMessage::PointerMove {
				slow_key: Key::Shift,
				increments_key: Key::Control,
			})
			.await;

		let after_scale_transform = get_layer_transform(&mut editor, layer).await.unwrap();

		// Verifying translation is preserved
		let translation_diff = (after_scale_transform.translation - original_transform.translation).length();
		assert!(translation_diff > 1.0, "Translation should be preserved through the chain");

		// Verifying rotation is preserved
		let rotation_matrix_diff = (after_scale_transform.matrix2.x_axis - after_grab_transform.matrix2.x_axis).length();
		assert!(rotation_matrix_diff > 0.1, "Rotation should be preserved through the chain");

		// Verifying scaling was applied
		let scale_diff_x = (after_scale_transform.matrix2.x_axis.length() - after_rotate_transform.matrix2.x_axis.length()).abs();
		let scale_diff_y = (after_scale_transform.matrix2.y_axis.length() - after_rotate_transform.matrix2.y_axis.length()).abs();
		assert!(scale_diff_x > 0.1 || scale_diff_y > 0.1, "Scaling should be applied in the chain");

		editor.handle_message(TransformLayerMessage::ApplyTransformOperation { final_transform: true }).await;

		let final_transform = get_layer_transform(&mut editor, layer).await.unwrap();
		assert_eq!(after_scale_transform, final_transform, "Final transform should match the chained operations");
	}
}


Review comment (suggestion):
I don't really understand why you are doing this. I'd suggest that you utilise the [`DAffine2::abs_diff_eq`](https://docs.rs/glam/latest/glam/f64/struct.DAffine2.html#method.abs_diff_eq) to compare the transformation to an expected matrix (which you can build using [`DAffine2::from_scale_angle_translation`](https://docs.rs/glam/latest/glam/f64/struct.DAffine2.html#method.from_scale_angle_translation)).

Code after:
				slow_key: Key::Shift,
				increments_key: Key::Control,
			})
			.await;
		let after_rotate_transform = get_layer_transform(&mut editor, layer).await.unwrap();
		// Checking for off-diagonal elements close to 0.707, which corresponds to cos(45°) and sin(45°)
		assert!(
			!after_rotate_transform.matrix2.abs_diff_eq(after_grab_transform.matrix2, 1e-5) &&
			(after_rotate_transform.matrix2.x_axis.y.abs() - 0.707).abs() < 0.1 &&  // Check for off-diagonal elements close to 0.707
			(after_rotate_transform.matrix2.y_axis.x.abs() - 0.707).abs() < 0.1, // that would indicate ~45° rotation
			"Rotation should change matrix components with approximately 45° rotation"
		);

		// 3. Chain to scaling - scale(area) up by 2x
		editor.handle_message(TransformLayerMessage::BeginScale).await;
		editor.move_mouse(250.0, 200.0, ModifierKeys::empty(), MouseKeys::NONE).await;
		editor
			.handle_message(TransformLayerMessage::PointerMove {
				slow_key: Key::Shift,
				increments_key: Key::Control,
			})
			.await;

		let after_scale_transform = get_layer_transform(&mut editor, layer).await.unwrap();
		let before_scale_det = after_rotate_transform.matrix2.determinant();
		let after_scale_det = after_scale_transform.matrix2.determinant();
		assert!(
			after_scale_det >= 2.0 * before_scale_det,
			"Scale should increase the determinant of the matrix (before: {}, after: {})",
			before_scale_det,
			after_scale_det
		);

		editor.handle_message(TransformLayerMessage::ApplyTransformOperation { final_transform: true }).await;
		let final_transform = get_layer_transform(&mut editor, layer).await.unwrap();

		assert!(final_transform.abs_diff_eq(after_scale_transform, 1e-5), "Final transform should match the transform before committing");
		assert!(!final_transform.abs_diff_eq(original_transform, 1e-5), "Final transform should be different from original transform");
	}
}