diff options
author | David Snopek <dsnopek@gmail.com> | 2024-05-07 12:55:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-07 12:55:23 -0500 |
commit | 43be24f34ccaba20faf05c76d724edb2a5339931 (patch) | |
tree | d7df360d17728f4667a4a47953cfddeac590b344 /src/variant/vector2i.cpp | |
parent | 54fe2f9891525891a52c47ffbd190d15c38cccab (diff) | |
parent | b65970860e2cb0b255528553392965b893cbb35f (diff) | |
download | redot-cpp-43be24f34ccaba20faf05c76d724edb2a5339931.tar.gz |
Merge pull request #1437 from AThousandShips/vec_elem_scalar
Add scalar versions of `Vector*` `min/max/clamp/snap(ped)`
Diffstat (limited to 'src/variant/vector2i.cpp')
-rw-r--r-- | src/variant/vector2i.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/variant/vector2i.cpp b/src/variant/vector2i.cpp index c1c1ab0..4baff3b 100644 --- a/src/variant/vector2i.cpp +++ b/src/variant/vector2i.cpp @@ -35,12 +35,30 @@ namespace godot { +Vector2i Vector2i::snapped(const Vector2i &p_step) const { + return Vector2i( + Math::snapped(x, p_step.x), + Math::snapped(y, p_step.y)); +} + +Vector2i Vector2i::snappedi(int32_t p_step) const { + return Vector2i( + Math::snapped(x, p_step), + Math::snapped(y, p_step)); +} + Vector2i Vector2i::clamp(const Vector2i &p_min, const Vector2i &p_max) const { return Vector2i( CLAMP(x, p_min.x, p_max.x), CLAMP(y, p_min.y, p_max.y)); } +Vector2i Vector2i::clampi(int32_t p_min, int32_t p_max) const { + return Vector2i( + CLAMP(x, p_min, p_max), + CLAMP(y, p_min, p_max)); +} + int64_t Vector2i::length_squared() const { return x * (int64_t)x + y * (int64_t)y; } |