From 20d72e462b8984a96600fcce997da07f0800f00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berke=20Kocao=C4=9Flu?= Date: Sun, 6 Mar 2022 11:16:30 +0300 Subject: Implement `Deconstruct` methods for C# vectors See https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/deconstruct#user-defined-types --- modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs | 9 +++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs | 9 +++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs | 10 ++++++++++ modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs | 10 ++++++++++ 4 files changed, 38 insertions(+) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 8679f28132..ee218cb1f8 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -81,6 +81,15 @@ namespace Godot } } + /// + /// Helper method for deconstruction into a tuple. + /// + public void Deconstruct(out real_t x, out real_t y) + { + x = this.x; + y = this.y; + } + internal void Normalize() { real_t lengthsq = LengthSquared(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs index 9b51de5c8c..412a885daa 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs @@ -81,6 +81,15 @@ namespace Godot } } + /// + /// Helper method for deconstruction into a tuple. + /// + public void Deconstruct(out int x, out int y) + { + x = this.x; + y = this.y; + } + /// /// Returns a new vector with all components in absolute values (i.e. positive). /// diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index 1e60fb9523..45e5287610 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -96,6 +96,16 @@ namespace Godot } } + /// + /// Helper method for deconstruction into a tuple. + /// + public void Deconstruct(out real_t x, out real_t y, out real_t z) + { + x = this.x; + y = this.y; + z = this.z; + } + internal void Normalize() { real_t lengthsq = LengthSquared(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs index eb06d2b87e..abfd2ae720 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs @@ -96,6 +96,16 @@ namespace Godot } } + /// + /// Helper method for deconstruction into a tuple. + /// + public void Deconstruct(out int x, out int y, out int z) + { + x = this.x; + y = this.y; + z = this.z; + } + /// /// Returns a new vector with all components in absolute values (i.e. positive). /// -- cgit v1.2.3