diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 14:29:06 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:54:55 +0200 |
commit | 07bc4e2f96f8f47991339654ff4ab16acc19d44f (patch) | |
tree | 43cdc7cfe8239c23065616a931de3769d2db1e86 /core/math | |
parent | 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a (diff) |
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.
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/aabb.cpp | 5 | ||||
-rw-r--r-- | core/math/basis.cpp | 1 | ||||
-rw-r--r-- | core/math/camera_matrix.cpp | 1 | ||||
-rw-r--r-- | core/math/geometry.cpp | 1 | ||||
-rw-r--r-- | core/math/octree.h | 1 | ||||
-rw-r--r-- | core/math/transform.cpp | 2 | ||||
-rw-r--r-- | core/math/transform.h | 2 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 3 | ||||
-rw-r--r-- | core/math/transform_2d.h | 2 | ||||
-rw-r--r-- | core/math/vector2.cpp | 4 | ||||
-rw-r--r-- | core/math/vector2.h | 4 | ||||
-rw-r--r-- | core/math/vector3.cpp | 3 | ||||
-rw-r--r-- | core/math/vector3.h | 2 | ||||
-rw-r--r-- | core/math/vector3i.cpp | 2 | ||||
-rw-r--r-- | core/math/vector3i.h | 2 |
15 files changed, 35 insertions, 0 deletions
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 588ee84f58..d9cb928944 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -39,6 +39,7 @@ real_t AABB::get_area() const { bool AABB::operator==(const AABB &p_rval) const { return ((position == p_rval.position) && (size == p_rval.size)); } + bool AABB::operator!=(const AABB &p_rval) const { return ((position != p_rval.position) || (size != p_rval.size)); } @@ -238,6 +239,7 @@ Vector3 AABB::get_longest_axis() const { return axis; } + int AABB::get_longest_axis_index() const { int axis = 0; real_t max_size = size.x; @@ -269,6 +271,7 @@ Vector3 AABB::get_shortest_axis() const { return axis; } + int AABB::get_shortest_axis_index() const { int axis = 0; real_t max_size = size.x; @@ -290,11 +293,13 @@ AABB AABB::merge(const AABB &p_with) const { aabb.merge_with(p_with); return aabb; } + AABB AABB::expand(const Vector3 &p_vector) const { AABB aabb = *this; aabb.expand_to(p_vector); return aabb; } + AABB AABB::grow(real_t p_by) const { AABB aabb = *this; aabb.grow_by(p_by); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index e6bf6110f7..9981b673ed 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -327,6 +327,7 @@ void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) { // M -> (M.R.Minv).M = M.R. *this = rotated_local(p_axis, p_phi); } + Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const { return (*this) * Basis(p_axis, p_phi); } diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 4b147bd987..c7a3918fe5 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -238,6 +238,7 @@ real_t CameraMatrix::get_z_far() const { return new_plane.d; } + real_t CameraMatrix::get_z_near() const { const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] + matrix[2], diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 3085997225..f1676ec152 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -51,6 +51,7 @@ bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> } return false; } + */ void Geometry::MeshData::optimize_vertices() { diff --git a/core/math/octree.h b/core/math/octree.h index 0782a39804..067103112d 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -1218,6 +1218,7 @@ void Octree<T, use_pairs, AL>::set_pair_callback(PairCallback p_callback, void * pair_callback = p_callback; pair_callback_userdata = p_userdata; } + template <class T, bool use_pairs, class AL> void Octree<T, use_pairs, AL>::set_unpair_callback(UnpairCallback p_callback, void *p_userdata) { unpair_callback = p_callback; diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 0f62c8b2c0..0274dd18af 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -145,6 +145,7 @@ void Transform::scale_basis(const Vector3 &p_scale) { void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) { translate(Vector3(p_tx, p_ty, p_tz)); } + void Transform::translate(const Vector3 &p_translation) { for (int i = 0; i < 3; i++) { origin[i] += basis[i].dot(p_translation); @@ -174,6 +175,7 @@ bool Transform::is_equal_approx(const Transform &p_transform) const { bool Transform::operator==(const Transform &p_transform) const { return (basis == p_transform.basis && origin == p_transform.origin); } + bool Transform::operator!=(const Transform &p_transform) const { return (basis != p_transform.basis || origin != p_transform.origin); } diff --git a/core/math/transform.h b/core/math/transform.h index 7f7e9ce833..71847d36ac 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -117,6 +117,7 @@ _FORCE_INLINE_ Vector3 Transform::xform(const Vector3 &p_vector) const { basis[1].dot(p_vector) + origin.y, basis[2].dot(p_vector) + origin.z); } + _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { Vector3 v = p_vector - origin; @@ -138,6 +139,7 @@ _FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const { return Plane(normal, d); } + _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index f82d1d99c4..eecfc862f5 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -123,15 +123,18 @@ void Transform2D::scale(const Size2 &p_scale) { scale_basis(p_scale); elements[2] *= p_scale; } + void Transform2D::scale_basis(const Size2 &p_scale) { elements[0][0] *= p_scale.x; elements[0][1] *= p_scale.y; elements[1][0] *= p_scale.x; elements[1][1] *= p_scale.y; } + void Transform2D::translate(real_t p_tx, real_t p_ty) { translate(Vector2(p_tx, p_ty)); } + void Transform2D::translate(const Vector2 &p_translation) { elements[2] += basis_xform(p_translation); } diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index 66958257d7..46e97abaa7 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -153,6 +153,7 @@ Vector2 Transform2D::xform(const Vector2 &p_vec) const { tdoty(p_vec)) + elements[2]; } + Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { Vector2 v = p_vec - elements[2]; @@ -160,6 +161,7 @@ Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { elements[0].dot(v), elements[1].dot(v)); } + Rect2 Transform2D::xform(const Rect2 &p_rect) const { Vector2 x = elements[0] * p_rect.size.x; Vector2 y = elements[1] * p_rect.size.y; diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index d06f64b40b..7f264ce119 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -192,13 +192,16 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const { Vector2i Vector2i::operator+(const Vector2i &p_v) const { return Vector2i(x + p_v.x, y + p_v.y); } + void Vector2i::operator+=(const Vector2i &p_v) { x += p_v.x; y += p_v.y; } + Vector2i Vector2i::operator-(const Vector2i &p_v) const { return Vector2i(x - p_v.x, y - p_v.y); } + void Vector2i::operator-=(const Vector2i &p_v) { x -= p_v.x; y -= p_v.y; @@ -236,6 +239,7 @@ Vector2i Vector2i::operator-() const { bool Vector2i::operator==(const Vector2i &p_vec2) const { return x == p_vec2.x && y == p_vec2.y; } + bool Vector2i::operator!=(const Vector2i &p_vec2) const { return x != p_vec2.x || y != p_vec2.y; } 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; } diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 8acbe31f35..4a9b251406 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -46,6 +46,7 @@ void Vector3::set_axis(int p_axis, real_t p_value) { ERR_FAIL_INDEX(p_axis, 3); coord[p_axis] = p_value; } + real_t Vector3::get_axis(int p_axis) const { ERR_FAIL_INDEX_V(p_axis, 3, 0); return operator[](p_axis); @@ -54,6 +55,7 @@ real_t Vector3::get_axis(int p_axis) const { int Vector3::min_axis() const { return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); } + int Vector3::max_axis() const { return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); } @@ -63,6 +65,7 @@ void Vector3::snap(Vector3 p_val) { y = Math::stepify(y, p_val.y); z = Math::stepify(z, p_val.z); } + Vector3 Vector3::snapped(Vector3 p_val) const { Vector3 v = *this; v.snap(p_val); diff --git a/core/math/vector3.h b/core/math/vector3.h index 5fc412628f..3e35a5bba2 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -256,6 +256,7 @@ Vector3 &Vector3::operator-=(const Vector3 &p_v) { z -= p_v.z; return *this; } + Vector3 Vector3::operator-(const Vector3 &p_v) const { return Vector3(x - p_v.x, y - p_v.y, z - p_v.z); } @@ -266,6 +267,7 @@ Vector3 &Vector3::operator*=(const Vector3 &p_v) { z *= p_v.z; return *this; } + Vector3 Vector3::operator*(const Vector3 &p_v) const { return Vector3(x * p_v.x, y * p_v.y, z * p_v.z); } diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp index e621d5493a..718a1553a0 100644 --- a/core/math/vector3i.cpp +++ b/core/math/vector3i.cpp @@ -34,6 +34,7 @@ void Vector3i::set_axis(int p_axis, int32_t p_value) { ERR_FAIL_INDEX(p_axis, 3); coord[p_axis] = p_value; } + int32_t Vector3i::get_axis(int p_axis) const { ERR_FAIL_INDEX_V(p_axis, 3, 0); return operator[](p_axis); @@ -42,6 +43,7 @@ int32_t Vector3i::get_axis(int p_axis) const { int Vector3i::min_axis() const { return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); } + int Vector3i::max_axis() const { return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); } diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 5ecd3228b2..524f45b452 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -132,6 +132,7 @@ Vector3i &Vector3i::operator-=(const Vector3i &p_v) { z -= p_v.z; return *this; } + Vector3i Vector3i::operator-(const Vector3i &p_v) const { return Vector3i(x - p_v.x, y - p_v.y, z - p_v.z); } @@ -142,6 +143,7 @@ Vector3i &Vector3i::operator*=(const Vector3i &p_v) { z *= p_v.z; return *this; } + Vector3i Vector3i::operator*(const Vector3i &p_v) const { return Vector3i(x * p_v.x, y * p_v.y, z * p_v.z); } |