Example #1
0
        private static IEnumerable <IEnumerable <Vector2> > FindSpecialBuildingsWithinDistanceFromHouse(
            IEnumerable <Vector2> specialBuildings,
            IEnumerable <Tuple <Vector2, float> > housesAndDistances)
        {
            Func <Tuple <Vector2, float>, Predicate <Vector2> > predicate = t => v => Euclosure.Invoke(t.Item1).Invoke(v) < t.Item2;
            var specialBuildingsTree = Tree2D.FromEnumerable(specialBuildings);
            var newSpecialBuildings  = new List <List <Vector2> >();

            foreach (var tuple in housesAndDistances)
            {
                var p = predicate.Invoke(tuple);
                newSpecialBuildings.Add(Tree2D.FilterTree(specialBuildingsTree, p));
            }
            return(newSpecialBuildings);
        }
        //----------------------------------------------------------------------
        private static IntSet <PartyId> SearchNearLocation(
            Timer t,
            int desiredResultCount,
            Location centroid,
            double nonGeoMatchAbsDensity,
            out double?maxRadiusMi)
        {
            double searchRadiusMi = InitialGeoSearchRadiusMi;

            maxRadiusMi = searchRadiusMi;

            // KLUDGE: Scale the desired result count up by the non-geographic
            // match absolute density in the database.  In doing so, we attempt
            // to return enough results that we'll get close to the desired
            // result count in the end.
            desiredResultCount = (int)(desiredResultCount / nonGeoMatchAbsDensity);

            // Allocate an initial list large enough that we'll (hopefully)
            // avoid re-allocating space as we iterate.
            List <int>   partyIds = new List <int>(2 * desiredResultCount);
            Tree2D <int> tree2d   = Snap.Cache.Cache.PartyLocation;

            int   iterationCount = 0;
            Timer tree2dTimer    = new Timer(t, String.Format(
                                                 "Expand MBR to fit {0} Parties", desiredResultCount));

            while ((partyIds.Count < desiredResultCount) &&
                   (searchRadiusMi < MaxGeoSearchRadiusMi))
            {
                iterationCount++;
                maxRadiusMi = searchRadiusMi;
                partyIds.Clear();
                tree2d.Search(
                    new BoundingBox(centroid, searchRadiusMi),
                    (partyId) => partyIds.Add(partyId));
                searchRadiusMi *= GeoSearchRadiusScalar;
            }
            tree2dTimer.Stop(String.Format("in {0} iterations", iterationCount));

            return(IntSet <PartyId> .CreateFromUnsorted(partyIds));
        }