LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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
This file declares a class for representing circular regions on the unit sphere.
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:133
This file declares a class for representing elliptical regions on the unit sphere.
This file declares a class for representing unit vectors in ℝ³.
A base class for image defects.
This file defines an interface for spherical regions.
This file declares a class for representing longitude/latitude angle boxes on the unit sphere...
STL class.
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199
This file declares a class for representing convex polygons with great circle edges on the unit spher...