Add project files.

This commit is contained in:
max
2025-12-18 01:04:21 +01:00
parent 532b1f4c53
commit c22452c66c
11 changed files with 1138 additions and 0 deletions

39
Car simulation/Vector2.cs Normal file
View File

@@ -0,0 +1,39 @@
public struct Vector2
{
public float X, Y;
public Vector2(float x, float y) { X = x; Y = y; }
public float Length => MathF.Sqrt(X * X + Y * Y);
public float LengthSquared => X * X + Y * Y;
// Returns a normalized copy
public Vector2 Normalized()
{
float length = Length;
if (length > 0.0001f)
return new Vector2(X / length, Y / length);
return new Vector2(0, 0);
}
// Normalizes in place
public void Normalize()
{
float length = Length;
if (length > 0.0001f)
{
X /= length;
Y /= length;
}
}
// Static normalize
public static Vector2 Normalize(Vector2 v) => v.Normalized();
// Operators
public static Vector2 operator *(Vector2 v, float s) => new Vector2(v.X * s, v.Y * s);
public static Vector2 operator *(float s, Vector2 v) => new Vector2(v.X * s, v.Y * s);
public static Vector2 operator /(Vector2 v, float s) => new Vector2(v.X / s, v.Y / s);
public static Vector2 operator +(Vector2 a, Vector2 b) => new Vector2(a.X + b.X, a.Y + b.Y);
public static Vector2 operator -(Vector2 a, Vector2 b) => new Vector2(a.X - b.X, a.Y - b.Y);
}