LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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.
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:34
This file declares a class for representing unit vectors in ℝ³.
A base class for image defects.
This file declares a class for representing elliptical regions on the unit sphere.
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.
This file declares a class for representing convex polygons with great circle edges on the unit spher...
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199