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 | |
31 | #include "vector4i.h" |
32 | |
33 | #include "core/math/vector4.h" |
34 | #include "core/string/ustring.h" |
35 | |
36 | Vector4i::Axis Vector4i::min_axis_index() const { |
37 | uint32_t min_index = 0; |
38 | int32_t min_value = x; |
39 | for (uint32_t i = 1; i < 4; i++) { |
40 | if (operator[](i) <= min_value) { |
41 | min_index = i; |
42 | min_value = operator[](i); |
43 | } |
44 | } |
45 | return Vector4i::Axis(min_index); |
46 | } |
47 | |
48 | Vector4i::Axis Vector4i::max_axis_index() const { |
49 | uint32_t max_index = 0; |
50 | int32_t max_value = x; |
51 | for (uint32_t i = 1; i < 4; i++) { |
52 | if (operator[](i) > max_value) { |
53 | max_index = i; |
54 | max_value = operator[](i); |
55 | } |
56 | } |
57 | return Vector4i::Axis(max_index); |
58 | } |
59 | |
60 | Vector4i Vector4i::clamp(const Vector4i &p_min, const Vector4i &p_max) const { |
61 | return Vector4i( |
62 | CLAMP(x, p_min.x, p_max.x), |
63 | CLAMP(y, p_min.y, p_max.y), |
64 | CLAMP(z, p_min.z, p_max.z), |
65 | CLAMP(w, p_min.w, p_max.w)); |
66 | } |
67 | |
68 | Vector4i Vector4i::snapped(const Vector4i &p_step) const { |
69 | return Vector4i( |
70 | Math::snapped(x, p_step.x), |
71 | Math::snapped(y, p_step.y), |
72 | Math::snapped(z, p_step.z), |
73 | Math::snapped(w, p_step.w)); |
74 | } |
75 | |
76 | Vector4i::operator String() const { |
77 | return "(" + itos(x) + ", " + itos(y) + ", " + itos(z) + ", " + itos(w) + ")" ; |
78 | } |
79 | |
80 | Vector4i::operator Vector4() const { |
81 | return Vector4(x, y, z, w); |
82 | } |
83 | |
84 | Vector4i::Vector4i(const Vector4 &p_vec4) { |
85 | x = (int32_t)p_vec4.x; |
86 | y = (int32_t)p_vec4.y; |
87 | z = (int32_t)p_vec4.z; |
88 | w = (int32_t)p_vec4.w; |
89 | } |
90 | |
91 | static_assert(sizeof(Vector4i) == 4 * sizeof(int32_t)); |
92 | |