public bool Contains(IEnvelop b) { return(MinPointLongitude <= b.MinPointLongitude && MinPointLatitude <= b.MinPointLatitude && b.MaxPointLongitude <= MaxPointLongitude && b.MaxPointLatitude <= MaxPointLatitude); }
public bool Intersects(IEnvelop b) { return(b.MinPointLongitude <= MaxPointLongitude && b.MinPointLatitude <= MaxPointLatitude && b.MaxPointLongitude >= MinPointLongitude && b.MaxPointLatitude >= MinPointLatitude); }
public SpatialIndexNode(uint data, IEnvelop envelope, SpatialIndexNode[] children) { Data = data; Envelope = envelope; Children = children; IsLeaf = false; }
private static void AdjutsParentBounds(IEnvelop bbox, List <RTreeNode> path, int level) { // adjust bboxes along the given tree path for (var i = level; i >= 0; i--) { path[i].Envelope.Extend(bbox); } }
public void Extend(IEnvelop by) { MinPointLatitude = Math.Min(MinPointLatitude, by.MinPointLatitude); MinPointLongitude = Math.Min(MinPointLongitude, by.MinPointLongitude); MaxPointLatitude = Math.Max(MaxPointLatitude, by.MaxPointLatitude); MaxPointLongitude = Math.Max(MaxPointLongitude, by.MaxPointLongitude); }
private static double CombinedArea(IEnvelop what, IEnvelop with) { var minX1 = Math.Max(what.MinPointLongitude, with.MinPointLongitude); var minY1 = Math.Max(what.MinPointLatitude, with.MinPointLatitude); var maxX2 = Math.Min(what.MaxPointLongitude, with.MaxPointLongitude); var maxY2 = Math.Min(what.MaxPointLatitude, with.MaxPointLatitude); return((maxX2 - minX1) * (maxY2 - minY1)); }
private static double IntersectionArea(IEnvelop what, IEnvelop with) { var minX = Math.Max(what.MinPointLongitude, with.MinPointLongitude); var minY = Math.Max(what.MinPointLatitude, with.MinPointLatitude); var maxX = Math.Min(what.MaxPointLongitude, with.MaxPointLongitude); var maxY = Math.Min(what.MaxPointLatitude, with.MaxPointLatitude); return(Math.Max(0, maxX - minX) * Math.Max(0, maxY - minY)); }
public LocksController( IEnvelop envelop, ICommand<LockInfo> putLockCmd, ICommand<LockInfo> removeLockCmd) : base(envelop) { _putLockCmd = putLockCmd; _removeLockCmd = removeLockCmd; }
private RTreeNode ChooseSubtree(IEnvelop bbox, RTreeNode node, int level, List <RTreeNode> path) { while (true) { path.Add(node); if (node.IsLeaf || path.Count - 1 == level) { break; } var minArea = double.MaxValue; var minEnlargement = double.MaxValue; RTreeNode targetNode = null; if (node.HasChildren) { for (var i = 0; i < node.Children.Count; i++) { var child = node.Children[i]; var area = child.Envelope.Area; var enlargement = CombinedArea(bbox, child.Envelope) - area; // choose entry with the least area enlargement if (enlargement < minEnlargement) { minEnlargement = enlargement; minArea = area < minArea ? area : minArea; targetNode = child; } else if (Math.Abs(enlargement - minEnlargement) < double.Epsilon) { // otherwise choose one with the smallest area if (area < minArea) { minArea = area; targetNode = child; } } } } Debug.Assert(targetNode != null); node = targetNode; } return(node); }
public DocumentsController( IEnvelop envelop, IQuery<EmptyRequest, IEnumerable<DocumentDetails>> getAllDocuments, IQuery<Guid, DocumentDetails> getDocument, ICommand<Document> submitDocumentCmd, ICommand<Document> updateDocumentCmd, ICommand<DocumentReference> deleteDocument) : base(envelop) { _getAllDocuments = getAllDocuments; _getDocument = getDocument; _submitDocumentCmd = submitDocumentCmd; _updateDocumentCmd = updateDocumentCmd; _deleteDocument = deleteDocument; }
private IObservable <T> Search(IEnvelop envelope, int zoomLevel) { var minMargin = ZoomHelper.GetMinMargin(zoomLevel); return(Observable.Create <T>(observer => { var node = Root; if (!envelope.Intersects(node.Envelope)) { observer.OnCompleted(); return Disposable.Empty; } var nodesToSearch = new Stack <RTreeNode>(); while (node != null && node.Envelope != null) { if (node.Children != null) { foreach (var child in node.Children) { var childEnvelope = child.Envelope; if (envelope.Intersects(childEnvelope)) { if (node.IsLeaf && childEnvelope.Margin >= minMargin) { observer.OnNext(child.Data); } else if (envelope.Contains(childEnvelope)) { Collect(child, minMargin, observer); } else { nodesToSearch.Push(child); } } } } node = nodesToSearch.TryPop(); } observer.OnCompleted(); return Disposable.Empty; })); }
private static bool ReadNode(BinaryReader reader, out SpatialIndexNode root) { var data = reader.ReadUInt32(); if (data == Marker) { root = default(SpatialIndexNode); return(true); } var packedValues = reader.ReadByte(); bool isPointEnvelop = (packedValues & 1) > 0; bool isLeaf = (packedValues >> 1) > 0; IEnvelop envelop = isPointEnvelop ? (IEnvelop) new PointEnvelop(reader.ReadInt32(), reader.ReadInt32()) : new Envelop(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); List <SpatialIndexNode> children = null; while (true) { SpatialIndexNode child; if (ReadNode(reader, out child)) { break; } if (children == null) { children = new List <SpatialIndexNode>(64); } children.Add(child); } root = new SpatialIndexNode(data, envelop, children != null && children.Count > 0 ? children.ToArray() : null); root.IsLeaf = isLeaf; return(false); }
public TicketsController( IEnvelop envelop, IQuery<EmptyRequest, IEnumerable<TicketDetails>> allTicketsQuery, IQuery<Guid, TicketDetails> getTicketQuery, IQuery<HttpRequestMessage, ulong> versionQuery, ICommand<Ticket> addTicketCmd, ICommand<Ticket> updateTicketCmd, ICommand<TicketReference> deleteTicketCmd) : base(envelop) { _getTicketQuery = getTicketQuery; _allTicketsQuery = allTicketsQuery; _addTicketCmd = addTicketCmd; _updateTicketCmd = updateTicketCmd; _deleteTicketCmd = deleteTicketCmd; _versionQuery = versionQuery; }
public RTreeNode(T data, IEnvelop envelope) { Data = data; Envelope = envelope; }
public void Extend(IEnvelop @by) { throw new NotImplementedException(); }
public bool Intersects(IEnvelop b) { throw new NotImplementedException(); }
public bool Contains(IEnvelop b) { throw new NotImplementedException(); }
internal void Insert(T data, IEnvelop bounds) { Insert(new RTreeNode(data, bounds)); }