public static Direction DetermineLongestDirectionInSection(this Route route, RoutePoint startingWaypoint, Section section) { var directions = new[] { Direction.Forward, Direction.Backward }; return(directions .OrderByDescending(direction => { var wayPoints = route.GetEnumerable(startingWaypoint, direction) .TakeWhile(waypoint => route.GetSectionForPosition(waypoint) == section) .ToArray(); double distance = 0; if (wayPoints.Length == 1) { return distance; } for (var index = 0; index < wayPoints.Length - 1; index++) { var wayPoint = wayPoints[index]; var nextWaypoint = wayPoints[index + 1]; distance += wayPoint.Distance(nextWaypoint); } return distance; }) .ThenBy(direction => directions.IndexOf(direction)) .First()); }
public void CreatePointLineList() { GameObject routeListObj = GameObject.Find(routeGroup); routeManager = new RouteManager(); int i = 0; while (i < routeListObj.transform.childCount) { Transform parent = routeListObj.transform.GetChild(i); RoutePointList routePointList = new RoutePointList(); Debug.LogError("child: " + i + " " + parent.name); int j = 0; while (j < parent.transform.childCount) { Transform childNode = parent.transform.GetChild(j); Debug.LogError("child: " + j + " " + childNode.name); RoutePoint routePoint = new RoutePoint(); routePoint.pointPos = childNode.position; routePoint.pointName = childNode.name; routePointList.pointList.Add(routePoint); j++; } i++; routeManager.routeList.Add(routePointList); } }
private void FillPoints() { PointList = new List <RoutePoint>(); var query = string.Format(@"SELECT p.[objID], p.[stateID], p.[_divisionID], d.[name], p.[position] FROM [_RoutePoint] p, [{1}] d WHERE d.[objID] = p.[_divisionID] AND p.[typeID] = {0} AND (p.[isArchived] is NULL OR p.[isArchived] = 'false')", TypesList.SelectedValue, hasWork ? "_Division" : "Division"); var dt = new DataTable(); var da = new SqlDataAdapter(query, ConString); da.Fill(dt); if (dt.Rows.Count == 0) { return; } foreach (DataRow item in dt.Rows) { var point = new RoutePoint(); point.ID = item.ItemArray[0].ToString(); point.stateID = item.ItemArray[1].ToString(); point.divisionID = item.ItemArray[2].ToString(); point.divisionName = item.ItemArray[3].ToString(); point.position = Convert.ToInt32(item.ItemArray[4]); point.typeID = TypesList.SelectedValue; PointList.Add(point); } }
public void DeserializeRoutePointFromJson() { //Arrange string jsonData = "{\"code\":\"2208530\",\"station\":\"Херсон_station\",\"stationTrain\":\"Херсон_train\",\"date\":\"суббота, 01.06.2019\",\"time\":\"15:52\",\"sortTime\":1559393520,\"srcDate\":\"2019-06-01\"}"; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.Converters.Add(MultiDateConverter.DefaultConverter); DateTime assertionTime = DateTime.Today; assertionTime = assertionTime.AddHours(15).AddMinutes(52); //Act RoutePoint obj = JsonConvert.DeserializeObject <RoutePoint>(jsonData, settings); //Assert Assert.Multiple(() => { Assert.That(obj.Code, Is.EqualTo(2208530)); Assert.That(obj.Station, Is.EqualTo("Херсон_station")); Assert.That(obj.TrainName, Is.EqualTo("Херсон_train")); Assert.That(obj.Date, Is.EqualTo(new DateTime(2019, 06, 01))); Assert.That(obj.Time, Is.EqualTo(assertionTime)); Assert.That(obj.SortTime, Is.EqualTo(1559393520)); Assert.That(obj.SrcDate, Is.EqualTo(new DateTime(2019, 6, 1))); }); }
public static void Select(RoutePoint p) { var obj = p.gameObject; Selection.objects = new GameObject[] { obj }; SceneView.currentDrawingSceneView.LookAt(obj.transform.position); }
private void OnRoutePointRemoved(RoutePointRemovedEvent obj) { RoutePoint routePoint = RoutePoints.FirstOrDefault(x => x.Id == obj.RoutePointId); if (routePoint != null) { RoutePoints.Remove(routePoint); } AircraftRouteViewModel routeViewModel = Routes.FirstOrDefault(x => x.AircraftId == obj.AircraftId); if (routeViewModel != null) { Routes.Remove(routeViewModel); } Aircraft aircraft = Aircrafts.FirstOrDefault(x => x.Id == obj.AircraftId); if (aircraft != null) { AircraftRouteViewModel route = _routeService.GetRouteLine(aircraft); route.IsSelected = true; Routes.Add(route); } }
public RouteManager() { basePos = new RoutePoint(); basePos.pointPos = Vector3.zero; routeList = new List <RoutePointList> (); }
private RoutePoint GeneratePoint() { var user = _random.Next(1, _numUsers); RoutePoint prev, cur; if (_previousPoint.TryGetValue(user, out prev)) { cur = new RoutePoint() { Latitude = NextCoord(prev.Latitude, _maxRange / 100.0), Longitude = NextCoord(prev.Longitude, _maxRange / 100.0), UserID = user.ToString(), MeasurementTime = DateTime.UtcNow }; } else { cur = new RoutePoint() { Latitude = NextCoord(_centerLat, _maxRange), Longitude = NextCoord(_centerLon, _maxRange), UserID = user.ToString(), MeasurementTime = DateTime.UtcNow }; } _previousPoint[user] = cur; Trace.TraceInformation("Generated {0}", cur); return(cur); }
public async Task<IActionResult> PutRoutePoint([FromRoute] int id, [FromBody] RoutePoint routePoint) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != routePoint.Id) { return BadRequest(); } _context.Entry(routePoint).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoutePointExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task CleanUp() { // get all routes in the db List <RoutePoint> routePoints = await _context.RoutePoints.ToListAsync(); _context.Remove(route1); _context.Remove(route2); // walk through and remove them for (int i = 0; i < routePoints.Count; i++) { RoutePoint rp = routePoints[i]; _ = _context.Remove(rp); _context.Entry(rp).State = EntityState.Deleted; } var queryPoints = await _context.Points.ToListAsync(); for (int i = 0; i < queryPoints.Count; i++) { Point p = queryPoints[i]; _ = _context.Remove(p); _context.Entry(p).State = EntityState.Deleted; } // tell the db all the routes were removed await _context.SaveChangesAsync(); }
public async Task <IActionResult> Edit(int id, [Bind("RpId,CityName,StopName")] RoutePoint routePoint) { if (id != routePoint.RpId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(routePoint); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoutePointExists(routePoint.RpId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(routePoint)); }
// Token: 0x060013B0 RID: 5040 RVA: 0x0001C9BC File Offset: 0x0001B9BC protected override void OnMessage(OnTriggerEnter message) { if (base.Entrant.PersonaId == message.PersonaId) { if (message.TriggerKey == this.RoutingState.CurrentTarget.Key) { RoutePoint expectedPreviousTarget = base.InstancedEvent.RoutingMethod.GetExpectedPreviousTarget(base.InstancedEvent, this.RoutingState); if (expectedPreviousTarget != null && expectedPreviousTarget != this.RoutingState.PreviousTarget) { return; } this.RoutingState = base.InstancedEvent.RoutingMethod.HitTrigger(base.InstancedEvent, base.Entrant, this.RoutingState); if (this.RoutingState.CurrentTarget != null) { base.Entrant.Opponent.SetNextPathPoint(this.RoutingState.CurrentTarget.Position, this.RoutingState.CurrentTarget.Direction); } if (this.RoutingState.IsRoutingFinished) { base.InstancedEvent.ScoringMethod.OnRoutingFinished(base.Entrant); this.Close(); } } RoutePoint routePoint2 = base.InstancedEvent.Route.Find((RoutePoint routePoint) => routePoint.Key == message.TriggerKey); if (routePoint2 != null) { this.RoutingState.PreviousTarget = routePoint2; } } }
void DrawCurve(Bezier3D bezier, Quaternion rot, RoutePoint pt0, RoutePoint pt1) { var p0 = pt0.transform.position; var p1 = p0 + rot * pt0.next_weight_point; var p3 = pt1.transform.position; var p2 = p3 + rot * pt1.prev_weight_point; bezier.Set(p0, p1, p2, p3); float iv = 1 / ((p0 - p3).magnitude / (step_length * 2)); if (iv < 0.001f) { //间隔太大 iv = 0.001f; } Gizmos.color = pt0.color; if ((pt0.delta_next.magnitude == 0 && pt1.delta_next.magnitude == 0)) { Gizmos.DrawLine(p0, p3); } else { int arrow = 0; float t = 0; Vector3 lp = p0; Color dc = pt1.color - pt0.color; do { t += iv; if (t > 1.0f) { t = 1.0f; } Vector3 p = bezier.Get(t); Gizmos.color = pt0.color + dc * t; Gizmos.DrawLine(lp, p); if (arrow++ % 2 == 0) { Vector3 tangent = bezier.GetTangent(t); var angle = RouteMath.GetPolarEular(tangent); var quat = Quaternion.AngleAxis(angle, RouteMath.kAxisY); Vector3 v0 = quat * RouteMath.kAxisX; Vector3 axis = Vector3.Cross(p - lp, v0); v0 *= 0.3f; Vector3 v1 = Quaternion.AngleAxis(-70, axis) * v0; Gizmos.DrawLine(p, p - v1); v1 = Quaternion.AngleAxis(-110, axis) * v0; Gizmos.DrawLine(p, p - v1); } lp = p; } while(t < 1.0f); } }
/// <summary>Empfängt Ereignisse vom zentralen Ereignis-Manager.</summary> /// <param name="managerType"> /// Der Typ, der die <see cref="T:System.Windows.WeakEventManager" /> Aufrufen dieser Methode. /// </param> /// <param name="sender"> /// Objekt, das das Ereignis ausgelöst wurde. /// </param> /// <param name="e">Ereignisdaten.</param> /// <returns> /// <see langword="true" /> Wenn der Listener das Ereignis behandelt. /// Fehler durch gilt die <see cref="T:System.Windows.WeakEventManager" /> Behandlung in WPF Registrieren eines Listeners für ein Ereignis, das der Listener nicht behandelt wird. /// Die Methode sollte jedoch unabhängig davon zurückgeben <see langword="false" /> wenn ein Ereignis empfangen wird, die nicht erkannt oder behandelt. /// </returns> public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) { if (sender is RoutePoint) { SelectedRoutePoint = (RoutePoint)sender; } return(true); }
private void OnDeleteSelectedRoutePoint() { Guid routePointId = SelectedRoutePoint.Id; _aircraftService.RemoveRoutePointFromAircraft(_aircraft, SelectedRoutePoint); SelectedRoutePoint = null; _eventAggregator.GetEvent <PubSubEvent <RoutePointRemovedEvent> >().Publish(new RoutePointRemovedEvent(_aircraft.Id, routePointId)); }
public RoutePoint AddRoutePointToAircraft(Aircraft aircraft, Location location) { RoutePoint routePoint = new RoutePoint(location, aircraft.Id); aircraft.Route.Add(routePoint); aircraft.Update(_routeService.GetRouteLenght(aircraft)); return(routePoint); }
public ActionResult DeleteConfirmed(int id) { RoutePoint routepoint = db.RoutePoint.Find(id); db.RoutePoint.Remove(routepoint); db.SaveChanges(); return(RedirectToAction("Index")); }
private void OnLocationSelected(LocationSelectedEvent obj) { if (IsActive) { RoutePoint addedRoutePoint = _aircraftService.AddRoutePointToAircraft(_aircraft, obj.Location); PropertyChangedEventManager.AddListener(addedRoutePoint, this, nameof(RoutePoint.IsSelected)); _eventAggregator.GetEvent <PubSubEvent <RoutePointAddedEvent> >().Publish(new RoutePointAddedEvent(_aircraft.Id, addedRoutePoint)); } }
/// <summary> /// Creates the route point on edge. /// </summary> /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param> /// <param name="hitEdge">The hit edge.</param> private void CreateRoutePointOnEdge(MouseButtonEventArgs e, GraphSharp.Controls.EdgeControl hitEdge) { ExperimentNodeConnection connection = (ExperimentNodeConnection)hitEdge.Edge; Point canvasPoint = e.GetPosition(GraphLayout); RoutePoint finalPoint = new RoutePoint(canvasPoint.X, canvasPoint.Y); connection.RoutePoints.Add(finalPoint); }
public void DeleteRoutePoint(RoutePoint routePoint) { if (SelectedWaypoint == routePoint) { SelectedWaypoint = null; } Route.Waypoints.Remove(routePoint); _map.UpdateRoute(Route); }
internal async void OpenPointPropertiesAsync(double latitude, double longitude) { RoutePoint point = _routePointManager.GetPointByCoordinates(latitude, longitude); if (point != null && point.MainRoute != null) { var routePointPage = new RoutePointV2Page(point.MainRoute.RouteId, point.RoutePointId); await Navigation.PushModalAsync(routePointPage, true); } }
//删除一个路径点 public void RemoveRoutePoint(RoutePoint vRP) { for (int i = 0; i < routeList_.Count; i++) { if (routeList_[i] == vRP) { routeList_.RemoveAt(i); return; } } }
private void ActivateNextWaypoint() { _distanceWalkedMiles += GetLastWayPoint().Distance(NextWaypoint); VisitedWaypoints.Add(RouteEnumerator.Current); if (!RouteEnumerator.MoveNext()) { OnNavigationFinished(); } NextWaypoint = RouteEnumerator.Current; }
public TableAdjustment EditRoutePoint(LatticeData <RoutePoint, RoutePointRow> latticeData, RoutePointRow routePointRow, int routeId) { RoutePoint routePoint; if (routePointRow.RouteId == 0) { routePoint = new RoutePoint { RouteId = routeId, StationOrder = _context.RoutePoints.Where(x => x.RouteId == routeId) .Select(x => x.StationOrder) .DefaultIfEmpty(0) .Max() + 1 }; _context.RoutePoints.Add(routePoint); } else { routePoint = _context.RoutePoints .FirstOrDefault(x => x.RouteId == routePointRow.RouteId && x.StationOrder == routePointRow.StationOrder); } Station station = _context.Stations.FirstOrDefault(x => x.StationName == routePointRow.StationName); if (station == null) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"There is no station with name {routePointRow.StationName}")) )); } if (_context.RoutePoints.Any(x => x.RouteId == routeId && x.StationOrder != routePoint.StationOrder && x.Station.StationId == station.StationId)) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"The route already has station {station.StationName}")) )); } routePoint.Station = station; _context.SaveChanges(); return(latticeData.Adjust(x => x .Update(routePoint) .Message(LatticeMessage.User("success", "Editing", "Route saved")) )); }
/// <summary> /// Преобразование элемента XML в точку марщрута /// </summary> /// <returns>The route point.</returns> /// <param name="element">Element.</param> private static IRoutePoint ToRoutePoint(this XElement element) { var result = new RoutePoint(); var timeValue = element.Elements().FirstOrDefault(x => x.Name.LocalName.Equals("time")); var ci = CultureInfo.InvariantCulture; if (timeValue != null) { DateTime time; if (DateTime.TryParse(timeValue.Value, ci, DateTimeStyles.AssumeUniversal, out time)) { result.Time = time; } } var latValue = element.Attributes().FirstOrDefault(x => x.Name.LocalName.Equals("lat")); if (latValue != null) { double lat; if (double.TryParse(latValue.Value, NumberStyles.Number, ci, out lat)) { result.Position.Lat = lat; } } var lonValue = element.Attributes().FirstOrDefault(x => x.Name.LocalName.Equals("lon")); if (lonValue != null) { double lon; if (double.TryParse(lonValue.Value, NumberStyles.Number, ci, out lon)) { result.Position.Lon = lon; } } var speedValue = element.Elements().FirstOrDefault(x => x.Name.LocalName.Equals("speed")); if (speedValue != null) { double speed; if (double.TryParse(speedValue.Value, NumberStyles.Number, ci, out speed)) { result.Speed = speed; } else { result.Speed = -1; } } else { result.Speed = -1; } return(result); }
public async Task<IActionResult> PostRoutePoint([FromBody] RoutePoint routePoint) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _context.RoutePoint.Add(routePoint); await _context.SaveChangesAsync(); return CreatedAtAction("GetRoutePoint", new { id = routePoint.Id }, routePoint); }
public ActionResult Edit([Bind(Include = "IdRoutePoint,IdPlace,IdRoute,PositionInRoute")] RoutePoint routepoint) { if (ModelState.IsValid) { db.Entry(routepoint).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdPlace = new SelectList(db.Place, "ID", "dscrb", routepoint.IdPlace); ViewBag.IdRoute = new SelectList(db.Route, "ID", "typOfRoute", routepoint.IdRoute); return(View(routepoint)); }
/// <summary> /// 获取曲线类 /// </summary> /// <param name="index"></param> /// <returns></returns> public Bezier3D GetBezier3D(int index) { if (index < 0) { index = 0; } if (loop_) { if (index > points_.Length - 1) { index = points_.Length - 1; } } else { if (index > points_.Length - 2) { index = points_.Length - 2; } } #if UNITY_EDITOR if (beziers_ == null) { beziers_ = new Bezier3D[points_.Length]; } #endif Bezier3D b = beziers_[index]; if (b == null) { Quaternion rot = transform.rotation; RoutePoint pt0 = null, pt1 = null; if (index < points_.Length - 1) { pt0 = points_[index]; pt1 = points_[index + 1]; } else { pt0 = points_[index]; pt1 = points_[0]; } var p0 = pt0.transform.position; var p1 = p0 + rot * pt0.next_weight_point; var p3 = pt1.transform.position; var p2 = p3 + rot * pt1.prev_weight_point; b = new Bezier3D(p0, p1, p2, p3); beziers_[index] = b; } return(b); }
public static RoutePointDb FromDomain(RoutePoint point) { return(new RoutePointDb() { Name = point.Name, Description = point.Description, Coordinates = new CoordinatesDb() { Lat = point.Coordinates.Lat, Lng = point.Coordinates.Lng } }); }
private void LoadRoutes(XmlElement vNode) {//读取路径数据 XmlNodeList xnList = vNode.SelectNodes("Route"); for (int i = 0; i < xnList.Count; i++) { float stopTime = float.Parse(xnList[i].Attributes["stoptime"].Value); RoutePoint rp = new RoutePoint( XYClientCommon.AdjustToGround(GameUtility.StrToVector3(xnList[i].Attributes["position"].Value), false), stopTime); this.routeList_.Add(rp); } }
/// <summary> /// Calculates the TSP. /// </summary> /// <param name="operation">The operation request.</param> /// <param name="router">The router.</param> /// <param name="matcher">Contains an algorithm to match points to the route network.</param> /// <param name="open">Flag indicating the type of TSP problem, open or not.</param> /// <returns></returns> private RoutingResponse DoTSP( RoutingOperation operation, Router<SimpleWeighedEdge> router, IEdgeMatcher matcher, bool open) { // create the response. var response = new RoutingResponse(); // resolve the points and do the routing. var hooksPerRouterPoints = new Dictionary<RouterPoint, List<RoutingHook>>(); var routerPoints = new List<RouterPoint>(); var unroutableHooks = new List<RoutingHook>(); // save the unroutable hooks. for (int idx = 0; idx < operation.Hooks.Length; idx++) { // routing hook tags. IDictionary<string, string> tags = operation.Hooks[idx].Tags.ConvertToDictionary(); // resolve the point. RouterPoint routerPoint = router.Resolve(operation.Vehicle, new GeoCoordinate( operation.Hooks[idx].Latitude, operation.Hooks[idx].Longitude), matcher, tags); // check the result. if (routerPoint == null) { // this hook is not routable. unroutableHooks.Add(operation.Hooks[idx]); } else { // a point to hook on was found! List<RoutingHook> hooksAtPoint; if (!hooksPerRouterPoints.TryGetValue(routerPoint, out hooksAtPoint)) { // the router point does not exist yet. // check if the router point is routable. if (router.CheckConnectivity(operation.Vehicle, routerPoint, 200)) {// the point is routable. // create the hooks list at this point. hooksAtPoint = new List<RoutingHook>(); hooksPerRouterPoints.Add(routerPoint, hooksAtPoint); // add the new router point to the list. routerPoint.Tags.Add(new KeyValuePair<string, string>("id", routerPoints.Count.ToString( System.Globalization.CultureInfo.InvariantCulture))); routerPoints.Add(routerPoint); // add the hook. hooksAtPoint.Add(operation.Hooks[idx]); } else {// this hook is not routable. unroutableHooks.Add(operation.Hooks[idx]); } } else { // add the hook. hooksAtPoint.Add(operation.Hooks[idx]); } } } // add the unroutable hooks. response.UnroutableHooks = unroutableHooks.ToArray(); // calculate all the weights. double[][] weights = router.CalculateManyToManyWeight(operation.Vehicle, routerPoints.ToArray(), routerPoints.ToArray()); // calculate the TSP. var tspSolver = new RouterTSPAEXGenetic(300, 100); IRoute tspRoute = tspSolver.CalculateTSP(weights, routerPoints.Select(x => x.Location).ToArray(), 0, !open); // calculate the actual route. OsmSharpRoute route = null; foreach (Edge edge in tspRoute.Edges()) { // calculate the actual edge-route. OsmSharpRoute edgeRoute = router.Calculate(operation.Vehicle, routerPoints[edge.From], routerPoints[edge.To]); // add the routing hook tags. List<RoutingHook> fromHooks = hooksPerRouterPoints[routerPoints[edge.From]]; edgeRoute.Entries[0].Points = new RoutePoint[fromHooks.Count]; for (int hookIdx = 0; hookIdx < fromHooks.Count; hookIdx++) { var hookPoint = new RoutePoint { Latitude = fromHooks[hookIdx].Latitude, Longitude = fromHooks[hookIdx].Longitude, Tags = fromHooks[hookIdx].Tags.ConvertToList().ConvertFrom() }; edgeRoute.Entries[0].Points[hookIdx] = hookPoint; } List<RoutingHook> toHooks = hooksPerRouterPoints[routerPoints[edge.To]]; edgeRoute.Entries[edgeRoute.Entries.Length - 1].Points = new RoutePoint[toHooks.Count]; for (int hookIdx = 0; hookIdx < toHooks.Count; hookIdx++) { var hookPoint = new RoutePoint { Latitude = toHooks[hookIdx].Latitude, Longitude = toHooks[hookIdx].Longitude, Tags = toHooks[hookIdx].Tags.ConvertToList().ConvertFrom() }; edgeRoute.Entries[edgeRoute.Entries.Length - 1].Points[hookIdx] = hookPoint; } // concatenate routes. if (route == null) { route = edgeRoute; } else { route = OsmSharpRoute.Concatenate(route, edgeRoute); } } response.Route = route; // set the response as successfull. response.Status = OsmSharpServiceResponseStatusEnum.Success; return response; }
public RoutePoint(RoutePoint r) { this.x = r.x; this.y = r.y; }
private RoutePoint GeneratePoint() { var user = _random.Next(1, _numUsers); RoutePoint prev, cur; if (_previousPoint.TryGetValue(user, out prev)) { cur = new RoutePoint() { Latitude = NextCoord(prev.Latitude, _maxRange / 100.0), Longitude = NextCoord(prev.Longitude, _maxRange / 100.0), UserID = user.ToString(), MeasurementTime = DateTime.UtcNow }; } else { cur = new RoutePoint() { Latitude = NextCoord(_centerLat, _maxRange), Longitude = NextCoord(_centerLon, _maxRange), UserID = user.ToString(), MeasurementTime = DateTime.UtcNow }; } _previousPoint[user] = cur; Trace.TraceInformation("Generated {0}", cur); return cur; }