UnityEngine.Mathf.Approximately C# (CSharp) Method

Approximately() public static method

public static Approximately ( float a, float b ) : bool
a float
b float
return bool
        public static bool Approximately(float a, float b)
        {
            return Abs(b - a) < (double)Max(1E-06f * Max(Abs(a), Abs(b)), 1.121039E-44f);
        }

Usage Example

コード例 #1
0
        private void OptimizeAtlas()
        {
            for (int atlasIndex = 0; atlasIndex < atlassedMaterials.Count; atlasIndex++)
            {
                var     material = atlassedMaterials[atlasIndex];
                Vector2 usedArea = new Vector2(0, 0);
                for (int atlasElementIndex = 0; atlasElementIndex < material.materialFragments.Count; atlasElementIndex++)
                {
                    if (material.materialFragments[atlasElementIndex].atlasRegion.xMax > usedArea.x)
                    {
                        usedArea.x = material.materialFragments[atlasElementIndex].atlasRegion.xMax;
                    }

                    if (material.materialFragments[atlasElementIndex].atlasRegion.yMax > usedArea.y)
                    {
                        usedArea.y = material.materialFragments[atlasElementIndex].atlasRegion.yMax;
                    }
                }

                //Headless mode ends up with zero usedArea
                if (Mathf.Approximately(usedArea.x, 0f) || Mathf.Approximately(usedArea.y, 0f))
                {
                    material.cropResolution = new Vector2(0.0f, 0.0f);
                    return;
                }

                Vector2 tempResolution = new Vector2(umaGenerator.atlasResolution, umaGenerator.atlasResolution);

                bool done = false;
                while (!done && Mathf.Abs(usedArea.x) > 0.0001)
                {
                    if (tempResolution.x * 0.5f >= usedArea.x)
                    {
                        tempResolution = new Vector2(tempResolution.x * 0.5f, tempResolution.y);
                    }
                    else
                    {
                        done = true;
                    }
                }

                done = false;
                while (!done && Mathf.Abs(usedArea.y) > 0.0001)
                {
                    if (tempResolution.y * 0.5f >= usedArea.y)
                    {
                        tempResolution = new Vector2(tempResolution.x, tempResolution.y * 0.5f);
                    }
                    else
                    {
                        done = true;
                    }
                }

                material.cropResolution = tempResolution;
            }
        }
All Usage Examples Of UnityEngine.Mathf::Approximately