24#include "mongo/util/assert_util.h"
66template <
typename TCoordinates>
81 BoundingBox(
const TCoordinates& min,
const TCoordinates& max);
169template <
typename TCoordinates>
171 : _min(min), _max(max) {}
173template <
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);
201template <
typename TCoordinates>
206template <
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]);
218template <
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());
Definition bsonobjbuilder.h:765
BSONArray arr()
destructive - ownership moves to returned BSONArray
Definition bsonobjbuilder.h:804
BSONElement represents an "element" in a BSONObj.
Definition bsonelement.h:55
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
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
BSONElement getField(const StringData &name) const
Get the field of the specified name.
Represents a bounding box.
Definition boundingbox.h:67
TCoordinates getMin() const
Get the minimum coordinates of this bounding box.
Definition boundingbox.h:112
TCoordinates getMax() const
Get the maximum coordinates of this bounding box.
Definition boundingbox.h:122
BSONArray toBSONArray() const
Obtain a flat BSONArray representation of the coordinate values defined by this bounding box.
Definition boundingbox.h:207
BSONArray toNestedBSONArray() const
Obtain a nested BSONArray representation of the coordinate values defined by this bounding box.
Definition boundingbox.h:219
BSONObj toBSON() const
Obtain a BSON representation of this bounding box.
Definition boundingbox.h:202
BoundingBox(const TCoordinates &min, const TCoordinates &max)
BoundingBox constructor.
Definition boundingbox.h:170
const char kBoundingBoxFieldName[]
The special field names defined by the GeoJSON specification.
Definition constants.h:26
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20