49 if (a.asRadians() < 0.0) {
52 if (a.asRadians() >=
PI) {
55 double s =
sin(0.5 * a);
62 if (squaredChordLength < 0.0) {
65 if (squaredChordLength >= 4.0) {
82 return _openingAngle >
94 return cc > _openingAngle +
x._openingAngle +
111 Angle a = _openingAngle;
142 Angle o = 0.5 * (cx + _openingAngle);
143 Angle r = 0.5 * (cx - _openingAngle);
173 Angle o = 0.5 * (cc + _openingAngle +
x._openingAngle);
184 Angle r = o - _openingAngle;
196 (r.asRadians() > 0.0 || r.asRadians() < 0.0)) {
197 Angle o = _openingAngle + r;
207 _squaredChordLength = 4.0;
211 _squaredChordLength = -1.0;
212 _openingAngle =
Angle(-1.0);
215 _squaredChordLength = 4.0 - _squaredChordLength;
216 _openingAngle =
Angle(
PI) - _openingAngle;
230 static double const MAX_BOUNDARY_ERROR = 6.2e-16;
255 double s =
sin(_openingAngle);
256 double c =
cos(_openingAngle);
257 for (
int i = 0; i < 3; ++i) {
258 double ci = _center(i);
260 double bmin = 1.0, bmax = -1.0;
261 if (2.0 - 2.0 * ci <= _squaredChordLength) {
264 if (2.0 + 2.0 * ci <= _squaredChordLength) {
267 double b0 = ci * c + di * s;
268 bmax =
std::max(bmax, b0 + MAX_BOUNDARY_ERROR);
269 bmin =
std::min(bmin, b0 - MAX_BOUNDARY_ERROR);
270 double b1 = ci * c - di * s;
271 bmax =
std::max(bmax, b1 + MAX_BOUNDARY_ERROR);
272 bmin =
std::min(bmin, b1 - MAX_BOUNDARY_ERROR);
275 return Box3d(e[0], e[1], e[2]);
282 return DISJOINT | WITHIN;
289 return invert(
b.relate(*
this));
295 return CONTAINS | DISJOINT | WITHIN;
297 return DISJOINT | WITHIN;
299 return CONTAINS | DISJOINT;
304 return CONTAINS | WITHIN;
313 return CONTAINS | WITHIN;
341 return b.overlaps(*
this);
372 if (buffer ==
nullptr || n != ENCODED_SIZE || *buffer !=
TYPE_CODE) {
380 double squaredChordLength =
decodeDouble(buffer); buffer += 8;
381 double openingAngle =
decodeDouble(buffer); buffer += 8;
383 circle->_squaredChordLength = squaredChordLength;
384 circle->_openingAngle =
Angle(openingAngle);
391 return os <<
"{\"Circle\": [" << c.
getCenter() << tail;
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.
double asRadians() const
asRadians returns the value of this angle in units of radians.
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...
Circle is a circular region on the unit sphere that contains its boundary.
static constexpr std::uint8_t TYPE_CODE
bool contains(Circle const &x) const
contains returns true if the intersection of this circle and x is equal to x.
static Angle openingAngleFor(double squaredChordLength)
openingAngleFor computes and returns the angular separation between points in S² that are separated b...
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Circle & clipTo(UnitVector3d const &x)
Circle & dilateBy(Angle r)
If r is positive, dilateBy increases the opening angle of this circle to include all points within an...
TriState overlaps(Region const &other) const override
bool isDisjointFrom(UnitVector3d const &x) const
std::vector< std::uint8_t > encode() const override
encode serializes this region into an opaque byte string.
static std::unique_ptr< Circle > decode(std::vector< std::uint8_t > const &s)
Relationship relate(UnitVector3d const &v) const
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.
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Circle & complement()
complement sets this circle to the closure of its complement.
Circle & expandTo(UnitVector3d const &x)
Circle()
This constructor creates an empty circle.
static double squaredChordLengthFor(Angle openingAngle)
squaredChordLengthFor computes and returns the squared chord length between points in S² that are sep...
bool isEmpty() const override
isEmpty returns true when a region does not contain any points.
ConvexPolygon is a closed convex polygon on the unit sphere.
TriState overlaps(Region const &other) const override
Relationship relate(Region const &r) const override
Ellipse is an elliptical region on the sphere.
Relationship relate(Region const &r) const override
TriState overlaps(Region const &other) const override
Interval1d represents closed intervals of ℝ.
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
NormalizedAngle is an angle that lies in the range [0, 2π), with one exception - a NormalizedAngle ca...
TriState represents a boolean value with additional unknown state.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
static UnitVector3d orthogonalTo(Vector3d const &v)
orthogonalTo returns an arbitrary unit vector that is orthogonal to v.
Vector3d cross(Vector3d const &v) const
cross returns the cross product of this unit vector and v.
This file contains simple helper functions for encoding and decoding primitive types to/from byte str...
double decodeDouble(std::uint8_t const *buffer)
decodeDouble extracts an IEEE double from the 8 byte little-endian byte sequence in buffer.
void encodeDouble(double item, std::vector< std::uint8_t > &buffer)
encodeDouble appends an IEEE double in little-endian byte order to the end of buffer.
constexpr double MAX_ASIN_ERROR
std::ostream & operator<<(std::ostream &, Angle const &)
double sin(Angle const &a)
double cos(Angle const &a)
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.