23 #ifndef LSST_SPHGEOM_BOX_H_
24 #define LSST_SPHGEOM_BOX_H_
56 static constexpr uint8_t TYPE_CODE =
'b';
59 static Box fromDegrees(
double lon1,
double lat1,
double lon2,
double lat2) {
60 return Box(NormalizedAngleInterval::fromDegrees(lon1, lon2),
61 AngleInterval::fromDegrees(lat1, lat2));
64 static Box fromRadians(
double lon1,
double lat1,
double lon2,
double lat2) {
65 return Box(NormalizedAngleInterval::fromRadians(lon1, lon2),
66 AngleInterval::fromRadians(lat1, lat2));
69 static Box empty() {
return Box(); }
82 return NormalizedAngleInterval::full();
109 _enforceInvariants();
118 _enforceInvariants();
127 _enforceInvariants();
132 return _lon == b._lon && _lat == b._lat;
135 bool operator!=(
Box const & b)
const {
return !(*
this == b); }
139 return _lat == p.getLat() && _lon == p.getLon();
142 bool operator!=(
LonLat const & p)
const {
return !(*
this == p); }
220 _enforceInvariants();
230 _enforceInvariants();
273 Box dilatedBy(Angle r)
const {
return Box(*this).dilateBy(r); }
291 Box dilatedBy(Angle w, Angle h)
const {
return Box(*this).dilateBy(w, h); }
293 Box & erodeBy(Angle w, Angle h) {
return dilateBy(-w, -h); }
294 Box erodedBy(Angle r)
const {
return dilatedBy(-r); }
295 Box erodedBy(Angle w, Angle h)
const {
return dilatedBy(-w, -h); }
303 std::unique_ptr<Region>
clone()
const override {
304 return std::unique_ptr<Box>(
new Box(*
this));
329 return ((r1 & r2) & (CONTAINS | WITHIN)) | ((r1 | r2) & DISJOINT);
332 Relationship relate(Circle
const &)
const override;
333 Relationship relate(ConvexPolygon
const &)
const override;
334 Relationship relate(Ellipse
const &)
const override;
336 std::vector<uint8_t>
encode()
const override;
340 static std::unique_ptr<Box>
decode(std::vector<uint8_t>
const & s) {
341 return decode(s.data(), s.size());
343 static std::unique_ptr<Box>
decode(uint8_t
const * buffer,
size_t n);
347 static constexpr
size_t ENCODED_SIZE = 33;
349 void _enforceInvariants() {
358 _lat = AngleInterval();
362 NormalizedAngleInterval _lon;
366 std::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:40
Box & clipTo(Box const &x)
Definition: Box.h:227
Box clippedTo(LonLat const &x) const
clippedTo returns the intersection of this box and x.
Definition: Box.h:235
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition: Box.h:307
bool operator==(LonLat const &p) const
A box is equal to a point p if it contains only p.
Definition: Box.h:138
static NormalizedAngle halfWidthForCircle(Angle r, Angle lat)
Definition: Box.cc:43
Box()
This constructor creates an empty box.
Definition: Box.h:92
std::vector< uint8_t > encode() const override
Definition: Box.cc:447
NormalizedAngle getWidth() const
Definition: Box.h:165
double getArea() const
getArea returns the area of this box in steradians.
Definition: Box.cc:115
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition: Box.cc:127
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
Definition: Box.h:148
Box & clipTo(LonLat const &x)
Definition: Box.h:217
Box expandedTo(LonLat const &x) const
Definition: Box.h:263
bool operator==(Box const &b) const
Two boxes are equal if they contain the same points.
Definition: Box.h:131
Box(LonLat const &p1, LonLat const &p2)
Definition: Box.h:105
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition: Box.h:311
bool isDisjointFrom(LonLat const &x) const
Definition: Box.h:186
Box & expandTo(LonLat const &x)
Definition: Box.h:246
static std::unique_ptr< Box > decode(std::vector< uint8_t > const &s)
Definition: Box.h:340
Box(LonLat const &p)
This constructor creates a box containing a single point.
Definition: Box.h:95
bool isFull() const
Definition: Box.h:155
virtual bool contains(UnitVector3d const &) const=0
contains tests whether the given unit vector is inside this region.
Box & dilateBy(Angle r)
Definition: Box.cc:78
Angle getHeight() const
Definition: Box.h:169
LonLat getCenter() const
Definition: Box.h:159
Box(LonLat const &p, Angle w, Angle h)
Definition: Box.h:114
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Definition: Box.h:145
static NormalizedAngleInterval allLongitudes()
Definition: Box.h:81
Box(NormalizedAngleInterval const &lon, AngleInterval const &lat)
Definition: Box.h:123
bool isWithin(LonLat const &x) const
Definition: Box.h:206
Relationship relate(Region const &r) const override
Definition: Box.h:317
Box clippedTo(Box const &x) const
Definition: Box.h:240
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Box.h:303
static AngleInterval allLatitudes()
Definition: Box.h:87
bool contains(LonLat const &x) const
Definition: Box.h:174
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition: Box.h:151
bool intersects(LonLat const &x) const
Definition: Box.h:194
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition: Box.cc:187
bool isWithin(Scalar x) const
Definition: Interval.h:140
Interval & expandTo(Scalar x)
Definition: Interval.h:192
Scalar getSize() const
Definition: Interval.h:93
Interval & clipTo(Scalar x)
Definition: Interval.h:159
bool isEmpty() const
isEmpty returns true if this interval does not contain any points.
Definition: Interval.h:83
Relationship relate(Scalar x) const
Definition: Interval.h:249
bool intersects(Scalar x) const
Definition: Interval.h:130
Scalar getCenter() const
Definition: Interval.h:89
bool contains(Scalar x) const
Definition: Interval.h:98
Definition: NormalizedAngle.h:43
Definition: NormalizedAngleInterval.h:57
NormalizedAngleInterval & clipTo(NormalizedAngle x)
clipTo shrinks this interval until all its points are in x.
Definition: NormalizedAngleInterval.h:203
bool isFull() const
isFull returns true if this interval contains all normalized angles.
Definition: NormalizedAngleInterval.h:129
NormalizedAngle getCenter() const
Definition: NormalizedAngleInterval.h:139
Relationship relate(NormalizedAngle x) const
Definition: NormalizedAngleInterval.cc:88
NormalizedAngle getSize() const
Definition: NormalizedAngleInterval.h:145
NormalizedAngleInterval & expandTo(NormalizedAngle x)
Definition: NormalizedAngleInterval.cc:189
bool intersects(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:173
bool isWithin(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:185
bool contains(NormalizedAngle x) const
Definition: NormalizedAngleInterval.h:150
bool isEmpty() const
Definition: NormalizedAngleInterval.h:126
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:55
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
Relationship invert(Relationship r)
Definition: Relationship.h:55