// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable MemberCanBeProtected.Global
// ReSharper disable ReturnTypeCanBeEnumerable.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedMember.Global
using System;
using RGB.NET.Core;
using RGB.NET.Presets.Textures.Gradients;
namespace RGB.NET.Presets.Textures;
///
///
/// Represents a texture drawing a conical gradient.
///
public sealed class ConicalGradientTexture : AbstractGradientTexture
{
#region Constants
private const float PI2 = MathF.PI * 2.0f;
#endregion
#region Properties & Fields
private float _origin = MathF.Atan2(-1, 0);
///
/// Gets or sets the origin (radian-angle) this is drawn to. (default: -π/2)
///
public float Origin
{
get => _origin;
set => SetProperty(ref _origin, value);
}
private Point _center = new(0.5f, 0.5f);
///
/// Gets or sets the center (as percentage in the range [0..1]) of the drawn by this . (default: 0.5, 0.5)
///
public Point Center
{
get => _center;
set => SetProperty(ref _center, value);
}
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The size of the texture.
/// The drawn by this .
public ConicalGradientTexture(Size size, IGradient gradient)
: base(size, gradient)
{ }
///
/// Initializes a new instance of the class.
///
/// The size of the texture.
/// The drawn by this .
/// The center (as percentage in the range [0..1]).
public ConicalGradientTexture(Size size, IGradient gradient, Point center)
: base(size, gradient)
{
this.Center = center;
}
///
/// Initializes a new instance of the class.
///
/// The size of the texture.
/// The drawn by this .
/// The center (as percentage in the range [0..1]).
/// The origin (radian-angle) the gradient is drawn to.
public ConicalGradientTexture(Size size, IGradient gradient, Point center, float origin)
: base(size, gradient)
{
this.Center = center;
this.Origin = origin;
}
#endregion
#region Methods
///
protected override Color GetColor(in Point point)
{
float angle = MathF.Atan2(point.Y - Center.Y, point.X - Center.X) - Origin;
if (angle < 0) angle += PI2;
float offset = angle / PI2;
return Gradient.GetColor(offset);
}
#endregion
}