From 90908cd67d3f44ba70cc4b7b32f024ce508cc0ee Mon Sep 17 00:00:00 2001 From: Anilforextra Date: Tue, 21 Sep 2021 00:33:52 +0545 Subject: Add Get Center Method for Rect2/Rect2i and AABB. --- modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs | 10 ++++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs | 10 ++++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs | 14 +++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) (limited to 'modules/mono/glue') 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 @@ -66,6 +66,16 @@ namespace Godot return new AABB(topLeft, _size.Abs()); } + /// + /// Returns the center of the , which is equal + /// to + ( / 2). + /// + /// The center. + public Vector3 GetCenter() + { + return _position + (_size * 0.5f); + } + /// /// Returns if this completely encloses another one. /// 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 @@ -164,6 +164,16 @@ namespace Godot return _size.x * _size.y; } + /// + /// Returns the center of the , which is equal + /// to + ( / 2). + /// + /// The center. + public Vector2 GetCenter() + { + return _position + (_size * 0.5f); + } + /// /// Returns a copy of the grown by the specified amount /// on all sides. 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 } /// - /// Returns the area of the . + /// Returns the area of the . /// /// The area. public int GetArea() @@ -159,6 +159,18 @@ namespace Godot return _size.x * _size.y; } + /// + /// Returns the center of the , which is equal + /// to + ( / 2). + /// If is an odd number, the returned center + /// value will be rounded towards . + /// + /// The center. + public Vector2i GetCenter() + { + return _position + (_size / 2); + } + /// /// Returns a copy of the grown by the specified amount /// on all sides. -- cgit v1.2.3