lsst.afw  14.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spherePoint.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 AURA/LSST.
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 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
25 
26 #include <memory>
27 
28 #include "lsst/utils/python.h"
29 #include "lsst/afw/geom/Angle.h"
30 #include "lsst/afw/geom/Point.h"
32 
33 namespace py = pybind11;
34 using namespace py::literals;
35 
36 namespace lsst {
37 namespace afw {
38 namespace geom {
39 
40 using PySpherePoint = py::class_<SpherePoint, std::shared_ptr<SpherePoint>>;
41 
42 PYBIND11_PLUGIN(spherePoint) {
43  py::module mod("spherePoint");
44 
45  py::module::import("lsst.afw.geom.angle");
46  py::module::import("lsst.afw.geom.coordinates");
47 
48  /* Module level */
49  PySpherePoint cls(mod, "SpherePoint");
50 
51  /* Constructors */
52  cls.def(py::init<Angle const &, Angle const &>(), "longitude"_a, "latitude"_a);
53  cls.def(py::init<Point3D const &>(), "vector"_a);
54  // do not wrap SpherePoint(double const lonLatRad[2]) because it is not as safe as the other constructors
55  cls.def(py::init<SpherePoint const &>(), "other"_a);
56 
57  /* Operators */
58  cls.def("__getitem__",
59  [](SpherePoint const &self, std::ptrdiff_t i) { return self[utils::python::cppIndex(2, i)]; });
60  cls.def("__eq__", &SpherePoint::operator==, py::is_operator());
61  cls.def("__ne__", &SpherePoint::operator!=, py::is_operator());
62 
63  /* Members */
64  cls.def("getLongitude", &SpherePoint::getLongitude);
65  cls.def("getLatitude", &SpherePoint::getLatitude);
66  cls.def("getVector", &SpherePoint::getVector);
67  cls.def("atPole", &SpherePoint::atPole);
68  cls.def("isFinite", &SpherePoint::isFinite);
69  cls.def("bearingTo", &SpherePoint::bearingTo, "other"_a);
70  cls.def("separation", &SpherePoint::separation, "other"_a);
71  cls.def("rotated", &SpherePoint::rotated, "axis"_a, "amount"_a);
72  cls.def("offset", &SpherePoint::offset, "bearing"_a, "amount"_a);
73  cls.def("__str__", [](SpherePoint const &self) {
74  std::ostringstream os;
75  os << std::fixed << self;
76  return os.str();
77  });
78  cls.def("__len__", [](SpherePoint const &) { return 2; });
79  cls.def("__reduce__", [cls](SpherePoint const &self) {
80  return py::make_tuple(cls,
81  py::make_tuple(py::cast(self.getLongitude()), py::cast(self.getLatitude())));
82  });
83 
84  return mod.ptr();
85 }
86 }
87 }
88 } // namespace lsst::afw::geom
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:60
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
double const _a
Definition: RandomImage.cc:77
py::class_< SpherePoint, std::shared_ptr< SpherePoint >> PySpherePoint
Definition: spherePoint.cc:40