示例#1
0
        public static float GetAverage <T>(this List <T> list, System.Func <T, float> property, AverageType averageType = AverageType.Mean)
        {
            if (averageType == AverageType.Least)
            {
                return(list.Min(property));
            }
            else if (averageType == AverageType.Greatest)
            {
                return(list.Max(property));
            }
            else if (averageType == AverageType.Mean)
            {
                return(list.Average(property));
            }
            else if (averageType == AverageType.Median)
            {
                list = list.OrderBy(property).ToList <T>();

                if (RMath.Odd(list.Count))
                {
                    //++++++++++++NEEDS TO BE FIXED
                    //USE System.Func on induvidual value to get property
                    return(property(list[(int)(Mathf.Ceil(list.Count / 2f) - 1)]));
                }
                else if (RMath.Even(list.Count))
                {
                    return((
                               property(list[(list.Count / 2) - 1]) +
                               property(list[(list.Count / 2) + 1 - 1])
                               ) / 2f);
                }
            }
            else if (averageType == AverageType.Mode)
            {
                Dictionary <float, int> ocurrances = new Dictionary <float, int>();

                foreach (T i in list)
                {
                    if (ocurrances.ContainsKey(property(i)))
                    {
                        ocurrances[property(i)] = ocurrances[property(i)] + 1;
                    }
                    else
                    {
                        ocurrances[property(i)] = 1;
                    }
                }

                return(list.Max((f) => ocurrances[property(f)]));
            }
            else if (averageType == AverageType.Range)
            {
                return(list.Max(property) - list.Min(property));
            }
            else if (averageType == AverageType.MidRange)
            {
                return((list.Min(property) + list.Max(property)) / 2f);
            }

            return(1f);
        }
示例#2
0
 public Vector2Int(Vector2Float vector2Float)
 {
     this.x = RMath.SignFloorToInt(vector2Float.x);
     this.y = RMath.SignFloorToInt(vector2Float.y);
 }
示例#3
0
 public static float CustomSignCeil(this float f, float increment = 1f, float offset = 0f)
 {
     return(f.CustomRound((n) => RMath.SignCeil(n), increment, offset));
 }
示例#4
0
 public Vector3Int(Vector3Float vector3Float)
 {
     this.x = RMath.SignFloorToInt(vector3Float.x);
     this.y = RMath.SignFloorToInt(vector3Float.y);
     this.z = RMath.SignFloorToInt(vector3Float.z);
 }