30#ifndef LSST_SPHGEOM_BOX_H_
31#define LSST_SPHGEOM_BOX_H_
64 static constexpr std::uint8_t TYPE_CODE =
'b';
67 static Box fromDegrees(
double lon1,
double lat1,
double lon2,
double lat2) {
68 return Box(NormalizedAngleInterval::fromDegrees(lon1, lon2),
69 AngleInterval::fromDegrees(lat1, lat2));
72 static Box fromRadians(
double lon1,
double lat1,
double lon2,
double lat2) {
73 return Box(NormalizedAngleInterval::fromRadians(lon1, lon2),
74 AngleInterval::fromRadians(lat1, lat2));
77 static Box empty() {
return Box(); }
90 return NormalizedAngleInterval::full();
107 _enforceInvariants();
117 _enforceInvariants();
126 _enforceInvariants();
135 _enforceInvariants();
140 return _lon == b._lon && _lat == b._lat;
143 bool operator!=(
Box const & b)
const {
return !(*
this == b); }
147 return _lat == p.getLat() && _lon == p.getLon();
150 bool operator!=(
LonLat const & p)
const {
return !(*
this == p); }
159 bool isEmpty()
const override {
return _lat.isEmpty(); }
168 return LonLat(_lon.getCenter(), _lat.getCenter());
183 return _lat.contains(x.getLat()) && _lon.contains(x.getLon());
203 return _lat.intersects(x.getLat()) && _lon.intersects(x.getLon());
215 return _lat.isWithin(x.getLat()) && _lon.isWithin(x.getLon());
228 _enforceInvariants();
238 _enforceInvariants();
281 Box dilatedBy(Angle r)
const {
return Box(*this).dilateBy(r); }
299 Box dilatedBy(Angle w, Angle h)
const {
return Box(*this).dilateBy(w, h); }
301 Box & erodeBy(Angle w, Angle h) {
return dilateBy(-w, -h); }
302 Box erodedBy(Angle r)
const {
return dilatedBy(-r); }
303 Box erodedBy(Angle w, Angle h)
const {
return dilatedBy(-w, -h); }
311 std::unique_ptr<Region>
clone()
const override {
312 return std::unique_ptr<Box>(
new Box(*
this));
337 return ((r1 & r2) & (CONTAINS | WITHIN)) | ((r1 | r2) & DISJOINT);
341 Relationship relate(ConvexPolygon
const &)
const override;
352 std::vector<std::uint8_t>
encode()
const override;
356 static std::unique_ptr<Box>
decode(std::vector<std::uint8_t>
const & s) {
357 return decode(s.data(), s.size());
359 static std::unique_ptr<Box>
decode(std::uint8_t
const * buffer,
size_t n);
363 static constexpr size_t ENCODED_SIZE = 33;
365 void _enforceInvariants() {
374 _lat = AngleInterval();
378 NormalizedAngleInterval _lon;
382std::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:243
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition Box.h:315
bool operator==(LonLat const &p) const
A box is equal to a point p if it contains only p.
Definition Box.h:146
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
Definition Box.h:156
static NormalizedAngle halfWidthForCircle(Angle r, Angle lat)
Definition Box.cc:50
Box()
This constructor creates an empty box.
Definition Box.h:100
NormalizedAngle getWidth() const
Definition Box.h:173
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:271
bool operator==(Box const &b) const
Two boxes are equal if they contain the same points.
Definition Box.h:139
Box(LonLat const &p1, LonLat const &p2)
Definition Box.h:113
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Definition Box.h:153
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition Box.h:319
bool isDisjointFrom(LonLat const &x) const
Definition Box.h:194
static std::unique_ptr< Box > decode(std::vector< std::uint8_t > const &s)
Definition Box.h:356
Box(LonLat const &p)
This constructor creates a box containing a single point.
Definition Box.h:103
bool isFull() const
Definition Box.h:163
std::vector< std::uint8_t > encode() const override
Definition Box.cc:474
bool isEmpty() const override
isEmpty returns true if this box does not contain any points.
Definition Box.h:159
Box & dilateBy(Angle r)
Definition Box.cc:85
Angle getHeight() const
Definition Box.h:177
LonLat getCenter() const
Definition Box.h:167
Box(LonLat const &p, Angle w, Angle h)
Definition Box.h:122
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition Box.h:311
static NormalizedAngleInterval allLongitudes()
Definition Box.h:89
Box & clipTo(Box const &x)
Definition Box.h:235
Box(NormalizedAngleInterval const &lon, AngleInterval const &lat)
Definition Box.h:131
bool isWithin(LonLat const &x) const
Definition Box.h:214
Relationship relate(Region const &r) const override
Definition Box.h:325
Box clippedTo(Box const &x) const
Definition Box.h:248
Box & expandTo(LonLat const &x)
Definition Box.h:254
static AngleInterval allLatitudes()
Definition Box.h:95
TriState overlaps(Region const &other) const override
Definition Box.h:344
bool contains(LonLat const &x) const
Definition Box.h:182
Box & clipTo(LonLat const &x)
Definition Box.h:225
bool intersects(LonLat const &x) const
Definition Box.h:202
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition Box.cc:194
Definition ConvexPolygon.h:65
bool isWithin(Scalar x) const
Definition Interval.h:147
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
Interval & expandTo(Scalar x)
Definition Interval.h:199
bool contains(Scalar x) const
Definition Interval.h:105
Definition NormalizedAngleInterval.h:64
Relationship relate(NormalizedAngle x) const
Definition NormalizedAngleInterval.cc:95
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
Definition NormalizedAngle.h:50
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.
virtual TriState overlaps(Region const &other) const =0
Definition Region.cc:59
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