public void addCoord(Coordinat _C) { if (!GeoCoords.Contains(_C)) { GeoCoords.Add(_C); } }
private object getLocations(Coordinat coord, ICollection <Location> locations, int userId = -1, int page = 0) { var hostName = GetHostName(); var Locations = (from l in locations select new { Images = getImages(l.LocationImages), Comments = getComments(l.UserComments), ID = l.Location_ID, Banner = Path.Combine(hostName, l.Location_Banner), Name = l.Location_Name, Info = l.Location_Info, TypeId = l.LocationType_ID, ImageCount = l.LocationImages.Count, Latitude = l.Location_Latitude, Longtitude = l.Location_Longtitude, TypeName = l.LocationType != null ? l.LocationType.LocationType_Name : "", CommentCount = l.UserComments.Count, LikeCount = l.UserLikes.Count, DistanceToUser = coord.Longtitude > 0 ? GetDistance(l.Location_Latitude, l.Location_Longtitude, coord.Latitude, coord.Longtitude) : 0, IsLiked = userId != -1 ? l.UserLikes.FirstOrDefault(u => u.User_ID == userId && u.Location_ID == l.Location_ID) != null ? true : false : false }); if (page >= 0) { Locations = Locations.OrderBy(u => u.DistanceToUser).Skip(page * 6).Take(6); } return(Locations); }
public void Start() { input = Utils.ReadFromFile("10"); getValues(); GetAsteroidCoordinates(); best = CalculateBestPosition(); Console.WriteLine(best); Console.WriteLine(DestroyAsteroids()); }
private int CalculalteAsteroidsInSight(Coordinat current) { angles = new List <double>(); foreach (Coordinat c in AsteroidCoords) { int deltaX = current.x - c.x; int deltaY = current.y - c.y; angles.Add(Math.Atan2(deltaX, deltaY) * 180 / Math.PI); } return(angles.Distinct().Count()); }
public HttpResponseMessage GetLocations(Coordinat coordinat, int userId = -1, int page = 0) { var hostName = GetHostName(); var list = (from location in _db.Locations select location).ToList(); try { var result = getLocations(coordinat, list, userId, page); return(Request.CreateResponse(HttpStatusCode.OK, result));; } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException)); } }
private int FindClosest(List <int> toDestroy) { int closestIndex = 0; int curClosestDistance = int.MaxValue; foreach (int i in toDestroy) { Coordinat c = AsteroidCoords[i]; int distance = Math.Abs(c.x - best.x) + Math.Abs(c.y - best.y); if (distance < curClosestDistance && distance > 0) { curClosestDistance = distance; closestIndex = i; } } return(closestIndex); }
private Coordinat DestroyAsteroids() { int count = 0; double currentAngle = 0; Coordinat current = new Coordinat(); List <int> ToDestroy = new List <int>(); for (int i = 0; i < AsteroidCoords.Count; i++) { AsteroidCoords[i] = new Coordinat() { x = AsteroidCoords[i].x, y = AsteroidCoords[i].y, Angle = BestAngles[i] }; } AsteroidCoords = AsteroidCoords.OrderByDescending(x => x.Angle).ToList(); while (AsteroidCoords.Count > 0) { for (int i = 0; i < AsteroidCoords.Count; i++) { if (AsteroidCoords[i].Angle == currentAngle) { ToDestroy.Add(i); } } if (ToDestroy.Count > 0) { count++; int index = FindClosest(ToDestroy); ToDestroy.Clear(); current = AsteroidCoords[index]; Console.WriteLine("[" + count + "] ima bout to blow up " + current + " at angle " + currentAngle); AsteroidCoords.RemoveAt(index); } currentAngle = currentAngle == -180 ? 180 : GetNextAngle(currentAngle); } return(current); }
private Coordinat CalculateBestPosition() { int best = 0; Coordinat bestCoord = new Coordinat { x = 0, y = 0 }; int temp; for (int i = 0; i < AsteroidCoords.Count; i++) { temp = CalculalteAsteroidsInSight(AsteroidCoords[i]); AsteroidCoords[i] = new Coordinat() { x = AsteroidCoords[i].x, y = AsteroidCoords[i].y, AsteroidsInSight = temp }; if (temp >= best) { best = temp; bestCoord = AsteroidCoords[i]; BestAngles = angles; } } return(bestCoord); }
//per Button die localen GPS Daten speichern public void btnAddCoord() { var C = new Coordinat(GPS.Instance.latitude, GPS.Instance.longitude, 0.5f, "Selbst erstellt"); GeoCoordManager.Instance.addCoord(C); }
public void remove(Coordinat _C) { GeoCoords.Remove(_C); }