Example #1
0
        public static Vector2Int Snap(Vector2Int v, Angle snap, bool searchClockwise = false)
        {
            Vector2Int output            = (Vector2.right * v.magnitude).ToVec2Int();
            float      minDegreesBetween = Mathf.Infinity;
            float      degreesBetween;
            Angle      currentAngle = new Angle();

            do
            {
                degreesBetween = Mathf.Abs(currentAngle.degrees - snap.degrees);
                if (minDegreesBetween > degreesBetween)
                {
                    minDegreesBetween = degreesBetween;
                    output            = VectorExtensions.FromFacingAngle(currentAngle.degrees, v.magnitude);
                }
                currentAngle.degrees += snap.degrees;
            } while (currentAngle.degrees < 360);
            return(output);
        }
Example #2
0
 public static Rect GrowToPoint(this Rect rect, Vector2 point)
 {
     rect.min = VectorExtensions.GetMinComponents(rect.min, point);
     rect.max = VectorExtensions.GetMaxComponents(rect.max, point);
     return(rect);
 }