Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/laser.fl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ func objects(nodes, count=10)
for i in ..10
let period=2*beta(:beta)[i]+1 phase=uniform(:phase)[i] b=beat/period+phase
let x=map(quad(b%1), beta(:x;i)[b], beta(:x;i)[b+1])-0.5 y=map(quad(b%1), beta(:y;i)[b], beta(:y;i)[b+1])-0.5
let c=map(quad(b%1), hsv(uniform(:hue;i)[b];1;0.5), hsv(uniform(:hue;i)[b+1];1;1))
let c=map(quad(b%1), hsv(uniform(:hue;i)[b];1;1), hsv(uniform(:hue;i)[b+1];1;1))
!group translate=x;y rotate=phase color=c
if i % 2
!ellipse radius=0.05
Expand Down
1 change: 1 addition & 0 deletions src/flitter/model.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cdef class Vector:
cdef int compare(self, Vector other) except -2
cdef Vector slice(self, Vector index)
cdef Vector item(self, int i)
cdef Vector items(self, int start, int end)
cpdef double squared_sum(self) noexcept
cpdef Vector normalize(self)
cpdef Vector dot(self, Vector other)
Expand Down
30 changes: 29 additions & 1 deletion src/flitter/model.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,34 @@ cdef class Vector:
result.numbers[0] = self.numbers[i]
return result

cdef Vector items(self, int start, int end):
cdef int i, j, n = self.length, m = end - start
if m <= 0 or end <= 0 or start >= n:
return null_
cdef list objects = self.objects
cdef PyObject* objptr
cdef Vector result = Vector.__new__(Vector)
result.allocate_numbers(m)
if objects is not None:
j = 0
for i in range(start, end):
objptr = PyList_GET_ITEM(objects, i)
if type(<object>objptr) is float:
result.numbers[j] = PyFloat_AS_DOUBLE(<object>objptr)
elif type(<object>objptr) is int:
result.numbers[j] = PyLong_AsDouble(<object>objptr)
else:
result.deallocate_numbers()
result.objects = list(self.objects)
break
j += 1
else:
j = 0
for i in range(start, end):
result.numbers[j] = self.numbers[i]
j += 1
return result

@cython.cdivision(True)
cpdef double squared_sum(self) noexcept:
cdef int i, n = self.length
Expand Down Expand Up @@ -1871,7 +1899,7 @@ cdef class Node:
for i in range(result.allocate_numbers(n)):
result.numbers[i] = value.numbers[0]
return result
elif m == n:
elif m == n or n == 0:
return value
return default

Expand Down
Loading