namespace Otter {
///
/// Class used to represent a range using a min and max.
///
public class Range {
#region Public Fields
///
/// The minimum of the range.
///
public float Min;
///
/// The maximum of the range.
///
public float Max;
#endregion
#region Public Properties
///
/// Get a random int from the range. Floors the Min and Ceils the Max.
///
/// A random int.
public int RandInt {
get {
return Rand.Int((int)Min, (int)Util.Ceil(Max));
}
}
///
/// Get a random float from the range.
///
/// A random float.
public float RandFloat {
get {
return Rand.Float(Min, Max);
}
}
#endregion
#region Constructors
///
/// Create a new Range.
///
/// Minimum value.
/// Maximum value.
public Range(float min, float max) {
Min = min;
Max = max;
}
///
/// Create a new Range.
///
/// Maximum value. Minimum is -Maximum.
public Range(float max) : this(-max, max) { }
#endregion
#region Public Methods
///
/// Test if this Range overlaps another Range.
///
/// The Range to test against.
/// True if the ranges overlap.
public bool Overlap(Range r) {
if (r.Max < Min) return false;
if (r.Min > Max) return false;
return true;
}
public override string ToString() {
return string.Format("{0}, {1}", Min, Max);
}
#endregion
}
}