AbstractedSheep.ShuttleTrackerWorld.Stop.SnapToRoute C# (CSharp) Method

SnapToRoute() private method

private SnapToRoute ( Route r ) : void
r Route
return void
        internal void SnapToRoute(Route r)
        {
            Coordinate c1, c2;
            Coordinate closestPoint = null, tempClosestPoint = null;
            int precedingPointId = -1;
            double shortestDistance = 10000, tempShortestDistance = 10000;

            for (int i = 0; i < r.coordinates.Count; i++)
            {
                if (i == 0)
                    c1 = r.coordinates.Last();
                else
                    c1 = r.coordinates[i - 1];

                c2 = r.coordinates[i];

                tempClosestPoint = this.Location.ClosestPoint(c1, c2);
                tempShortestDistance = tempClosestPoint.DistanceTo(this.Location);

                if (tempShortestDistance < shortestDistance)
                {
                    shortestDistance = tempShortestDistance;
                    closestPoint = tempClosestPoint;
                    precedingPointId = i == 0 ? r.coordinates.Count - 1 : i;
                }
            }

            this.snappedCoordinate.Add(r.Id, closestPoint);
            this.precedingCoordinate.Add(r.Id, precedingPointId);
            this.precedingCoordinateDistance.Add(r.Id, r.coordinates[precedingPointId].DistanceTo(Location));
        }

Usage Example

Example #1
0
        private void AddStop(string stopId, Coordinate location, string name, List <int> routes)
        {
            Stop s = new Stop(stopId, name, location);

            stops.Add(s.Id, s);

            foreach (int i in routes)
            {
                Route r = this.routes[i];
                s.routes.Add(r.Id, r);
                r.stops.Add(s.Id, s);
                s.SnapToRoute(r);
            }
        }
All Usage Examples Of AbstractedSheep.ShuttleTrackerWorld.Stop::SnapToRoute