diff --git a/cython/python_solvespace/slvs.pxd b/cython/python_solvespace/slvs.pxd index 7208fcd8..92f01762 100644 --- a/cython/python_solvespace/slvs.pxd +++ b/cython/python_solvespace/slvs.pxd @@ -268,6 +268,7 @@ cdef class SolverSystem: cdef void free(self) cpdef void set_group(self, size_t g) cpdef int group(self) + cpdef void set_params(self, Params p, object params) cpdef tuple params(self, Params p) cpdef int dof(self) cpdef object constraints(self) diff --git a/cython/python_solvespace/slvs.pyi b/cython/python_solvespace/slvs.pyi index 2a5b80d7..868726ee 100644 --- a/cython/python_solvespace/slvs.pyi +++ b/cython/python_solvespace/slvs.pyi @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from typing import Tuple, List, Counter +from typing import Tuple, List, Sequence, Counter from enum import IntEnum, auto @@ -164,6 +164,9 @@ class SolverSystem: def group(self) -> int: ... + def set_params(self, p: Params, params: Sequence[float]): + ... + def params(self, p: Params) -> Tuple[float, ...]: ... diff --git a/cython/python_solvespace/slvs.pyx b/cython/python_solvespace/slvs.pyx index 586b15cb..a2dfbe85 100644 --- a/cython/python_solvespace/slvs.pyx +++ b/cython/python_solvespace/slvs.pyx @@ -309,6 +309,19 @@ cdef class SolverSystem: """Return the current group by integer.""" return self.g + cpdef void set_params(self, Params p, object params): + """Set the parameters by Params object and sequence object.""" + params = tuple(params) + cdef int i = p.param_list.size() + if i != len(params): + raise ValueError(f"number of parameters {len(params)} are not match {i}") + + i = 0 + cdef Slvs_hParam h + for h in p.param_list: + self.param_list[h].val = params[i] + i += 1 + cpdef tuple params(self, Params p): """Get the parameters by Params object.""" cdef list param_list = []