19 using System.Collections.Generic;
20 using System.Collections.ObjectModel;
21 using System.Diagnostics;
22 using System.Runtime.CompilerServices;
23 using Spatial4n.Core.Shapes;
25 namespace Lucene.Net.Spatial.Prefix.Tree
27 public abstract class Node : IComparable<Node>
29 public static byte LEAF_BYTE = (byte)
'+';
46 this.spatialPrefixTree = spatialPrefixTree;
48 if (token.Length > 0 && token[token.Length - 1] == (
char)LEAF_BYTE)
50 this.token = token.Substring(0, token.Length - 1);
58 public virtual void Reset(
string newToken)
60 Debug.Assert(GetLevel() != 0);
61 this.token = newToken;
62 shapeRel = SpatialRelation.NULL_VALUE;
66 private void b_fixLeaf()
68 if (GetLevel() == spatialPrefixTree.GetMaxLevels())
74 public SpatialRelation GetShapeRel()
81 return shapeRel == SpatialRelation.WITHIN;
86 Debug.Assert(GetLevel() != 0);
87 shapeRel = SpatialRelation.WITHIN;
93 public String GetTokenString()
96 throw new InvalidOperationException(
"Somehow we got a null token");
122 public int GetLevel()
139 public IList<Node> GetSubCells(Shape shapeFilter)
142 var point = shapeFilter as Point;
146 return new ReadOnlyCollectionBuilder<Node>(
new[] {GetSubCell(point)}).ToReadOnlyCollection();
148 return new List<Node>(
new[]{GetSubCell(point)}).AsReadOnly();
153 var cells = GetSubCells();
154 if (shapeFilter == null)
158 var copy =
new List<Node>(cells.Count);
159 foreach (var cell
in cells)
161 SpatialRelation rel = cell.GetShape().Relate(shapeFilter);
162 if (rel == SpatialRelation.DISJOINT)
177 public abstract Node GetSubCell(Point p);
187 public abstract IList<Node> GetSubCells();
192 public abstract int GetSubCellsSize();
194 public abstract Shape GetShape();
196 public virtual Point GetCenter()
198 return GetShape().GetCenter();
204 return System.String.CompareOrdinal(GetTokenString(), o.
GetTokenString());
207 public override bool Equals(
object obj)
209 return !(obj == null || !(obj is
Node)) && GetTokenString().Equals(((
Node) obj).GetTokenString());
212 public override int GetHashCode()
214 return GetTokenString().GetHashCode();
217 public override string ToString()
219 return GetTokenString() + (IsLeaf() ?
new string(
new[] {(char) LEAF_BYTE}) :
string.Empty);