51 if (r <=
Angle(0.0)) {
118 _enforceInvariants();
130 double dz = sin(_lat.
getB()) - sin(_lat.
getA());
141 double slata = sin(_lat.
getA()), clata = cos(_lat.
getA());
142 double slatb = sin(_lat.
getB()), clatb = cos(_lat.
getB());
143 double slona = sin(_lon.
getA()), clona = cos(_lon.
getA());
144 double slonb = sin(_lon.
getB()), clonb = cos(_lon.
getB());
204 if (
w.asRadians() <=
PI) {
268 double phi1, phi2, phi3;
269 double c = cos(0.5 *
w);
281 if (phi1 <= phi3 && phi3 <= phi2) {
286 if (p1.
dot(boxVerts[0]) > p2.
dot(boxVerts[1])) {
295 double cl2 = (p - boxVerts[0]).getSquaredNorm();
296 for (
int i = 1; i < 4; ++i) {
297 cl2 =
std::max(cl2, (p - boxVerts[i]).getSquaredNorm());
318 if (!_lon.
isFull() && 0.5 *
w < r) {
328 return CONTAINS | DISJOINT | WITHIN;
330 return DISJOINT | WITHIN;
332 return CONTAINS | DISJOINT;
336 return CONTAINS | WITHIN;
355 for (
int i = 0; i < 4; ++i) {
357 double d = (verts[i] - c.
getCenter()).getSquaredNorm();
366 }
else if (inside !=
b) {
378 for (
int i = 0; i < 2; ++i) {
380 c.
getCenter(), verts[2 * i + 1], verts[2 * i], norms[i]);
416 for (
int i = 0; i < 2; ++i) {
418 c.
getCenter(), verts[2 * i + 1], verts[2 * i], norms[i]);
467 if (buffer ==
nullptr || n != ENCODED_SIZE || *buffer !=
TYPE_CODE) {
478 box->_enforceInvariants();
483 return os <<
"{\"Box\": [" <<
b.getLon() <<
", " <<
b.getLat() <<
"]}";
This file declares a class for representing axis-aligned bounding boxes in ℝ³.
This file declares a class for representing circular regions on the unit sphere.
This file declares a class for representing convex polygons with great circle edges on the unit spher...
Angle represents an angle in radians.
bool isNan() const
isNan returns true if the angle value is NaN.
double asRadians() const
asRadians returns the value of this angle in units of radians.
AngleInterval represents closed intervals of arbitrary angles.
static AngleInterval fromRadians(double x, double y)
Box3d represents a box in ℝ³.
static Box3d aroundUnitSphere()
aroundUnitSphere returns a minimal Box3d containing the unit sphere.
Box represents a rectangle in spherical coordinate space that contains its boundary.
static NormalizedAngle halfWidthForCircle(Angle r, Angle lat)
halfWidthForCircle computes the half-width of bounding boxes for circles with radius r and centers at...
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
NormalizedAngle getWidth() const
getWidth returns the width in longitude angle of this box.
double getArea() const
getArea returns the area of this box in steradians.
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Relationship relate(LonLat const &p) const
static std::unique_ptr< Box > decode(std::vector< uint8_t > const &s)
bool isFull() const
isFull returns true if this box contains all points on the unit sphere.
static constexpr uint8_t TYPE_CODE
Box & dilateBy(Angle r)
dilateBy minimally expands this Box to include all points within angular separation r of its boundary...
bool contains(LonLat const &x) const
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Circle is a circular region on the unit sphere that contains its boundary.
double getSquaredChordLength() const
getSquaredChordLength returns the squared length of chords between the circle center and points on th...
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
static double squaredChordLengthFor(Angle openingAngle)
squaredChordLengthFor computes and returns the squared chord length between points in S² that are sep...
ConvexPolygon is a closed convex polygon on the unit sphere.
Relationship relate(Region const &r) const override
Ellipse is an elliptical region on the sphere.
Relationship relate(Region const &r) const override
Interval1d represents closed intervals of ℝ.
Scalar getCenter() const
getCenter returns the center of this interval.
Scalar getA() const
getA returns the lower endpoint of this interval.
bool contains(Scalar x) const
Scalar getB() const
getB returns the upper endpoint of this interval.
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
NormalizedAngle getLon() const
NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle ca...
double asRadians() const
asRadians returns the value of this angle in units of radians.
bool isFull() const
isFull returns true if this interval contains all normalized angles.
NormalizedAngle getA() const
getA returns the first endpoint of this interval.
NormalizedAngle getCenter() const
getCenter returns the center of this interval.
NormalizedAngleInterval & dilateBy(Angle x)
NormalizedAngle getSize() const
getSize returns the size (length, width) of this interval.
NormalizedAngle getB() const
getB returns the second endpoint of this interval.
static NormalizedAngleInterval fromRadians(double a, double b)
bool contains(NormalizedAngle x) const
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
double dot(Vector3d const &v) const
dot returns the inner product of this unit vector and v.
static UnitVector3d orthogonalTo(Vector3d const &v)
orthogonalTo returns an arbitrary unit vector that is orthogonal to v.
This file contains simple helper functions for encoding and decoding primitive types to/from byte str...
Angle getMinAngleToCircle(Angle x, Angle c)
getMinAngleToCircle returns the minimum angular separation between a point at latitude x and the poin...
constexpr double MAX_ASIN_ERROR
Angle abs(Angle const &a)
void encodeDouble(double item, std::vector< uint8_t > &buffer)
encodeDouble appends an IEEE double in little-endian byte order to the end of buffer.
std::ostream & operator<<(std::ostream &, Angle const &)
double getMaxSquaredChordLength(Vector3d const &v, Vector3d const &a, Vector3d const &b, Vector3d const &n)
Let p be the unit vector furthest from v that lies on the plane with normal n in the direction of the...
double getMinSquaredChordLength(Vector3d const &v, Vector3d const &a, Vector3d const &b, Vector3d const &n)
Let p be the unit vector closest to v that lies on the plane with normal n in the direction of the cr...
constexpr double MAX_SQUARED_CHORD_LENGTH_ERROR
double tan(Angle const &a)
double decodeDouble(uint8_t const *buffer)
decodeDouble extracts an IEEE double from the 8 byte little-endian byte sequence in buffer.
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
This file declares a class for representing longitude/latitude angle boxes on the unit sphere.
This file declares a class for representing elliptical regions on the unit sphere.
This file declares miscellaneous utility functions.