using o0.Geometry2D.Float; using System; using UnityEngine; namespace ZIM.Unity { public static partial class ZIMMath { // Projects a vector onto another vector. public static Vector2 Project(this Vector2 vector, Vector2 onNormal) { float dotProduct = Vector2.Dot(vector, onNormal); float magnitudeSquared = onNormal.sqrMagnitude; if (magnitudeSquared < Mathf.Epsilon) return Vector2.zero; return (dotProduct / magnitudeSquared) * onNormal; } public static float LengthManhattan(this Vector2 v) => Math.Abs(v.x) + Math.Abs(v.y); public static double LengthManhattan(Vector2 v1, Vector2 v2) => (v1 - v2).LengthManhattan(); } }