LSSTApplications  20.0.0
LSSTDataManagementBasePackage
circle.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 
24 #include <memory>
25 
26 #include "lsst/sphgeom/Box.h"
27 #include "lsst/sphgeom/Circle.h"
29 #include "lsst/sphgeom/Ellipse.h"
30 #include "lsst/sphgeom/Region.h"
32 
35 
36 namespace py = pybind11;
37 using namespace pybind11::literals;
38 
39 namespace lsst {
40 namespace sphgeom {
41 namespace {
42 
44  uint8_t const *buffer = reinterpret_cast<uint8_t const *>(
45  PYBIND11_BYTES_AS_STRING(bytes.ptr()));
46  size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
47  return Circle::decode(buffer, n);
48 }
49 
50 PYBIND11_MODULE(circle, mod) {
51  py::module::import("lsst.sphgeom.region");
52 
53  py::class_<Circle, std::unique_ptr<Circle>, Region> cls(mod, "Circle");
54 
55  cls.attr("TYPE_CODE") = py::int_(Circle::TYPE_CODE);
56 
57  cls.def_static("empty", &Circle::empty);
58  cls.def_static("full", &Circle::full);
59  cls.def_static("squaredChordLengthFor", &Circle::squaredChordLengthFor,
60  "openingAngle"_a);
61  cls.def_static("openingAngleFor", &Circle::openingAngleFor,
62  "squaredChordLength"_a);
63 
64  cls.def(py::init<>());
65  cls.def(py::init<UnitVector3d const &>(), "center"_a);
66  cls.def(py::init<UnitVector3d const &, Angle>(), "center"_a, "angle"_a);
67  cls.def(py::init<UnitVector3d const &, double>(), "center"_a,
68  "squaredChordLength"_a);
69  cls.def(py::init<Circle const &>(), "circle"_a);
70 
71  cls.def("__eq__", &Circle::operator==, py::is_operator());
72  cls.def("__ne__", &Circle::operator!=, py::is_operator());
73  cls.def("__contains__",
74  (bool (Circle::*)(Circle const &) const) & Circle::contains,
75  py::is_operator());
76  // Rewrap this base class method since there are overloads in this subclass
77  cls.def("__contains__",
78  (bool (Circle::*)(UnitVector3d const &) const) & Circle::contains,
79  py::is_operator());
80 
81  cls.def("isEmpty", &Circle::isEmpty);
82  cls.def("isFull", &Circle::isFull);
83  cls.def("getCenter", &Circle::getCenter);
84  cls.def("getSquaredChordLength", &Circle::getSquaredChordLength);
85  cls.def("getOpeningAngle", &Circle::getOpeningAngle);
86  cls.def("contains",
87  (bool (Circle::*)(Circle const &) const) & Circle::contains);
88  // Rewrap this base class method since there are overloads in this subclass
89  cls.def("contains",
90  (bool (Circle::*)(UnitVector3d const &) const) & Circle::contains);
91 
92  cls.def("isDisjointFrom",
93  (bool (Circle::*)(UnitVector3d const &) const) &
94  Circle::isDisjointFrom);
95  cls.def("isDisjointFrom",
96  (bool (Circle::*)(Circle const &) const) & Circle::isDisjointFrom);
97  cls.def("intersects",
98  (bool (Circle::*)(UnitVector3d const &) const) &
99  Circle::intersects);
100  cls.def("intersects",
101  (bool (Circle::*)(Circle const &) const) & Circle::intersects);
102  cls.def("isWithin",
103  (bool (Circle::*)(UnitVector3d const &) const) & Circle::isWithin);
104  cls.def("isWithin",
105  (bool (Circle::*)(Circle const &) const) & Circle::isWithin);
106  cls.def("clipTo",
107  (Circle & (Circle::*)(UnitVector3d const &)) & Circle::clipTo);
108  cls.def("clipTo", (Circle & (Circle::*)(Circle const &)) & Circle::clipTo);
109  cls.def("clippedTo",
110  (Circle(Circle::*)(UnitVector3d const &) const) &
111  Circle::clippedTo);
112  cls.def("clippedTo",
113  (Circle(Circle::*)(Circle const &) const) & Circle::clippedTo);
114  cls.def("expandTo",
115  (Circle & (Circle::*)(UnitVector3d const &)) & Circle::expandTo);
116  cls.def("expandTo",
117  (Circle & (Circle::*)(Circle const &)) & Circle::expandTo);
118  cls.def("expandedTo",
119  (Circle(Circle::*)(UnitVector3d const &) const) &
120  Circle::expandedTo);
121  cls.def("expandedTo",
122  (Circle(Circle::*)(Circle const &) const) & Circle::expandedTo);
123  cls.def("dilateBy", &Circle::dilateBy, "radius"_a);
124  cls.def("dilatedBy", &Circle::dilatedBy, "radius"_a);
125  cls.def("erodeBy", &Circle::erodeBy, "radius"_a);
126  cls.def("erodedBy", &Circle::erodedBy, "radius"_a);
127  cls.def("getArea", &Circle::getArea);
128  cls.def("complement", &Circle::complement);
129  cls.def("complemented", &Circle::complemented);
130 
131  // Note that the Region interface has already been wrapped.
132 
133  // The lambda is necessary for now; returning the unique pointer
134  // directly leads to incorrect results and crashes.
135  cls.def_static("decode",
136  [](py::bytes bytes) { return decode(bytes).release(); },
137  "bytes"_a);
138 
139  cls.def("__str__", [](Circle const &self) {
140  return py::str("Circle({!s}, {!s})")
141  .format(self.getCenter(), self.getOpeningAngle());
142  });
143  cls.def("__repr__", [](Circle const &self) {
144  return py::str("Circle({!r}, {!r})")
145  .format(self.getCenter(), self.getOpeningAngle());
146  });
147  cls.def(py::pickle(
148  [](const Circle &self) { return python::encode(self); },
149  [](py::bytes bytes) { return decode(bytes).release(); }));
150 }
151 
152 } // <anonymous>
153 } // sphgeom
154 } // lsst
Region.h
This file defines an interface for spherical regions.
utils.h
UnitVector3d.h
This file declares a class for representing unit vectors in ℝ³.
Circle.h
This file declares a class for representing circular regions on the unit sphere.
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
astshim.fitsChanContinued.contains
def contains(self, name)
Definition: fitsChanContinued.py:127
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
Ellipse.h
This file declares a class for representing elliptical regions on the unit sphere.
bytes
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199
relationship.h
Box.h
This file declares a class for representing longitude/latitude angle boxes on the unit sphere.
pybind11
Definition: _GenericMap.cc:40
std::unique_ptr
STL class.
lsst::afw::cameraGeom::PYBIND11_MODULE
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:133
ConvexPolygon.h
This file declares a class for representing convex polygons with great circle edges on the unit spher...