OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{PluginHostGeometry.cpp} Namespace Reference

Functions

Polygon parse_polygon (py::handle h, const char *who)
Polygon as_polygon (py::handle h, const char *who)

Function Documentation

◆ as_polygon()

Polygon Slic3r::anonymous_namespace{PluginHostGeometry.cpp}::as_polygon ( py::handle h,
const char * who )
64{
65 if (py::isinstance<Polygon>(h))
66 return h.cast<Polygon>();
67 return parse_polygon(h, who);
68}
Definition Polygon.hpp:31
Polygon parse_polygon(py::handle h, const char *who)
Definition PluginHostGeometry.cpp:37

References as_polygon(), and parse_polygon().

Referenced by as_polygon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_polygon()

Polygon Slic3r::anonymous_namespace{PluginHostGeometry.cpp}::parse_polygon ( py::handle h,
const char * who )
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 // dtype already validated as int64; forcecast here only guarantees a C-contiguous buffer.
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>();
53 Polygon poly;
54 poly.points.reserve((size_t) arr.shape(0));
55 for (py::ssize_t i = 0; i < arr.shape(0); ++i)
56 poly.points.emplace_back((coord_t) r(i, 0), (coord_t) r(i, 1));
57 return poly;
58}
int64_t coord_t
Definition libslic3r.h:48

References parse_polygon().

Referenced by as_polygon(), and parse_polygon().

Here is the call graph for this function:
Here is the caller graph for this function: