JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed crashes, autopilot working
[vor.git] / float.h
diff --git a/float.h b/float.h
index 83e0a90..1f07d6c 100644 (file)
--- a/float.h
+++ b/float.h
@@ -12,6 +12,37 @@ fclip(float f, float max)
        return f < SMIDGE || f >= (max - SMIDGE);
 }
 
+static inline float
+fconstrain(float f, float max)
+{
+       max -= SMIDGE;
+
+       if(f > max) {
+               return max;
+       }
+       if(f < SMIDGE) {
+               return SMIDGE;
+       }
+
+       return f;
+}
+
+static inline float
+fconstrain2(float f, float min, float max)
+{
+       min += SMIDGE;
+       max -= SMIDGE;
+
+       if(f > max) {
+               return max;
+       }
+       if(f < min) {
+               return min;
+       }
+
+       return f;
+}
+
 // wrap f so it's within the range [SMIDGE..(max-SMIDGE)]
 // assumes f is not outside this range by more than (max - (2 * SMIDGE))
 static inline float