A game framework written with osu! in mind.
at master 55 lines 1.7 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osuTK; 5using System; 6using System.Diagnostics.CodeAnalysis; 7using System.Runtime.InteropServices; 8 9namespace osu.Framework.Graphics.Primitives 10{ 11 [Serializable, StructLayout(LayoutKind.Sequential)] 12 public struct Vector2I : IEquatable<Vector2I> 13 { 14 public int X; 15 public int Y; 16 17 public Vector2I(int val) 18 : this(val, val) 19 { 20 } 21 22 public Vector2I(int x, int y) 23 { 24 X = x; 25 Y = y; 26 } 27 28 public static readonly Vector2I Zero; 29 30 public static readonly Vector2I One = new Vector2I(1); 31 32 public static implicit operator Vector2(Vector2I r) => new Vector2(r.X, r.Y); 33 34 public static bool operator ==(Vector2I left, Vector2I right) => left.Equals(right); 35 36 public static bool operator !=(Vector2I left, Vector2I right) => !(left == right); 37 38 public static Vector2I operator +(Vector2I left, Vector2I right) => new Vector2I(left.X + right.X, left.Y + right.Y); 39 40 public static Vector2I operator -(Vector2I left, Vector2I right) => new Vector2I(left.X - right.X, left.Y - right.Y); 41 42 public readonly bool Equals(Vector2I other) => other.X == X && other.Y == Y; 43 44 public override readonly bool Equals(object obj) 45 { 46 if (!(obj is Vector2I)) 47 return false; 48 49 return Equals((Vector2I)obj); 50 } 51 52 [SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] 53 public override readonly int GetHashCode() => (int)(((uint)X ^ ((uint)Y << 13)) | ((uint)Y >> 0x13)); 54 } 55}