38{
39 if (!py::isinstance<py::array>(h))
40 throw py::value_error(std::string(who) + ": each contour/hole must be an (N,2) int64 ndarray");
41 py::array a = py::reinterpret_borrow<py::array>(h);
42 if (a.dtype().kind() !=
'i' || a.itemsize() != (py::ssize_t)
sizeof(
coord_t))
43 throw py::value_error(std::string(who) + ": polygon coordinates must be int64 (scaled coords)");
44 if (a.ndim() != 2 || a.shape(1) != 2)
45 throw py::value_error(std::string(who) + ": each polygon array must have shape (N,2)");
46 if (a.shape(0) < 3)
47 throw py::value_error(std::string(who) + ": a polygon needs at least 3 points");
48
49 auto arr = py::array_t<coord_t, py::array::c_style | py::array::forcecast>::ensure(a);
50 if (!arr)
51 throw py::value_error(std::string(who) + ": could not read polygon as a contiguous int64 array");
52 auto r = arr.unchecked<2>();
54 poly.points.reserve((size_t) arr.shape(0));
55 for (py::ssize_t i = 0; i < arr.shape(0); ++i)
57 return poly;
58}
int64_t coord_t
Definition libslic3r.h:48