#include "harness.hpp" #include using plot::Transform; PLOT_TEST(linear_round_trip) { Transform t{2.0, 10.0, 3.0, -1.0, false, false}; PLOT_CHECK_NEAR(t.to_screen_x(0.0), 10.0, 1e-12); PLOT_CHECK_NEAR(t.to_screen_x(5.0), 20.0, 1e-12); PLOT_CHECK_NEAR(t.to_data_x(20.0), 5.0, 1e-12); PLOT_CHECK_NEAR(t.to_data_y(t.to_screen_y(7.5)), 7.5, 1e-12); } PLOT_TEST(log_x_round_trip) { Transform t{100.0, 0.0, 1.0, 0.0, true, false}; PLOT_CHECK_NEAR(t.to_screen_x(1.0), 0.0, 1e-12); PLOT_CHECK_NEAR(t.to_screen_x(10.0), 100.0, 1e-12); PLOT_CHECK_NEAR(t.to_data_x(100.0), 10.0, 1e-9); } PLOT_TEST(zoom_anchor_is_invariant) { // Anchoring a zoom at a data coordinate must leave that coordinate's screen // position unchanged. Transform t{1.0, 0.0, 1.0, 0.0, false, false}; const double anchor_data = 3.25; const double before = t.to_screen_x(anchor_data); t.sx *= 4.0; t.tx = before - anchor_data * t.sx; PLOT_CHECK_NEAR(t.to_screen_x(anchor_data), before, 1e-12); }