From 88e3ce5e4f8a942a5cf8f74aa295f5cab68d781b Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 28 Jun 2020 14:55:44 +0000 Subject: add fclamp. --- geometry.h | 1 + quaternion.c | 2 +- utils.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/geometry.h b/geometry.h index 7c273d1..3d99b41 100644 --- a/geometry.h +++ b/geometry.h @@ -37,6 +37,7 @@ struct Triangle3 { /* utils */ double flerp(double, double, double); +double fclamp(double, double, double); /* Point2 */ Point2 Pt2(double, double, double); diff --git a/quaternion.c b/quaternion.c index 8ef32b8..686c04e 100644 --- a/quaternion.c +++ b/quaternion.c @@ -85,6 +85,6 @@ qrotate(Point3 p, Point3 axis, double θ) θ /= 2; qaxis = Quatvec(cos(θ), mulpt3(axis, sin(θ))); - qr = mulq(mulq(qaxis, Quatvec(0, p)), invq(qaxis)); + qr = mulq(mulq(qaxis, Quatvec(0, p)), invq(qaxis)); /* qpq⁻¹ */ return Pt3(qr.i, qr.j, qr.k, p.w); } diff --git a/utils.c b/utils.c index 54141e3..9825923 100644 --- a/utils.c +++ b/utils.c @@ -7,3 +7,9 @@ flerp(double a, double b, double t) { return a + (b - a)*t; } + +double +fclamp(double n, double min, double max) +{ + return n < min? min: n > max? max: n; +} -- cgit v1.2.3