Skip to content

Add missing std::isfinite check for mean[2] in 3D approximation classes#155

Merged
davideberly merged 1 commit intodavideberly:masterfrom
CodeReclaimers:fix/appr-3d-isfinite-mean2
Feb 28, 2026
Merged

Add missing std::isfinite check for mean[2] in 3D approximation classes#155
davideberly merged 1 commit intodavideberly:masterfrom
CodeReclaimers:fix/appr-3d-isfinite-mean2

Conversation

@CodeReclaimers
Copy link
Contributor

Summary

  • ApprOrthogonalLine3.h, ApprGaussian3.h, ApprHeightPlane3.h checked std::isfinite(mean[0]) && std::isfinite(mean[1]) but omitted std::isfinite(mean[2])
  • When z-coordinates produce a non-finite mean (e.g. NaN from inf + (-inf)), the fitting functions proceed into the computation block and can return true with NaN in the output parameters
  • The corresponding 2D classes correctly check all components

Test plan

test_issue_2_8.cpp
// Points with finite x,y but z = +inf and z = -inf, so mean[2] = NaN.
// Without fix: Fit() returns true with NaN parameters.
// With fix: Fit() returns false (correctly rejects non-finite mean).

#include <Mathematics/Logger.h>
#include <Mathematics/ApprHeightPlane3.h>

int main()
{
    double inf = std::numeric_limits<double>::infinity();
    std::vector<gte::Vector3<double>> points = {
        gte::Vector3<double>{ 1.0, 0.0,  inf },
        gte::Vector3<double>{ 0.0, 1.0, -inf },
        gte::Vector3<double>{ -1.0, -1.0, 1.0 }
    };

    gte::ApprHeightPlane3<double> fitter;
    bool result = fitter.Fit(points.size(), points.data());
    // Before fix: result=true, parameters contain NaN -> FAIL
    // After fix: result=false -> PASS
}

Before fix: Fit() returns true with NaN in the fitted plane parameters
After fix: Fit() correctly returns false

🤖 Generated with Claude Code

ApprOrthogonalLine3, ApprGaussian3, and ApprHeightPlane3 checked
std::isfinite for mean[0] and mean[1] but not mean[2]. When z-coordinates
produce a non-finite mean (e.g. NaN from inf + (-inf)), the fitting
functions could return true with NaN in the output parameters.

The corresponding 2D classes (ApprOrthogonalLine2, ApprGaussian2) correctly
check all components.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davideberly davideberly merged commit 8584835 into davideberly:master Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants