- added sdf folder ( doesnt work via pip or git=)

This commit is contained in:
bklronin
2025-08-16 20:33:44 +02:00
parent d373b50644
commit 54261bb8fd
19 changed files with 3937 additions and 68 deletions

32
sdf/util.py Normal file
View File

@@ -0,0 +1,32 @@
import math
import functools
import inspect
import numpy as np
pi = math.pi
degrees = math.degrees
radians = math.radians
def n_trailing_ascending_positive(d):
"""
Determine how many elements in a given sequence are positive and ascending.
Args:
d (sequence of numbers): the sequence to check
Returns:
int : the amount of trailing ascending positive elements
"""
d = np.array(d).flatten()
# is the next element larger than previous and positive?
order = (d[1:] > d[:-1]) & (d[:-1] > 0)
# TODO: Not happy at all with this if/else mess. Is there no easier way to find the
# index in a numpy array after which the values are only ascending? 🤔
if np.all(order): # all ascending
return d.size
elif np.all(~order): # none ascending
return 0
else: # count from end how many are ascending
return np.argmin(order[::-1]) + 1