/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Tizen.Multimedia { /// /// Represents a range(min, max) value. /// /// 3 public struct Range { /// /// Initializes a new instance of the range with the specified values. /// /// Minimum value of the range. /// Maximum value of the range. /// is less than . /// 3 public Range(int min, int max) { if (min > max) { throw new ArgumentException($"min can't be greater than max."); } Min = min; Max = max; } /// /// Gets or sets the minimum value of the range. /// /// 3 public int Min { get; set; } /// /// Gets or sets the maximum value of the range. /// /// 3 public int Max { get; set; } /// /// Gets the length of the range. /// /// 3 public int Length => Max - Min; /// /// Determines if the specified value is within the range. /// /// The value to check. /// true if the value is within the range; otherwise false. /// 3 public bool IsInside(int value) { return Min <= value && value <= Max; } /// /// Returns a string that represents the current object. /// /// A string that represents the current object. /// 3 public override string ToString() => $"Min={Min.ToString()}, Max={Max.ToString()}"; /// /// Gets the hash code for this instance of . /// /// The hash code for this instance of . /// 3 public override int GetHashCode() { return new { Min, Max }.GetHashCode(); } /// /// Compares an object to an instance of for equality. /// /// A to compare. /// true if the two ranges are equal; otherwise, false. /// 3 public override bool Equals(object obj) { return obj is Range && this == (Range)obj; } /// /// Compares two instances of for equality. /// /// A to compare. /// A to compare. /// true if the two instances of are equal; otherwise false. /// 3 public static bool operator ==(Range range1, Range range2) { return range1.Min == range2.Min && range1.Max == range2.Max; } /// /// Compares two instances of for inequality. /// /// A to compare. /// A to compare. /// true if the two instances of are not equal; otherwise false. /// 3 public static bool operator !=(Range range1, Range range2) { return !(range1 == range2); } } }