diff --git a/src/core/model/Field.hpp b/src/core/model/Field.hpp index e7c2a2b..6e1d65f 100644 --- a/src/core/model/Field.hpp +++ b/src/core/model/Field.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace geopro::core { // 规则三维标量场(IInterpolator 输出;render 层转 vtkImageData)。 @@ -24,12 +25,14 @@ private: }; // 规则二维网格剖面(x=距离 i, y=深度 j)。values 存 [j*nx + i],i 最快。 +// NaN 值=无效/测区外(凸包裁剪据此)。 class Grid { public: Grid(int nx, int ny) : nx_(nx), ny_(ny), values_(static_cast(nx) * ny, 0.0) {} int nx() const { return nx_; } int ny() const { return ny_; } double& valueAt(int i, int j) { return values_[static_cast(j) * nx_ + i]; } double valueAt(int i, int j) const { return values_[static_cast(j) * nx_ + i]; } + bool hasValue(int i, int j) const { return !std::isnan(valueAt(i, j)); } const std::vector& values() const { return values_; } std::vector& values() { return values_; } std::vector x, y; // 轴坐标(规则) diff --git a/tests/core/test_model_data.cpp b/tests/core/test_model_data.cpp index 701ae4a..51e99d7 100644 --- a/tests/core/test_model_data.cpp +++ b/tests/core/test_model_data.cpp @@ -23,3 +23,12 @@ TEST(DataModel, AnomalyHolds) { EXPECT_EQ(a.markType, AnomalyMarkType::Polyline); EXPECT_EQ(a.localPts.size(), 2u); } + +#include +TEST(GridNaN, HasValueReflectsNaN) { + geopro::core::Grid g(2, 2); + g.valueAt(0, 0) = 3.0; + g.valueAt(1, 0) = std::nan(""); + EXPECT_TRUE(g.hasValue(0, 0)); + EXPECT_FALSE(g.hasValue(1, 0)); +}