UISprite.AdjustRadial C# (CSharp) Method

AdjustRadial() private method

Adjust the specified quad, making it be radially filled instead.
private AdjustRadial ( Vector2 xy, Vector2 uv, float fill, bool invert ) : bool
xy Vector2
uv Vector2
fill float
invert bool
return bool
    bool AdjustRadial(Vector2[] xy, Vector2[] uv, float fill, bool invert)
    {
        // Nothing to fill
        if (fill < 0.001f) return false;

        // Nothing to adjust
        if (!invert && fill > 0.999f) return true;

        // Convert 0-1 value into 0 to 90 degrees angle in radians
        float angle = Mathf.Clamp01(fill);
        if (!invert) angle = 1f - angle;
        angle *= 90f * Mathf.Deg2Rad;

        // Calculate the effective X and Y factors
        float fx = Mathf.Sin(angle);
        float fy = Mathf.Cos(angle);

        // Normalize the result, so it's projected onto the side of the rectangle
        if (fx > fy)
        {
            fy *= 1f / fx;
            fx = 1f;

            if (!invert)
            {
                xy[0].y = Mathf.Lerp(xy[2].y, xy[0].y, fy);
                xy[3].y = xy[0].y;

                uv[0].y = Mathf.Lerp(uv[2].y, uv[0].y, fy);
                uv[3].y = uv[0].y;
            }
        }
        else if (fy > fx)
        {
            fx *= 1f / fy;
            fy = 1f;

            if (invert)
            {
                xy[0].x = Mathf.Lerp(xy[2].x, xy[0].x, fx);
                xy[1].x = xy[0].x;

                uv[0].x = Mathf.Lerp(uv[2].x, uv[0].x, fx);
                uv[1].x = uv[0].x;
            }
        }
        else
        {
            fx = 1f;
            fy = 1f;
        }

        if (invert)
        {
            xy[1].y = Mathf.Lerp(xy[2].y, xy[0].y, fy);
            uv[1].y = Mathf.Lerp(uv[2].y, uv[0].y, fy);
        }
        else
        {
            xy[3].x = Mathf.Lerp(xy[2].x, xy[0].x, fx);
            uv[3].x = Mathf.Lerp(uv[2].x, uv[0].x, fx);
        }
        return true;
    }