Пример #1
0
        public void TestScalarGeoPointDistance()
        {
            List <IpGeopoint> list;

            using (var conn = TestCrateConnection())
            {
                conn.Open();
                list = conn.Where <IpGeopoint>(t => Geo.Distance(t.Pin, new GeoPoint(21, 2)) > 1);
            }
            Assert.GreaterOrEqual(list.Count, 1);
        }
Пример #2
0
        public static void Check_Distance()
        {
            GeoPoint point1 = new GeoPoint(46.599550, 14.270328);
            GeoPoint point2 = new GeoPoint(47.051497, 15.452759);

            Assert.Equal(103.04, Geo.Distance(point1, point2), 2);

            //point1 = new GeoPoint(46.619906, 14.304134);
            //point2 = new GeoPoint(46.599582, 14.270487);

            //DbGeography geoPoint1 = DbGeography.FromText(point1.ToString());
            //DbGeography geoPoint2 = DbGeography.FromText(point2.ToString());
            //double? distance = geoPoint1.Distance(geoPoint2);

            //Assert.Equal(103.04, Geo.Distance(point1, point2), 2);
        }
Пример #3
0
        public override void Step()
        {
            for (int i = 0; i < Game.Players.Count; i++)
            {
                var player = Game.Players[i];

                if (player.Actors.Count > 1)
                {
                    foreach (var actor in player.Actors)
                    {
                        foreach (var other in player.Actors)
                        {
                            if (actor != other)
                            {
                                var minimumDistance = actor.Radius + other.Radius;
                                if (actor.Position.X == other.Position.X &&
                                    actor.Position.Y == other.Position.Y)
                                {
                                    actor.Position.X += Game.Random.Next(1, 3);
                                    actor.Position.Y += Game.Random.Next(1, 3);
                                }

                                var distance = Geo.Distance(actor.Position, other.Position);
                                if (distance < minimumDistance)
                                {
                                    var actorVector = actor.Position.ToVector();
                                    var motion      = actorVector - other.Position.ToVector();
                                    motion           = VectorUtil.Normalize(motion);
                                    actorVector     += motion * (minimumDistance - distance) * Game.Configuration.SeparationSpeed;
                                    actor.Position.X = (int)actorVector.X;
                                    actor.Position.Y = (int)actorVector.Y;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public override void Step()
        {
            for (int i = 0; i < Game.Actors.Count; i++)
            {
                var actor = Game.Actors[i];

                for (int x = 0; x < Game.Actors.Count; x++)
                {
                    if (i != x)
                    {
                        var other = Game.Actors[x];
                        if (other.CanBeEatenBy(actor))
                        {
                            if (Geo.Distance(actor.Position, other.Position) < ((other.Radius * Game.Configuration.EatDistanceThreshold) + actor.Radius))
                            {
                                actor.Mass += other.Mass - (other.Mass * Game.Configuration.EatCost);
                                actor.Mass  = Math.Min(actor.Mass, Game.Configuration.CellMaxMass);
                                other.Die();
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Create and sort the distance list
 /// </summary>
 private void ProcessData()
 {
     _distList = new List <VerticesGroup>();
     foreach (var v in Vertices)
     {
         var dist = new List <(Vertex, double)>();
         foreach (var j in Vertices)
         {
             double d = Geo.Distance(v.Lat, v.Lon, j.Lat, j.Lon);
             if (d != 0)
             {
                 dist.Add((j, d));
             }
         }
         dist.Sort((a, b) =>
         {
             return((int)(a.Item2 - b.Item2));
         });
         _distList.Add(new VerticesGroup()
         {
             From = v, Dist = dist
         });
     }
 }
Пример #6
0
        /// <summary>
        /// Ermittelt alle Clubs die in einem angegebenen Bereich liegen inkl.
        /// der Besucher und Freunde in den Clubs
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <SearchClubsOutput> SearchClubs(SearchClubsInput input)
        {
            DateTime          actTime        = input.ActualTime.HasValue ? input.ActualTime.Value : DateTime.Now;
            GeoPoint          actualPoint    = new GeoPoint(input.Latitude, input.Longitude);
            DbGeography       actualGeoPoint = DbGeography.FromText(actualPoint.ToString());
            SearchClubsOutput output         = new SearchClubsOutput();

            var friends = _memberRepository.GetAll()
                          .Include(x => x.Friends)
                          .Where(x => x.UserName.ToUpper() == input.UserName.ToUpper()).First()
                          .Friends.ToList();

            double distanceM = input.DistanceKm * 1000;

            var clubs = _clubRepository.GetAll()
                        .Include(x => x.OpenTimes)
                        .Include(x => x.Categories);

            if (input.Latitude > 0)
            {
                clubs = clubs.Where(x => x.Location.Distance(actualGeoPoint) < distanceM);
            }

            var clubsDto = new List <ClubSearchDto>();

            foreach (var club in clubs.ToList())
            {
                double distanceToClub = Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude));
                if (input.Latitude == 0 || distanceToClub <= input.DistanceKm)
                {
                    var visits = await _clubVisitRepository.GetAll().Where(x => x.ClubId == club.Id &&
                                                                           !x.HasLeft && actTime <= x.LeavingDate).ToListAsync();

                    int numberOfVisits = visits.Count();

                    int numberOfFriends = visits.Select(x => x.MemberId).Intersect(friends.Select(x => x.Id)).Count();

                    var imageModification = await _clubImageRepository.GetAll()
                                            .Where(x => x.Id == club.Id)
                                            .Select(x => x.LastModificationTime)
                                            .FirstOrDefaultAsync();

                    ClubSearchDto clubDto = new ClubSearchDto
                    {
                        Id                        = club.Id,
                        Name                      = club.Name,
                        IsOpen                    = club.IsOpen(actTime),
                        Distance                  = Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude)),
                        Longitude                 = club.Longitude,
                        Latitude                  = club.Latitude,
                        Categories                = string.Join(", ", club.Categories.Select(x => x.Name)),
                        FriendsInside             = numberOfFriends,
                        PeopleInside              = numberOfVisits,
                        LastImageModificationTime = imageModification
                    };

                    clubsDto.Add(clubDto);
                }
            }
            output.Clubs = clubsDto.OrderBy(x => x.Distance).ToList();
            return(output);
        }
Пример #7
0
        public async Task <CheckVisitOutput> CheckVisit(CheckVisitInput input)
        {
            var output = new CheckVisitOutput {
                IsOut = false
            };
            Member member = await _memberRepository.GetAll().Where(m => m.UserName.ToUpper() == input.UserName.ToUpper()).FirstAsync();

            GeoPoint actualPoint = new GeoPoint(input.Latitude, input.Longitude);
            DateTime actualTime  = input.ActualTime.HasValue ? input.ActualTime.Value : DateTime.Now;

            var visits = await _clubVisitRepository.GetAll().Where(x => x.MemberId == member.Id &&
                                                                   !x.HasLeft && x.LeavingDate > actualTime).ToListAsync();

            if (!input.IsOut) // in jedem Fall Visits beenden
            {
                foreach (var oldVisit in visits)
                {
                    oldVisit.HasLeft = true;
                    await _clubVisitRepository.UpdateAsync(oldVisit);
                }
                return(output);
            }

            var clubs = await _clubRepository.GetAll().Include(x => x.OpenTimes).ToListAsync();

            Dictionary <Club, double> clubDistances = new Dictionary <Club, double>();

            foreach (var club in clubs)
            {
                if (club.IsOpen(actualTime) && Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude)) <= _allowedDistance)
                {
                    clubDistances.Add(club, Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude)));
                }
            }
            if (clubDistances.Count > 0)
            {
                Club   shortest_club     = new Club();
                double shortest_distance = -1;
                foreach (var cd in clubDistances)
                {
                    if (shortest_distance == -1)
                    {
                        shortest_club     = cd.Key;
                        shortest_distance = cd.Value;
                    }
                    else
                    {
                        if (cd.Value < shortest_distance)
                        {
                            shortest_club     = cd.Key;
                            shortest_distance = cd.Value;
                        }
                    }
                }

                var visit = visits.FirstOrDefault(x => x.ClubId == shortest_club.Id);
                if (visit != null)
                {
                    output.IsOut  = true;
                    output.ClubId = shortest_club.Id;
                    return(output);
                }
                else
                {
                    var ot          = shortest_club.OpenTimes.Where(x => x.IsOpen(actualTime)).First();
                    var closingTime = ot.GetActualCloseTime(actualTime);

                    var newVisit = new ClubVisit {
                        ClubId = shortest_club.Id, MemberId = member.Id, EntryDate = actualTime, LeavingDate = closingTime
                    };
                    await _clubVisitRepository.InsertAsync(newVisit);

                    output.IsOut  = true;
                    output.ClubId = shortest_club.Id;

                    foreach (var oldVisit in visits)
                    {
                        oldVisit.HasLeft = true;
                        await _clubVisitRepository.UpdateAsync(oldVisit);
                    }
                    return(output);
                }
            }

            /*foreach (var club in clubs)
             * {
             *  if (club.IsOpen(actualTime) && Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude)) <= _allowedDistance)
             *  {
             *      var visit = visits.FirstOrDefault(x => x.ClubId == club.Id);
             *      if (visit != null)
             *      {
             *          output.IsOut = true;
             *          output.ClubId = club.Id;
             *          return output;
             *      }
             *      else
             *      {
             *          var ot = club.OpenTimes.Where(x => x.IsOpen(actualTime)).First();
             *          var closingTime = ot.GetActualCloseTime(actualTime);
             *
             *          var newVisit = new ClubVisit { ClubId = club.Id, MemberId = member.Id, EntryDate = actualTime, LeavingDate = closingTime };
             *          await _clubVisitRepository.InsertAsync(newVisit);
             *          output.IsOut = true;
             *          output.ClubId = club.Id;
             *
             *          foreach (var oldVisit in visits)
             *          {
             *              oldVisit.HasLeft = true;
             *              await _clubVisitRepository.UpdateAsync(oldVisit);
             *          }
             *          return output;
             *      }
             *  }
             * }*/

            foreach (var oldVisit in visits)
            {
                oldVisit.HasLeft = true;
                await _clubVisitRepository.UpdateAsync(oldVisit);
            }
            return(output);
        }