24 #include "mongo/util/assert_util.h"
66 template <
typename TCoordinates>
81 BoundingBox(
const TCoordinates& min,
const TCoordinates& max);
169 template <
typename TCoordinates>
171 : _min(min), _max(max) {}
173 template <
typename TCoordinates>
178 uassert(0,
"bson argument to BoundingBox ctor must define the field \"bbox\"", !bbox.
eoo());
180 std::vector<BSONElement> bboxCoords = bbox.Array();
185 const size_t n = TCoordinates::dimensionality();
187 "bbox field must have exactly 2 * n elements, where n is the number of dimensions "
188 "in the coordinate system",
189 bboxCoords.size() == 2 * n);
192 std::vector<double> minCoords, maxCoords;
193 for (
size_t i = 0; i < n; ++i) {
194 minCoords.push_back(bboxCoords[i].Double());
195 maxCoords.push_back(bboxCoords[n + i].Double());
197 _min = TCoordinates(minCoords);
198 _max = TCoordinates(maxCoords);
201 template <
typename TCoordinates>
203 return BSON(kBoundingBoxFieldName << toBSONArray());
206 template <
typename TCoordinates>
209 std::vector<double> minCoords = _min.getValues();
210 std::vector<double> maxCoords = _max.getValues();
211 for (
size_t i = 0; i < minCoords.size(); ++i)
212 bab.append(minCoords[i]);
213 for (
size_t i = 0; i < maxCoords.size(); ++i)
214 bab.append(maxCoords[i]);
218 template <
typename TCoordinates>
221 std::vector<double> minCoords = _min.getValues();
222 std::vector<double> maxCoords = _max.getValues();
223 for (
size_t i = 0; i < minCoords.size(); ++i)
224 minBab.append(minCoords[i]);
225 for (
size_t i = 0; i < maxCoords.size(); ++i)
226 maxBab.append(maxCoords[i]);
227 return BSON_ARRAY(minBab.
arr() << maxBab.
arr());
TCoordinates getMax() const
Get the maximum coordinates of this bounding box.
Definition: boundingbox.h:122
BSONArray arr()
destructive - ownership moves to returned BSONArray
Definition: bsonobjbuilder.h:804
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
TCoordinates getMin() const
Get the minimum coordinates of this bounding box.
Definition: boundingbox.h:112
BoundingBox(const TCoordinates &min, const TCoordinates &max)
BoundingBox constructor.
Definition: boundingbox.h:170
BSONElement getField(const StringData &name) const
Get the field of the specified name.
BSONObj toBSON() const
Obtain a BSON representation of this bounding box.
Definition: boundingbox.h:202
bool eoo() const
Indicates if it is the end-of-object element, which is present at the end of every BSON object...
Definition: bsonelement.h:172
BSONElement represents an "element" in a BSONObj.
Definition: bsonelement.h:55
Definition: bsonobj.h:581
Definition: bsonobjbuilder.h:765
BSONArray toBSONArray() const
Obtain a flat BSONArray representation of the coordinate values defined by this bounding box...
Definition: boundingbox.h:207
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78
BSONArray toNestedBSONArray() const
Obtain a nested BSONArray representation of the coordinate values defined by this bounding box...
Definition: boundingbox.h:219
Represents a bounding box.
Definition: boundingbox.h:67