use super::handles::{hit_kind, hit_radius_px, selection_hint_due};
use indicatrix_editor::manipulate::{HANDLE_HIT_RADIUS_PX, HandleKind, HandleLayout, ScreenPoint};
fn layout() -> HandleLayout {
HandleLayout {
anchor: ScreenPoint::new(100.0, 100.0),
angle_tip: ScreenPoint::new(100.0, 40.0),
depth_tip: ScreenPoint::new(400.0, 100.0),
index_tip: ScreenPoint::new(-200.0, 100.0),
angle_dir: (0.0, -1.0),
depth_dir: (1.0, 0.0),
index_dir: (-1.0, 0.0),
pixels_per_degree: 2.0,
pixels_per_mast_unit: 100.0,
pixels_per_tooth: 10.0,
}
}
#[test]
fn normal_handles_keep_the_original_hit_radius() {
assert!((hit_radius_px(1.0, 1.0) - HANDLE_HIT_RADIUS_PX).abs() < 1e-6);
let doubled = 2.0_f32.mul_add(-HANDLE_HIT_RADIUS_PX, hit_radius_px(2.0, 1.0));
assert!(doubled.abs() < 1e-6);
}
#[test]
fn larger_handles_multiply_the_hit_radius_by_the_drawn_scale() {
let radius = hit_radius_px(1.5, 1.6);
let error = (HANDLE_HIT_RADIUS_PX * 1.5).mul_add(-1.6, radius);
assert!(error.abs() < 1e-4);
assert!(radius > hit_radius_px(1.5, 1.0));
}
#[test]
fn a_press_that_misses_a_normal_handle_still_grabs_a_larger_one() {
let layout = layout();
let press = ScreenPoint::new(100.0, 22.0);
assert_eq!(
hit_kind(&layout, false, press, hit_radius_px(1.0, 1.0)),
None
);
assert_eq!(
hit_kind(&layout, false, press, hit_radius_px(1.0, 1.6)),
Some(HandleKind::Angle)
);
let far = ScreenPoint::new(100.0, 15.0);
assert_eq!(hit_kind(&layout, false, far, hit_radius_px(1.0, 1.6)), None);
}
#[test]
fn the_selection_hint_shows_for_a_new_committed_selection_with_large_handles() {
assert!(selection_hint_due(true, None, (3, false)));
assert!(selection_hint_due(true, Some((2, false)), (3, false)));
assert!(selection_hint_due(true, Some((3, true)), (3, false)));
}
#[test]
fn the_selection_hint_stays_quiet_otherwise() {
assert!(!selection_hint_due(false, None, (3, false)));
assert!(!selection_hint_due(true, Some((3, false)), (3, false)));
assert!(!selection_hint_due(true, None, (3, true)));
assert!(!selection_hint_due(true, Some((2, false)), (3, true)));
}