Commit fbc428e6 by Dennis Gläser

### [python][vector] add ctor from list

parent 2ea4d9e9
 ... ... @@ -19,7 +19,9 @@ #ifndef FRACKIT_PYTHON_GEOMETRY_VECTOR_HH #define FRACKIT_PYTHON_GEOMETRY_VECTOR_HH #include #include #include #include #include ... ... @@ -42,7 +44,6 @@ namespace Detail { std::string className("VectorBase_" + std::to_string(Base::worldDimension())); py::class_ cls(module, className.c_str()); cls.def(py::init<>()); cls.def("name", &Base::name, "name of the geometry class"); cls.def("squaredLength", &Base::squaredLength, "squared length of the vector"); cls.def("length", &Base::length, "length of the vector"); ... ... @@ -76,6 +77,23 @@ namespace Detail { cls.def(py::init<>()); cls.def(py::init(), "source"_a, "target"_a); cls.def(py::init(), "direction"_a); cls.def(py::init( [] (py::list x) -> Vector { // create array of matching size and fill with values // from the list. Use zeros at the end if list is shorter. std::array vals; std::fill(vals.begin(), vals.end(), 0.0); unsigned int minDim = std::min(worldDim, static_cast(x.size())); for (unsigned int i = 0; i < minDim; ++i) vals[i] = x[i].template cast(); if constexpr (worldDim == 1) return {vals[0]}; else if constexpr (worldDim == 2) return {vals[0], vals[1]}; else return {vals[0], vals[1], vals[2]}; } ), "coordinates"_a); if constexpr (worldDim == 1) cls.def(py::init(), "x"_a); ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!