public void IntersectionTestFindsCorrectData() { ConcurrentGeoQuadtree <object> quadtree = new ConcurrentGeoQuadtree <object>(1, 5, 25); Random rand = new Random(12345); List <ConcurrentGeoQuadtree <object> .IElement> inElements = new List <ConcurrentGeoQuadtree <object> .IElement>(); for (int i = 0; i < 10; ++i) { inElements.Add(quadtree.InsertElement(null, new GeoCoordinates(rand.NextDouble() * 5 - 2.5, rand.NextDouble() * 5 - 2.5))); } List <ConcurrentGeoQuadtree <object> .IElement> outElements = new List <ConcurrentGeoQuadtree <object> .IElement>(); for (int i = 0; i < 10; ++i) { outElements.Add(quadtree.InsertElement(null, new GeoCoordinates(rand.NextDouble() * 5 + 40, rand.NextDouble() * 5 + 40))); } quadtree.EfficientlyReindex(); // All inElements should be in here, no outElements should be in here. Rect inRect = new Rect(-3, -3, 6, 6); var foundElements = quadtree.GetElementsInside(inRect.Intersects); foreach (var elt in inElements) { Assert.True(foundElements.Contains(elt)); } foreach (var elt in outElements) { Assert.False(foundElements.Contains(elt)); } }
public async Task <(IList <PendingRideRequestCenter.MatchableRideRequest>, RideInfo)> GetRide( UserRideOffer offer, ConcurrentGeoQuadtree <PendingRideRequestCenter.MatchableRideRequest> origins, ConcurrentGeoQuadtree <PendingRideRequestCenter.MatchableRideRequest> destinations) { if (origins.Count == 0) { return( new List <PendingRideRequestCenter.MatchableRideRequest>(), new RideInfo(offer.User.UserInfo.UserId, offer.RideOffer.Car, new Route(new Route.Stop[] { new Route.Stop(offer.RideOffer.Trip.Source), new Route.Stop(offer.RideOffer.Trip.Destination) })) ); } RequestElement element = origins.GetElementsInside((r) => true).First(); UserInfo passenger = element.Data.Request.User.UserInfo; GeoCoordinates passengerPickUp = element.Coordinates; GeoCoordinates passengerDropOff = element.Data.DestinationElement.Coordinates; return( new List <PendingRideRequestCenter.MatchableRideRequest> { element.Data }, new RideInfo(offer.User.UserInfo.UserId, offer.RideOffer.Car, new Route(new Route.Stop[] { new Route.Stop(offer.RideOffer.Trip.Source), new Route.Stop(passengerPickUp, passenger, true), new Route.Stop(passengerDropOff, passenger), new Route.Stop(offer.RideOffer.Trip.Destination) })) ); }
GetElementsInsideAsync( ConcurrentGeoQuadtree <MatchableRideRequest> quadtree, Predicate <Rect> area) { return(Task.Run(() => quadtree.GetElementsInside(area))); }