#include #include "ContourBands.hpp" using namespace geopro::core; using namespace geopro::render; // 上采样 2x:色带边界更密 → 多边形数应多于不上采样。 TEST(ContourBands, UpsampleIncreasesDetail) { Grid g(3, 3); g.x = {0, 1, 2}; g.y = {0, 1, 2}; for (int j = 0; j < 3; ++j) for (int i = 0; i < 3; ++i) g.valueAt(i, j) = static_cast(i * i + j); g.vmin = 0; g.vmax = 6; ColorScale cs; cs.addStop(0, Rgba{0,0,255,255}); cs.addStop(3, Rgba{0,255,0,255}); cs.addStop(6, Rgba{255,0,0,255}); ContourOptions a; a.upsample = 1; a.smooth = 0; a.simplifyTol = 0; ContourOptions b; b.upsample = 2; b.smooth = 0; b.simplifyTol = 0; auto ra = buildContourBands(g, cs, a); auto rb = buildContourBands(g, cs, b); EXPECT_GT(rb.bands.size(), ra.bands.size()); } // 2x2 平滑梯度网格 + 2 段色阶 → 至少 1 个色带多边形,多边形顶点 >=3。 TEST(ContourBands, ProducesNonEmptyBands) { Grid g(3, 3); g.x = {0, 1, 2}; g.y = {0, 1, 2}; for (int j = 0; j < 3; ++j) for (int i = 0; i < 3; ++i) g.valueAt(i, j) = static_cast(i + j); // 0..4 g.vmin = 0; g.vmax = 4; ColorScale cs; cs.addStop(0.0, Rgba{0, 0, 255, 255}); cs.addStop(2.0, Rgba{0, 255, 0, 255}); cs.addStop(4.0, Rgba{255, 0, 0, 255}); ContourOptions opt; opt.upsample = 1; opt.smooth = 0; opt.simplifyTol = 0; auto r = buildContourBands(g, cs, opt); ASSERT_FALSE(r.bands.empty()); for (const auto& b : r.bands) EXPECT_GE(b.ring.size(), 3u); }