Files
Prism/Prism-ScriptCore/Src/Prism/Math/Vec2.cs

44 lines
851 B
C#

using System.Runtime.InteropServices;
namespace Prism
{
[StructLayout(LayoutKind.Sequential)]
public struct Vec2
{
public float X;
public float Y;
public Vec2(float scalar)
{
X = Y = scalar;
}
public Vec2(float x, float y)
{
X = x;
Y = y;
}
public Vec2(Vec3 vec) {
X = vec.X;
Y = vec.Y;
}
public void Clamp(Vec2 min, Vec2 max) {
if (X < min.X)
X = min.X;
if (X > max.X)
X = max.X;
if (Y < min.Y)
Y = min.Y;
if (Y > max.Y)
Y = max.Y;
}
public static Vec2 operator -(Vec2 vector)
{
return new Vec2(-vector.X, -vector.Y);
}
}
}