Exemple #1
0
        public static IEnumerable <TResult> Zip <T1, T2, TResult>(IEnumerable <T1> enum1, IEnumerable <T2> enum2, Func <T1, T2, TResult> transform)
        {
            ThrowIf.ArgumentIsNull(enum1, "enum1");
            ThrowIf.ArgumentIsNull(enum2, "enum2");

            IEnumerator <T1> e1 = enum1.GetEnumerator();
            IEnumerator <T2> e2 = enum2.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                yield return(transform(e1.Current, e2.Current));
            }
        }
Exemple #2
0
        public static bool TryGetValueSafe <TValue>(this IList <TValue> array, int index, out TValue value)
        {
            ThrowIf.ArgumentIsNull(array, "array");

            if (index < 0 || index >= array.Count)
            {
                value = default(TValue);
                return(false);
            }

            value = array[index];
            return(true);
        }
Exemple #3
0
        public static float MaxAbs <T>(this IEnumerable <T> enumerable, Func <T, float> selector)
        {
            ThrowIf.ArgumentIsNull(selector, "selector");

            var max = 0.0f;

            foreach (float item in enumerable.Select(selector))
            {
                if (Mathf.Abs(item) > Mathf.Abs(max))
                {
                    max = item;
                }
            }

            return(max);
        }
Exemple #4
0
        public static Vector2 MaxAbs <T>(this IEnumerable <T> enumerable, Func <T, Vector2> selector)
        {
            ThrowIf.ArgumentIsNull(selector, "selector");

            Vector2 max = Vector2.zero;

            foreach (Vector2 item in enumerable.Select(selector))
            {
                if (Mathf.Abs(item.x) > Mathf.Abs(max.x))
                {
                    max.x = item.x;
                }
                if (Mathf.Abs(item.y) > Mathf.Abs(max.y))
                {
                    max.y = item.y;
                }
            }

            return(max);
        }
Exemple #5
0
        public static void DrawLines(Vector2[] points, Color[] colors, float width)
        {
            ThrowIf.ArgumentIsNull(points, "points");
            ThrowIf.ArgumentIsNull(colors, "colors");
            ThrowIf.False(points.Length == colors.Length, "Points and colors array must be the same length.");

            for (int i = 0; i < points.Length; ++i)
            {
                Vector2 start = points[i];
                Vector2 end   = points[MathEx.Wrap(i + 1, 0, points.Length - 1)];
                Color   color = colors[i];

                if (Mathf.Abs(start.x - end.x) > Mathf.Abs(start.y - end.y))
                {
                    GUIEx.DrawBox(new Rect(start.x, start.y, end.x - start.x, width), color);
                }
                else
                {
                    GUIEx.DrawBox(new Rect(start.x, start.y, width, end.y - start.y), color);
                }
                GUIEx.PopColor();
            }
        }
Exemple #6
0
        public static T FindClosestToPointOrDefault <T>(this IEnumerable <T> points, Vector3 point, Func <T, Vector3> pointSelector)
        {
            ThrowIf.ArgumentIsNull(points, "points");
            ThrowIf.ArgumentIsNull(pointSelector, "pointSelector");

            T     closestItem = default(T);
            float minDistance = float.MaxValue;

            foreach (T item in points)
            {
                Vector3 pointA = pointSelector(item);

                Vector3 vector   = pointA - point;
                float   distance = vector.sqrMagnitude;

                if (distance < minDistance)
                {
                    closestItem = item;
                    minDistance = distance;
                }
            }

            return(closestItem);
        }
 /// <summary>
 /// Returns the first component of type <typeparamref name="TComponent"/> in
 /// each descendent subtree.
 /// </summary>
 /// <typeparam name="TComponent">The type of the <see cref="Component"/>.</typeparam>
 /// <param name="component">The <see cref="Component"/>.</param>
 /// <returns>
 /// The first component of type <typeparamref name="TComponent"/> found in
 /// each descendent subtree.
 /// </returns>
 public static TComponent[] GetFirstComponentsInChildren <TComponent>(this Component component)
     where TComponent : Component
 {
     ThrowIf.ArgumentIsNull(component, "component");
     return(component.GetFirstComponentInChildrenInternal <TComponent>().ToArray());
 }
 /// <summary>
 /// Returns the first component of type <typeparamref name="TComponent"/> in
 /// any descendent subtree.
 /// </summary>
 /// <typeparam name="TComponent">The type of the <see cref="Component"/>.</typeparam>
 /// <param name="component">The <see cref="Component"/>.</param>
 /// <returns>
 /// The first component of type <typeparamref name="TComponent"/> found in
 /// any descendent subtree.
 /// </returns>
 public static TComponent GetFirstComponentInChildren <TComponent>(this Component component)
     where TComponent : Component
 {
     ThrowIf.ArgumentIsNull(component, "component");
     return(component.GetFirstComponentInChildrenInternal <TComponent>().FirstOrDefault());
 }
Exemple #9
0
 public static void ArgumentIsEmpty <T>(IEnumerable <T> argument, string argumentName)
 {
     ThrowIf.Empty(argument, "Argument \"{0}\" should not be null or empty.", argumentName);
 }
Exemple #10
0
 public static void ArgumentIsNull(object argument, string argumentName)
 {
     ThrowIf.Null(argument, "Argument \"{0}\" should not be null.", argumentName);
 }
Exemple #11
0
 public static void Empty <T>(IEnumerable <T> obj, string message, params object[] args)
 {
     ThrowIf.Null(obj, message, args);
     ThrowIf.False(obj.Any(), message, args);
 }
Exemple #12
0
 public static void Null(object obj, string message, params object[] args)
 {
     ThrowIf.True(obj == null, message, args);
 }
Exemple #13
0
 public static void False(bool condition, string message, params object[] args)
 {
     ThrowIf.True(!condition, message, args);
 }