// 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; using System.Runtime.InteropServices; namespace SharpNav { /// /// A bounding box for vertices in a . /// [StructLayout(LayoutKind.Sequential)] public struct PolyBounds : IEquatable { /// /// The lower bound of the bounding box. /// public PolyVertex Min; /// /// The upper bound of the bounding box. /// public PolyVertex Max; /// /// Initializes a new instance of the struct. /// /// The lower bound of the bounding box. /// The upper bound of the bounding box. public PolyBounds(PolyVertex min, PolyVertex max) { Min = min; Max = max; } /// /// Checks whether two boudning boxes are intersecting. /// /// The first bounding box. /// The second bounding box. /// A value indicating whether the two bounding boxes are overlapping. public static bool Overlapping(ref PolyBounds a, ref PolyBounds b) { return !(a.Min.X > b.Max.X || a.Max.X < b.Min.X || a.Min.Y > b.Max.Y || a.Max.Y < b.Min.Y || a.Min.Z > b.Max.Z || a.Max.Z < b.Min.Z); } /// /// Compares two instances for equality. /// /// A bounding box. /// Another bounding box. /// A value indicating whether the two bounding boxes are equal. public static bool operator ==(PolyBounds left, PolyBounds right) { return left.Equals(right); } /// /// Compares two instances for inequality. /// /// A bounding box. /// Another bounding box. /// A value indicating whether the two bounding boxes are not equal. public static bool operator !=(PolyBounds left, PolyBounds right) { return !(left == right); } /// /// Compares another instance with this instance for equality. /// /// A bounding box. /// A value indicating whether the bounding box is equal to this instance. public bool Equals(PolyBounds other) { return Min == other.Min && Max == other.Max; } /// /// Compares another object with this instance for equality. /// /// An object. /// A value indicating whether the object is equal to this instance. public override bool Equals(object obj) { PolyBounds? b = obj as PolyBounds?; if (b.HasValue) return this.Equals(b.Value); return false; } /// /// Calculates a hash code unique to the contents of this instance. /// /// A hash code. public override int GetHashCode() { //TODO write a better hash code return Min.GetHashCode() ^ Max.GetHashCode(); } /// /// Creates a human-readable string with the contents of this instance. /// /// A human-readable string. public override string ToString() { return "[" + Min.ToString() + ", " + Max.ToString() + "]"; } } }