summaryrefslogtreecommitdiff
path: root/modules/mono/glue
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-09-21 21:30:30 +0200
committerGitHub <noreply@github.com>2021-09-21 21:30:30 +0200
commitba57252bd8d7928c29e818b1ccf557e279c33ca0 (patch)
tree6b037a4a0b8b6907d571b1b847ed6ab3bc7507c3 /modules/mono/glue
parent726b826b310900ff475122ed65934d2499b8db4d (diff)
parent90908cd67d3f44ba70cc4b7b32f024ce508cc0ee (diff)
Merge pull request #52878 from AnilBK/add-get-center
Diffstat (limited to 'modules/mono/glue')
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs10
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs10
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs14
3 files changed, 33 insertions, 1 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs
index 8b12537f7f..70a2cf5695 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs
@@ -67,6 +67,16 @@ namespace Godot
}
/// <summary>
+ /// Returns the center of the <see cref="AABB"/>, which is equal
+ /// to <see cref="Position"/> + (<see cref="Size"/> / 2).
+ /// </summary>
+ /// <returns>The center.</returns>
+ public Vector3 GetCenter()
+ {
+ return _position + (_size * 0.5f);
+ }
+
+ /// <summary>
/// Returns <see langword="true"/> if this <see cref="AABB"/> completely encloses another one.
/// </summary>
/// <param name="with">The other <see cref="AABB"/> that may be enclosed.</param>
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
index 1d001fba2d..af94484577 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs
@@ -165,6 +165,16 @@ namespace Godot
}
/// <summary>
+ /// Returns the center of the <see cref="Rect2"/>, which is equal
+ /// to <see cref="Position"/> + (<see cref="Size"/> / 2).
+ /// </summary>
+ /// <returns>The center.</returns>
+ public Vector2 GetCenter()
+ {
+ return _position + (_size * 0.5f);
+ }
+
+ /// <summary>
/// Returns a copy of the <see cref="Rect2"/> grown by the specified amount
/// on all sides.
/// </summary>
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs
index 250b0d0baf..03f406a910 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs
@@ -151,7 +151,7 @@ namespace Godot
}
/// <summary>
- /// Returns the area of the <see cref="Rect2"/>.
+ /// Returns the area of the <see cref="Rect2i"/>.
/// </summary>
/// <returns>The area.</returns>
public int GetArea()
@@ -160,6 +160,18 @@ namespace Godot
}
/// <summary>
+ /// Returns the center of the <see cref="Rect2i"/>, which is equal
+ /// to <see cref="Position"/> + (<see cref="Size"/> / 2).
+ /// If <see cref="Size"/> is an odd number, the returned center
+ /// value will be rounded towards <see cref="Position"/>.
+ /// </summary>
+ /// <returns>The center.</returns>
+ public Vector2i GetCenter()
+ {
+ return _position + (_size / 2);
+ }
+
+ /// <summary>
/// Returns a copy of the <see cref="Rect2i"/> grown by the specified amount
/// on all sides.
/// </summary>