2017-11-30 22:45:39 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace SBRL.Utilities
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a single point in 2D space.
|
|
|
|
|
/// May also be used to represent a direction with a magnitude.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <version>v0.1</version>
|
|
|
|
|
/// <changelog>
|
|
|
|
|
/// v0.1 - 1st April 2017
|
|
|
|
|
/// - Added this changelog
|
|
|
|
|
/// </changelog>
|
|
|
|
|
public struct Vector2
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Vector 2 with all it's proeprties initialised to zero.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Vector2 Zero = new Vector2() { X = 0, Y = 0 };
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The X coordinate.
|
|
|
|
|
/// </summary>
|
2017-11-30 23:03:55 +00:00
|
|
|
|
public float X { get; set; }
|
2017-11-30 22:45:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Y coordinate.
|
|
|
|
|
/// </summary>
|
2017-11-30 23:03:55 +00:00
|
|
|
|
public float Y { get; set; }
|
2017-11-30 22:45:39 +00:00
|
|
|
|
|
|
|
|
|
|
2017-11-30 23:03:55 +00:00
|
|
|
|
public Vector2(float x, float y)
|
2017-11-30 22:45:39 +00:00
|
|
|
|
{
|
|
|
|
|
X = x;
|
|
|
|
|
Y = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Vector2 Add(Vector2 b)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
X + b.X,
|
2017-12-02 16:44:12 +00:00
|
|
|
|
Y + b.Y
|
2017-11-30 22:45:39 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
public Vector2 Subtract(Vector2 b)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
X - b.X,
|
2017-12-02 16:44:12 +00:00
|
|
|
|
Y - b.Y
|
2017-11-30 22:45:39 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
public Vector2 Divide(int b)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
X / b,
|
|
|
|
|
Y / b
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-12-03 15:51:22 +00:00
|
|
|
|
public Vector2 Divide(Vector2 b)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
X / b.X,
|
|
|
|
|
Y / b.Y
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-11-30 22:45:39 +00:00
|
|
|
|
public Vector2 Multiply(int b)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
X * b,
|
|
|
|
|
Y * b
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-11-30 23:15:52 +00:00
|
|
|
|
public Vector2 Multiply(Vector2 b)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
X * b.X,
|
|
|
|
|
Y * b.Y
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-11-30 22:45:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|