using System; using System.Collections.Generic; using System.Data.Common; using System.Runtime; using System.Runtime.InteropServices; using System.Text; namespace StgSharp.Math { [StructLayout(LayoutKind.Explicit)] public struct Vec2D:IEquatable { [FieldOffset(0)] public float X; [FieldOffset(sizeof(float))] public float Y; public Vec2D(float x,float y) { X = x; Y = y; } public bool Equals(Vec2D other) { if (this.GetHashCode() != other.GetHashCode()) { return false; } else { return this.X == other.X && this.Y == other.Y; } } public override bool Equals(object obj) { if (obj == null) { return false; } else if (obj.GetType() != typeof(Vec2D)) { return false; } else { return this.Equals((Vec2D)obj); } } public override int GetHashCode() { return HashCode.Combine(X, Y); } public override string ToString() { return $"{this.X}\t{this.Y}"; } public static bool operator ==(Vec2D vec1, Vec2D vec2) { return vec1.X==vec2.X && vec1.Y==vec2.Y; } public static bool operator !=(Vec2D vec1, Vec2D vec2) { return !(vec1.X == vec2.X && vec1.Y == vec2.Y); } public static Vec2D operator +(Vec2D vec1, Vec2D vec2) { return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y); } public static Vec2D operator -(Vec2D vec1, Vec2D vec2) { return new Vec2D(vec1.X + vec2.X, vec1.Y + vec2.Y); } public static float operator *(Vec2D vec1, Vec2D vec2) { return vec1.X * vec2.X + vec1.Y*vec2.Y; } public static Vec2D operator *(Vec2D vec, float x) { return new Vec2D(vec.X * x, vec.Y * x); } public static Vec2D operator /(Vec2D vec, float x) { return new Vec2D(vec.X/x, vec.Y/x); } } }