LSST Applications g0265f82a02+6e43cdb38f,g08227fae09+a0048d8a1f,g08a116f7bc+b558f3f931,g2079a07aa2+8986e19ce8,g2b3836372d+aeafac9030,g2bbee38e9b+6e43cdb38f,g337abbeb29+6e43cdb38f,g3435824250+22db99657a,g3ddfee87b4+6b3e986545,g44018dc512+6e43cdb38f,g50ff169b8f+f00c948d2c,g52b1c1532d+81bc2a20b4,g5f6f997623+81bc2a20b4,g6770999e7e+6b3e986545,g7d743f24c3+9b4905acca,g858d7b2824+a0048d8a1f,g99855d9996+0389348573,g9ddcbc5298+fe33e4d80d,ga1e77700b3+22687c87ca,ga8c6da7877+f1d6485c37,gae46bcf261+6e43cdb38f,gb700894bec+4c2d6e2d6e,gba4ed39666+5d7a39cad3,gbeb006f7da+8e9ce45c15,gc72ce4b948+bef421641f,gc86a011abf+a0048d8a1f,gcb20ee0ffd+597c5c75a1,gcf0d15dbbd+6b3e986545,gd162630629+0e4253f749,gdaeeff99f8+6ceac51f81,gdb4ec4c597+6e43cdb38f,gee10cc3b42+81bc2a20b4,gf041782ebf+f5cd4f2466,gf1cff7945b+a0048d8a1f,gf748b16de2+382729e994,w.2024.01
LSST Data Management Base Package
Loading...
Searching...
No Matches
_box.cc
Go to the documentation of this file.
1/*
2 * LSST Data Management System
3 * See COPYRIGHT file at the top of the source tree.
4 *
5 * This product includes software developed by the
6 * LSST Project (http://www.lsst.org/).
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the LSST License Statement and
19 * the GNU General Public License along with this program. If not,
20 * see <https://www.lsstcorp.org/LegalNotices/>.
21 */
22#include "pybind11/pybind11.h"
23#include "pybind11/numpy.h"
24
25#include "lsst/sphgeom/python.h"
26
28#include "lsst/sphgeom/Box.h"
29#include "lsst/sphgeom/Box3d.h"
30#include "lsst/sphgeom/Circle.h"
33#include "lsst/sphgeom/LonLat.h"
35#include "lsst/sphgeom/Region.h"
37
40
41namespace py = pybind11;
42using namespace pybind11::literals;
43
44namespace lsst {
45namespace sphgeom {
46
47template <>
48void defineClass(py::class_<Box, std::unique_ptr<Box>, Region> &cls) {
49 cls.attr("TYPE_CODE") = py::int_(Box::TYPE_CODE);
50
51 cls.def_static("fromDegrees", &Box::fromDegrees, "lon1"_a, "lat1"_a,
52 "lon2"_a, "lat2"_a);
53 cls.def_static("fromRadians", &Box::fromRadians, "lon1"_a, "lat1"_a,
54 "lon2"_a, "lat2"_a);
55 cls.def_static("empty", &Box::empty);
56 cls.def_static("full", &Box::full);
57 cls.def_static("halfWidthForCircle", &Box::halfWidthForCircle, "radius"_a,
58 "lat"_a);
59 cls.def_static("allLongitudes", &Box::allLongitudes);
60 cls.def_static("allLatitudes", &Box::allLatitudes);
61
62 cls.def(py::init<>());
63 cls.def(py::init<LonLat const &>(), "point"_a);
64 cls.def(py::init<LonLat const &, LonLat const &>(), "point1"_a, "point2"_a);
65 cls.def(py::init<LonLat const &, Angle, Angle>(), "center"_a, "width"_a,
66 "height"_a);
67 cls.def(py::init<NormalizedAngleInterval const &, AngleInterval const &>(),
68 "lon"_a, "lat"_a);
69 cls.def(py::init<Box const &>(), "box"_a);
70
71 cls.def("__eq__", (bool (Box::*)(Box const &) const) & Box::operator==,
72 py::is_operator());
73 cls.def("__eq__", (bool (Box::*)(LonLat const &) const) & Box::operator==,
74 py::is_operator());
75 cls.def("__ne__", (bool (Box::*)(Box const &) const) & Box::operator!=,
76 py::is_operator());
77 cls.def("__ne__", (bool (Box::*)(LonLat const &) const) & Box::operator!=,
78 py::is_operator());
79 cls.def("__contains__",
80 (bool (Box::*)(LonLat const &) const) & Box::contains,
81 py::is_operator());
82 cls.def("__contains__", (bool (Box::*)(Box const &) const) & Box::contains,
83 py::is_operator());
84 // Rewrap this base class method since there are overloads in this subclass
85 cls.def("__contains__",
86 (bool (Box::*)(UnitVector3d const &) const) & Box::contains,
87 py::is_operator());
88
89 cls.def("getLon", &Box::getLon);
90 cls.def("getLat", &Box::getLat);
91 cls.def("isEmpty", &Box::isEmpty);
92 cls.def("isFull", &Box::isFull);
93 cls.def("getCenter", &Box::getCenter);
94 cls.def("getWidth", &Box::getWidth);
95 cls.def("getHeight", &Box::getHeight);
96 cls.def("contains", (bool (Box::*)(LonLat const &) const) & Box::contains);
97 cls.def("contains", (bool (Box::*)(Box const &) const) & Box::contains);
98 // Rewrap these base class methods since there are overloads in this subclass
99 cls.def("contains",
100 (bool (Box::*)(UnitVector3d const &) const) & Box::contains);
101 cls.def("contains", py::vectorize((bool (Box::*)(double, double, double) const)&Box::contains),
102 "x"_a, "y"_a, "z"_a);
103 cls.def("contains", py::vectorize((bool (Box::*)(double, double) const)&Box::contains),
104 "lon"_a, "lat"_a);
105 cls.def("isDisjointFrom",
106 (bool (Box::*)(LonLat const &) const) & Box::isDisjointFrom);
107 cls.def("isDisjointFrom",
108 (bool (Box::*)(Box const &) const) & Box::isDisjointFrom);
109 cls.def("intersects",
110 (bool (Box::*)(LonLat const &) const) & Box::intersects);
111 cls.def("intersects", (bool (Box::*)(Box const &) const) & Box::intersects);
112 cls.def("isWithin", (bool (Box::*)(LonLat const &) const) & Box::isWithin);
113 cls.def("isWithin", (bool (Box::*)(Box const &) const) & Box::isWithin);
114 cls.def("clipTo", (Box & (Box::*)(LonLat const &)) & Box::clipTo);
115 cls.def("clipTo", (Box & (Box::*)(Box const &)) & Box::clipTo);
116 cls.def("clippedTo", (Box(Box::*)(LonLat const &) const) & Box::clippedTo);
117 cls.def("clippedTo", (Box(Box::*)(Box const &) const) & Box::clippedTo);
118 cls.def("expandTo", (Box & (Box::*)(LonLat const &)) & Box::expandTo);
119 cls.def("expandTo", (Box & (Box::*)(Box const &)) & Box::expandTo);
120 cls.def("expandedTo",
121 (Box(Box::*)(LonLat const &) const) & Box::expandedTo);
122 cls.def("expandedTo", (Box(Box::*)(Box const &) const) & Box::expandedTo);
123 cls.def("dilateBy", (Box & (Box::*)(Angle)) & Box::dilateBy, "angle"_a);
124 cls.def("dilateBy", (Box & (Box::*)(Angle, Angle)) & Box::dilateBy,
125 "width"_a, "height"_a);
126 cls.def("dilatedBy", (Box(Box::*)(Angle) const) & Box::dilatedBy,
127 "angle"_a);
128 cls.def("dilatedBy", (Box(Box::*)(Angle, Angle) const) & Box::dilatedBy,
129 "width"_a, "height"_a);
130 cls.def("erodeBy", (Box & (Box::*)(Angle)) & Box::erodeBy, "angle"_a);
131 cls.def("erodeBy", (Box & (Box::*)(Angle, Angle)) & Box::erodeBy, "width"_a,
132 "height"_a);
133 cls.def("erodedBy", (Box(Box::*)(Angle) const) & Box::erodedBy, "angle"_a);
134 cls.def("erodedBy", (Box(Box::*)(Angle, Angle) const) & Box::erodedBy,
135 "width"_a, "height"_a);
136 cls.def("getArea", &Box::getArea);
137 cls.def("relate",
138 (Relationship(Box::*)(LonLat const &) const) & Box::relate,
139 "point"_a);
140 // Rewrap this base class method since there are overloads in this subclass
141 cls.def("relate",
142 (Relationship(Box::*)(Region const &) const) & Box::relate,
143 "region"_a);
144
145 // Note that the Region interface has already been wrapped.
146
147 cls.def("__str__", [](Box const &self) {
148 return py::str("Box({!s}, {!s})").format(self.getLon(), self.getLat());
149 });
150 cls.def("__repr__", [](Box const &self) {
151 return py::str("Box({!r}, {!r})").format(self.getLon(), self.getLat());
152 });
153 cls.def(py::pickle(&python::encode, &python::decode<Box>));
154}
155
156} // sphgeom
157} // lsst
This file defines a class for representing angle intervals.
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...
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 ℝ³.
Angle represents an angle in radians.
Definition Angle.h:43
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition Box.h:54
Box clippedTo(LonLat const &x) const
clippedTo returns the intersection of this box and x.
Definition Box.h:235
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
Definition Box.h:148
Box dilatedBy(Angle r) const
Definition Box.h:273
static NormalizedAngle halfWidthForCircle(Angle r, Angle lat)
halfWidthForCircle computes the half-width of bounding boxes for circles with radius r and centers at...
Definition Box.cc:43
Box & erodeBy(Angle r)
Definition Box.h:292
NormalizedAngle getWidth() const
getWidth returns the width in longitude angle of this box.
Definition Box.h:165
double getArea() const
getArea returns the area of this box in steradians.
Definition Box.cc:115
static Box fromRadians(double lon1, double lat1, double lon2, double lat2)
Definition Box.h:64
Box expandedTo(LonLat const &x) const
Definition Box.h:263
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Definition Box.h:145
Relationship relate(LonLat const &p) const
Definition Box.h:297
bool isDisjointFrom(LonLat const &x) const
Definition Box.h:186
static Box empty()
Definition Box.h:69
bool isFull() const
isFull returns true if this box contains all points on the unit sphere.
Definition Box.h:155
static constexpr uint8_t TYPE_CODE
Definition Box.h:56
Box & dilateBy(Angle r)
dilateBy minimally expands this Box to include all points within angular separation r of its boundary...
Definition Box.cc:78
Angle getHeight() const
getHeight returns the height in latitude angle of this box.
Definition Box.h:169
LonLat getCenter() const
getCenter returns the center of this box.
Definition Box.h:159
static NormalizedAngleInterval allLongitudes()
allLongitudes returns a normalized angle interval containing all valid longitude angles.
Definition Box.h:81
bool isWithin(LonLat const &x) const
Definition Box.h:206
Box erodedBy(Angle r) const
Definition Box.h:294
Box & expandTo(LonLat const &x)
Definition Box.h:246
static AngleInterval allLatitudes()
allLatitudes returns an angle interval containing all valid latitude angles.
Definition Box.h:87
bool contains(LonLat const &x) const
Definition Box.h:174
static Box fromDegrees(double lon1, double lat1, double lon2, double lat2)
Definition Box.h:59
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition Box.h:151
Box & clipTo(LonLat const &x)
clipTo shrinks this box until it contains only x.
Definition Box.h:217
static Box full()
Definition Box.h:71
bool intersects(LonLat const &x) const
Definition Box.h:194
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition LonLat.h:48
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:79
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
pybind11::bytes encode(Region const &self)
Encode a Region as a pybind11 bytes object.
Definition utils.h:53
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
void defineClass(Pybind11Class &cls)
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.