fwt_software/tests/test_geometry.cpp

33 lines
1023 B
C++

#include <doctest/doctest.h>
#include "fgc/Geometry.h"
using namespace fgc;
TEST_CASE("AxisMap converts degrees and counts with an offset") {
AxisMap m{983.33, 500000, -90.0, 90.0};
CHECK(m.toCounts(0.0) == 500000);
CHECK(m.toCounts(90.0) == 588500); // lround(500000 + 90*983.33)
CHECK(m.toDeg(500000) == doctest::Approx(0.0));
CHECK(m.toDeg(m.toCounts(45.0)) == doctest::Approx(45.0).epsilon(0.001));
}
TEST_CASE("AxisMap clamps to the soft range on the way out") {
AxisMap m{10.0, 0, -90.0, 90.0};
CHECK(m.toCounts(200.0) == 900); // clamped to +90
CHECK(m.toCounts(-200.0) == -900); // clamped to -90
CHECK(m.toCounts(45.0) == 450);
}
TEST_CASE("AxisMap supports a negative (flipped) direction") {
AxisMap m{-10.0, 1000, -90.0, 90.0};
CHECK(m.toCounts(10.0) == 900);
CHECK(m.toDeg(900) == doctest::Approx(10.0));
}
TEST_CASE("AxisMap toDeg guards against a zero scale") {
AxisMap m{0.0, 0, -90.0, 90.0};
CHECK(m.toDeg(12345) == doctest::Approx(0.0));
}