CUE.NET.Brushes.RadialGradientBrush.GetColorAtPoint C# (CSharp) Method

GetColorAtPoint() protected method

Gets the color at an specific point assuming the brush is drawn into the given rectangle.
protected GetColorAtPoint ( RectangleF rectangle, BrushRenderTarget renderTarget ) : CorsairColor
rectangle System.Drawing.RectangleF The rectangle in which the brush should be drawn.
renderTarget BrushRenderTarget The target (key/point) from which the color should be taken.
return CorsairColor
        protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
        {
            if(Gradient == null) return CorsairColor.Transparent;

            PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y);

            // Calculate the distance to the farthest point from the center as reference (this has to be a corner)
            // ReSharper disable once RedundantCast - never trust this ...
            float refDistance = (float)Math.Max(Math.Max(Math.Max(GradientHelper.CalculateDistance(rectangle.Location, centerPoint),
                GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y), centerPoint)),
                GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)),
                GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), centerPoint));

            float distance = GradientHelper.CalculateDistance(renderTarget.Point, centerPoint);
            float offset = distance / refDistance;
            return Gradient.GetColor(offset);
        }