#region MIT License /*Copyright (c) 2012-2015 Robert Rouhani SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #endregion using System; using System.Runtime.InteropServices; using FT_Long = System.IntPtr; using FT_ULong = System.UIntPtr; namespace SharpFont { /// /// A structure used to hold an outline's bounding box, i.e., the /// coordinates of its extrema in the horizontal and vertical directions. /// [StructLayout(LayoutKind.Sequential)] public struct BBox : IEquatable { #region Fields private FT_Long xMin, yMin; private FT_Long xMax, yMax; #endregion #region Constructors /// /// Initializes a new instance of the struct. /// /// The left bound. /// The bottom bound. /// The right bound. /// The upper bound. public BBox(int left, int bottom, int right, int top) { xMin = (IntPtr)left; yMin = (IntPtr)bottom; xMax = (IntPtr)right; yMax = (IntPtr)top; } #endregion #region Properties /// /// Gets the horizontal minimum (left-most). /// public int Left { get { return (int)xMin; } } /// /// Gets the vertical minimum (bottom-most). /// public int Bottom { get { return (int)yMin; } } /// /// Gets the horizontal maximum (right-most). /// public int Right { get { return (int)xMax; } } /// /// Gets the vertical maximum (top-most). /// public int Top { get { return (int)yMax; } } #endregion #region Operators /// /// Compares two instances of for equality. /// /// A . /// Another . /// A value indicating equality. public static bool operator ==(BBox left, BBox right) { return left.Equals(right); } /// /// Compares two instances of for inequality. /// /// A . /// Another . /// A value indicating inequality. public static bool operator !=(BBox left, BBox right) { return !left.Equals(right); } #endregion #region Methods /// /// Compares this instance of to another for equality. /// /// A . /// A value indicating equality. public bool Equals(BBox other) { return xMin == other.xMin && yMin == other.yMin && xMax == other.xMax && yMax == other.yMax; } /// /// Compares this instance of to an object for equality. /// /// An object. /// A value indicating equality. public override bool Equals(object obj) { if (obj is BBox) return this.Equals((BBox)obj); return false; } /// /// Gets a unique hash code for this instance. /// /// A hash code. public override int GetHashCode() { //TODO better hash algo return xMin.GetHashCode() ^ yMin.GetHashCode() ^ xMax.GetHashCode() ^ yMax.GetHashCode(); } /// /// Gets a string that represents this instance. /// /// A string representation of this instance. public override string ToString() { return "Min: (" + (int)xMin + ", " + (int)yMin + "), Max: (" + (int)xMax + ", " + (int)yMax + ")"; } #endregion } }