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));
315 Box getBoundingBox()
const override {
return *
this; }
316 Box3d getBoundingBox3d()
const override;
317 Circle getBoundingCircle()
const override;
319 bool contains(UnitVector3d
const & v)
const override {
323 using Region::contains;
327 return invert(r.relate(*
this));
337 return ((r1 & r2) & (CONTAINS | WITHIN)) | ((r1 | r2) & DISJOINT);
341 Relationship relate(ConvexPolygon
const &)
const override;
344 TriState overlaps(Region
const& other)
const override {
345 return other.overlaps(*
this);
347 TriState overlaps(
Box const &)
const override;
348 TriState overlaps(Circle
const &)
const override;
349 TriState overlaps(ConvexPolygon
const &)
const override;
350 TriState overlaps(Ellipse
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);
364 std::string
toIvoaStcsBody(std::string
const & frame =
"")
const override;
366 static constexpr size_t ENCODED_SIZE = 33;
368 void _enforceInvariants() {
377 _lat = AngleInterval();
381 NormalizedAngleInterval _lon;
385std::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 ℝ³.
Definition _continue_class.py:109
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
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
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 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
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
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
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
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
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
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 NormalizedAngle.h:50
Definition NormalizedAngleInterval.h:64
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 std::string toIvoaStcsBody(std::string const &frame="") const
virtually.
Definition Region.h:258
Relationship invert(Relationship r)
Definition Relationship.h:62
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition Relationship.h:42