@@ -5,7 +5,7 @@ This module provides:
55 - CBaseTrajSeq: a contiguous C buffer of BaseTrajC items with append/reserve access.
66 - Quadratic Lagrange interpolation on the raw buffer without allocating Python objects.
77 - Convenience methods to locate and interpolate a point by an independent variable
8- (time, mach, position.{x,y,z}, velocity.{x,y,z}) and slant height .
8+ (time, mach, position.{x,y,z}, velocity.{x,y,z}) and slant_height .
99
1010Design note: nogil helpers operate on a tiny C struct view of the sequence to avoid
1111 passing Python cdef-class instances into nogil code paths.
@@ -47,10 +47,29 @@ ctypedef struct _CBaseTrajSeq_cview:
4747
4848__all__ = [' CBaseTrajSeq' , ' BaseTrajC' ]
4949
50+ cdef inline double _key_val_from_kind_buf(BaseTrajC* p, int key_kind) noexcept nogil:
51+ if key_kind == < int > KEY_TIME:
52+ return p.time
53+ elif key_kind == < int > KEY_MACH:
54+ return p.mach
55+ elif key_kind == < int > KEY_POS_X:
56+ return p.px
57+ elif key_kind == < int > KEY_POS_Y:
58+ return p.py
59+ elif key_kind == < int > KEY_POS_Z:
60+ return p.pz
61+ elif key_kind == < int > KEY_VEL_X:
62+ return p.vx
63+ elif key_kind == < int > KEY_VEL_Y:
64+ return p.vy
65+ elif key_kind == < int > KEY_VEL_Z:
66+ return p.vz
67+ return < double > 0.0
68+
5069
5170# Interpolation helper (pure C math; safe to call with or without GIL)
52- cdef int _interpolate_nogil_raw(_CBaseTrajSeq_cview* seq, Py_ssize_t idx, int key_kind, double key_value, BaseTrajC* out) noexcept:
53- """ Interpolate at idx using points (idx-1, idx, idx+1) keyed by key_kind at key_value."""
71+ cdef int _interpolate_nogil_raw(_CBaseTrajSeq_cview* seq, Py_ssize_t idx, int key_kind, double key_value, BaseTrajC* out) noexcept nogil :
72+ """ Interpolate at idx using points (idx-1, idx, idx+1), computing new BaseTrajC where out.key_kind== key_value."""
5473 cdef BaseTrajC* buffer = seq._buffer
5574 cdef Py_ssize_t plength = < Py_ssize_t> seq._length
5675 cdef BaseTrajC * p0
@@ -124,29 +143,11 @@ cdef int _interpolate_nogil_raw(_CBaseTrajSeq_cview* seq, Py_ssize_t idx, int ke
124143 return 1
125144
126145
127- cdef inline double _key_val_from_kind_buf(BaseTrajC* p, int key_kind) noexcept:
128- if key_kind == < int > KEY_TIME:
129- return p.time
130- elif key_kind == < int > KEY_MACH:
131- return p.mach
132- elif key_kind == < int > KEY_POS_X:
133- return p.px
134- elif key_kind == < int > KEY_POS_Y:
135- return p.py
136- elif key_kind == < int > KEY_POS_Z:
137- return p.pz
138- elif key_kind == < int > KEY_VEL_X:
139- return p.vx
140- elif key_kind == < int > KEY_VEL_Y:
141- return p.vy
142- elif key_kind == < int > KEY_VEL_Z:
143- return p.vz
144- return < double > 0.0
145-
146- cdef inline double _slant_val_buf(BaseTrajC* p, double ca, double sa) noexcept:
146+ cdef inline double _slant_val_buf(BaseTrajC* p, double ca, double sa) noexcept nogil:
147+ """ Computes the slant_height of a trajectory point `p` given cosine `ca` and sine `sa` of look_angle."""
147148 return p.py * ca - p.px * sa
148149
149- cdef Py_ssize_t _bisect_center_idx_buf(BaseTrajC* buf, size_t length, int key_kind, double key_value) noexcept:
150+ cdef Py_ssize_t _bisect_center_idx_buf(BaseTrajC* buf, size_t length, int key_kind, double key_value) noexcept nogil :
150151 cdef Py_ssize_t n = < Py_ssize_t> length
151152 if n < 3 :
152153 return < Py_ssize_t> (- 1 )
@@ -176,7 +177,7 @@ cdef Py_ssize_t _bisect_center_idx_buf(BaseTrajC* buf, size_t length, int key_ki
176177 return n - 2
177178 return lo
178179
179- cdef Py_ssize_t _bisect_center_idx_slant_buf(BaseTrajC* buf, size_t length, double ca, double sa, double value) noexcept:
180+ cdef Py_ssize_t _bisect_center_idx_slant_buf(BaseTrajC* buf, size_t length, double ca, double sa, double value) noexcept nogil :
180181 cdef Py_ssize_t n = < Py_ssize_t> length
181182 if n < 3 :
182183 return < Py_ssize_t> (- 1 )
@@ -208,9 +209,9 @@ cdef Py_ssize_t _bisect_center_idx_slant_buf(BaseTrajC* buf, size_t length, doub
208209
209210
210211cdef class CBaseTrajSeq:
211- """ Contiguous C buffer of BaseTrajC with fast append and interpolation.
212+ """ Contiguous C buffer of BaseTrajC points with fast append and interpolation.
212213
213- Python-facing access returns lightweight BaseTrajDataT objects; internal
214+ Python-facing access lazily creates lightweight BaseTrajDataT objects; internal
214215 nogil helpers work directly on the C buffer for speed.
215216 """
216217 def __cinit__ (self ):
@@ -282,8 +283,8 @@ cdef class CBaseTrajSeq:
282283 """ Number of points in the sequence."""
283284 return < Py_ssize_t> self ._length
284285
285- def __getitem__ (self , idx ) :
286- """ Return BaseTrajDataT for the given index (supports negative indices) ."""
286+ def __getitem__ (self , idx: int ) -> BaseTrajDataT :
287+ """Return BaseTrajDataT for the given index. Supports negative indices."""
287288 cdef V3dT position
288289 cdef V3dT velocity
289290 cdef BaseTrajC* entry_ptr
@@ -350,12 +351,12 @@ cdef class CBaseTrajSeq:
350351 """ Interpolate using points (idx-1, idx, idx+1) keyed by key_attribute at key_value."""
351352 return self ._interpolate_at_c(idx, key_attribute, key_value)
352353
353- def get_at (self , str key_attribute , double key_value , start_from = None , start_from_time = None ):
354- """ Get BaseTrajDataT where key_attribute == key_value (quadratic interpolation).
354+ def get_at (self , str key_attribute , double key_value , start_from_time = None ):
355+ """ Get BaseTrajDataT where key_attribute == key_value (via quadratic interpolation).
355356
356357 If start_from_time > 0, search is centered from the first point where time >= start_from_time,
357358 and proceeds forward or backward depending on local direction, mirroring
358- trajectory_data.HitResult.get_at.
359+ trajectory_data.HitResult.get_at() .
359360 """
360361 cdef int key_kind
361362 cdef Py_ssize_t n
@@ -399,8 +400,6 @@ cdef class CBaseTrajSeq:
399400 sft = < double > 0.0
400401 if start_from_time is not None :
401402 sft = < double > float (start_from_time)
402- elif start_from is not None :
403- sft = < double > float (start_from)
404403 if sft > < double > 0.0 and key_kind != < int > KEY_TIME:
405404 buf = self ._buffer
406405 start_idx = < Py_ssize_t> 0
0 commit comments