From 179f46b42c3a65f63c59dfe9cd3dad9fbead5cda Mon Sep 17 00:00:00 2001 From: gaozheng Date: Thu, 11 Jun 2026 11:34:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20Grid=20=E5=A2=9E=20NaN=20?= =?UTF-8?q?=E7=BA=A6=E5=AE=9A=20+=20hasValue=EF=BC=88=E5=87=B8=E5=8C=85?= =?UTF-8?q?=E8=A3=81=E5=89=AA=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/model/Field.hpp | 3 +++ tests/core/test_model_data.cpp | 9 +++++++++ 2 files changed, 12 insertions(+) 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)); +}