use c++ vector of internal storage in linetypes.pyx
CPython/Cython: 6.5x
@@ -7,6 +7,7 @@ from .vector cimport (
Vec3, v3_isclose, v3_add, v3_sub, v3_magnitude, v3_mul, isclose
)
import cython
+from libcpp.vector cimport vector
if TYPE_CHECKING:
from ezdxf.math import UVec
@@ -15,10 +16,9 @@ LineSegment = Tuple[Vec3, Vec3]
DEF ABS_TOL = 1e-12
DEF REL_TOL = 1e-9
-DEF MAX_DASHES = 32
cdef class _LineTypeRenderer:
- cdef double _dashes[MAX_DASHES]
+ cdef vector[double] _dashes
cdef int _dash_count
cdef readonly bint is_solid
cdef bint _is_dash
@@ -26,14 +26,8 @@ cdef class _LineTypeRenderer:
cdef double _current_dash_length
def __init__(self, dashes: Sequence[float]):
- cdef int i
- self._dash_count = len(dashes)
- if self._dash_count > MAX_DASHES:
- raise ValueError(
- f"line pattern too long, maximum of len(dashes) is 32"
- )
- for i in range(self._dash_count):
- self._dashes[i] = dashes[i]
+ self._dashes = dashes # this really works!!
+ self._dash_count = self._dashes.size()
self.is_solid = True
self._is_dash = False
@@ -50,7 +44,7 @@ cdef class _LineTypeRenderer:
cdef Vec3 _end = Vec3(end)
cdef Vec3 segment_vec, segment_dir
cdef double segment_length, dash_length
- cdef list dashes = []
+ cdef vector[double] dashes
if self.is_solid or v3_isclose(_start, _end, ABS_TOL, REL_TOL):
yield _start, _end
@@ -68,10 +62,10 @@ cdef class _LineTypeRenderer:
yield _start, _end
_start = _end
- cdef _render_dashes(self, double length, list dashes):
+ cdef _render_dashes(self, double length, vector[double] &dashes):
if length <= self._current_dash_length:
self._current_dash_length -= length
- dashes.append(length if self._is_dash else -length)
+ dashes.push_back(length if self._is_dash else -length)
if self._current_dash_length < ABS_TOL:
self._cycle_dashes()
else:
