30#ifndef LSST_SPHGEOM_BOX_H_
31#define LSST_SPHGEOM_BOX_H_
63 static constexpr uint8_t TYPE_CODE =
'b';
66 static Box fromDegrees(
double lon1,
double lat1,
double lon2,
double lat2) {
67 return Box(NormalizedAngleInterval::fromDegrees(lon1, lon2),
68 AngleInterval::fromDegrees(lat1, lat2));
71 static Box fromRadians(
double lon1,
double lat1,
double lon2,
double lat2) {
72 return Box(NormalizedAngleInterval::fromRadians(lon1, lon2),
73 AngleInterval::fromRadians(lat1, lat2));
76 static Box empty() {
return Box(); }
89 return NormalizedAngleInterval::full();
106 _enforceInvariants();
116 _enforceInvariants();
125 _enforceInvariants();
134 _enforceInvariants();
139 return _lon == b._lon && _lat == b._lat;
142 bool operator!=(
Box const & b)
const {
return !(*
this == b); }
146 return _lat == p.getLat() && _lon == p.getLon();
149 bool operator!=(
LonLat const & p)
const {
return !(*
this == p); }
227 _enforceInvariants();
237 _enforceInvariants();
280 Box dilatedBy(Angle r)
const {
return Box(*this).dilateBy(r); }
298 Box dilatedBy(Angle w, Angle h)
const {
return Box(*this).dilateBy(w, h); }
299 Box & erodeBy(Angle r) {
return dilateBy(-r); }
300 Box & erodeBy(Angle w, Angle h) {
return dilateBy(-w, -h); }
301 Box erodedBy(Angle r)
const {
return dilatedBy(-r); }
302 Box erodedBy(Angle w, Angle h)
const {
return dilatedBy(-w, -h); }
310 std::unique_ptr<Region>
clone()
const override {
311 return std::unique_ptr<Box>(
new Box(*
this));
336 return ((r1 & r2) & (CONTAINS | WITHIN)) | ((r1 | r2) & DISJOINT);
340 Relationship relate(ConvexPolygon
const &)
const override;
343 std::vector<uint8_t>
encode()
const override;
347 static std::unique_ptr<Box>
decode(std::vector<uint8_t>
const & s) {
348 return decode(s.data(), s.size());
350 static std::unique_ptr<Box>
decode(uint8_t
const * buffer,
size_t n);
354 static constexpr size_t ENCODED_SIZE = 33;
356 void _enforceInvariants() {
365 _lat = AngleInterval();
369 NormalizedAngleInterval _lon;
373std::ostream & operator<<(std::ostream &, Box
const &);
This file defines a class for representing angle intervals.
This file contains a class representing spherical coordinates.
This file declares a class representing closed intervals of normalized angles, i.e....
This file defines an interface for spherical regions.
This file declares a class for representing unit vectors in ℝ³.
AngleInterval represents closed intervals of arbitrary angles.
Definition AngleInterval.h:47
Box clippedTo(LonLat const &x) const
clippedTo returns the intersection of this box and x.
Definition Box.h:242
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition Box.h:314
bool operator==(LonLat const &p) const
A box is equal to a point p if it contains only p.
Definition Box.h:145
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
Definition Box.h:155
static NormalizedAngle halfWidthForCircle(Angle r, Angle lat)
Definition Box.cc:50
Box()
This constructor creates an empty box.
Definition Box.h:99
std::vector< uint8_t > encode() const override
Definition Box.cc:454
NormalizedAngle getWidth() const
Definition Box.h:172
double getArea() const
getArea returns the area of this box in steradians.
Definition Box.cc:122
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition Box.cc:134
Box expandedTo(LonLat const &x) const
Definition Box.h:270
bool operator==(Box const &b) const
Two boxes are equal if they contain the same points.
Definition Box.h:138
Box(LonLat const &p1, LonLat const &p2)
Definition Box.h:112
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Definition Box.h:152
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition Box.h:318
static std::unique_ptr< Box > decode(std::vector< uint8_t > const &s)
Definition Box.h:347
bool isDisjointFrom(LonLat const &x) const
Definition Box.h:193
Box(LonLat const &p)
This constructor creates a box containing a single point.
Definition Box.h:102
bool isFull() const
Definition Box.h:162
Box & dilateBy(Angle r)
Definition Box.cc:85
Angle getHeight() const
Definition Box.h:176
LonLat getCenter() const
Definition Box.h:166
Box(LonLat const &p, Angle w, Angle h)
Definition Box.h:121
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition Box.h:310
static NormalizedAngleInterval allLongitudes()
Definition Box.h:88
Box & clipTo(Box const &x)
Definition Box.h:234
Box(NormalizedAngleInterval const &lon, AngleInterval const &lat)
Definition Box.h:130
bool isWithin(LonLat const &x) const
Definition Box.h:213
Relationship relate(Region const &r) const override
Definition Box.h:324
Box clippedTo(Box const &x) const
Definition Box.h:247
Box & expandTo(LonLat const &x)
Definition Box.h:253
static AngleInterval allLatitudes()
Definition Box.h:94
bool contains(LonLat const &x) const
Definition Box.h:181
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition Box.h:158
Box & clipTo(LonLat const &x)
Definition Box.h:224
bool intersects(LonLat const &x) const
Definition Box.h:201
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition Box.cc:194
bool isWithin(Scalar x) const
Definition Interval.h:147
Scalar getSize() const
Definition Interval.h:100
Interval & clipTo(Scalar x)
Definition Interval.h:166
bool isEmpty() const
isEmpty returns true if this interval does not contain any points.
Definition Interval.h:90
Relationship relate(Scalar x) const
Definition Interval.h:256
bool intersects(Scalar x) const
Definition Interval.h:137
Scalar getCenter() const
Definition Interval.h:96
Interval & expandTo(Scalar x)
Definition Interval.h:199
bool contains(Scalar x) const
Definition Interval.h:105
Definition NormalizedAngle.h:50
Definition NormalizedAngleInterval.h:64
bool isFull() const
isFull returns true if this interval contains all normalized angles.
Definition NormalizedAngleInterval.h:136
NormalizedAngleInterval & clipTo(NormalizedAngle x)
clipTo shrinks this interval until all its points are in x.
Definition NormalizedAngleInterval.h:210
NormalizedAngle getCenter() const
Definition NormalizedAngleInterval.h:146
Relationship relate(NormalizedAngle x) const
Definition NormalizedAngleInterval.cc:95
NormalizedAngle getSize() const
Definition NormalizedAngleInterval.h:152
NormalizedAngleInterval & expandTo(NormalizedAngle x)
Definition NormalizedAngleInterval.cc:196
bool intersects(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:180
bool isWithin(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:192
bool contains(NormalizedAngle x) const
Definition NormalizedAngleInterval.h:157
bool isEmpty() const
Definition NormalizedAngleInterval.h:133
virtual Relationship relate(Region const &) const =0
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
Definition UnitVector3d.h:62
Relationship invert(Relationship r)
Definition Relationship.h:62
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition Relationship.h:42