vector4i.cpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**************************************************************************/
  2. /* vector4i.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "vector4i.h"
  31. #include "core/math/vector4.h"
  32. #include "core/string/ustring.h"
  33. Vector4i::Axis Vector4i::min_axis_index() const {
  34. uint32_t min_index = 0;
  35. int32_t min_value = x;
  36. for (uint32_t i = 1; i < 4; i++) {
  37. if (operator[](i) <= min_value) {
  38. min_index = i;
  39. min_value = operator[](i);
  40. }
  41. }
  42. return Vector4i::Axis(min_index);
  43. }
  44. Vector4i::Axis Vector4i::max_axis_index() const {
  45. uint32_t max_index = 0;
  46. int32_t max_value = x;
  47. for (uint32_t i = 1; i < 4; i++) {
  48. if (operator[](i) > max_value) {
  49. max_index = i;
  50. max_value = operator[](i);
  51. }
  52. }
  53. return Vector4i::Axis(max_index);
  54. }
  55. Vector4i Vector4i::clamp(const Vector4i &p_min, const Vector4i &p_max) const {
  56. return Vector4i(
  57. CLAMP(x, p_min.x, p_max.x),
  58. CLAMP(y, p_min.y, p_max.y),
  59. CLAMP(z, p_min.z, p_max.z),
  60. CLAMP(w, p_min.w, p_max.w));
  61. }
  62. Vector4i Vector4i::snapped(const Vector4i &p_step) const {
  63. return Vector4i(
  64. Math::snapped(x, p_step.x),
  65. Math::snapped(y, p_step.y),
  66. Math::snapped(z, p_step.z),
  67. Math::snapped(w, p_step.w));
  68. }
  69. Vector4i::operator String() const {
  70. return "(" + itos(x) + ", " + itos(y) + ", " + itos(z) + ", " + itos(w) + ")";
  71. }
  72. Vector4i::operator Vector4() const {
  73. return Vector4(x, y, z, w);
  74. }
  75. Vector4i::Vector4i(const Vector4 &p_vec4) {
  76. x = (int32_t)p_vec4.x;
  77. y = (int32_t)p_vec4.y;
  78. z = (int32_t)p_vec4.z;
  79. w = (int32_t)p_vec4.w;
  80. }
  81. static_assert(sizeof(Vector4i) == 4 * sizeof(int32_t));