Generic.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef CORE_GENERIC_H
  2. #define CORE_GENERIC_H
  3. #ifdef IMPORT_CORE
  4. #define addSet(a, b) \
  5. _Generic((a), \
  6. Vector2 *: addSetV2, \
  7. Vector3 *: addSetV3, \
  8. Vector4 *: addSetV4, \
  9. IntVector2 *: addSetIV2, \
  10. IntVector3 *: addSetIV3, \
  11. IntVector4 *: addSetIV4)(a, b)
  12. #define add(a, b, c) \
  13. _Generic((a), \
  14. Vector2 *: addV2, \
  15. Vector3 *: addV3, \
  16. Vector4 *: addV4, \
  17. IntVector2 *: addIV2, \
  18. IntVector3 *: addIV3, \
  19. IntVector4 *: addIV4)(a, b, c)
  20. #define subSet(a, b) \
  21. _Generic((a), \
  22. Vector2 *: subSetV2, \
  23. Vector3 *: subSetV3, \
  24. Vector4 *: subSetV4, \
  25. IntVector2 *: subSetIV2, \
  26. IntVector3 *: subSetIV3, \
  27. IntVector4 *: subSetIV4)(a, b)
  28. #define sub(a, b, c) \
  29. _Generic((a), \
  30. Vector2 *: subV2, \
  31. Vector3 *: subV3, \
  32. Vector4 *: subV4, \
  33. IntVector2 *: subIV2, \
  34. IntVector3 *: subIV3, \
  35. IntVector4 *: subIV4)(a, b, c)
  36. #define mulSet(a, b) \
  37. _Generic((a), \
  38. Vector2 *: _Generic((b), Vector2 *: mulSetV2, default: mulSetV2F), \
  39. Vector3 *: _Generic((b), Vector3 *: mulSetV3, default: mulSetV3F), \
  40. Vector4 *: _Generic((b), Vector4 *: mulSetV4, default: mulSetV4F), \
  41. IntVector2 *: _Generic((b), \
  42. IntVector2 *: mulSetIV2, \
  43. default: mulSetIV2F), \
  44. IntVector3 *: _Generic((b), \
  45. IntVector3 *: mulSetIV3, \
  46. default: mulSetIV3F), \
  47. IntVector4 *: _Generic((b), \
  48. IntVector4 *: mulSetIV4, \
  49. default: mulSetIV4F))(a, b)
  50. #define mul(a, b, c) \
  51. _Generic((a), \
  52. Vector2 *: _Generic((c), Vector2 *: mulV2, default: mulV2F), \
  53. Vector3 *: _Generic((c), Vector3 *: mulV3, default: mulV3F), \
  54. Vector4 *: _Generic((c), Vector4 *: mulV4, default: mulV4F), \
  55. IntVector2 *: _Generic((c), IntVector2 *: mulIV2, default: mulIV2F), \
  56. IntVector3 *: _Generic((c), IntVector3 *: mulIV3, default: mulIV3F), \
  57. IntVector4 *: _Generic((c), IntVector4 *: mulIV4, default: mulIV4F))( \
  58. a, b, c)
  59. #define divSet(a, b) \
  60. _Generic((a), \
  61. Vector2 *: _Generic((b), Vector2 *: divSetV2, default: divSetV2F), \
  62. Vector3 *: _Generic((b), Vector3 *: divSetV3, default: divSetV3F), \
  63. Vector4 *: _Generic((b), Vector4 *: divSetV4, default: divSetV4F), \
  64. IntVector2 *: _Generic((b), \
  65. IntVector2 *: divSetIV2, \
  66. default: divSetIV2F), \
  67. IntVector3 *: _Generic((b), \
  68. IntVector3 *: divSetIV3, \
  69. default: divSetIV3F), \
  70. IntVector4 *: _Generic((b), \
  71. IntVector4 *: divSetIV4, \
  72. default: divSetIV4F))(a, b)
  73. #define div(a, b, c) \
  74. _Generic((a), \
  75. Vector2 *: _Generic((c), Vector2 *: divV2, default: divV2F), \
  76. Vector3 *: _Generic((c), Vector3 *: divV3, default: divV3F), \
  77. Vector4 *: _Generic((c), Vector4 *: divV4, default: divV4F), \
  78. IntVector2 *: _Generic((c), IntVector2 *: divIV2, default: divIV2F), \
  79. IntVector3 *: _Generic((c), IntVector3 *: divIV3, default: divIV3F), \
  80. IntVector4 *: _Generic((c), IntVector4 *: divIV4, default: divIV4F))( \
  81. a, b, c)
  82. #define invertSet(a) \
  83. _Generic((a), \
  84. Vector2 *: invertSetV2, \
  85. Vector3 *: invertSetV3, \
  86. Vector4 *: invertSetV4, \
  87. IntVector2 *: invertSetIV2, \
  88. IntVector3 *: invertSetIV3, \
  89. IntVector4 *: invertSetIV4)(a)
  90. #define invert(a, b) \
  91. _Generic((a), \
  92. Vector2 *: invertV2, \
  93. Vector3 *: invertV3, \
  94. Vector4 *: invertV4, \
  95. IntVector2 *: invertIV2, \
  96. IntVector3 *: invertIV3, \
  97. IntVector4 *: invertIV4)(a, b)
  98. #define dot(a, b) \
  99. _Generic((a), Vector2 *: dotV2, Vector3 *: dotV3, Vector4 *: dotV4)(a, b)
  100. #define squareLength(a) \
  101. _Generic((a), \
  102. Vector2 *: squareLengthV2, \
  103. Vector3 *: squareLengthV3, \
  104. Vector4 *: squareLengthV4)(a)
  105. #define length(a) \
  106. _Generic((a), \
  107. Vector2 *: lengthV2, \
  108. Vector3 *: lengthV3, \
  109. Vector4 *: lengthV4)(a)
  110. #define normalize(a) \
  111. _Generic((a), \
  112. Vector2 *: normalizeV2, \
  113. Vector3 *: normalizeV3, \
  114. Vector4 *: normalizeV4)(a)
  115. #define convert(a, b) \
  116. _Generic((a), \
  117. Vector2 *: convertIV2, \
  118. Vector3 *: convertIV3, \
  119. Vector4 *: convertIV4, \
  120. IntVector2 *: convertV2, \
  121. IntVector3 *: convertV3, \
  122. IntVector4 *: convertV4)(a, b)
  123. // #define toStringV2 coreToStringV2
  124. #endif
  125. #endif