Unverified Commit c89add10 authored by Oleg Alexandrov's avatar Oleg Alexandrov Committed by GitHub
Browse files

Brent root fix (#362)

* Bugfix for brent_root: It could fail to identify the bracket correctly

* Refine the bugfix per Wikipedia, and fix the test
parent 5ef20008
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -296,6 +296,12 @@ double brentRoot(double lowerBound, double upperBound,
    previousPoint = currentPoint;
    previousFunc = currentFunc;
    nextFunc = func(nextPoint);

    // This is a bugfix. Without it, the code gets lost and can't find the solution.
    // See also the implementation at https://en.wikipedia.org/wiki/Brent%27s_method
    if (nextFunc == 0)
      return nextPoint;

    if (counterFunc * nextFunc < 0) {
      currentPoint = nextPoint;
      currentFunc = nextFunc;
+2 −2
Original line number Diff line number Diff line
@@ -84,10 +84,10 @@ TEST_F(SarSensorModel, computeGroundPartials) {
  ASSERT_EQ(partials.size(), 6);
  EXPECT_NEAR(partials[0], 6.5128150576280552e-09, 1e-8);
  EXPECT_NEAR(partials[1], -5.1810407815840636e-15, 1e-8);
  EXPECT_NEAR(partials[2], -0.13309947654685725, 1e-8);
  EXPECT_NEAR(partials[2], -0.13333333443071135, 1e-8);
  EXPECT_NEAR(partials[3], -33.057625791698072, 1e-8);
  EXPECT_NEAR(partials[4], 6.1985123841926308e-05, 1e-8);
  EXPECT_NEAR(partials[5], 0.007743051337209989, 1e-8);
  EXPECT_NEAR(partials[5], 0.0077565105243007169, 1e-8);
}

TEST_F(SarSensorModel, imageToProximateImagingLocus) {