-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathmapnik_coord.cpp
More file actions
64 lines (61 loc) · 2.48 KB
/
mapnik_coord.cpp
File metadata and controls
64 lines (61 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2024 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/coord.hpp>
//pybind11
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
namespace py = pybind11;
using mapnik::coord;
void export_coord(py::module const& m)
{
py::class_<coord<double,2> >(m, "Coord")
.def(py::init<double, double>(),
// class docstring is in mapnik/__init__.py, class _Coord
"Constructs a new object with the given coordinates.\n",
py::arg("x"), py::arg("y"))
.def_readwrite("x", &coord<double,2>::x,
"Gets or sets the x/lon coordinate of the point.\n")
.def_readwrite("y", &coord<double,2>::y,
"Gets or sets the y/lat coordinate of the point.\n")
.def(py::self == py::self) // __eq__
.def(py::self + py::self) //__add__
.def(py::self + float())
.def(float() + py::self)
.def(py::self - py::self) //__sub__
.def(py::self - float())
.def(py::self * float()) //__mult__
.def(float() * py::self)
.def(py::self / float()) // __div__
.def(py::pickle(
[](coord<double,2> & c) {
return py::make_tuple(c.x, c.y);
},
[](py::tuple t) {
if (t.size() != 2)
throw std::runtime_error("Invalid state");
coord<double,2> c{t[0].cast<double>(),t[1].cast<double>()};
return c;
}))
;
}