Skip to content

Commit

Permalink
feat: add utility methods and props to point/tex (#697)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Lodico <lodico.rj@gmail.com>
  • Loading branch information
jcsnider and lodicolo committed May 10, 2021
1 parent d476afb commit 9131d2c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Intersect.Client.Framework/GenericClasses/Pointf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace Intersect.Client.Framework.GenericClasses

public struct Pointf
{
public static Pointf Empty => new Pointf();

public static Pointf UnitX => new Pointf(1, 0);

public static Pointf UnitY => new Pointf(0, 1);

private const float TOLERANCE = 0.001f;

Expand All @@ -20,9 +25,9 @@ public Pointf(float x, float y)

public override bool Equals(object obj)
{
if (obj is Pointf)
if (obj is Pointf point)
{
return (Pointf) obj == this;
return point == this;
}

return false;
Expand All @@ -33,12 +38,11 @@ public bool Equals(Pointf other)
return Math.Abs(X - other.X) < TOLERANCE && Math.Abs(Y - other.Y) < TOLERANCE;
}

public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode();

public static Pointf Empty => new Pointf();
public Pointf StripX() => new Pointf(0, Y);

public Pointf StripY() => new Pointf(X, 0);

public static bool operator !=(Pointf left, Pointf right)
{
Expand All @@ -50,6 +54,13 @@ public override int GetHashCode()
return Math.Abs(left.X - right.X) < TOLERANCE && Math.Abs(left.Y - right.Y) < TOLERANCE;
}

public static Pointf operator +(Pointf left, Pointf right) => new Pointf(left.X + right.X, left.Y + right.Y);

public static Pointf operator -(Pointf left, Pointf right) => new Pointf(left.X - right.X, left.Y - right.Y);

public static Pointf operator *(Pointf point, float scalar) => new Pointf(point.X * scalar, point.Y * scalar);

public static Pointf operator /(Pointf point, float scalar) => new Pointf(point.X / scalar, point.Y / scalar);
}

}
13 changes: 13 additions & 0 deletions Intersect.Client.Framework/Graphics/GameTexture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;

using Intersect.Client.Framework.Content;
using Intersect.Client.Framework.GenericClasses;

namespace Intersect.Client.Framework.Graphics
{
Expand All @@ -10,6 +11,18 @@ public abstract class GameTexture : IAsset

public string Name => GetName() ?? throw new ArgumentNullException(nameof(GetName));

public int Width => GetWidth();

public int Height => GetHeight();

public Pointf Dimensions => new Pointf(Width, Height);

public Pointf Center => Dimensions / 2;

public object PlatformTextureObject => GetTexture();

public GameTexturePackFrame TexturePackFrame => GetTexturePackFrame();

public abstract string GetName();

public abstract int GetWidth();
Expand Down

0 comments on commit 9131d2c

Please sign in to comment.