From 486c95f9cded5b8669acb2fea316ff5ecded998c Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 24 Dec 2016 14:24:38 +0700 Subject: [PATCH] + IsoPoint2 --- Assets/IsoTools/Scripts/Internal/IsoPoint2.cs | 76 +++++++++++++++++++ .../Scripts/Internal/IsoPoint2.cs.meta | 12 +++ 2 files changed, 88 insertions(+) create mode 100644 Assets/IsoTools/Scripts/Internal/IsoPoint2.cs create mode 100644 Assets/IsoTools/Scripts/Internal/IsoPoint2.cs.meta diff --git a/Assets/IsoTools/Scripts/Internal/IsoPoint2.cs b/Assets/IsoTools/Scripts/Internal/IsoPoint2.cs new file mode 100644 index 0000000..020b1b0 --- /dev/null +++ b/Assets/IsoTools/Scripts/Internal/IsoPoint2.cs @@ -0,0 +1,76 @@ +namespace IsoTools.Internal { + public struct IsoPoint2 { + public int x; + public int y; + + public IsoPoint2(int x, int y) : this() { + this.x = x; + this.y = y; + } + + public IsoPoint2(IsoPoint2 other) : this() { + x = other.x; + y = other.y; + } + + public void Set(int x, int y) { + this.x = x; + this.y = y; + } + + public void Set(IsoPoint2 other) { + x = other.x; + y = other.y; + } + + public override bool Equals(object other) { + return (other is IsoPoint2) + ? Equals((IsoPoint2)other) + : false; + } + + public bool Equals(IsoPoint2 other) { + return x == other.x && y == other.y; + } + + public override int GetHashCode() { + return x ^ y; + } + + public static IsoPoint2 operator+(IsoPoint2 a, IsoPoint2 b) { + return new IsoPoint2(a.x + b.x, a.y + b.y); + } + + public static IsoPoint2 operator-(IsoPoint2 a, IsoPoint2 b) { + return new IsoPoint2(a.x - b.x, a.y - b.y); + } + + public static IsoPoint2 operator-(IsoPoint2 a) { + return new IsoPoint2(-a.x, -a.y); + } + + public static bool operator==(IsoPoint2 lhs, IsoPoint2 rhs) { + return lhs.x == rhs.x && lhs.y == rhs.y; + } + + public static bool operator!=(IsoPoint2 lhs, IsoPoint2 rhs) { + return lhs.x != rhs.x || lhs.y != rhs.y; + } + + public static IsoPoint2 one { + get { return new IsoPoint2(1, 1); } + } + + public static IsoPoint2 oneX { + get { return new IsoPoint2(1, 0); } + } + + public static IsoPoint2 oneY { + get { return new IsoPoint2(0, 1); } + } + + public static IsoPoint2 zero { + get { return new IsoPoint2(0, 0); } + } + } +} \ No newline at end of file diff --git a/Assets/IsoTools/Scripts/Internal/IsoPoint2.cs.meta b/Assets/IsoTools/Scripts/Internal/IsoPoint2.cs.meta new file mode 100644 index 0000000..50971fb --- /dev/null +++ b/Assets/IsoTools/Scripts/Internal/IsoPoint2.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 534645fda9ef2415a9b5db4a91c601b5 +timeCreated: 1482561634 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: