SupaLidlGame/Extensions/Vector2.cs

41 lines
974 B
C#
Raw Permalink Normal View History

2022-11-27 19:37:16 -08:00
using Godot;
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.Extensions;
public static class Vector2Extensions
2022-11-27 19:37:16 -08:00
{
2023-06-03 18:21:46 -07:00
public static Vector2 Midpoint(this Vector2 vector, Vector2 other)
2022-11-27 19:37:16 -08:00
{
2023-06-03 18:21:46 -07:00
return new Vector2((vector.X + other.X) / 2,
(vector.Y + other.Y) / 2);
}
2022-11-27 19:37:16 -08:00
2023-06-03 18:21:46 -07:00
public static Vector2 Midpoints(params Vector2[] vectors)
{
int length = vectors.Length;
float x = 0;
float y = 0;
2022-11-27 19:37:16 -08:00
2023-06-03 18:21:46 -07:00
for (int i = 0; i < length; i++)
2022-11-27 19:37:16 -08:00
{
2023-06-03 18:21:46 -07:00
x += vectors[i].X;
y += vectors[i].Y;
2022-11-27 19:37:16 -08:00
}
2023-06-03 18:21:46 -07:00
return new Vector2(x / length, y / length);
}
/// <summary>
/// Returns this vector 90 degrees counter clockwise (x, y) -> (-y, x)
/// </summary>
public static Vector2 Counterclockwise90(this Vector2 vector)
{
return new Vector2(-vector.Y, vector.X);
}
public static Vector2 Clockwise90(this Vector2 vector)
{
return new Vector2(vector.Y, -vector.X);
2022-11-27 19:37:16 -08:00
}
}