mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-12-29 08:04:31 +00:00
Compare commits
6 Commits
slerp-nan
...
general_ma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea6ab8e64e | ||
|
|
69f8a38912 | ||
|
|
44aca901ea | ||
|
|
f925f83683 | ||
|
|
81659df32d | ||
|
|
9d5baac382 |
766
HandmadeMath.h
766
HandmadeMath.h
File diff suppressed because it is too large
Load Diff
@@ -10,11 +10,8 @@ To get started, go download [the latest release](https://github.com/HandmadeMath
|
||||
|
||||
Version | Changes |
|
||||
----------------|----------------|
|
||||
**1.12.1** | Added extra parentheses around some macros |
|
||||
**1.12.0** | Added Unary Minus operator for `HMM_Vec2`, `HMM_Vec3`, and `HMM_Vec4`. |
|
||||
**1.11.1** | Added HMM_PREFIX macro to a few functions that were missing it. |
|
||||
**1.11.0** | Added ability to customize or remove the default `HMM_` prefix on function names by defining a macro called `HMM_PREFIX(name)`. |
|
||||
**1.10.1** | Removed stdint.h, this doesn't exist on some really old compilers and we didn't really use it anyways. |
|
||||
**1.10.2** | Introduced safe floating point comparison in HMM_EqualsVec2, HMM_EqualsVec3, HMM_EqualsVec4. SIMD'd HMM_EqualsVec4 comparison |
|
||||
**1.10.1** | Removed use of stdint.h, this doesn't exist on some really old compilers and we didn't really use it anyways. |
|
||||
**1.10.0** | Made HMM_Perspective use vertical FOV instead of horizontal FOV for consistency with other graphics APIs. |
|
||||
**1.9.0** | Added SSE versions of quaternion operations. |
|
||||
**1.8.0** | Added fast vector normalization routines that use fast inverse square roots.
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#define HMM_PREFIX(name) WOW_##name
|
||||
|
||||
#define HANDMADE_MATH_IMPLEMENTATION
|
||||
#define HANDMADE_MATH_NO_INLINE
|
||||
#include "../HandmadeMath.h"
|
||||
|
||||
int main() {
|
||||
hmm_vec4 a = WOW_Vec4(1, 2, 3, 4);
|
||||
hmm_vec4 b = WOW_Vec4(5, 6, 7, 8);
|
||||
|
||||
WOW_Add(a, b);
|
||||
}
|
||||
@@ -58,7 +58,6 @@
|
||||
#define HANDMADETEST_H
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -153,7 +152,7 @@ INITIALIZER(_HMT_COVERCASE_FUNCNAME_INIT(name)) { \
|
||||
_HMT_CASE_START(); \
|
||||
float actual = (_actual); \
|
||||
float diff = actual - (_expected); \
|
||||
if (isnan(actual) || diff < -FLT_EPSILON || FLT_EPSILON < diff) { \
|
||||
if (diff < -FLT_EPSILON || FLT_EPSILON < diff) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f, got %f", (_expected), actual); \
|
||||
} \
|
||||
@@ -163,7 +162,7 @@ INITIALIZER(_HMT_COVERCASE_FUNCNAME_INIT(name)) { \
|
||||
_HMT_CASE_START(); \
|
||||
float actual = (_actual); \
|
||||
float diff = actual - (_expected); \
|
||||
if (isnan(actual) || diff < -(_epsilon) || (_epsilon) < diff) { \
|
||||
if (diff < -(_epsilon) || (_epsilon) < diff) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f, got %f", (_expected), actual); \
|
||||
} \
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
BUILD_DIR=./build
|
||||
|
||||
CXXFLAGS+=-g -Wall -Wextra -pthread -Wno-missing-braces -Wno-missing-field-initializers -Wfloat-equal
|
||||
CXXFLAGS+=-g -Wall -Wextra -pthread -Wno-missing-braces -Wno-missing-field-initializers
|
||||
|
||||
all: c c_no_sse cpp cpp_no_sse build_c_without_coverage build_cpp_without_coverage build_cpp_different_prefix
|
||||
all: c c_no_sse cpp cpp_no_sse build_c_without_coverage build_cpp_without_coverage
|
||||
|
||||
build_all: build_c build_c_no_sse build_cpp build_cpp_no_sse
|
||||
|
||||
@@ -58,7 +58,7 @@ build_cpp_no_sse: HandmadeMath.cpp test_impl
|
||||
|
||||
test_impl: hmm_test.cpp hmm_test.c
|
||||
|
||||
build_c_without_coverage: HandmadeMath.c test_impl
|
||||
build_c_without_coverage: HandmadeMath.c
|
||||
@echo "\nCompiling in C mode"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR)\
|
||||
@@ -75,11 +75,3 @@ build_cpp_without_coverage: HandmadeMath.cpp test_impl
|
||||
&& $(CXX) $(CPPFLAGS) $(CXXFLAGS) -ohmm_test_cpp_no_sse \
|
||||
-DHANDMADE_MATH_CPP_MODE -DWITHOUT_COVERAGE \
|
||||
../HandmadeMath.cpp ../hmm_test.cpp
|
||||
|
||||
build_cpp_different_prefix: HandmadeMath.cpp
|
||||
@echo "\nCompiling C++ with different prefix"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR) \
|
||||
&& $(CXX) $(CPPFLAGS) $(CXXFLAGS) -ohmm_test_cpp_different_prefix \
|
||||
-DHANDMADE_MATH_CPP_MODE -DDIFFERENT_PREFIX \
|
||||
../HandmadeMathDifferentPrefix.cpp
|
||||
|
||||
@@ -66,39 +66,14 @@ TEST(QuaternionOps, NLerp)
|
||||
|
||||
TEST(QuaternionOps, Slerp)
|
||||
{
|
||||
// Normal operation
|
||||
{
|
||||
hmm_quaternion from = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
hmm_quaternion to = HMM_Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
hmm_quaternion from = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
hmm_quaternion to = HMM_Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
|
||||
hmm_quaternion result = HMM_Slerp(from, 0.5f, to);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.86602540f);
|
||||
}
|
||||
|
||||
// Same quat twice
|
||||
{
|
||||
hmm_quaternion q = HMM_Quaternion(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
|
||||
hmm_quaternion result = HMM_Slerp(q, 0.5f, q);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.W, 1.0f);
|
||||
}
|
||||
|
||||
// Identity quat twice
|
||||
{
|
||||
hmm_quaternion q = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
hmm_quaternion result = HMM_Slerp(q, 0.5f, q);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 1.0f);
|
||||
}
|
||||
hmm_quaternion result = HMM_Slerp(from, 0.5f, to);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.86602540f);
|
||||
}
|
||||
|
||||
TEST(QuaternionOps, QuatToMat4)
|
||||
|
||||
@@ -74,9 +74,9 @@ TEST(ScalarMath, Power)
|
||||
|
||||
TEST(ScalarMath, PowerF)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(2.0f, 0.0f), 1.0f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, 4.1f), 17.148376f, 0.0001f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, -2.5f), 0.176777f, 0.0001f);
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(2.0f, 0), 1.0f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, 4.1), 17.148376f, 0.0001f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, -2.5), 0.176777f, 0.0001f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, Lerp)
|
||||
|
||||
@@ -199,32 +199,3 @@ TEST(Subtraction, Quaternion)
|
||||
EXPECT_FLOAT_EQ(q1.W, -4.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
TEST(UnaryMinus, Vec2)
|
||||
{
|
||||
hmm_vec2 VectorOne = {1.0f, 2.0f};
|
||||
hmm_vec2 Result = -VectorOne;
|
||||
EXPECT_FLOAT_EQ(Result.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
|
||||
}
|
||||
|
||||
TEST(UnaryMinus, Vec3)
|
||||
{
|
||||
hmm_vec3 VectorOne = {1.0f, 2.0f, 3.0f};
|
||||
hmm_vec3 Result = -VectorOne;
|
||||
EXPECT_FLOAT_EQ(Result.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Z, -3.0f);
|
||||
}
|
||||
|
||||
TEST(UnaryMinus, Vec4)
|
||||
{
|
||||
hmm_vec4 VectorOne = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
hmm_vec4 Result = -VectorOne;
|
||||
EXPECT_FLOAT_EQ(Result.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Z, -3.0f);
|
||||
EXPECT_FLOAT_EQ(Result.W, -4.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user