Make separate ExtensionMethods file.

Add Point-deconstruction as an extension method.

GitOrigin-RevId: a804ba797a9b939b65652df67987628b1742dad6
This commit is contained in:
Colin McMillen 2020-02-24 20:45:38 -05:00
parent ab2a57d632
commit 6802b3f162
3 changed files with 21 additions and 10 deletions

View File

@ -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);
}
}

View File

@ -5,16 +5,6 @@ using System;
namespace SemiColinGames { 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. // Math functions that return floats rather than doubles, for convenience.
public static class FMath { public static class FMath {
public const float PI = (float) Math.PI; public const float PI = (float) Math.PI;

View File

@ -10,6 +10,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Camera.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Camera.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ExtensionMethods.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Textures.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Textures.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Clock.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Clock.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Geometry.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Geometry.cs" />