// Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE using System; namespace SharpNav.Geometry { /// /// A 2d bounding box represeted by integers. /// [Serializable] public struct BBox2i : IEquatable { /// /// The minimum of the bounding box. /// public Vector2i Min; /// /// The maximum of the bounding box. /// public Vector2i Max; /// /// Initializes a new instance of the struct. /// /// A minimum bound. /// A maximum bound. public BBox2i(Vector2i min, Vector2i max) { Min = min; Max = max; } /// /// Initializes a new instance of the struct. /// /// The minimum X bound. /// The minimum Y bound. /// The maximum X bound. /// The maximum Y bound. public BBox2i(int minX, int minY, int maxX, int maxY) { Min.X = minX; Min.Y = minY; Max.X = maxX; Max.Y = maxY; } /// /// Compares two instances of for equality. /// /// An instance of . /// Another instance of . /// A value indicating whether the two instances are equal. public static bool operator ==(BBox2i left, BBox2i right) { return left.Equals(right); } /// /// Compares two instances of for inequality. /// /// An instance of . /// Another instance of . /// A value indicating whether the two instances are unequal. public static bool operator !=(BBox2i left, BBox2i right) { return !(left == right); } /// /// Turns the instance into a human-readable string. /// /// A string representing the instance. public override string ToString() { return "{ Min: " + Min.ToString() + ", Max: " + Max.ToString() + " }"; } /// /// Gets a unique hash code for this instance. /// /// A hash code. public override int GetHashCode() { //TODO write a good hash code. return Min.GetHashCode() ^ Max.GetHashCode(); } /// /// Checks for equality between this instance and a specified object. /// /// An object. /// A value indicating whether this instance and the object are equal. public override bool Equals(object obj) { BBox2i? objV = obj as BBox2i?; if (objV != null) return this.Equals(objV); return false; } /// /// Checks for equality between this instance and a specified instance of . /// /// An instance of . /// A value indicating whether this instance and the other instance are equal. public bool Equals(BBox2i other) { return Min == other.Min && Max == other.Max; } } }