From b62a78765dbc5b6cb1342c3660982bc5b6387b84 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 7 Oct 2019 18:07:57 +1100 Subject: [PATCH] Remove Math_FastTan Despite the name, it's not even fast at all. And it's only used from one place where replacing with a simple sin(x) / cos(x) will do anyways. --- src/ExtMath.c | 12 ------------ src/ExtMath.h | 1 - src/Vectors.c | 3 ++- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/ExtMath.c b/src/ExtMath.c index f0f785cb1..e5e3398c2 100644 --- a/src/ExtMath.c +++ b/src/ExtMath.c @@ -72,18 +72,6 @@ bool Math_IsPowOf2(int value) { return value != 0 && (value & (value - 1)) == 0; } -/* Not the most precise Tan(x), but within 10^-15 of answer, so good enough for here */ -double Math_FastTan(double angle) { - double cosA = Math_Cos(angle), sinA = Math_Sin(angle); - int sign; - if (cosA < -0.00000001 || cosA > 0.00000001) return sinA / cosA; - - /* tan line is parallel to y axis, infinite gradient */ - sign = Math_Sign(sinA); - if (cosA) sign *= Math_Sign(cosA); - return sign * MATH_POS_INF; -} - double Math_FastLog(double x) { /* x = 2^exp * mantissa */ /* so log(x) = log(2^exp) + log(mantissa) */ diff --git a/src/ExtMath.h b/src/ExtMath.h index 250f67d02..6ae7f74ba 100644 --- a/src/ExtMath.h +++ b/src/ExtMath.h @@ -31,7 +31,6 @@ double Math_Log(double x); /* Computes e^x. Can also be used to approximate y^x. */ /* e.g. for 3^x, use: Math_Exp(log(3)*x) */ double Math_Exp(double x); -double Math_FastTan(double x); int Math_Floor(float value); int Math_Ceil(float value); diff --git a/src/Vectors.c b/src/Vectors.c index ac8fdf58c..f17e71f33 100644 --- a/src/Vectors.c +++ b/src/Vectors.c @@ -183,8 +183,9 @@ void Matrix_OrthographicOffCenter(struct Matrix* result, float left, float right result->Row3.Z = -(zFar + zNear) / (zFar - zNear); } +static double Tan_Simple(double x) { return Math_Sin(x) / Math_Cos(x); } void Matrix_PerspectiveFieldOfView(struct Matrix* result, float fovy, float aspect, float zNear, float zFar) { - float c = zNear * (float)Math_FastTan(0.5f * fovy); + float c = zNear * (float)Tan_Simple(0.5f * fovy); Matrix_PerspectiveOffCenter(result, -c * aspect, c * aspect, -c, c, zNear, zFar); }