diff --git a/gtsam/base/std_optional_serialization.h b/gtsam/base/std_optional_serialization.h index 3dac79284..22a4369e8 100644 --- a/gtsam/base/std_optional_serialization.h +++ b/gtsam/base/std_optional_serialization.h @@ -1,6 +1,7 @@ // A hack to serialize std::optional to boost::archive // Don't know if it will work. Trying to follow this: // PR: https://github.com/boostorg/serialization/pull/148/files# +#pragma once #include #include diff --git a/gtsam/geometry/Point2.cpp b/gtsam/geometry/Point2.cpp index 06c32526b..54c94addb 100644 --- a/gtsam/geometry/Point2.cpp +++ b/gtsam/geometry/Point2.cpp @@ -52,7 +52,7 @@ double distance2(const Point2& p, const Point2& q, OptionalJacobian<1, 2> H1, /* ************************************************************************* */ // Math inspired by http://paulbourke.net/geometry/circlesphere/ -boost::optional circleCircleIntersection(double R_d, double r_d, +std::optional circleCircleIntersection(double R_d, double r_d, double tol) { double R2_d2 = R_d*R_d; // Yes, RD-D2 ! @@ -61,17 +61,17 @@ boost::optional circleCircleIntersection(double R_d, double r_d, // h^2<0 is equivalent to (d > (R + r) || d < (R - r)) // Hence, there are only solutions if >=0 - if (h2<-tol) return boost::none; // allow *slightly* negative + if (h2<-tol) return {}; // allow *slightly* negative else if (h2 circleCircleIntersection(Point2 c1, Point2 c2, - boost::optional fh) { + std::optional fh) { list solutions; - // If fh==boost::none, there are no solutions, i.e., d > (R + r) || d < (R - r) + // If fh==std::nullopt, there are no solutions, i.e., d > (R + r) || d < (R - r) if (fh) { // vector between circle centers Point2 c12 = c2-c1; @@ -107,7 +107,7 @@ list circleCircleIntersection(Point2 c1, double r1, Point2 c2, // Calculate f and h given normalized radii double _d = 1.0/d, R_d = r1*_d, r_d=r2*_d; - boost::optional fh = circleCircleIntersection(R_d,r_d); + std::optional fh = circleCircleIntersection(R_d,r_d); // Call version that takes fh return circleCircleIntersection(c1, c2, fh); diff --git a/gtsam/geometry/Point2.h b/gtsam/geometry/Point2.h index d8b6daca8..2b4f48197 100644 --- a/gtsam/geometry/Point2.h +++ b/gtsam/geometry/Point2.h @@ -18,8 +18,11 @@ #pragma once #include +#include #include +#include + namespace gtsam { /// As of GTSAM 4, in order to make GTSAM more lean, @@ -62,7 +65,7 @@ inline Point2 operator*(double s, const Point2& p) { * @param tol: absolute tolerance below which we consider touching circles * @return optional Point2 with f and h, boost::none if no solution. */ -GTSAM_EXPORT boost::optional circleCircleIntersection(double R_d, double r_d, double tol = 1e-9); +GTSAM_EXPORT std::optional circleCircleIntersection(double R_d, double r_d, double tol = 1e-9); /* * @brief Circle-circle intersection, from the normalized radii solution. @@ -70,7 +73,7 @@ GTSAM_EXPORT boost::optional circleCircleIntersection(double R_d, double * @param c2 center of second circle * @return list of solutions (0,1, or 2). Identical circles will return empty list, as well. */ -GTSAM_EXPORT std::list circleCircleIntersection(Point2 c1, Point2 c2, boost::optional fh); +GTSAM_EXPORT std::list circleCircleIntersection(Point2 c1, Point2 c2, std::optional fh); /// Calculate the two means of a set of Point2 pairs GTSAM_EXPORT Point2Pair means(const std::vector &abPointPairs); diff --git a/gtsam_unstable/slam/SmartRangeFactor.h b/gtsam_unstable/slam/SmartRangeFactor.h index 301508c0f..d512ed85a 100644 --- a/gtsam_unstable/slam/SmartRangeFactor.h +++ b/gtsam_unstable/slam/SmartRangeFactor.h @@ -19,6 +19,7 @@ #include #include #include +#include namespace gtsam { @@ -105,7 +106,7 @@ class SmartRangeFactor: public NoiseModelFactor { } Circle2 circle1 = circles.front(); - boost::optional best_fh; + std::optional best_fh; auto bestCircle2 = boost::make_optional(false, circle1); // fixes issue #38 // loop over all circles @@ -115,7 +116,7 @@ class SmartRangeFactor: public NoiseModelFactor { if (d < 1e-9) continue; // skip circles that are in the same location // Find f and h, the intersection points in normalized circles - boost::optional fh = circleCircleIntersection( + std::optional fh = circleCircleIntersection( circle1.radius / d, it.radius / d); // Check if this pair is better by checking h = fh->y() // if h is large, the intersections are well defined.