protected QtreeNode(QtreeNode parent, double top, double bottom, double left, double right) { Depth = parent == null ? 0 : parent.Depth + 1; Parent = parent; Top = top; Bottom = bottom; Left = left; Right = right; }
private static QtreeNode GetQtree(int empresa, int linea) { var lastMod = ReferenciaGeograficaDAO.GetLastUpdate(empresa, linea); var key = GetQtreeKey(empresa, linea); var root = Qtrees.ContainsKey(key) ? Qtrees[key] : null; if (root != null && lastMod < root.LastUpdate) { return(root); } if (Monitor.TryEnter(Qtrees)) { try { STrace.Error("ResetQtree", string.Format("qtree UPDATE ---> Empresa: {0} - Linea: {1}", empresa, linea)); using (var transaction = SmartTransaction.BeginTransaction()) { var daoFactory = new DAOFactory(); var geocercas = daoFactory.ReferenciaGeograficaDAO.GetGeocercasFor(empresa, linea); transaction.Commit(); var keyToRemove = string.Empty; if (root != null) { keyToRemove = key; } root = new QtreeNode(); foreach (var geocerca in geocercas) { root.AddValue(geocerca); } if (keyToRemove != string.Empty) { Qtrees.Remove(keyToRemove); } Qtrees.Add(key, root); } STrace.Trace("DispatcherLock", string.Format("qtree NEW ---> {0} | {1}", empresa, linea)); } finally { Monitor.Exit(Qtrees); } } else { STrace.Trace("DispatcherLock", string.Format("qtree OLD ---> {0} | {1}", empresa, linea)); } return(root); }
protected QtreeNode AddQuadrant(int i) { double top, bottom, left, right; switch (i) { case 0: top = Top; bottom = (Top + Bottom) / 2.0; left = Left; right = (Left + Right) / 2.0; Quadrant1 = new QtreeNode(this, top, bottom, left, right); break; case 1: top = Top; bottom = (Top + Bottom) / 2.0; left = (Left + Right) / 2.0; right = Right; Quadrant2 = new QtreeNode(this, top, bottom, left, right); break; case 2: top = (Top + Bottom) / 2.0; bottom = Bottom; left = Left; right = (Left + Right) / 2.0; Quadrant3 = new QtreeNode(this, top, bottom, left, right); break; case 3: top = (Top + Bottom) / 2.0; bottom = Bottom; left = (Left + Right) / 2.0; right = Right; Quadrant4 = new QtreeNode(this, top, bottom, left, right); break; } return(GetQuadrant(i)); }