/// <summary> /// Test if point is located inside bounding box. /// Currently only two dimensions are handled. /// </summary> /// <param name="boundingBox">Bounding box.</param> /// <param name='point'>Point.</param> /// <returns>True if point is located inside bounding box.</returns> public static Boolean IsPointInside(this WebBoundingBox boundingBox, WebPoint point) { return(boundingBox.IsNotNull() && point.IsNotNull() && (boundingBox.Max.X >= point.X) && (boundingBox.Min.X <= point.X) && (boundingBox.Max.Y >= point.Y) && (boundingBox.Min.Y <= point.Y)); }
/// <summary> /// Add buffer to bounding box. /// </summary> /// <param name="boundingBox">Bounding box.</param> /// <param name="buffer">Buffer size in all directions.</param> public static void AddBuffer(this WebBoundingBox boundingBox, Double buffer) { if (boundingBox.IsNotNull()) { boundingBox.Max.X += buffer; boundingBox.Max.Y += buffer; boundingBox.Min.X -= buffer; boundingBox.Min.Y -= buffer; } }
/// <summary> /// Convert bounding box to a string. /// </summary> /// <param name="boundingBox">Bounding box that should be converted.</param> /// <returns>Bounding box as a string.</returns> public static String WebToString(this WebBoundingBox boundingBox) { StringBuilder stringBuilder; stringBuilder = new StringBuilder(); if (boundingBox.IsNotNull() && boundingBox.Min.IsNotNull() && boundingBox.Max.IsNotNull()) { stringBuilder.Append("Bounding box = ["); stringBuilder.Append("[" + boundingBox.Min.X.WebToStringR() + ", " + boundingBox.Max.Y.WebToStringR() + "],"); stringBuilder.Append("[" + boundingBox.Max.X.WebToStringR() + ", " + boundingBox.Min.Y.WebToStringR() + "]"); stringBuilder.Append("]"); } return(stringBuilder.ToString()); }
/// <summary> /// Convert bounding box from one coordinate system to /// another coordinate system. /// Converted bounding box is returned as a polygon /// since it probably is not a rectangle any more. /// </summary> /// <param name="boundingBox">Bounding box that should be converted.</param> /// <param name="fromCoordinateSystem">From coordinate system.</param> /// <param name="toCoordinateSystem">To coordinate system.</param> /// <returns>Polygon with coordinates according to toCoordinateSystem</returns> public virtual WebPolygon GetConvertedBoundingBox(WebBoundingBox boundingBox, WebCoordinateSystem fromCoordinateSystem, WebCoordinateSystem toCoordinateSystem) { WebPolygon toPolygon; toPolygon = null; if (boundingBox.IsNotNull()) { toPolygon = boundingBox.GetPolygon(); toPolygon = GetConvertedPolygon(toPolygon, fromCoordinateSystem, toCoordinateSystem); } return(toPolygon); }
/// <summary> /// Check that data is valid. /// </summary> /// <param name="boundingBox">Bounding box.</param> public static void CheckData(this WebBoundingBox boundingBox) { if (boundingBox.IsNotNull()) { // Check points. boundingBox.Max.CheckNotNull("Max"); boundingBox.Max.CheckData(); boundingBox.Min.CheckNotNull("Min"); boundingBox.Min.CheckData(); // Check that points are of the same dimension. if (boundingBox.Max.IsMSpecified != boundingBox.Min.IsMSpecified) { throw new ArgumentException("WebBoundingBox: Min and max has different M dimensions"); } if (boundingBox.Max.IsZSpecified != boundingBox.Min.IsZSpecified) { throw new ArgumentException("WebBoundingBox: Min and max has different Z dimensions"); } // Check that all min values are lower than all max values. if (boundingBox.Max.X < boundingBox.Min.X) { throw new ArgumentException("WebBoundingBox: Max.X is smaller than Min.X"); } if (boundingBox.Max.Y < boundingBox.Min.Y) { throw new ArgumentException("WebBoundingBox: Max.Y is smaller than Min.Y"); } if (boundingBox.Max.IsZSpecified && (boundingBox.Max.Z < boundingBox.Min.Z)) { throw new ArgumentException("WebBoundingBox: Max.Z is smaller than Min.Z"); } if (boundingBox.Max.IsMSpecified && (boundingBox.Max.M < boundingBox.Min.M)) { throw new ArgumentException("WebBoundingBox: Max.M is smaller than Min.M"); } } }