From e5e05deadbb0043db98c64acc8d148ffa81cbe19 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Sat, 6 Jun 2026 00:08:11 -0400 Subject: [PATCH] =?UTF-8?q?port(m1):=20wave=206f=20=E2=80=94=20Unity=20pri?= =?UTF-8?q?mitive=20operators=20(362->304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CS0019 operator gaps on value-type shims: - Vector2: ==/!=, Vector2*Vector2, Equals/GetHashCode. - Vector4: *float, +/-, ==/!=, Equals/GetHashCode. - Color: ==/!= (Color==Color32 via existing implicit conv), Equals/GetHashCode. - Rect: ==/!=; Matrix4x4: *, GetColumn/GetRow/indexer. Co-Authored-By: Claude Opus 4.8 --- SVSim.BattleEngine/Shim/UnityEngine/Primitives.cs | 9 +++++++++ SVSim.BattleEngine/Shim/UnityEngine/UnityShim.cs | 6 +++++- SVSim.BattleEngine/Shim/UnityEngine/UnityShimExt.cs | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/SVSim.BattleEngine/Shim/UnityEngine/Primitives.cs b/SVSim.BattleEngine/Shim/UnityEngine/Primitives.cs index 215cfdc..930106f 100644 --- a/SVSim.BattleEngine/Shim/UnityEngine/Primitives.cs +++ b/SVSim.BattleEngine/Shim/UnityEngine/Primitives.cs @@ -27,6 +27,11 @@ namespace UnityEngine public static Vector2 operator *(Vector2 a, float s) => new Vector2(a.x * s, a.y * s); public static Vector2 operator *(float s, Vector2 a) => new Vector2(a.x * s, a.y * s); public static Vector2 operator /(Vector2 a, float s) => new Vector2(a.x / s, a.y / s); + public static Vector2 operator *(Vector2 a, Vector2 b) => new Vector2(a.x * b.x, a.y * b.y); + public static bool operator ==(Vector2 a, Vector2 b) => a.x == b.x && a.y == b.y; + public static bool operator !=(Vector2 a, Vector2 b) => !(a == b); + public override bool Equals(object o) => o is Vector2 v && this == v; + public override int GetHashCode() => x.GetHashCode() ^ (y.GetHashCode() << 2); public static implicit operator Vector2(Vector3 v) => new Vector2(v.x, v.y); public static implicit operator Vector3(Vector2 v) => new Vector3(v.x, v.y, 0); } @@ -109,6 +114,10 @@ namespace UnityEngine public static implicit operator Color32(Color c) => new Color32( (byte)(Mathf.Clamp01(c.r) * 255f), (byte)(Mathf.Clamp01(c.g) * 255f), (byte)(Mathf.Clamp01(c.b) * 255f), (byte)(Mathf.Clamp01(c.a) * 255f)); + public static bool operator ==(Color a, Color b) => a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; + public static bool operator !=(Color a, Color b) => !(a == b); + public override bool Equals(object o) => o is Color c && this == c; + public override int GetHashCode() => r.GetHashCode() ^ (g.GetHashCode() << 2) ^ (b.GetHashCode() << 4) ^ (a.GetHashCode() << 6); } public static class Mathf diff --git a/SVSim.BattleEngine/Shim/UnityEngine/UnityShim.cs b/SVSim.BattleEngine/Shim/UnityEngine/UnityShim.cs index 1f603d7..36d2402 100644 --- a/SVSim.BattleEngine/Shim/UnityEngine/UnityShim.cs +++ b/SVSim.BattleEngine/Shim/UnityEngine/UnityShim.cs @@ -41,8 +41,12 @@ namespace UnityEngine public bool Contains(Vector3 p) => false; public bool Overlaps(Rect other) => false; public static Rect MinMaxRect(float xmin, float ymin, float xmax, float ymax) => new Rect(xmin, ymin, xmax - xmin, ymax - ymin); + public static bool operator ==(Rect a, Rect b) => a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; + public static bool operator !=(Rect a, Rect b) => !(a == b); + public override bool Equals(object o) => o is Rect r && this == r; + public override int GetHashCode() => x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (width.GetHashCode() << 4) ^ (height.GetHashCode() << 6); } - public struct Matrix4x4 { public static Matrix4x4 identity => new Matrix4x4(); public Vector3 MultiplyPoint(Vector3 p) => p; public Vector3 MultiplyPoint3x4(Vector3 p) => p; public Vector3 MultiplyVector(Vector3 v) => v; public static Matrix4x4 TRS(Vector3 t, Quaternion r, Vector3 s) => identity; public Matrix4x4 inverse => identity; } + public struct Matrix4x4 { public static Matrix4x4 identity => new Matrix4x4(); public Vector3 MultiplyPoint(Vector3 p) => p; public Vector3 MultiplyPoint3x4(Vector3 p) => p; public Vector3 MultiplyVector(Vector3 v) => v; public static Matrix4x4 TRS(Vector3 t, Quaternion r, Vector3 s) => identity; public Matrix4x4 inverse => identity; public static Matrix4x4 operator *(Matrix4x4 a, Matrix4x4 b) => identity; public Vector4 GetColumn(int i) => default; public Vector4 GetRow(int i) => default; public float this[int row, int col] { get => 0f; set { } } } public struct Plane { public Plane(Vector3 normal, Vector3 point) { } public Plane(Vector3 a, Vector3 b, Vector3 c) { } public bool Raycast(Ray r, out float enter) { enter = 0; return false; } } public struct Ray { public Ray(Vector3 origin, Vector3 dir) { this.origin = origin; this.direction = dir; } public Vector3 origin; public Vector3 direction; public Vector3 GetPoint(float d) => origin; } public struct RaycastHit { public Vector3 point; public Vector3 normal; public float distance; public Collider collider; public Transform transform; public GameObject gameObject; } diff --git a/SVSim.BattleEngine/Shim/UnityEngine/UnityShimExt.cs b/SVSim.BattleEngine/Shim/UnityEngine/UnityShimExt.cs index e0ebf8c..9c6c0c8 100644 --- a/SVSim.BattleEngine/Shim/UnityEngine/UnityShimExt.cs +++ b/SVSim.BattleEngine/Shim/UnityEngine/UnityShimExt.cs @@ -11,6 +11,14 @@ namespace UnityEngine { public static Vector4 zero => default; public static Vector4 one => new Vector4(1f, 1f, 1f, 1f); + public static Vector4 operator *(Vector4 a, float s) => new Vector4(a.x * s, a.y * s, a.z * s, a.w * s); + public static Vector4 operator *(float s, Vector4 a) => new Vector4(a.x * s, a.y * s, a.z * s, a.w * s); + public static Vector4 operator +(Vector4 a, Vector4 b) => new Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + public static Vector4 operator -(Vector4 a, Vector4 b) => new Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + public static bool operator ==(Vector4 a, Vector4 b) => a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; + public static bool operator !=(Vector4 a, Vector4 b) => !(a == b); + public override bool Equals(object o) => o is Vector4 v && this == v; + public override int GetHashCode() => x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (z.GetHashCode() << 4) ^ (w.GetHashCode() << 6); public Vector4(float x, float y, float z) { this.x = x; this.y = y; this.z = z; this.w = 0f; } public Vector4(float x, float y) { this.x = x; this.y = y; this.z = 0f; this.w = 0f; } // UnityEngine implicitly promotes/truncates between Vector2/3/4.