#include #include #include "actors/AxesActor.hpp" #include "geo/GeoLocalFrame.hpp" using namespace geopro::render; namespace { constexpr double kFeetPerMeter = 3.28084; } // unitScaleFactor:米=1,英尺=3.28084。 TEST(AxesActor, UnitScaleFactor) { EXPECT_DOUBLE_EQ(unitScaleFactor(AxesUnit::Meter), 1.0); EXPECT_DOUBLE_EQ(unitScaleFactor(AxesUnit::Feet), kFeetPerMeter); } // 不显示模式 → 返回 nullptr(不入场景)。 TEST(AxesActor, NoneModeReturnsNull) { double b[6] = {0, 10, 0, 20, -5, 0}; AxesOptions opts; opts.mode = AxesMode::None; EXPECT_EQ(buildAxes(b, opts, nullptr), nullptr); } // 退化包围盒(全 0)→ nullptr。 TEST(AxesActor, DegenerateBoundsReturnsNull) { double zero[6] = {0, 0, 0, 0, 0, 0}; AxesOptions opts; opts.mode = AxesMode::Standard; EXPECT_EQ(buildAxes(zero, opts, nullptr), nullptr); double inverted[6] = {10, 0, 0, 20, -5, 0}; // xmin>xmax EXPECT_EQ(buildAxes(inverted, opts, nullptr), nullptr); } // 标准模式 + 米:构建非空,几何 bounds 保留,X 显示范围 = 原值。 TEST(AxesActor, StandardMeterKeepsRange) { double b[6] = {0, 100, 0, 200, -50, 0}; AxesOptions opts; opts.mode = AxesMode::Standard; opts.unit = AxesUnit::Meter; auto ax = buildAxes(b, opts, nullptr); ASSERT_NE(ax, nullptr); double xr[2]; ax->GetXAxisRange(xr); EXPECT_NEAR(xr[0], 0.0, 1e-9); EXPECT_NEAR(xr[1], 100.0, 1e-9); // 几何 bounds 不变。 double gb[6]; ax->GetBounds(gb); EXPECT_NEAR(gb[1], 100.0, 1e-9); } // 英尺:显示范围 = 米值 × 3.28084(几何 bounds 仍为米)。 TEST(AxesActor, FeetScalesDisplayRange) { double b[6] = {0, 100, 0, 200, -50, 0}; AxesOptions opts; opts.mode = AxesMode::Standard; opts.unit = AxesUnit::Feet; auto ax = buildAxes(b, opts, nullptr); ASSERT_NE(ax, nullptr); double xr[2]; ax->GetXAxisRange(xr); EXPECT_NEAR(xr[1], 100.0 * kFeetPerMeter, 1e-6); // 几何 bounds 仍是米,不被换算。 double gb[6]; ax->GetBounds(gb); EXPECT_NEAR(gb[1], 100.0, 1e-9); } // 经纬度:X 显示范围反算为经度(在 lon0 附近、随 +x 增大)。 TEST(AxesActor, LatLonUsesFrameReverse) { geopro::core::GeoLocalFrame frame(22.5, 114.16); double b[6] = {0, 1000, 0, 1000, -50, 0}; // 1km 范围 AxesOptions opts; opts.mode = AxesMode::Standard; opts.unit = AxesUnit::LatLon; opts.frame = &frame; auto ax = buildAxes(b, opts, nullptr); ASSERT_NE(ax, nullptr); double xr[2], yr[2]; ax->GetXAxisRange(xr); ax->GetYAxisRange(yr); // x=0 → lon0;x=1000m → 略大于 lon0。 EXPECT_NEAR(xr[0], 114.16, 1e-9); EXPECT_GT(xr[1], 114.16); EXPECT_NEAR(yr[0], 22.5, 1e-9); EXPECT_GT(yr[1], 22.5); } // 经纬度但无 frame → 退化为米(不反算,显示范围 = 原值)。 TEST(AxesActor, LatLonWithoutFrameFallsBackToMeter) { double b[6] = {0, 100, 0, 200, -50, 0}; AxesOptions opts; opts.mode = AxesMode::Standard; opts.unit = AxesUnit::LatLon; opts.frame = nullptr; auto ax = buildAxes(b, opts, nullptr); ASSERT_NE(ax, nullptr); double xr[2]; ax->GetXAxisRange(xr); EXPECT_NEAR(xr[1], 100.0, 1e-9); // 米回退 }