Exemple #1
0
        /// <summary>
        /// from a givne percent, from 0 to 1,
        /// get the index corresponding
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection">list</param>
        /// <param name="percent">from 0 to 1</param>
        /// <returns>index found from percent</returns>
        public static int GetIndexFromPercent <T>(this T[] collection, float percent)
        {
            float remapped = ExtMathf.Remap(percent, 0, 1, 0, collection.Length);
            int   index    = (int)remapped;

            return(index);
        }
        public static float RemapFromSeedDecimal(float min, float max, System.Random randomSeed)
        {
            float zeroToOneValue = (float)randomSeed.NextDouble();
            float minToMaxValue  = ExtMathf.Remap(zeroToOneValue, 0, 1, min, max);

            return(minToMaxValue);
        }
        /// <summary>
        /// here we have a min & max, we remap the random 0,1 value finded to this min&max
        /// warning: we cast it into an int at the end
        /// use:
        /// System.Random seed = ExtRandom.Seedrandom("hash");
        /// int randomInt = ExtRandom.RemapFromSeed(0, 50, seed);
        /// </summary>
        public static int RemapFromSeed(double min, double max, System.Random randomSeed)
        {
            double zeroToOneValue = randomSeed.NextDouble();
            int    minToMaxValue  = (int)ExtMathf.Remap(zeroToOneValue, 0, 1, min, max);

            return(minToMaxValue);
        }
        public static double RemapFromSeedDecimal(double min, double max, System.Random randomSeed)
        {
            double zeroToOneValue = randomSeed.NextDouble();
            double minToMaxValue  = ExtMathf.Remap(zeroToOneValue, 0, 1, min, max);

            return(minToMaxValue);
        }
Exemple #5
0
        public static bool Is3dPointInside2dRectInScreenSpace(Camera camera, Rect rect, Vector3 point)
        {
            Vector2 point2d = camera.WorldToScreenPoint(point);
            bool    xOk     = point2d.x >= rect.x && point2d.x <= rect.x + rect.width;

            float yInverse = ExtMathf.MirrorFromInterval(point2d.y, 0, camera.pixelHeight);
            bool  yOk      = yInverse >= rect.y && yInverse <= rect.y + rect.height;
            bool  isInside = xOk && yOk;

            return(isInside);
        }