namespace Unosquare.RaspberryIO.Camera { using System.Globalization; using Swan; /// /// Defines the Raspberry Pi camera's sensor ROI (Region of Interest). /// public struct CameraRect { /// /// The default ROI which is the entire area. /// public static readonly CameraRect Default = new CameraRect { X = 0M, Y = 0M, W = 1.0M, H = 1.0M }; /// /// Gets or sets the x in relative coordinates. (0.0 to 1.0). /// /// /// The x. /// public decimal X { get; set; } /// /// Gets or sets the y location in relative coordinates. (0.0 to 1.0). /// /// /// The y. /// public decimal Y { get; set; } /// /// Gets or sets the width in relative coordinates. (0.0 to 1.0). /// /// /// The w. /// public decimal W { get; set; } /// /// Gets or sets the height in relative coordinates. (0.0 to 1.0). /// /// /// The h. /// public decimal H { get; set; } /// /// Gets a value indicating whether this instance is equal to the default (The entire area). /// /// /// true if this instance is default; otherwise, false. /// public bool IsDefault { get { Clamp(); return X == Default.X && Y == Default.Y && W == Default.W && H == Default.H; } } /// /// Clamps the members of this ROI to their minimum and maximum values. /// public void Clamp() { X = X.Clamp(0M, 1M); Y = Y.Clamp(0M, 1M); W = W.Clamp(0M, 1M - X); H = H.Clamp(0M, 1M - Y); } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() => $"{X.ToString(CultureInfo.InvariantCulture)},{Y.ToString(CultureInfo.InvariantCulture)},{W.ToString(CultureInfo.InvariantCulture)},{H.ToString(CultureInfo.InvariantCulture)}"; } }