Skip to content

Commit

Permalink
Merge pull request borglab#542 from Alexma3312/sim3
Browse files Browse the repository at this point in the history
Point3 mean to throw an exception when input size=0 .
  • Loading branch information
dellaert authored Sep 29, 2020
2 parents 182dfbd + 983652b commit 6fdf39d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions gtsam/geometry/Point3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ double dot(const Point3 &p, const Point3 &q, OptionalJacobian<1, 3> H1,

Point3Pair mean(const std::vector<Point3Pair> &abPointPairs) {
const size_t n = abPointPairs.size();
if (n == 0) throw std::invalid_argument("Point3::mean input Point3Pair vector is empty");
Point3 aCentroid(0, 0, 0), bCentroid(0, 0, 0);
for (const Point3Pair &abPair : abPointPairs) {
aCentroid += abPair.first;
Expand Down
1 change: 1 addition & 0 deletions gtsam/geometry/Point3.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ GTSAM_EXPORT double dot(const Point3& p, const Point3& q,
/// mean
template <class CONTAINER>
GTSAM_EXPORT Point3 mean(const CONTAINER& points) {
if (points.size() == 0) throw std::invalid_argument("Point3::mean input container is empty");
Point3 sum(0, 0, 0);
sum = std::accumulate(points.begin(), points.end(), sum);
return sum / points.size();
Expand Down

0 comments on commit 6fdf39d

Please sign in to comment.