-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathgeometry.cpp
67 lines (62 loc) · 2.67 KB
/
geometry.cpp
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
65
66
67
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "conversion.hpp"
#include "wrapper.hpp"
#include <jupedsim/jupedsim.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
void init_geometry(py::module_& m)
{
py::class_<JPS_Geometry_Wrapper>(m, "Geometry")
.def(
"boundary",
[](const JPS_Geometry_Wrapper& w) {
const auto len = JPS_Geometry_GetBoundarySize(w.handle);
const auto data = JPS_Geometry_GetBoundaryData(w.handle);
return intoTuple(data, data + len);
})
.def("holes", [](const JPS_Geometry_Wrapper& w) {
const auto holeCount = JPS_Geometry_GetHoleCount(w.handle);
std::vector<std::vector<std::tuple<double, double>>> res{};
res.reserve(holeCount);
for(size_t index = 0; index < holeCount; ++index) {
const auto len = JPS_Geometry_GetHoleSize(w.handle, index, nullptr);
const auto data = JPS_Geometry_GetHoleData(w.handle, index, nullptr);
res.emplace_back(intoTuple(data, data + len));
}
return res;
});
py::class_<JPS_GeometryBuilder_Wrapper>(m, "GeometryBuilder")
.def(py::init([]() {
return std::make_unique<JPS_GeometryBuilder_Wrapper>(JPS_GeometryBuilder_Create());
}))
.def(
"add_accessible_area",
[](const JPS_GeometryBuilder_Wrapper& w,
std::vector<std::tuple<double, double>> polygon) {
const auto pts = intoJPS_Point(polygon);
JPS_GeometryBuilder_AddAccessibleArea(w.handle, pts.data(), pts.size());
},
"Add area where agents can move")
.def(
"exclude_from_accessible_area",
[](const JPS_GeometryBuilder_Wrapper& w,
std::vector<std::tuple<double, double>> polygon) {
const auto pts = intoJPS_Point(polygon);
JPS_GeometryBuilder_ExcludeFromAccessibleArea(w.handle, pts.data(), pts.size());
},
"Add areas where agents can not move (obstacles)")
.def(
"build",
[](const JPS_GeometryBuilder_Wrapper& w) {
JPS_ErrorMessage errorMsg{};
auto result = JPS_GeometryBuilder_Build(w.handle, &errorMsg);
if(result) {
return std::make_unique<JPS_Geometry_Wrapper>(result);
}
auto msg = std::string(JPS_ErrorMessage_GetMessage(errorMsg));
JPS_ErrorMessage_Free(errorMsg);
throw std::runtime_error{msg};
},
"Geometry builder");
}