diff --git a/cython/python_solvespace/__init__.py b/cython/python_solvespace/__init__.py index 7a418578..b2058fda 100644 --- a/cython/python_solvespace/__init__.py +++ b/cython/python_solvespace/__init__.py @@ -10,7 +10,6 @@ __license__ = "GPLv3+" __email__ = "pyslvs@gmail.com" __version__ = "3.0.6" -from enum import IntEnum, auto from .slvs import ( quaternion_u, quaternion_v, @@ -32,51 +31,3 @@ __all__ = [ 'Entity', 'SolverSystem', ] - - -class Constraint(IntEnum): - """Symbol of the constraint types.""" - # Expose macro of constraint types - POINTS_COINCIDENT = 100000 - PT_PT_DISTANCE = auto() - PT_PLANE_DISTANCE = auto() - PT_LINE_DISTANCE = auto() - PT_FACE_DISTANCE = auto() - PT_IN_PLANE = auto() - PT_ON_LINE = auto() - PT_ON_FACE = auto() - EQUAL_LENGTH_LINES = auto() - LENGTH_RATIO = auto() - EQ_LEN_PT_LINE_D = auto() - EQ_PT_LN_DISTANCES = auto() - EQUAL_ANGLE = auto() - EQUAL_LINE_ARC_LEN = auto() - SYMMETRIC = auto() - SYMMETRIC_HORIZ = auto() - SYMMETRIC_VERT = auto() - SYMMETRIC_LINE = auto() - AT_MIDPOINT = auto() - HORIZONTAL = auto() - VERTICAL = auto() - DIAMETER = auto() - PT_ON_CIRCLE = auto() - SAME_ORIENTATION = auto() - ANGLE = auto() - PARALLEL = auto() - PERPENDICULAR = auto() - ARC_LINE_TANGENT = auto() - CUBIC_LINE_TANGENT = auto() - EQUAL_RADIUS = auto() - PROJ_PT_DISTANCE = auto() - WHERE_DRAGGED = auto() - CURVE_CURVE_TANGENT = auto() - LENGTH_DIFFERENCE = auto() - - -class ResultFlag(IntEnum): - """Symbol of the result flags.""" - # Expose macro of result flags - OKAY = 0 - INCONSISTENT = auto() - DIDNT_CONVERGE = auto() - TOO_MANY_UNKNOWNS = auto() diff --git a/cython/python_solvespace/slvs.pxd b/cython/python_solvespace/slvs.pxd index 430d5364..0394beff 100644 --- a/cython/python_solvespace/slvs.pxd +++ b/cython/python_solvespace/slvs.pxd @@ -252,7 +252,7 @@ cdef class SolverSystem: cpdef int dof(self) cpdef object constraints(self) cpdef list failures(self) - cpdef int solve(self) + cdef int solve_c(self) nogil cpdef size_t param_len(self) cpdef size_t entity_len(self) diff --git a/cython/python_solvespace/slvs.pyx b/cython/python_solvespace/slvs.pyx index 1cfa1f00..55db88ba 100644 --- a/cython/python_solvespace/slvs.pyx +++ b/cython/python_solvespace/slvs.pyx @@ -10,6 +10,7 @@ email: pyslvs@gmail.com """ from cpython.object cimport Py_EQ, Py_NE +from enum import IntEnum, auto from collections import Counter @@ -65,6 +66,54 @@ cpdef tuple make_quaternion(double ux, double uy, double uz, double vx, double v return qw, qx, qy, qz +class Constraint(IntEnum): + """Symbol of the constraint types.""" + # Expose macro of constraint types + POINTS_COINCIDENT = 100000 + PT_PT_DISTANCE = auto() + PT_PLANE_DISTANCE = auto() + PT_LINE_DISTANCE = auto() + PT_FACE_DISTANCE = auto() + PT_IN_PLANE = auto() + PT_ON_LINE = auto() + PT_ON_FACE = auto() + EQUAL_LENGTH_LINES = auto() + LENGTH_RATIO = auto() + EQ_LEN_PT_LINE_D = auto() + EQ_PT_LN_DISTANCES = auto() + EQUAL_ANGLE = auto() + EQUAL_LINE_ARC_LEN = auto() + SYMMETRIC = auto() + SYMMETRIC_HORIZ = auto() + SYMMETRIC_VERT = auto() + SYMMETRIC_LINE = auto() + AT_MIDPOINT = auto() + HORIZONTAL = auto() + VERTICAL = auto() + DIAMETER = auto() + PT_ON_CIRCLE = auto() + SAME_ORIENTATION = auto() + ANGLE = auto() + PARALLEL = auto() + PERPENDICULAR = auto() + ARC_LINE_TANGENT = auto() + CUBIC_LINE_TANGENT = auto() + EQUAL_RADIUS = auto() + PROJ_PT_DISTANCE = auto() + WHERE_DRAGGED = auto() + CURVE_CURVE_TANGENT = auto() + LENGTH_DIFFERENCE = auto() + + +class ResultFlag(IntEnum): + """Symbol of the result flags.""" + # Expose macro of result flags + OKAY = 0 + INCONSISTENT = auto() + DIDNT_CONVERGE = auto() + TOO_MANY_UNKNOWNS = auto() + + cdef class Params: """Python object to handle multiple parameter handles.""" @@ -384,7 +433,7 @@ cdef class SolverSystem: """Return a list of failed constraint numbers.""" return self.failed_list - cpdef int solve(self): + cdef int solve_c(self) nogil: """Start the solving, return the result flag.""" cdef Slvs_System sys # Parameters @@ -406,6 +455,9 @@ cdef class SolverSystem: self.dof_v = sys.dof return sys.result + def solve(self): + return ResultFlag(self.solve_c()) + cpdef size_t param_len(self): """The length of parameter list.""" return self.param_list.size()