public double GetWaypointIndexFromParameterizedLocation(ParameterizedLocation pl) { if (pl == null) { return(0); } List <AdjustedWaypoint> waypoints = segments[pl.SegmentIndex].Waypoints; if (pl.Value <= waypoints[0].ParameterizedLocation.Value) { return(0); } if (pl.Value >= waypoints[waypoints.Count - 1].ParameterizedLocation.Value) { return(waypoints.Count - 1); } for (int i = 1; i < waypoints.Count; i++) { if (pl.Value <= waypoints[i].ParameterizedLocation.Value) { double t = (pl.Value - waypoints[i - 1].ParameterizedLocation.Value) / (waypoints[i].ParameterizedLocation.Value - waypoints[i - 1].ParameterizedLocation.Value); return(i - 1 + t); } } return(waypoints.Count - 1); }
public AdjustedWaypoint CreateWaypointFromParameterizedLocation(ParameterizedLocation pl, AdjustedWaypoint.AdjustedWaypointType type) { return(new AdjustedWaypoint( GetLocationFromParameterizedLocation(pl), pl, type)); }
public PointD GetLocationFromParameterizedLocation(ParameterizedLocation parameterizedLocation) { if (parameterizedLocation == null) { return(null); } List <AdjustedWaypoint> waypoints = segments[parameterizedLocation.SegmentIndex].Waypoints; if (parameterizedLocation.Value <= waypoints[0].ParameterizedLocation.Value) { return(waypoints[0].Location); } if (parameterizedLocation.Value >= waypoints[waypoints.Count - 1].ParameterizedLocation.Value) { return(waypoints[waypoints.Count - 1].Location); } for (var i = (int)parameterizedLocation.Value; i < waypoints.Count; i++) { if (parameterizedLocation.Value <= waypoints[i].ParameterizedLocation.Value) { PointD p0 = waypoints[i - 1].Location; PointD p1 = waypoints[i].Location; double t = (parameterizedLocation.Value - waypoints[i - 1].ParameterizedLocation.Value) / (waypoints[i].ParameterizedLocation.Value - waypoints[i - 1].ParameterizedLocation.Value); return(new PointD(p0.X + t * (p1.X - p0.X), p0.Y + t * (p1.Y - p0.Y))); } } return(waypoints[waypoints.Count - 1].Location); }
public bool IsEndOfSegment(ParameterizedLocation pl) { if (pl == null) { return(false); } return(pl.Value == segments[pl.SegmentIndex].Waypoints.Count - 1); }
public bool IsStartOfSegment(ParameterizedLocation pl) { if (pl == null) { return(false); } return(pl.Value == 0); }
/// <summary> /// Creates a handle based on parameterized location and time (used to prevent rounding errors when e g cutting a route). /// </summary> /// <param name="parameterizedLocation"></param> /// <param name="time"></param> /// <param name="location"></param> /// <param name="transformationMatrix"></param> /// <param name="markerDrawer"></param> /// <param name="type"></param> public Handle(ParameterizedLocation parameterizedLocation, DateTime?time, PointD location, GeneralMatrix transformationMatrix, IMarkerDrawer markerDrawer, HandleType type) { ParameterizedLocation = parameterizedLocation; Time = time; Location = location; TransformationMatrix = transformationMatrix; MarkerDrawer = markerDrawer; Type = type; }
public RoutePropertyType(RouteProperty rp) { Type = rp.GetType(); var rmp = rp as RouteMomentaneousProperty; if (rmp != null) { MomentaneousLocation = rmp.Location; } var rsp = rp as RouteSpanProperty; if (rsp != null) { SpanStart = rsp.Start; SpanEnd = rsp.End; } }
public RectangleD GetBoundingRectangle(ParameterizedLocation pl0, ParameterizedLocation pl1) { PointD p0 = GetLocationFromParameterizedLocation(pl0); PointD p1 = GetLocationFromParameterizedLocation(pl1); if (p0 == null || p1 == null) { return(null); } double minX = Math.Min(p0.X, p1.X); double maxX = Math.Max(p0.X, p1.X); double minY = Math.Min(p0.Y, p1.Y); double maxY = Math.Max(p0.Y, p1.Y); ParameterizedLocation pl = new ParameterizedLocation(pl0.SegmentIndex, Math.Ceiling(pl0.Value)); while (pl < pl1) { pl++; if ((int)pl.Value >= segments[pl.SegmentIndex].Waypoints.Count) { pl = new ParameterizedLocation(pl.SegmentIndex + 1, 0); } PointD p = segments[pl.SegmentIndex].Waypoints[(int)pl.Value].Location; if (p.X < minX) { minX = p.X; } if (p.X > maxX) { maxX = p.X; } if (p.Y < minY) { minY = p.Y; } if (p.Y > maxY) { maxY = p.Y; } } return(new RectangleD(minX, minY, maxX - minX, maxY - minY)); }
public PointD GetDirectionVectorFromParameterizedLocation(ParameterizedLocation pl) { if (pl == null) { return(null); } double wi = GetWaypointIndexFromParameterizedLocation(pl); if (wi == Math.Floor(wi)) { // exactly at a waypoint if (wi == 0) { // first waypoint AdjustedWaypoint wp0 = segments[pl.SegmentIndex].Waypoints[0]; AdjustedWaypoint wp1 = segments[pl.SegmentIndex].Waypoints[1]; return(LinearAlgebraUtil.Normalize(wp1.Location - wp0.Location)); } else if ((int)wi == segments[pl.SegmentIndex].Waypoints.Count - 1) { // last waypoint int lastWaypointIndex = segments[pl.SegmentIndex].Waypoints.Count - 1; AdjustedWaypoint wp0 = segments[pl.SegmentIndex].Waypoints[lastWaypointIndex - 1]; AdjustedWaypoint wp1 = segments[pl.SegmentIndex].Waypoints[lastWaypointIndex]; return(LinearAlgebraUtil.Normalize(wp1.Location - wp0.Location)); } else { AdjustedWaypoint wp0 = segments[pl.SegmentIndex].Waypoints[(int)wi - 1]; AdjustedWaypoint wp1 = segments[pl.SegmentIndex].Waypoints[(int)wi]; AdjustedWaypoint wp2 = segments[pl.SegmentIndex].Waypoints[(int)wi + 1]; return(LinearAlgebraUtil.Normalize( LinearAlgebraUtil.Normalize(wp2.Location - wp1.Location) + LinearAlgebraUtil.Normalize(wp1.Location - wp0.Location) )); } } else { AdjustedWaypoint wp0 = segments[pl.SegmentIndex].Waypoints[(int)Math.Floor(wi)]; AdjustedWaypoint wp1 = segments[pl.SegmentIndex].Waypoints[(int)Math.Ceiling(wi)]; return(LinearAlgebraUtil.Normalize(wp1.Location - wp0.Location)); } }
public ParameterizedLocation GetClosestParameterizedLocation(PointD location, out double distance) { if (location == null) { distance = 0; return(null); } double closestDistance = 0.0; ParameterizedLocation closestDistanceParameterizedLocation = new ParameterizedLocation(0, 0); bool closestDistanceSet = false; double limit = 2 * 32; for (int i = 0; i < segments.Count; i++) { List <AdjustedWaypoint> waypoints = segments[i].Waypoints; PointD p0 = waypoints[0].Location; for (int j = 1; j < waypoints.Count; j++) { PointD p1 = waypoints[j].Location; // long distance between p0 and p1? then we need to check more time-consuming ClosestDistancePointToLine even if p0 is far from location bool isLongLineSegment = (LinearAlgebraUtil.DistancePointToPoint(p0, p1) > limit); if (LinearAlgebraUtil.DistancePointToPoint(location, p1) < limit || isLongLineSegment) { double t; double tmpDistance = LinearAlgebraUtil.ClosestDistancePointToLine(location, p0, p1, out t); if (tmpDistance < closestDistance || !closestDistanceSet) { closestDistance = tmpDistance; closestDistanceParameterizedLocation = new ParameterizedLocation(i, waypoints[j - 1].ParameterizedLocation.Value + t * (waypoints[j].ParameterizedLocation.Value - waypoints[j - 1].ParameterizedLocation.Value)); closestDistanceSet = true; } } p0 = p1; } } distance = closestDistance; return(closestDistanceSet ? closestDistanceParameterizedLocation : null); }
public CutHandlesData Cut(ParameterizedLocation parameterizedLocation, CutType cutType) { CutHandlesData cutHandlesData = new CutHandlesData(); cutHandlesData.CutParamaterizedLocation = parameterizedLocation; cutHandlesData.CutType = cutType; switch (cutType) { case CutType.Before: foreach (Handle h in this) { if (h.ParameterizedLocation < parameterizedLocation) { cutHandlesData.CutHandles.Add(h); } } foreach (Handle h in cutHandlesData.CutHandles) { Remove(h); } foreach (Handle h in this) { h.ParameterizedLocation -= parameterizedLocation; } break; case CutType.After: foreach (Handle h in this) { if (h.ParameterizedLocation > parameterizedLocation) { cutHandlesData.CutHandles.Add(h); } } foreach (Handle h in cutHandlesData.CutHandles) { Remove(h); } break; } return(cutHandlesData); }
public AdjustedWaypoint(PointD location, ParameterizedLocation parameterizedLocation, AdjustedWaypointType type) { Location = location; ParameterizedLocation = parameterizedLocation; Type = type; }
/// <summary> /// Creates a handle based on parameterized location. /// </summary> /// <param name="parameterizedLocation"></param> /// <param name="location"></param> /// <param name="transformationMatrix"></param> /// <param name="markerDrawer"></param> /// <param name="type"></param> public Handle(ParameterizedLocation parameterizedLocation, PointD location, GeneralMatrix transformationMatrix, IMarkerDrawer markerDrawer, HandleType type) : this(parameterizedLocation, null, location, transformationMatrix, markerDrawer, HandleType.Handle) { }
/// <summary> /// Creates a handle based on parameterized location and time (used to prevent rounding errors when e g cutting a route). /// </summary> /// <param name="parameterizedLocation"></param> /// <param name="time"></param> /// <param name="location"></param> /// <param name="transformationMatrix"></param> /// <param name="markerDrawer"></param> public Handle(ParameterizedLocation parameterizedLocation, DateTime?time, PointD location, GeneralMatrix transformationMatrix, IMarkerDrawer markerDrawer) : this(parameterizedLocation, time, location, transformationMatrix, markerDrawer, HandleType.Handle) { }
public int CompareTo(Handle other) { return(ParameterizedLocation.CompareTo(other.ParameterizedLocation)); }
public LongLat GetLocation(Route route) { ParameterizedLocation pl = route.GetParameterizedLocationFromTime(time); return(route.GetLocationFromParameterizedLocation(pl)); }
public AlphaAdjustmentChange(ParameterizedLocation parameterizedLocation, double alphaAdjustment) { this.parameterizedLocation = parameterizedLocation; this.alphaAdjustment = alphaAdjustment; }
public AdjustedWaypoint(PointD location, ParameterizedLocation parameterizedLocation) { Location = location; ParameterizedLocation = parameterizedLocation; }
public int CompareTo(AdjustedWaypoint other) { int result = ParameterizedLocation.CompareTo(other.ParameterizedLocation); return(result != 0 ? result : Type.CompareTo(other.Type)); }