private void Divide() { IsParent = true; FirstChild = new RNode(); SecondChild = new RNode(); if (latitudeMax - latitudeMin > longitudeMax - longitudeMin) { list.Sort(CompareByCoordinateX); } else { list.Sort(CompareByCoordinateY); } FirstChild.Add(list[0]); SecondChild.Add(list[Size - 1]); list.RemoveAt(Size - 1); list.RemoveAt(0); foreach (Place Place in list) { if (OptimalInclude(FirstChild, SecondChild, Place)) { FirstChild.Add(Place); } else { SecondChild.Add(Place); } } }
public static RNode FillRTree(string filename) { RNode tree = new RNode(); List <string> list = new List <string>(); list = File.ReadAllLines(filename).ToList(); foreach (var item in list) { string[] buf = item.Split(';'); tree.Add(new Place(double.Parse(buf[0]), double.Parse(buf[1]), buf[2], buf[3], buf[4], buf[5])); } return(tree); }
public void Add(Place e) { Size++; if (Size == 1) { latitudeMax = latitudeMin = e.Latitude; longitudeMax = longitudeMin = e.Longitude; list.Add(e); } else { latitudeMax = FindBigger(e.Latitude, latitudeMax); longitudeMax = FindBigger(e.Longitude, longitudeMax); latitudeMin = FindLower(e.Latitude, latitudeMin); latitudeMax = FindLower(e.Latitude, latitudeMax); if (IsParent) { if (OptimalInclude(FirstChild, SecondChild, e)) { FirstChild.Add(e); } else { SecondChild.Add(e); } } else { list.Add(e); if (Size > capacity) { Divide(); } } } }