/// <summary>
 /// Calculates the distance between a point and a solid axis-aligned box.
 /// </summary>
 /// <param name="point">A <see cref="Vector2F"/> instance.</param>
 /// <param name="aabb">An <see cref="AxisAlignedBox"/> instance.</param>
 /// <returns>The distance between a point and a solid axis-aligned box.</returns>
 /// <remarks>
 /// Treating the box as solid means that any point inside the box has
 /// distance zero from the box.
 /// </remarks>
 public static float Distance(Vector2F point, AxisAlignedBox aabb)
 {
     return (float)System.Math.Sqrt(SquaredDistance(point, aabb));
 }
        /// <summary>
        /// Calculates the squared distance between a point and a solid axis-aligned box.
        /// </summary>
        /// <param name="point">A <see cref="Vector2F"/> instance.</param>
        /// <param name="aabb">An <see cref="AxisAlignedBox"/> instance.</param>
        /// <returns>The squared distance between a point and a solid axis-aligned box.</returns>
        /// <remarks>
        /// Treating the box as solid means that any point inside the box has
        /// distance zero from the box.
        /// </remarks>
        public static float SquaredDistance(Vector2F point, AxisAlignedBox aabb)
        {
            float sqrDistance = 0.0f;
            float delta;

            if (point.X < aabb.Min.X)
            {
                delta = point.X - aabb.Min.X;
                sqrDistance += delta*delta;
            }
            else if (point.X > aabb.Max.X)
            {
                delta = point.X - aabb.Max.X;
                sqrDistance += delta*delta;
            }

            if (point.Y < aabb.Min.Y)
            {
                delta = point.Y - aabb.Min.Y;
                sqrDistance += delta*delta;
            }
            else if (point.Y > aabb.Max.Y)
            {
                delta = point.Y - aabb.Max.Y;
                sqrDistance += delta*delta;
            }

            return sqrDistance;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AxisAlignedBox"/> class using given values from another box instance.
 /// </summary>
 /// <param name="box">A <see cref="AxisAlignedBox"/> instance to take values from.</param>
 public AxisAlignedBox(AxisAlignedBox box)
 {
     _min = box.Min;
     _max = box.Max;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AxisAlignedBox"/> class using given values from another box instance.
 /// </summary>
 /// <param name="box">A <see cref="AxisAlignedBox"/> instance to take values from.</param>
 public AxisAlignedBox(AxisAlignedBox box)
 {
     _min = box.Min;
     _max = box.Max;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Calculates the distance between a point and a solid axis-aligned box.
 /// </summary>
 /// <param name="point">A <see cref="Vector2F"/> instance.</param>
 /// <param name="aabb">An <see cref="AxisAlignedBox"/> instance.</param>
 /// <returns>The distance between a point and a solid axis-aligned box.</returns>
 /// <remarks>
 /// Treating the box as solid means that any point inside the box has
 /// distance zero from the box.
 /// </remarks>
 public static float Distance(Vector2F point, AxisAlignedBox aabb)
 {
     return((float)System.Math.Sqrt(SquaredDistance(point, aabb)));
 }