// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections.Generic;
using System.Drawing;
using Core.GIS.SharpMap.Api.Layers;
namespace Core.GIS.SharpMap.Rendering
{
///
/// Defines an axis-aligned box around a label, used for collision detection
///
public class LabelBox : IComparable
{
///
/// Initializes a new LabelBox instance
///
/// Left side of box
/// Top of box
/// Width of the box
/// Height of the box
public LabelBox(float left, float top, float width, float height)
{
Left = left;
Top = top;
Width = width;
Height = height;
}
///
/// Initializes a new LabelBox instance based on a rectangle
///
///
public LabelBox(RectangleF rectangle)
{
Left = rectangle.X;
Top = rectangle.Y;
Width = rectangle.Width;
Height = rectangle.Height;
}
///
/// The Left tie-point for the Label
///
public float Left { get; set; }
///
/// The Top tie-point for the label
///
public float Top { get; set; }
///
/// Width of the box
///
public float Width { get; set; }
///
/// Height of the box
///
public float Height { get; set; }
///
/// Right side of the box
///
public float Right
{
get
{
return Left + Width;
}
}
///
/// Bottom of th ebox
///
public float Bottom
{
get
{
return Top - Height;
}
}
///
/// Determines whether the boundingbox intersects another boundingbox
///
///
///
public bool Intersects(LabelBox box)
{
return !(box.Left > Left + Width ||
box.Left + box.Width < Left ||
box.Top - box.Height > Top ||
box.Top < Top - Height);
}
#region IComparable Members
///
/// Returns 0 if the boxes intersects each other
///
/// labelbox to perform intersectiontest with
/// 0 if the intersect
public int CompareTo(LabelBox other)
{
if (Intersects(other))
{
return 0;
}
else if (other.Left > Left + Width ||
other.Top - other.Height > Top)
{
return 1;
}
else
{
return -1;
}
}
#endregion
}
///
/// Class for storing a label instance
///
public class Label : IComparable