From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- core/math/vector2.h | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'core/math/vector2.h') diff --git a/core/math/vector2.h b/core/math/vector2.h index 5a3e6a0660..5aa40d45f7 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -37,7 +37,6 @@ struct Vector2i; struct Vector2 { - enum Axis { AXIS_X, AXIS_Y, @@ -123,13 +122,11 @@ struct Vector2 { real_t angle() const; _FORCE_INLINE_ Vector2 abs() const { - return Vector2(Math::abs(x), Math::abs(y)); } Vector2 rotated(real_t p_by) const; Vector2 tangent() const { - return Vector2(y, -x); } @@ -150,81 +147,65 @@ struct Vector2 { }; _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const { - return p_vec - *this * (dot(p_vec) - p_d); } _FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; } _FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const { - return Vector2(x + p_v.x, y + p_v.y); } _FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) { - x += p_v.x; y += p_v.y; } _FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const { - return Vector2(x - p_v.x, y - p_v.y); } _FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) { - x -= p_v.x; y -= p_v.y; } _FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v1) const { - return Vector2(x * p_v1.x, y * p_v1.y); }; _FORCE_INLINE_ Vector2 Vector2::operator*(const real_t &rvalue) const { - return Vector2(x * rvalue, y * rvalue); }; _FORCE_INLINE_ void Vector2::operator*=(const real_t &rvalue) { - x *= rvalue; y *= rvalue; }; _FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v1) const { - return Vector2(x / p_v1.x, y / p_v1.y); }; _FORCE_INLINE_ Vector2 Vector2::operator/(const real_t &rvalue) const { - return Vector2(x / rvalue, y / rvalue); }; _FORCE_INLINE_ void Vector2::operator/=(const real_t &rvalue) { - x /= rvalue; y /= rvalue; }; _FORCE_INLINE_ Vector2 Vector2::operator-() const { - return Vector2(-x, -y); } _FORCE_INLINE_ bool Vector2::operator==(const Vector2 &p_vec2) const { - return x == p_vec2.x && y == p_vec2.y; } _FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const { - return x != p_vec2.x || y != p_vec2.y; } Vector2 Vector2::lerp(const Vector2 &p_b, real_t p_t) const { - Vector2 res = *this; res.x += (p_t * (p_b.x - x)); @@ -253,7 +234,6 @@ typedef Vector2 Point2; /* INTEGER STUFF */ struct Vector2i { - enum Axis { AXIS_X, AXIS_Y, -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- core/math/vector2.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core/math/vector2.h') diff --git a/core/math/vector2.h b/core/math/vector2.h index 5aa40d45f7..e5774f1d55 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -157,13 +157,16 @@ _FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) { _FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const { return Vector2(x + p_v.x, y + p_v.y); } + _FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) { x += p_v.x; y += p_v.y; } + _FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const { return Vector2(x - p_v.x, y - p_v.y); } + _FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) { x -= p_v.x; y -= p_v.y; @@ -201,6 +204,7 @@ _FORCE_INLINE_ Vector2 Vector2::operator-() const { _FORCE_INLINE_ bool Vector2::operator==(const Vector2 &p_vec2) const { return x == p_vec2.x && y == p_vec2.y; } + _FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const { return x != p_vec2.x || y != p_vec2.y; } -- cgit v1.2.3