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