LSST Applications g06d8191974+de063e15a7,g180d380827+d0b6459378,g2079a07aa2+86d27d4dc4,g2305ad1205+f1ae3263cc,g29320951ab+5752d78b6e,g2bbee38e9b+85cf0a37e7,g337abbeb29+85cf0a37e7,g33d1c0ed96+85cf0a37e7,g3a166c0a6a+85cf0a37e7,g3ddfee87b4+b5254b9343,g48712c4677+9ea88d309d,g487adcacf7+05f7dba17f,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+48904e3942,g64a986408d+de063e15a7,g858d7b2824+de063e15a7,g864b0138d7+33ab2bc355,g8a8a8dda67+585e252eca,g99cad8db69+4508353287,g9c22b2923f+53520f316c,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+ccb7f83a87,gc120e1dc64+6caf640b9b,gc28159a63d+85cf0a37e7,gc3e9b769f7+548c5e05a3,gcf0d15dbbd+b5254b9343,gdaeeff99f8+f9a426f77a,ge6526c86ff+515b6c9330,ge79ae78c31+85cf0a37e7,gee10cc3b42+585e252eca,gff1a9f87cc+de063e15a7,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
interval.h
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
30#ifndef LSST_SPHGEOM_PYTHON_INTERVAL_H_
31#define LSST_SPHGEOM_PYTHON_INTERVAL_H_
32
33#include "pybind11/pybind11.h"
34
35#include "relationship.h"
36
37namespace py = pybind11;
38using namespace pybind11::literals;
39
40namespace lsst {
41namespace sphgeom {
42namespace python {
43namespace {
44
50template <typename PyClass, typename Class, typename Scalar>
51void defineInterval(PyClass& cls) {
52 cls.def("__eq__", [](Class const& self,
53 Class const& other) { return self == other; },
54 py::is_operator());
55 cls.def("__eq__",
56 [](Class const& self, Scalar other) { return self == other; },
57 py::is_operator());
58 cls.def("__ne__", [](Class const& self,
59 Class const& other) { return self != other; },
60 py::is_operator());
61 cls.def("__ne__",
62 [](Class const& self, Scalar other) { return self != other; },
63 py::is_operator());
64
65 cls.def("getA", [](Class const& self) { return self.getA(); });
66 cls.def("getB", [](Class const& self) { return self.getB(); });
67 cls.def("isEmpty", [](Class const& self) { return self.isEmpty(); });
68 cls.def("getCenter", [](Class const& self) { return self.getCenter(); });
69 cls.def("getSize", [](Class const& self) { return self.getSize(); });
70
71 cls.def("__contains__", [](Class const& self,
72 Scalar other) { return self.contains(other); },
73 py::is_operator());
74 cls.def("__contains__",
75 [](Class const& self, Class const& other) {
76 return self.contains(other);
77 },
78 py::is_operator());
79
80 cls.def("contains", [](Class const& self, Scalar other) {
81 return self.contains(other);
82 });
83 cls.def("contains", [](Class const& self, Class const& other) {
84 return self.contains(other);
85 });
86 cls.def("isDisjointFrom", [](Class const& self, Scalar other) {
87 return self.isDisjointFrom(other);
88 });
89 cls.def("isDisjointFrom", [](Class const& self, Class const& other) {
90 return self.isDisjointFrom(other);
91 });
92 cls.def("intersects", [](Class const& self, Scalar other) {
93 return self.intersects(other);
94 });
95 cls.def("intersects", [](Class const& self, Class const& other) {
96 return self.intersects(other);
97 });
98 cls.def("isWithin", [](Class const& self, Scalar other) {
99 return self.isWithin(other);
100 });
101 cls.def("isWithin", [](Class const& self, Class const& other) {
102 return self.isWithin(other);
103 });
104 cls.def("relate", [](Class const& self, Scalar other) {
105 return self.relate(other);
106 });
107 cls.def("relate", [](Class const& self, Class const& other) {
108 return self.relate(other);
109 });
110
111 // Note that when a reference to *this is returned in C++, it will
112 // have an existing wrapper object which is automatically returned
113 // by pybind11 - no return value policy is needed. The explicit
114 // reference return type for the corresponding lambdas seems to be
115 // required to obtain this behavior.
116
117 cls.def("clipTo", [](Class& self, Scalar other) -> Class & {
118 self.clipTo(other);
119 return self;
120 });
121 cls.def("clipTo", [](Class& self, Class const& other) -> Class & {
122 self.clipTo(other);
123 return self;
124 });
125 cls.def("clippedTo", [](Class const& self, Scalar other) {
126 Class instance = self.clippedTo(other);
127 return instance;
128 });
129 cls.def("clippedTo", [](Class const& self, Class const& other) {
130 Class instance = self.clippedTo(other);
131 return instance;
132 });
133 cls.def("expandTo", [](Class& self, Scalar other) -> Class & {
134 self.expandTo(other);
135 return self;
136 });
137 cls.def("expandTo", [](Class& self, Class const& other) -> Class & {
138 self.expandTo(other);
139 return self;
140 });
141 cls.def("expandedTo", [](Class const& self, Scalar other) {
142 Class instance = self.expandedTo(other);
143 return instance;
144 });
145 cls.def("expandedTo", [](Class const& self, Class const& other) {
146 Class instance = self.expandedTo(other);
147 return instance;
148 });
149
150 cls.def("dilateBy", [](Class& self, Scalar other) -> Class & {
151 self.dilateBy(other);
152 return self;
153 });
154 cls.def("dilatedBy", [](Class const& self, Scalar other) {
155 Class instance = self.dilatedBy(other);
156 return instance;
157 });
158 cls.def("erodeBy", [](Class& self, Scalar other) -> Class & {
159 self.erodeBy(other);
160 return self;
161 });
162 cls.def("erodedBy", [](Class const& self, Scalar other) {
163 Class instance = self.erodedBy(other);
164 return instance;
165 });
166
167 cls.def("__reduce__", [cls](Class const &self) {
168 return py::make_tuple(cls, py::make_tuple(self.getA(), self.getB()));
169 });
170}
171
172} // unnamed
173} // python
174} // sphgeom
175} // lsst
176
177#endif // LSST_SPHGEOM_PYTHON_INTERVAL_H_