95 lines
2.1 KiB
C#
95 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Math
|
|
{
|
|
[StructLayout(LayoutKind.Explicit)]
|
|
public struct Colum2D:IEquatable<Colum2D>
|
|
{
|
|
[FieldOffset(0)]
|
|
public float X;
|
|
[FieldOffset(4)]
|
|
public float Y;
|
|
|
|
public Colum2D(float x,float y)
|
|
{
|
|
X= x;
|
|
Y= y;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
return false;
|
|
}
|
|
else if (obj.GetType() != typeof(Colum2D))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return this.Equals((Colum2D)obj);
|
|
}
|
|
}
|
|
|
|
bool IEquatable<Colum2D>.Equals(Colum2D other)
|
|
{
|
|
if (this.GetHashCode() != other.GetHashCode())
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return X == other.X && Y == other.Y;
|
|
}
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(X,Y);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{X}\n{Y}";
|
|
}
|
|
|
|
public static Colum2D operator +(Colum2D c1,Colum2D c2)
|
|
{
|
|
return new Colum2D(
|
|
c1.X + c2.X,
|
|
c1.Y + c2.Y
|
|
);
|
|
}
|
|
|
|
public static Colum2D operator -(Colum2D c1, Colum2D c2)
|
|
{
|
|
return new Colum2D(
|
|
c1.X - c2.X,
|
|
c1.Y - c2.Y
|
|
);
|
|
}
|
|
|
|
public static Array2x2 operator *(Colum2D colum, Vec2D vec)
|
|
{
|
|
return new Array2x2(
|
|
colum.X * vec.X, colum.X * vec.Y,
|
|
colum.Y * vec.X, colum.Y * vec.Y
|
|
);
|
|
}
|
|
|
|
public static Colum2D operator *(Colum2D colum, float x)
|
|
{
|
|
return new Colum2D(colum.X * x,colum.Y * x);
|
|
}
|
|
|
|
public static Colum2D operator /(Colum2D colum, float x)
|
|
{
|
|
return new Colum2D(colum.X / x, colum.Y / x);
|
|
}
|
|
}
|
|
}
|