feat(core): Grid 增 NaN 约定 + hasValue(凸包裁剪用)

This commit is contained in:
gaozheng 2026-06-11 11:34:11 +08:00
parent 467dbb3841
commit 179f46b42c
2 changed files with 12 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <cstddef> #include <cstddef>
#include <cmath>
namespace geopro::core { namespace geopro::core {
// 规则三维标量场IInterpolator 输出render 层转 vtkImageData // 规则三维标量场IInterpolator 输出render 层转 vtkImageData
@ -24,12 +25,14 @@ private:
}; };
// 规则二维网格剖面x=距离 i, y=深度 j。values 存 [j*nx + i]i 最快。 // 规则二维网格剖面x=距离 i, y=深度 j。values 存 [j*nx + i]i 最快。
// NaN 值=无效/测区外(凸包裁剪据此)。
class Grid { class Grid {
public: public:
Grid(int nx, int ny) : nx_(nx), ny_(ny), values_(static_cast<size_t>(nx) * ny, 0.0) {} Grid(int nx, int ny) : nx_(nx), ny_(ny), values_(static_cast<size_t>(nx) * ny, 0.0) {}
int nx() const { return nx_; } int ny() const { return ny_; } int nx() const { return nx_; } int ny() const { return ny_; }
double& valueAt(int i, int j) { return values_[static_cast<size_t>(j) * nx_ + i]; } double& valueAt(int i, int j) { return values_[static_cast<size_t>(j) * nx_ + i]; }
double valueAt(int i, int j) const { return values_[static_cast<size_t>(j) * nx_ + i]; } double valueAt(int i, int j) const { return values_[static_cast<size_t>(j) * nx_ + i]; }
bool hasValue(int i, int j) const { return !std::isnan(valueAt(i, j)); }
const std::vector<double>& values() const { return values_; } const std::vector<double>& values() const { return values_; }
std::vector<double>& values() { return values_; } std::vector<double>& values() { return values_; }
std::vector<double> x, y; // 轴坐标(规则) std::vector<double> x, y; // 轴坐标(规则)

View File

@ -23,3 +23,12 @@ TEST(DataModel, AnomalyHolds) {
EXPECT_EQ(a.markType, AnomalyMarkType::Polyline); EXPECT_EQ(a.markType, AnomalyMarkType::Polyline);
EXPECT_EQ(a.localPts.size(), 2u); EXPECT_EQ(a.localPts.size(), 2u);
} }
#include <cmath>
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));
}