Files
Triangle.NET/Triangle.NET/Triangle/Geometry/BoundingBox.cs
T
SND\wo80_cp fcb6057f3d Code cleanup for Beta 2
git-svn-id: https://triangle.svn.codeplex.com/svn@68260 0e2699bc-83d4-4a8f-98e7-55e24ab8c7a5
2012-06-20 19:24:53 +00:00

117 lines
3.3 KiB
C#

// -----------------------------------------------------------------------
// <copyright file="BoundingBox.cs" company="">
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
// </copyright>
// -----------------------------------------------------------------------
namespace TriangleNet.Geometry
{
using System;
/// <summary>
/// A simple bounding box class.
/// </summary>
public class BoundingBox
{
double xmin, ymin, xmax, ymax;
/// <summary>
/// Initializes a new instance of the <see cref="BoundingBox" /> class.
/// </summary>
public BoundingBox()
{
xmin = double.MaxValue;
ymin = double.MaxValue;
xmax = -double.MaxValue;
ymax = -double.MaxValue;
}
/// <summary>
/// Initializes a new instance of the <see cref="BoundingBox" /> class
/// with predefined bounds.
/// </summary>
/// <param name="xmin">Minimum x value.</param>
/// <param name="ymin">Minimum y value.</param>
/// <param name="xmax">Maximum x value.</param>
/// <param name="ymax">Maximum y value.</param>
public BoundingBox(double xmin, double ymin, double xmax, double ymax)
{
this.xmin = xmin;
this.ymin = ymin;
this.xmax = xmax;
this.ymax = ymax;
}
/// <summary>
/// Gets the minimum x value (left boundary).
/// </summary>
public double Xmin
{
get { return xmin; }
}
/// <summary>
/// Gets the minimum y value (bottom boundary).
/// </summary>
public double Ymin
{
get { return ymin; }
}
/// <summary>
/// Gets the maximum x value (right boundary).
/// </summary>
public double Xmax
{
get { return xmax; }
}
/// <summary>
/// Gets the maximum y value (top boundary).
/// </summary>
public double Ymax
{
get { return ymax; }
}
/// <summary>
/// Gets the width of the bounding box.
/// </summary>
public double Width
{
get { return xmax - xmin; }
}
/// <summary>
/// Gets the height of the bounding box.
/// </summary>
public double Height
{
get { return ymax - ymin; }
}
/// <summary>
/// Update bounds.
/// </summary>
/// <param name="x">X coordinate.</param>
/// <param name="y">Y coordinate.</param>
public void Update(double x, double y)
{
xmin = Math.Min(xmin, x);
ymin = Math.Min(ymin, y);
xmax = Math.Max(xmax, x);
ymax = Math.Max(ymax, y);
}
/// <summary>
/// Check if given point is inside bounding box.
/// </summary>
/// <param name="pt">Point to check.</param>
/// <returns>Return true, if bounding box contains given point.</returns>
public bool Contains(Point pt)
{
return ((pt.x >= xmin) && (pt.x <= xmax) && (pt.y >= ymin) && (pt.y <= ymax));
}
}
}