using System; namespace NvAPIWrapper.Mosaic { /// /// Holds maximum and minimum possible values for overlaps /// public struct OverlapLimit : IEquatable { internal OverlapLimit(int minOverlapX, int maxOverlapX, int minOverlapY, int maxOverlapY) { MinimumHorizontalOverlap = minOverlapX; MaximumHorizontalOverlap = maxOverlapX; MinimumVerticalOverlap = minOverlapY; MaximumVerticalOverlap = maxOverlapY; } /// /// Minimum value for horizontal overlap (OverlapX) or maximum value of horizontal gap /// public int MinimumHorizontalOverlap { get; } /// /// Maximum value for horizontal overlap (OverlapX) /// public int MaximumHorizontalOverlap { get; } /// /// Minimum value for vertical overlap (OverlapY) or maximum value of vertical gap /// public int MinimumVerticalOverlap { get; } /// /// Maximum value for vertical overlap (OverlapY) /// public int MaximumVerticalOverlap { get; } /// public bool Equals(OverlapLimit other) { return MinimumHorizontalOverlap == other.MinimumHorizontalOverlap && MaximumHorizontalOverlap == other.MaximumHorizontalOverlap && MinimumVerticalOverlap == other.MinimumVerticalOverlap && MaximumVerticalOverlap == other.MaximumVerticalOverlap; } /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } return obj is OverlapLimit && Equals((OverlapLimit) obj); } /// public override int GetHashCode() { unchecked { var hashCode = MinimumHorizontalOverlap; hashCode = (hashCode * 397) ^ MaximumHorizontalOverlap; hashCode = (hashCode * 397) ^ MinimumVerticalOverlap; hashCode = (hashCode * 397) ^ MaximumVerticalOverlap; return hashCode; } } /// /// Checks for equality between two objects of same type /// /// The first object /// The second object /// true, if both objects are equal, otherwise false public static bool operator ==(OverlapLimit left, OverlapLimit right) { return left.Equals(right); } /// /// Checks for inequality between two objects of same type /// /// The first object /// The second object /// true, if both objects are not equal, otherwise false public static bool operator !=(OverlapLimit left, OverlapLimit right) { return !left.Equals(right); } /// public override string ToString() { return $"[{MinimumHorizontalOverlap}, {MaximumHorizontalOverlap}], [{MinimumVerticalOverlap}, {MaximumVerticalOverlap}]"; } /// /// Checks to see if the value falls in to the acceptable horizontal overlap range /// /// The horizontal overlap value /// true if the value falls into the range, otherwise false public bool IsInHorizontalRange(int overlapX) { return overlapX >= MinimumHorizontalOverlap && overlapX <= MaximumHorizontalOverlap; } /// /// Checks to see if the value falls in to the acceptable vertical overlap range /// /// The vertical overlap value /// true if the value falls into the range, otherwise false public bool IsInVerticalRange(int overlapY) { return overlapY >= MinimumVerticalOverlap && overlapY <= MaximumVerticalOverlap; } /// /// Checks to see if the overlap values fall in to the acceptable overlap ranges /// /// The overlap values /// true if the values fall into the range, otherwise false public bool IsInRange(Overlap overlap) { return IsInHorizontalRange(overlap.HorizontalOverlap) && IsInVerticalRange(overlap.VerticalOverlap); } } }