LSST Applications g07dc498a13+5a531fccd6,g1409bbee79+5a531fccd6,g1a7e361dbc+5a531fccd6,g1fd858c14a+bae9e05889,g28da252d5a+b6acab2954,g33399d78f5+749e2df9f6,g35bb328faa+e55fef2c71,g3bd4b5ce2c+753c3426d3,g3d4cdeeb7c+495e717508,g43bc871e57+32b9ddb877,g53246c7159+e55fef2c71,g60b5630c4e+f9e43d3906,g6e5c4a0e23+f441d97430,g78460c75b0+8427c4cc8f,g786e29fd12+307f82e6af,g8534526c7b+af2545e932,g85d8d04dbe+ded3a614ca,g89139ef638+5a531fccd6,g8b49a6ea8e+f9e43d3906,g9125e01d80+e55fef2c71,g989de1cb63+5a531fccd6,g9a9baf55bd+f1bd1a7c26,g9f33ca652e+c963d5c8aa,gaaedd4e678+5a531fccd6,gabe3b4be73+9c0c3c7524,gb092a606b0+a33ed67792,gb58c049af0+28045f66fd,gc2fcbed0ba+f9e43d3906,gca43fec769+e55fef2c71,gcf25f946ba+749e2df9f6,gd6cbbdb0b4+784e334a77,gde0f65d7ad+a0ab96d407,ge278dab8ac+25667260f6,geab183fbe5+f9e43d3906,gecb8035dfe+0fa5abcb94,gefa07fa684+89734069dd,gf58bf46354+e55fef2c71,gfe7187db8c+55cd7d2043,w.2025.01
LSST Data Management Base Package
Loading...
Searching...
No Matches
_box.cc
Go to the documentation of this file.
1/*
2 * This file is part of sphgeom.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (http://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This software is dual licensed under the GNU General Public License and also
11 * under a 3-clause BSD license. Recipients may choose which of these licenses
12 * to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
13 * respectively. If you choose the GPL option then the following text applies
14 * (but note that there is still no warranty even if you opt for BSD instead):
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29#include "pybind11/pybind11.h"
30#include "pybind11/numpy.h"
31
32#include "lsst/sphgeom/python.h"
33
35#include "lsst/sphgeom/Box.h"
36#include "lsst/sphgeom/Box3d.h"
37#include "lsst/sphgeom/Circle.h"
40#include "lsst/sphgeom/LonLat.h"
42#include "lsst/sphgeom/Region.h"
44
47
48namespace py = pybind11;
49using namespace pybind11::literals;
50
51namespace lsst {
52namespace sphgeom {
53
54template <>
55void defineClass(py::class_<Box, std::unique_ptr<Box>, Region> &cls) {
56 cls.attr("TYPE_CODE") = py::int_(Box::TYPE_CODE);
57
58 cls.def_static("fromDegrees", &Box::fromDegrees, "lon1"_a, "lat1"_a,
59 "lon2"_a, "lat2"_a);
60 cls.def_static("fromRadians", &Box::fromRadians, "lon1"_a, "lat1"_a,
61 "lon2"_a, "lat2"_a);
62 cls.def_static("empty", &Box::empty);
63 cls.def_static("full", &Box::full);
64 cls.def_static("halfWidthForCircle", &Box::halfWidthForCircle, "radius"_a,
65 "lat"_a);
66 cls.def_static("allLongitudes", &Box::allLongitudes);
67 cls.def_static("allLatitudes", &Box::allLatitudes);
68
69 cls.def(py::init<>());
70 cls.def(py::init<LonLat const &>(), "point"_a);
71 cls.def(py::init<LonLat const &, LonLat const &>(), "point1"_a, "point2"_a);
72 cls.def(py::init<LonLat const &, Angle, Angle>(), "center"_a, "width"_a,
73 "height"_a);
74 cls.def(py::init<NormalizedAngleInterval const &, AngleInterval const &>(),
75 "lon"_a, "lat"_a);
76 cls.def(py::init<Box const &>(), "box"_a);
77
78 cls.def("__eq__", (bool (Box::*)(Box const &) const) & Box::operator==,
79 py::is_operator());
80 cls.def("__eq__", (bool (Box::*)(LonLat const &) const) & Box::operator==,
81 py::is_operator());
82 cls.def("__ne__", (bool (Box::*)(Box const &) const) & Box::operator!=,
83 py::is_operator());
84 cls.def("__ne__", (bool (Box::*)(LonLat const &) const) & Box::operator!=,
85 py::is_operator());
86 cls.def("__contains__",
87 (bool (Box::*)(LonLat const &) const) & Box::contains,
88 py::is_operator());
89 cls.def("__contains__", (bool (Box::*)(Box const &) const) & Box::contains,
90 py::is_operator());
91 // Rewrap this base class method since there are overloads in this subclass
92 cls.def("__contains__",
93 (bool (Box::*)(UnitVector3d const &) const) & Box::contains,
94 py::is_operator());
95
96 cls.def("getLon", &Box::getLon);
97 cls.def("getLat", &Box::getLat);
98 cls.def("isFull", &Box::isFull);
99 cls.def("getCenter", &Box::getCenter);
100 cls.def("getWidth", &Box::getWidth);
101 cls.def("getHeight", &Box::getHeight);
102 cls.def("contains", (bool (Box::*)(LonLat const &) const) & Box::contains);
103 cls.def("contains", (bool (Box::*)(Box const &) const) & Box::contains);
104 // Rewrap these base class methods since there are overloads in this subclass
105 cls.def("contains",
106 (bool (Box::*)(UnitVector3d const &) const) & Box::contains);
107 cls.def("contains", py::vectorize((bool (Box::*)(double, double, double) const)&Box::contains),
108 "x"_a, "y"_a, "z"_a);
109 cls.def("contains", py::vectorize((bool (Box::*)(double, double) const)&Box::contains),
110 "lon"_a, "lat"_a);
111 cls.def("isDisjointFrom",
112 (bool (Box::*)(LonLat const &) const) & Box::isDisjointFrom);
113 cls.def("isDisjointFrom",
114 (bool (Box::*)(Box const &) const) & Box::isDisjointFrom);
115 cls.def("intersects",
116 (bool (Box::*)(LonLat const &) const) & Box::intersects);
117 cls.def("intersects", (bool (Box::*)(Box const &) const) & Box::intersects);
118 cls.def("isWithin", (bool (Box::*)(LonLat const &) const) & Box::isWithin);
119 cls.def("isWithin", (bool (Box::*)(Box const &) const) & Box::isWithin);
120 cls.def("clipTo", (Box & (Box::*)(LonLat const &)) & Box::clipTo);
121 cls.def("clipTo", (Box & (Box::*)(Box const &)) & Box::clipTo);
122 cls.def("clippedTo", (Box(Box::*)(LonLat const &) const) & Box::clippedTo);
123 cls.def("clippedTo", (Box(Box::*)(Box const &) const) & Box::clippedTo);
124 cls.def("expandTo", (Box & (Box::*)(LonLat const &)) & Box::expandTo);
125 cls.def("expandTo", (Box & (Box::*)(Box const &)) & Box::expandTo);
126 cls.def("expandedTo",
127 (Box(Box::*)(LonLat const &) const) & Box::expandedTo);
128 cls.def("expandedTo", (Box(Box::*)(Box const &) const) & Box::expandedTo);
129 cls.def("dilateBy", (Box & (Box::*)(Angle)) & Box::dilateBy, "angle"_a);
130 cls.def("dilateBy", (Box & (Box::*)(Angle, Angle)) & Box::dilateBy,
131 "width"_a, "height"_a);
132 cls.def("dilatedBy", (Box(Box::*)(Angle) const) & Box::dilatedBy,
133 "angle"_a);
134 cls.def("dilatedBy", (Box(Box::*)(Angle, Angle) const) & Box::dilatedBy,
135 "width"_a, "height"_a);
136 cls.def("erodeBy", (Box & (Box::*)(Angle)) & Box::erodeBy, "angle"_a);
137 cls.def("erodeBy", (Box & (Box::*)(Angle, Angle)) & Box::erodeBy, "width"_a,
138 "height"_a);
139 cls.def("erodedBy", (Box(Box::*)(Angle) const) & Box::erodedBy, "angle"_a);
140 cls.def("erodedBy", (Box(Box::*)(Angle, Angle) const) & Box::erodedBy,
141 "width"_a, "height"_a);
142 cls.def("getArea", &Box::getArea);
143 cls.def("relate",
144 (Relationship(Box::*)(LonLat const &) const) & Box::relate,
145 "point"_a);
146 // Rewrap this base class method since there are overloads in this subclass
147 cls.def("relate",
148 (Relationship(Box::*)(Region const &) const) & Box::relate,
149 "region"_a);
150
151 // Note that the Region interface has already been wrapped.
152
153 cls.def("__str__", [](Box const &self) {
154 return py::str("Box({!s}, {!s})").format(self.getLon(), self.getLat());
155 });
156 cls.def("__repr__", [](Box const &self) {
157 return py::str("Box({!r}, {!r})").format(self.getLon(), self.getLat());
158 });
159 cls.def(py::pickle(&python::encode, &python::decode<Box>));
160}
161
162} // sphgeom
163} // 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:50
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition Box.h:62
Box clippedTo(LonLat const &x) const
clippedTo returns the intersection of this box and x.
Definition Box.h:243
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
Definition Box.h:156
Box dilatedBy(Angle r) const
Definition Box.h:281
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:50
Box & erodeBy(Angle r)
Definition Box.h:300
NormalizedAngle getWidth() const
getWidth returns the width in longitude angle of this box.
Definition Box.h:173
double getArea() const
getArea returns the area of this box in steradians.
Definition Box.cc:122
static Box fromRadians(double lon1, double lat1, double lon2, double lat2)
Definition Box.h:72
Box expandedTo(LonLat const &x) const
Definition Box.h:271
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Definition Box.h:153
Relationship relate(LonLat const &p) const
Definition Box.h:305
bool isDisjointFrom(LonLat const &x) const
Definition Box.h:194
static constexpr std::uint8_t TYPE_CODE
Definition Box.h:64
static Box empty()
Definition Box.h:77
bool isFull() const
isFull returns true if this box contains all points on the unit sphere.
Definition Box.h:163
Box & dilateBy(Angle r)
dilateBy minimally expands this Box to include all points within angular separation r of its boundary...
Definition Box.cc:85
Angle getHeight() const
getHeight returns the height in latitude angle of this box.
Definition Box.h:177
LonLat getCenter() const
getCenter returns the center of this box.
Definition Box.h:167
static NormalizedAngleInterval allLongitudes()
allLongitudes returns a normalized angle interval containing all valid longitude angles.
Definition Box.h:89
bool isWithin(LonLat const &x) const
Definition Box.h:214
Box erodedBy(Angle r) const
Definition Box.h:302
Box & expandTo(LonLat const &x)
Definition Box.h:254
static AngleInterval allLatitudes()
allLatitudes returns an angle interval containing all valid latitude angles.
Definition Box.h:95
bool contains(LonLat const &x) const
Definition Box.h:182
static Box fromDegrees(double lon1, double lat1, double lon2, double lat2)
Definition Box.h:67
Box & clipTo(LonLat const &x)
clipTo shrinks this box until it contains only x.
Definition Box.h:225
static Box full()
Definition Box.h:79
bool intersects(LonLat const &x) const
Definition Box.h:202
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition LonLat.h:55
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:89
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
std::unique_ptr< R > decode(pybind11::bytes bytes)
Decode a Region from a pybind11 bytes object.
Definition utils.h:69
pybind11::bytes encode(Region const &self)
Encode a Region as a pybind11 bytes object.
Definition utils.h:61
void defineClass(Pybind11Class &cls)
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
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.