using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public static class Util
{
///
/// Extension that converts an array of Vector2 to an array of Vector3
///
public static Vector3[] ToVector3(this Vector2[] vectors)
{
return System.Array.ConvertAll(vectors, v => v);
}
///
/// Extension that, given a collection of vectors, returns a centroid
/// (i.e., an average of all vectors)
///
public static Vector2 Centroid(this ICollection vectors)
{
return vectors.Aggregate((agg, next) => agg + next) / vectors.Count();
}
///
/// Extension returning the absolute value of a vector
///
public static Vector2 Abs(this Vector2 vector)
{
return new Vector2(Mathf.Abs(vector.x), Mathf.Abs(vector.y));
}
}