Skip to content

Commit b3d6be9

Browse files
authored
Add tests for Line tool with PTZ (#2559)
* cli failing * cli failing * Adding tests for line tool with zoom pann and tilt
1 parent 6bc12c8 commit b3d6be9

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

editor/src/messages/tool/tool_messages/line_tool.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,39 @@ mod test_line_tool {
467467
}
468468
}
469469

470+
#[tokio::test]
471+
async fn test_line_tool_with_transformed_viewport() {
472+
let mut editor = EditorTestUtils::create();
473+
editor.new_document().await;
474+
editor.handle_message(NavigationMessage::CanvasZoomSet { zoom_factor: 2.0 }).await;
475+
editor.handle_message(NavigationMessage::CanvasPan { delta: DVec2::new(100.0, 50.0) }).await;
476+
editor.handle_message(NavigationMessage::CanvasTiltSet { angle_radians: 30.0_f64.to_radians() }).await;
477+
editor.drag_tool(ToolType::Line, 0., 0., 100., 100., ModifierKeys::empty()).await;
478+
if let Some((start_input, end_input)) = get_line_node_inputs(&mut editor).await {
479+
let document = editor.active_document();
480+
let document_to_viewport = document.metadata().document_to_viewport;
481+
let viewport_to_document = document_to_viewport.inverse();
482+
483+
let expected_start = viewport_to_document.transform_point2(DVec2::ZERO);
484+
let expected_end = viewport_to_document.transform_point2(DVec2::new(100.0, 100.0));
485+
486+
assert!(
487+
(start_input - expected_start).length() < 1.0,
488+
"Start point should match expected document coordinates. Got {:?}, expected {:?}",
489+
start_input,
490+
expected_start
491+
);
492+
assert!(
493+
(end_input - expected_end).length() < 1.0,
494+
"End point should match expected document coordinates. Got {:?}, expected {:?}",
495+
end_input,
496+
expected_end
497+
);
498+
} else {
499+
panic!("Line was not created successfully with transformed viewport");
500+
}
501+
}
502+
470503
#[tokio::test]
471504
async fn test_line_tool_ctrl_anglelock() {
472505
let mut editor = EditorTestUtils::create();

0 commit comments

Comments
 (0)