33from numpy .polynomial import polynomial as pl
44import numpy as np
55
6+ SMALL_NUMBER = 1e-8
7+ KINDA_SMALL_NUMBER = 1e-4
8+
9+ saturate = lambda x : min (1.0 , max (0.0 , x ))
10+
611def calc_bounds (points ):
712 xs , ys , zs = zip (* points )
813 x0 , y0 , z1 , x1 , y1 , z1 = min (xs ), min (ys ), min (zs ), max (xs ), max (ys ), max (zs )
@@ -29,17 +34,19 @@ def get_dist(a, b):
2934 """Returns the distance between two vectors."""
3035 return sqrt (get_dist_sq (a , b ))
3136
32- def get_direction (a , b ):
33- """Returns the direction from one 3D position to another."""
37+ def get_direction_safe (a , b ):
38+ """Returns the direction from one 3D position to another, or zero vector if they are too close ."""
3439 x , y , z = b [0 ] - a [0 ], b [1 ] - a [1 ], b [2 ] - a [2 ]
3540 k = sqrt (x * x + y * y + z * z )
41+ if k <= SMALL_NUMBER :
42+ return Vector ()
3643 return Vector ((x / k , y / k , z / k ))
3744
3845def get_range_pct (min_value , max_value , value ):
3946 """Calculates the percentage along a line from min_value to max_value."""
4047
4148 divisor = max_value - min_value
42- if divisor <= 0.0001 :
49+ if divisor <= SMALL_NUMBER :
4350 return 1.0 if value >= max_value else 0.0
4451 return (value - min_value ) / divisor
4552
0 commit comments