mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Use rcpSafe.
This commit is contained in:
@@ -896,7 +896,7 @@ namespace bx
|
|||||||
|
|
||||||
inline BX_CONST_FUNC Vec3 normalize(const Vec3 _a)
|
inline BX_CONST_FUNC Vec3 normalize(const Vec3 _a)
|
||||||
{
|
{
|
||||||
const float invLen = 1.0f/length(_a);
|
const float invLen = rcpSafe(length(_a) );
|
||||||
const Vec3 result = mul(_a, invLen);
|
const Vec3 result = mul(_a, invLen);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -957,14 +957,14 @@ namespace bx
|
|||||||
|
|
||||||
if (abs(nx) > abs(nz) )
|
if (abs(nx) > abs(nz) )
|
||||||
{
|
{
|
||||||
float invLen = 1.0f / sqrt(nx*nx + nz*nz);
|
const float invLen = rcpSafe(sqrt(nx*nx + nz*nz) );
|
||||||
_outT.x = -nz * invLen;
|
_outT.x = -nz * invLen;
|
||||||
_outT.y = 0.0f;
|
_outT.y = 0.0f;
|
||||||
_outT.z = nx * invLen;
|
_outT.z = nx * invLen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float invLen = 1.0f / sqrt(ny*ny + nz*nz);
|
const float invLen = rcpSafe(sqrt(ny*ny + nz*nz) );
|
||||||
_outT.x = 0.0f;
|
_outT.x = 0.0f;
|
||||||
_outT.y = nz * invLen;
|
_outT.y = nz * invLen;
|
||||||
_outT.z = -ny * invLen;
|
_outT.z = -ny * invLen;
|
||||||
@@ -1264,7 +1264,7 @@ namespace bx
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float invSa = 1.0f/sa;
|
const float invSa = rcpSafe(sa);
|
||||||
|
|
||||||
_outAxis = { _a.x * invSa, _a.y * invSa, _a.z * invSa };
|
_outAxis = { _a.x * invSa, _a.y * invSa, _a.z * invSa };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ namespace bx
|
|||||||
///
|
///
|
||||||
BX_CONSTEXPR_FUNC float rcp(float _a);
|
BX_CONSTEXPR_FUNC float rcp(float _a);
|
||||||
|
|
||||||
/// Returns reciprocal of _a.
|
/// Returns reciprocal of _a. Avoids divide by zero.
|
||||||
///
|
///
|
||||||
BX_CONSTEXPR_FUNC float rcpSafe(float _a);
|
BX_CONSTEXPR_FUNC float rcpSafe(float _a);
|
||||||
|
|
||||||
|
|||||||
@@ -670,6 +670,8 @@ void mtxCheck(const float* _a, const float* _b)
|
|||||||
|
|
||||||
TEST_CASE("vec3", "[math][vec3]")
|
TEST_CASE("vec3", "[math][vec3]")
|
||||||
{
|
{
|
||||||
|
REQUIRE(bx::isEqual({0.0f, 0.0f, 0.0f}, bx::normalize({0.0f, 0.0f, 0.0f}), 0.0f) );
|
||||||
|
|
||||||
bx::Vec3 normalized = bx::normalize({0.0f, 1.0f, 0.0f});
|
bx::Vec3 normalized = bx::normalize({0.0f, 1.0f, 0.0f});
|
||||||
REQUIRE(bx::isEqual(normalized, {0.0f, 1.0f, 0.0f}, 0.0f) );
|
REQUIRE(bx::isEqual(normalized, {0.0f, 1.0f, 0.0f}, 0.0f) );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user