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