| 35 | |
| 36 | namespace godot{ |
| 37 | struct Vector2 { |
| 38 | static const int AXIS_COUNT = 2; |
| 39 | |
| 40 | enum Axis { |
| 41 | AXIS_X, |
| 42 | AXIS_Y, |
| 43 | }; |
| 44 | |
| 45 | union { |
| 46 | struct { |
| 47 | union { |
| 48 | real_t x; |
| 49 | real_t width; |
| 50 | }; |
| 51 | union { |
| 52 | real_t y; |
| 53 | real_t height; |
| 54 | }; |
| 55 | }; |
| 56 | |
| 57 | real_t coord[2] = { 0 }; |
| 58 | }; |
| 59 | |
| 60 | void normalize() |
| 61 | { |
| 62 | real_t l = x * x + y * y; |
| 63 | if (l != 0) { |
| 64 | l = ::sqrt(l); |
| 65 | x /= l; |
| 66 | y /= l; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | Vector2 ceil() const |
| 71 | { |
| 72 | return Vector2(::ceil(x), ::ceil(y)); |
| 73 | } |
| 74 | |
| 75 | Vector2 normalized() const |
| 76 | { |
| 77 | Vector2 v = *this; |
| 78 | v.normalize(); |
| 79 | return v; |
| 80 | } |
| 81 | |
| 82 | Vector2 round() const |
| 83 | { |
| 84 | return Vector2(std::round(x), std::round(y)); |
| 85 | } |
| 86 | |
| 87 | real_t dot(const Vector2 &p_other) const |
| 88 | { |
| 89 | return x * p_other.x + y * p_other.y; |
| 90 | } |
| 91 | |
| 92 | real_t cross(const Vector2 &p_other) const |
| 93 | { |
| 94 | return x * p_other.y - y * p_other.x; |
no outgoing calls
no test coverage detected