mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
test(transform): move the Toggle Reference Point tests to their own file
The issue asks for the tests in transform_reference_point_tests.rs, so they go there and drive the box through the public begin and pointer.
This commit is contained in:
1 parent
78b3fd0225
commit
e04e2b23fa
4 files changed
+62
-34
No files matched your search
@@ -797,6 +797,9 @@ mod transform_undo_tests;
|
||||
#[cfg(test)]
|
||||
mod transform_type_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod transform_reference_point_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod transform_several_tests;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ use options_bar::{
|
||||
pub use options_bar::{options_bar, reset_warp};
|
||||
pub(crate) use pointer::{Gesture, Hit, hit, rotate_cursor_dir};
|
||||
#[cfg(test)]
|
||||
use pointer::{accepts_outside_click, box_hit, carry_pivot, near_rotate_corner, point_on_quad, rotation_degrees};
|
||||
use pointer::{accepts_outside_click, carry_pivot, near_rotate_corner, point_on_quad, rotation_degrees};
|
||||
pub use pointer::{cursor, pointer};
|
||||
pub(crate) use preview::solo_layer;
|
||||
use preview::{Above, composite_image, show_only};
|
||||
|
||||
@@ -776,39 +776,6 @@ fn the_nearest_handle_wins_on_a_small_box() {
|
||||
assert_eq!(hit(&s, [40.0, 40.0], 12.0), Hit::Outside);
|
||||
}
|
||||
|
||||
/// Toggle Reference Point (#11098): off by default, as in Photoshop, so a press on the centre
|
||||
/// moves the content instead of grabbing the hidden reference point; ticked, the centre drags
|
||||
/// the reference point again.
|
||||
#[test]
|
||||
fn the_reference_point_is_only_draggable_when_toggled_on() {
|
||||
let ctx = egui::Context::default();
|
||||
let none = egui::Modifiers::NONE;
|
||||
let mut app = app_with_square(64, photocraft_geom::Rect::new(4, 4, 60, 60));
|
||||
assert!(!app.ui.tool_options.transform_reference_point, "off by default");
|
||||
begin(&mut app, &ctx).unwrap();
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
let (quad, pivot) = (t.quad, t.pivot);
|
||||
assert_ne!(box_hit(&app, t, pivot, 12.0), Hit::Pivot);
|
||||
pointer(&mut app, ToolEvent::Down { x: pivot[0], y: pivot[1], pressure: 1.0 }, none);
|
||||
pointer(&mut app, ToolEvent::Move { x: pivot[0] + 5.0, y: pivot[1], pressure: 1.0 }, none);
|
||||
pointer(&mut app, ToolEvent::Up { x: pivot[0] + 5.0, y: pivot[1] }, none);
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
assert!(close(t.quad, quad.map(|[x, y]| [x + 5.0, y])), "the box moved: {:?}", t.quad);
|
||||
|
||||
let mut app = app_with_square(64, photocraft_geom::Rect::new(4, 4, 60, 60));
|
||||
app.ui.tool_options.transform_reference_point = true;
|
||||
begin(&mut app, &ctx).unwrap();
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
let (quad, pivot) = (t.quad, t.pivot);
|
||||
assert_eq!(box_hit(&app, t, pivot, 12.0), Hit::Pivot);
|
||||
pointer(&mut app, ToolEvent::Down { x: pivot[0], y: pivot[1], pressure: 1.0 }, none);
|
||||
pointer(&mut app, ToolEvent::Move { x: pivot[0] + 5.0, y: pivot[1], pressure: 1.0 }, none);
|
||||
pointer(&mut app, ToolEvent::Up { x: pivot[0] + 5.0, y: pivot[1] }, none);
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
assert_eq!(t.quad, quad, "the box stays");
|
||||
assert!((t.pivot[0] - pivot[0] - 5.0).abs() < 1e-6, "the reference point moved: {:?}", t.pivot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interior_patch_points_are_hidden_and_grid_anchors_stay() {
|
||||
assert!(on_section_edge(0, 0) && on_section_edge(1, 0) && on_section_edge(0, 2));
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//! Toggle Reference Point (#11098): off by default, as in Photoshop, so a press on the centre
|
||||
//! moves the content instead of grabbing the hidden reference point; ticked, the centre drags the
|
||||
//! reference point again.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::ToolEvent;
|
||||
|
||||
/// A 64 x 64 document with a layer filled at 4..60 and Free Transform open on it.
|
||||
fn transforming(reference_point: bool) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.sync_views();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
app.run("select.rect", json!({"x": 4, "y": 4, "width": 56, "height": 56})).unwrap();
|
||||
app.run("edit.fill", json!({"contents": "color", "color": "#ff0000"})).unwrap();
|
||||
app.run("select.deselect", json!({})).unwrap();
|
||||
app.ui.tool_options.transform_reference_point = reference_point;
|
||||
crate::transform_tool::begin(&mut app, &egui::Context::default()).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
/// Drags 5 px to the right from the reference point.
|
||||
fn drag_from_pivot(app: &mut PhotocraftApp) -> ([[f64; 2]; 4], [f64; 2]) {
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
let (quad, pivot) = (t.quad, t.pivot);
|
||||
let none = egui::Modifiers::NONE;
|
||||
crate::transform_tool::pointer(app, ToolEvent::Down { x: pivot[0], y: pivot[1], pressure: 1.0 }, none);
|
||||
crate::transform_tool::pointer(app, ToolEvent::Move { x: pivot[0] + 5.0, y: pivot[1], pressure: 1.0 }, none);
|
||||
crate::transform_tool::pointer(app, ToolEvent::Up { x: pivot[0] + 5.0, y: pivot[1] }, none);
|
||||
(quad, pivot)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_reference_point_is_off_by_default() {
|
||||
let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
assert!(!app.ui.tool_options.transform_reference_point);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_the_reference_point_off_the_centre_moves_the_content() {
|
||||
let mut app = transforming(false);
|
||||
let (quad, pivot) = drag_from_pivot(&mut app);
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
let moved = quad.map(|[x, y]| [x + 5.0, y]);
|
||||
assert!(t.quad.iter().flatten().zip(moved.iter().flatten()).all(|(a, b)| (a - b).abs() < 1e-6), "the box moved: {:?}", t.quad);
|
||||
assert!((t.pivot[0] - pivot[0] - 5.0).abs() < 1e-6, "the reference point moves with the box: {:?}", t.pivot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_the_reference_point_on_the_centre_drags_it() {
|
||||
let mut app = transforming(true);
|
||||
let (quad, pivot) = drag_from_pivot(&mut app);
|
||||
let t = app.ui.transform.as_ref().unwrap();
|
||||
assert_eq!(t.quad, quad, "the box stays");
|
||||
assert!((t.pivot[0] - pivot[0] - 5.0).abs() < 1e-6, "the reference point moved: {:?}", t.pivot);
|
||||
}
|
||||
Reference in new issue
Block a user