Browse Source

Merge reduced math into utils

Kajetan Johannes Hammerle 3 weeks ago
parent
commit
c58a5c206c
7 changed files with 32 additions and 56 deletions
  1. 0 13
      CMakeLists.txt
  2. 0 36
      include/core/Error.h
  3. 4 0
      include/core/Utility.h
  4. 0 1
      src/Utility.c
  5. 1 5
      test/Main.c
  6. 0 1
      test/Tests.h
  7. 27 0
      test/modules/UtilityTests.c

+ 0 - 13
CMakeLists.txt

@@ -11,7 +11,6 @@ set(SRC
     #"src/BitArray.cpp"
     #"src/Box.cpp"
     #"src/Clock.cpp"
-    #"src/FileReader.cpp"
     #"src/Frustum.cpp"
     #"src/Matrix.cpp"
     #"src/Mutex.cpp"
@@ -29,20 +28,15 @@ set(SRC_TESTS
     "test/modules/BufferTests.c"
     "test/modules/RandomTests.c"
     "test/modules/UtilityTests.c"
-    #"test/modules/ArrayListTests.cpp"
-    #"test/modules/ArrayTests.cpp"
     #"test/modules/BitArrayTests.cpp"
     #"test/modules/BoxTests.cpp"
-    #"test/modules/BufferedValueTests.cpp"
     #"test/modules/ClockTests.cpp"
     #"test/modules/ColorTests.cpp"
     #"test/modules/ComponentsTests.cpp"
-    #"test/modules/FileReaderTests.cpp"
     #"test/modules/FrustumTests.cpp"
     #"test/modules/HashMapTests.cpp"
     #"test/modules/LinkedListTests.cpp"
     #"test/modules/ListTests.cpp"
-    #"test/modules/MathTests.cpp"
     #"test/modules/MatrixStackTests.cpp"
     #"test/modules/MatrixTests.cpp"
     #"test/modules/PlaneTests.cpp"
@@ -167,13 +161,10 @@ target_sources(core PUBLIC
     FILES 
         ./include/core/Buffer.h
         ./include/core/Check.h
-        ./include/core/Error.h
         ./include/core/Logger.h
         ./include/core/Random.h
         ./include/core/Types.h
         ./include/core/Utility.h
-#        ./include/core/Array.hpp
-#        ./include/core/ArrayList.hpp
 #        ./include/core/BitArray.hpp
 #        ./include/core/Components.hpp
 #        ./include/core/HashMap.hpp
@@ -182,12 +173,8 @@ target_sources(core PUBLIC
 #        ./include/core/ProbingHashMap.hpp
 #        ./include/core/RingBuffer.hpp
 #        ./include/core/Stack.hpp
-#        ./include/core/File.hpp
-#        ./include/core/FileReader.hpp
 #        ./include/core/Box.hpp
-#        ./include/core/BufferedValue.hpp
 #        ./include/core/Frustum.hpp
-#        ./include/core/Math.hpp
 #        ./include/core/Matrix.hpp
 #        ./include/core/MatrixStack.hpp
 #        ./include/core/Plane.hpp

+ 0 - 36
include/core/Error.h

@@ -1,36 +0,0 @@
-#ifndef CORE_ERROR_H
-#define CORE_ERROR_H
-
-#include "core/Check.h"
-
-typedef int CoreError;
-#define CORE_ERROR_CODE(n) ((CoreError)(1 << n))
-
-#define CORE_ERROR_NONE 0
-#define CORE_ERROR_ERROR CORE_ERROR_CODE(0)
-#define CORE_ERROR_NEGATIVE_ARGUMENT CORE_ERROR_CODE(1)
-#define CORE_ERROR_CAPACITY_REACHED CORE_ERROR_CODE(2)
-#define CORE_ERROR_BLOCKED_STDOUT CORE_ERROR_CODE(3)
-#define CORE_ERROR_OUT_OF_MEMORY CORE_ERROR_CODE(4)
-#define CORE_ERROR_INVALID_CHAR CORE_ERROR_CODE(5)
-#define CORE_ERROR_NOT_FOUND CORE_ERROR_CODE(6)
-#define CORE_ERROR_INVALID_STATE CORE_ERROR_CODE(7)
-#define CORE_ERROR_INVALID_INDEX CORE_ERROR_CODE(8)
-#define CORE_ERROR_INVALID_ARGUMENT CORE_ERROR_CODE(9)
-#define CORE_ERROR_TIME_NOT_AVAILABLE CORE_ERROR_CODE(10)
-#define CORE_ERROR_SLEEP_INTERRUPTED CORE_ERROR_CODE(11)
-#define CORE_ERROR_THREAD_ERROR CORE_ERROR_CODE(12)
-#define CORE_ERROR_MUTEX_ERROR CORE_ERROR_CODE(13)
-#define CORE_ERROR_EXISTING_KEY CORE_ERROR_CODE(14)
-#define CORE_ERROR_CANNOT_OPEN_FILE CORE_ERROR_CODE(15)
-#define CORE_ERROR_END_OF_FILE CORE_ERROR_CODE(16)
-
-#define CORE_RETURN_ERROR(checked)                                             \
-    {                                                                          \
-        CoreError error = checked;                                             \
-        if(error != CORE_ERROR_NONE) [[unlikely]] {                            \
-            return error;                                                      \
-        }                                                                      \
-    }
-
-#endif

+ 4 - 0
include/core/Utility.h

@@ -5,6 +5,10 @@
 #include "core/Types.h"
 
 size_t corePopCount(u64 u);
+#define coreInterpolate(a, b, factor) (a * (1.0f - factor) + b * factor)
+#define CORE_PI 3.14159265358979323846f
+#define coreRadianToDegree(radians) (radians * (180.0f / CORE_PI))
+#define coreDegreeToRadian(degrees) (degrees * (CORE_PI / 180.0f))
 
 typedef void (*CoreExitHandler)(int, void*);
 void coreExitWithHandler(const char* file, int line, int value);

+ 0 - 1
src/Utility.c

@@ -5,7 +5,6 @@
 #include <string.h>
 
 #include "ErrorSimulator.h"
-#include "core/Error.h"
 #include "core/Logger.h"
 
 static CoreExitHandler exitHandler = nullptr;

+ 1 - 5
test/Main.c

@@ -30,18 +30,14 @@ int main(int argAmount, const char** args) {
             coreTestPostCanary();
         }
     }
-    // coreTestArrayList(light);
-    // coreTestArrayString();
+
     // coreTestBitArray();
     // coreTestBox();
     coreTestBuffer(light);
-    // coreTestBufferedValue();
     // coreTestClock(light);
     // coreTestColor();
     // coreTestComponents();
-    // coreTestFileReader();
     // coreTestFrustum();
-    // coreTestHashedString();
     // coreTestHashMap(light);
     // coreTestLinkedList(light);
     // coreTestList(light);

+ 0 - 1
test/Tests.h

@@ -3,7 +3,6 @@
 
 #include "Test.h"
 
-void coreTestArrayList(bool light);
 void coreTestBitArray(void);
 void coreTestBox(void);
 void coreTestBuffer(bool light);

+ 27 - 0
test/modules/UtilityTests.c

@@ -2,6 +2,8 @@
 #include "../Tests.h"
 #include "core/Utility.h"
 
+static const float eps = 0.0001f;
+
 static void testPopCount() {
     CORE_TEST_U64(4, corePopCount(0xF));
     CORE_TEST_U64(0, corePopCount(0x0));
@@ -32,10 +34,35 @@ static void testMemoryInfoList() {
     coreFree(nullptr);
 }
 
+static void testInterpolate() {
+    CORE_TEST_FLOAT(7.5f, coreInterpolate(5.0f, 10.0f, 0.5f), eps);
+    CORE_TEST_FLOAT(-2.0, coreInterpolate(-10.0f, 10.0f, 0.4f), eps);
+    CORE_TEST_FLOAT(10.0f, coreInterpolate(-3.0f, 10.0f, 1.0f), eps);
+    CORE_TEST_FLOAT(7.0f, coreInterpolate(7.0f, 10.0f, 0.0f), eps);
+    CORE_TEST_FLOAT(6.0f, coreInterpolate(0.0f, 10.0f, 0.6f), eps);
+}
+
+static void testRadianToDegree() {
+    CORE_TEST_FLOAT(45.0f, coreRadianToDegree(CORE_PI * 0.25f), eps);
+    CORE_TEST_FLOAT(90.0f, coreRadianToDegree(CORE_PI * 0.5f), eps);
+    CORE_TEST_FLOAT(180.0f, coreRadianToDegree(CORE_PI), eps);
+    CORE_TEST_FLOAT(360.0f, coreRadianToDegree(CORE_PI * 2.0f), eps);
+}
+
+static void testDegreeToRadian() {
+    CORE_TEST_FLOAT(CORE_PI * 0.25f, coreDegreeToRadian(45.0f), eps);
+    CORE_TEST_FLOAT(CORE_PI * 0.5f, coreDegreeToRadian(90.0f), eps);
+    CORE_TEST_FLOAT(CORE_PI, coreDegreeToRadian(180.0f), eps);
+    CORE_TEST_FLOAT(CORE_PI * 2.0f, coreDegreeToRadian(360.0f), eps);
+}
+
 void coreTestUtility() {
     testPopCount();
     testZeroRellocate();
     testMemoryInfoList();
+    testInterpolate();
+    testRadianToDegree();
+    testDegreeToRadian();
 }
 
 static void outOfMemory(void*) {