daily update on 20230219 by nitload youmu, vec3d added
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public struct Vec2D:IEquatable<Vec2D>
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Direction;
|
||||
public float Length;
|
||||
|
||||
public Vec2D(float x,float y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Direction = Calc.ATan(X,Y);
|
||||
Length = Calc.Sqrt(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},{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);
|
||||
}
|
||||
|
||||
public float x(Vec2D others)
|
||||
{
|
||||
return this.X * others.Y - this.Y * others.X;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user