using Unosquare.Swan; using System; using System.Globalization; namespace Unosquare.RaspberryIO.Camera { /// /// 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 Boolean IsDefault { get { this.Clamp(); return this.X == Default.X && this.Y == Default.Y && this.W == Default.W && this.H == Default.H; } } /// /// Clamps the members of this ROI to their minimum and maximum values /// public void Clamp() { this.X = this.X.Clamp(0M, 1M); this.Y = this.Y.Clamp(0M, 1M); this.W = this.W.Clamp(0M, 1M - this.X); this.H = this.H.Clamp(0M, 1M - this.Y); } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override String ToString() => $"{this.X.ToString(CultureInfo.InvariantCulture)},{this.Y.ToString(CultureInfo.InvariantCulture)},{this.W.ToString(CultureInfo.InvariantCulture)},{this.H.ToString(CultureInfo.InvariantCulture)}"; } }