using GeoAPI.Geometries;
using GisSharpBlog.NetTopologySuite.Geometries;
namespace GisSharpBlog.NetTopologySuite.Index.KdTree
{
///
/// A node of a , which represents one or more points in the same location.
///
/// The type of the object
/// dskea
public class KdNode
where T : class
{
private readonly Coordinate _p;
private readonly T _data;
///
/// Creates a new KdNode.
///
/// coordinate of point
/// coordinate of point
/// A data objects to associate with this node
public KdNode(double x, double y, T data)
{
_p = new Coordinate(x, y);
Left = null;
Right = null;
Count = 1;
_data = data;
}
///
/// Creates a new KdNode.
///
/// The point location of new node
/// A data objects to associate with this node
public KdNode(ICoordinate p, T data)
{
_p = new Coordinate(p);
Left = null;
Right = null;
Count = 1;
_data = data;
}
///
/// Gets x-ordinate of this node
///
public double X
{
get
{
return _p.X;
}
}
///
/// Gets y-ordinate of this node
///
public double Y
{
get
{
return _p.Y;
}
}
///
/// Gets the location of this node
///
public ICoordinate Coordinate
{
get
{
return _p;
}
}
///
/// Gets the user data object associated with this node.
///
public T Data
{
get
{
return _data;
}
}
///
/// Gets or sets the left node of the tree
///
public KdNode Left { get; set; }
///
/// Gets or sets the right node of the tree
///
public KdNode Right { get; set; }
///
/// Gets the number of inserted points that are coincident at this location.
///
public int Count { get; private set; }
///
/// Gets whether more than one point with this value have been inserted (up to the tolerance)
///
///
public bool IsRepeated
{
get
{
return Count > 1;
}
}
// Increments counts of points at this location
internal void Increment()
{
Count = Count + 1;
}
}
}