From 6802b3f16265b0cefa0ca0eda937d1f782b1efed Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Mon, 24 Feb 2020 20:45:38 -0500 Subject: [PATCH] Make separate ExtensionMethods file. Add Point-deconstruction as an extension method. GitOrigin-RevId: a804ba797a9b939b65652df67987628b1742dad6 --- Shared/ExtensionMethods.cs | 20 ++++++++++++++++++++ Shared/Geometry.cs | 10 ---------- Shared/Shared.projitems | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 Shared/ExtensionMethods.cs diff --git a/Shared/ExtensionMethods.cs b/Shared/ExtensionMethods.cs new file mode 100644 index 0000000..aeecc8e --- /dev/null +++ b/Shared/ExtensionMethods.cs @@ -0,0 +1,20 @@ +using Microsoft.Xna.Framework; + +// All extension methods on built-in types (of C# or MonoGame) go in this file. + +namespace SemiColinGames { + static class ExtensionMethods { + // Vector2 + public static Vector2 Rotate(this Vector2 point, float angle) { + float cos = FMath.Cos(angle); + float sin = FMath.Sin(angle); + return new Vector2( + point.X * cos - point.Y * sin, + point.Y * cos + point.X * sin); + } + + // Point + public static void Deconstruct(this Point point, out int x, out int y) => + (x, y) = (point.X, point.Y); + } +} diff --git a/Shared/Geometry.cs b/Shared/Geometry.cs index deb144a..22a2cfe 100644 --- a/Shared/Geometry.cs +++ b/Shared/Geometry.cs @@ -5,16 +5,6 @@ using System; namespace SemiColinGames { - public static class Geometry { - public static Vector2 Rotate(this Vector2 point, float angle) { - float cos = FMath.Cos(angle); - float sin = FMath.Sin(angle); - return new Vector2( - point.X * cos - point.Y * sin, - point.Y * cos + point.X * sin); - } - } - // Math functions that return floats rather than doubles, for convenience. public static class FMath { public const float PI = (float) Math.PI; diff --git a/Shared/Shared.projitems b/Shared/Shared.projitems index a028aa5..832e155 100644 --- a/Shared/Shared.projitems +++ b/Shared/Shared.projitems @@ -10,6 +10,7 @@ +