private static IEnumerable<MethodAndTypeMetrics> GetMethodOfLine(this MetricsReport metrics, LineLocation location) { return from type in metrics.Types from method in metrics.MethodsOfType(type) where IsMethodAtLine(method, location) select new MethodAndTypeMetrics(type, method); }
public void RegressionEncodeDecodeNegativeLongitude() { double delta = 0.0001; var location = new LineLocation() { First = new LocationReferencePoint() { Bearing = 101, Coordinate = new Coordinate() { Latitude = 52.932136535644531f, Longitude = -1.5213972330093384f }, DistanceToNext = 1111, FormOfWay = FormOfWay.Motorway, FuntionalRoadClass = FunctionalRoadClass.Frc0, LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc0 }, Last = new LocationReferencePoint() { Bearing = 276, Coordinate = new Coordinate() { Latitude = 52.929317474365234f, Longitude = -1.5055110454559326 }, DistanceToNext = 0, FormOfWay = FormOfWay.Motorway, FuntionalRoadClass = FunctionalRoadClass.Frc0 }, NegativeOffsetPercentage = 2.12239432f, PositiveOffsetPercentage = 1.46861947f }; // encode. var stringData = LineLocationCodec.Encode(location); // decode again (decoding was tested above). var decodedLocation = LineLocationCodec.Decode(stringData); Assert.IsNotNull(decodedLocation); Assert.IsInstanceOf <LineLocation>(decodedLocation); var lineLocation = (decodedLocation as LineLocation); // check first reference. Assert.IsNotNull(lineLocation.First); Assert.AreEqual(52.932136535644531f, lineLocation.First.Coordinate.Latitude, delta); Assert.AreEqual(-1.5213972330093384f, lineLocation.First.Coordinate.Longitude, delta); Assert.AreEqual(FunctionalRoadClass.Frc0, lineLocation.First.FuntionalRoadClass); Assert.AreEqual(FormOfWay.Motorway, lineLocation.First.FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc0, lineLocation.First.LowestFunctionalRoadClassToNext); // check second reference. Assert.IsNotNull(lineLocation.Last); Assert.AreEqual(-1.5055110454559326f, lineLocation.Last.Coordinate.Longitude, delta); // 6.12817° Assert.AreEqual(52.929317474365234f, lineLocation.Last.Coordinate.Latitude, delta); // 49.60305° Assert.AreEqual(FunctionalRoadClass.Frc0, lineLocation.Last.FuntionalRoadClass); Assert.AreEqual(FormOfWay.Motorway, lineLocation.Last.FormOfWay); }
/// <summary> /// Adds the specified line events to the <see cref="EventPoint"/>, unless <see /// cref="Lines"/> already contains events for the same line.</summary> /// <param name="line1"> /// The first element to add to the <see cref="Lines"/> collection.</param> /// <param name="location1"> /// The first element to add to the <see cref="Locations"/> collection.</param> /// <param name="line2"> /// The second element to add to the <see cref="Lines"/> collection.</param> /// <param name="location2"> /// The second element to add to the <see cref="Locations"/> collection.</param> /// <remarks> /// <b>TryAddLines</b> skips either or both argument pairs if the <see cref="Lines"/> /// collection already contains the corresponding element. The <see cref="Lines"/> and /// <see cref="Locations"/> collections are created if necessary.</remarks> internal void TryAddLines(int line1, LineLocation location1, int line2, LineLocation location2) { if (Lines == null) { Lines = new List <Int32>(2) { line1, line2 }; Locations = new List <LineLocation>(2) { location1, location2 }; return; } if (!Lines.Contains(line1)) { Lines.Add(line1); Locations.Add(location1); } if (!Lines.Contains(line2)) { Lines.Add(line2); Locations.Add(location2); } }
private static bool IsMethodAtLine(MethodMetricsReport method, LineLocation location) { return !method.CompilerGenerated && method.SourceLocation.IsAvailable && string.Compare(method.SourceLocation.Filename, location.File, true) == 0 && method.SourceLocation.Line >= location.Line; }
public void LineLocationCompareShouldCompareEqualValues() { var left = new LineLocation(1, 2); var right = new LineLocation(1, 2); Assert.AreEqual(0, left.CompareTo(right)); Assert.AreEqual(left, right); }
public void LineLocationCompareShouldCompareLessOrGreaterValues() { var left = new LineLocation(1, 2); var right = new LineLocation(3, 4); Assert.AreEqual(-1, left.CompareTo(right)); Assert.AreEqual(1, right.CompareTo(left)); }
/// <summary> /// Initializes a new instance of the <see cref="LineIntersection"/> structure with the /// specified shared coordinates, relative locations, and spatial relationship between the /// intersected lines.</summary> /// <param name="shared"> /// The <see cref="PointD"/> coordinates shared by the two line segments or their infinite /// extensions.</param> /// <param name="first"> /// The location of the <see cref="Shared"/> coordinates relative to the first line segment. /// </param> /// <param name="second"> /// The location of the <see cref="Shared"/> coordinates relative to the second line /// segment.</param> /// <param name="relation"> /// The spatial relationship between the two line segments.</param> public LineIntersection(PointD?shared, LineLocation first, LineLocation second, LineRelation relation) { Shared = shared; First = first; Second = second; Relation = relation; }
/// <summary> /// Adds the specified line event to the <see cref="EventPoint"/>.</summary> /// <param name="line"> /// The element to add to the <see cref="Lines"/> collection.</param> /// <param name="location"> /// The element to add to the <see cref="Locations"/> collection.</param> /// <remarks> /// <b>AddLine</b> does not check whether the <see cref="Lines"/> collection already /// contains the specified <paramref name="line"/>. The <see cref="Lines"/> and <see /// cref="Locations"/> collections are created if necessary.</remarks> internal void AddLine(int line, LineLocation location) { if (Lines == null) { Lines = new List <Int32>(2); Locations = new List <LineLocation>(2); } Lines.Add(line); Locations.Add(location); }
public static int ToPosition(this LineLocation location, string context) { if (location == null) return 0; var lines = context.Split('\n'); int position = 0; for (int i = 0; i < (location.Line - 1); i++) { // plus newline charachter position += lines[i].Length + 1; } position += location.Column; return position; }
/// <summary> /// Converts the given line location to features. /// </summary> public static FeatureCollection ToFeatures(this LineLocation line) { var featureCollection = new FeatureCollection(); featureCollection.Add(line.First.ToFeature()); if (line.Intermediate != null) { foreach (var p in line.Intermediate) { featureCollection.Add(p.ToFeature()); } } featureCollection.Add(line.Last.ToFeature()); return(featureCollection); }
public static Annotation ToAnnotation(this Clipping clipping) { return(new(clipping.Content, new DocumentReference { Title = clipping.Book, Author = clipping.Author }, MapAnnotationType(clipping.Type), new AnnotationContext { SerializedLocation = LineLocation.ToString(clipping.Location), PageNumber = clipping.PageNumber }, clipping.CreationDate)); }
/// <summary> /// Normalizes all <see cref="Locations"/> to match the corresponding <see /// cref="Lines"/>.</summary> /// <param name="lines"> /// An <see cref="Array"/> containing all input <see cref="LineD"/> segments.</param> /// <remarks><para> /// <b>Normalize</b> inverts any <see cref="LineLocation.Start"/> or <see /// cref="LineLocation.End"/> values in the <see cref="Locations"/> collection whose /// corresponding <see cref="Lines"/> element indicates a <see cref="LineD"/> whose <see /// cref="LineD.Start"/> and <see cref="LineD.End"/> points have the opposite orientation. /// </para><para> /// Therefore, the <see cref="Locations"/> collection no longer reflects the sweep line /// direction, but rather the point at which the corresponding <see cref="LineD"/> /// touches the <see cref="Shared"/> coordinates. Call this method to prepare for output /// generation, after the <see cref="EventPoint"/> has been removed from the schedule of /// the sweep line algorithm.</para></remarks> internal void Normalize(LineD[] lines) { for (int i = 0; i < Locations.Count; i++) { LineLocation location = Locations[i]; const LineLocation startEnd = LineLocation.Start | LineLocation.End; // check for start & end point events if ((location & startEnd) != 0) { LineD line = lines[Lines[i]]; // report orientation of inverted line if (PointDComparerY.CompareExact(line.Start, line.End) > 0) { location ^= startEnd; Locations[i] = location; } } } }
public static LineSpan LineSpan(LineLocation start, LineLocation end) { return(new LineSpan { Start = start, End = end }); }
/// <summary> /// Encodes the given location. /// </summary> public static LineLocation Encode(ReferencedLine referencedLocation, Coder coder, EncodingSettings settings) { try { // Step – 1: Check validity of the location and offsets to be encoded. // validate connected and traversal. referencedLocation.ValidateConnected(coder); // validate offsets. referencedLocation.ValidateOffsets(); // validate for binary. referencedLocation.ValidateBinary(); // Step – 2 Adjust start and end node of the location to represent valid map nodes. referencedLocation.AdjustToValidPoints(coder); // keep a list of LR-point. var points = new List <int>(new int[] { 0, referencedLocation.Vertices.Length - 1 }); // Step – 3 Determine coverage of the location by a shortest-path. // Step – 4 Check whether the calculated shortest-path covers the location completely. // Go to step 5 if the location is not covered completely, go to step 7 if the location is covered. // Step – 5 Determine the position of a new intermediate location reference point so that the part of the // location between the start of the shortest-path calculation and the new intermediate is covered // completely by a shortest-path. // Step – 6 Go to step 3 and restart shortest path calculation between the new intermediate location reference // point and the end of the location. if (settings.VerifyShortestPath) { bool isOnShortestPath = false; while (!isOnShortestPath) { // keep on adding intermediates until all paths between intermediates are on shortest paths. isOnShortestPath = true; // loop over all LRP-pairs. for (var i = 0; i < points.Count - 1; i++) { var fromPoint = points[i]; var toPoint = points[i + 1]; var fromEdge = referencedLocation.Edges[fromPoint]; var toEdge = referencedLocation.Edges[toPoint - 1]; var edgeCount = toPoint - fromPoint; // calculate shortest path between their first and last edge. var pathResult = coder.Router.TryCalculateRaw(coder.Profile.Profile, coder.Router.GetDefaultWeightHandler(coder.Profile.Profile), fromEdge, toEdge, coder.Profile.RoutingSettings); if (pathResult.IsError) { try { coder.Profile.RoutingSettings.SetMaxSearch(coder.Profile.Profile.FullName, float.MaxValue); pathResult = coder.Router.TryCalculateRaw(coder.Profile.Profile, coder.Router.GetDefaultWeightHandler(coder.Profile.Profile), fromEdge, toEdge, coder.Profile.RoutingSettings); if (pathResult.IsError) { throw new Exception("No path found between two edges of the line location."); } } catch { throw; } finally { coder.Profile.RoutingSettings.SetMaxSearch(coder.Profile.Profile.FullName, coder.Profile.MaxSearch); } } var path = pathResult.Value; var edges = new List <long>(); while (path.From != null) { edges.Add(path.Edge); path = path.From; } edges.Reverse(); // calculate converage. var splitAt = -1; for (var j = 0; j < edges.Count; j++) { var locationEdgeIdx = j + fromPoint; if (locationEdgeIdx >= referencedLocation.Edges.Length || edges[j] != referencedLocation.Edges[locationEdgeIdx]) { splitAt = j + fromPoint + 1; break; } } // split if needed. if (splitAt != -1) { points.Add(splitAt); points.Sort(); isOnShortestPath = false; break; } } } } // Step – 7 Concatenate the calculated shortest-paths for a complete coverage of the location and form an // ordered list of location reference points (from the start to the end of the location). // Step – 8 Check validity of the location reference path. If the location reference path is invalid then go // to step 9, if the location reference path is valid then go to step 10. // Step – 9 Add a sufficient number of additional intermediate location reference points if the distance // between two location reference points exceeds the maximum distance. Remove the start/end LR-point // if the positive/negative offset value exceeds the length of the corresponding path. referencedLocation.AdjustToValidDistance(coder, points); // Step – 10 Create physical representation of the location reference. var coordinates = referencedLocation.GetCoordinates(coder.Router.Db); var length = coordinates.Length(); // 3: The actual encoding now! // initialize location. var location = new LineLocation(); // build lrp's. var locationReferencePoints = new List <LocationReferencePoint>(); for (var idx = 0; idx < points.Count - 1; idx++) { locationReferencePoints.Add(referencedLocation.BuildLocationReferencePoint(coder, points[idx], points[idx + 1])); } locationReferencePoints.Add(referencedLocation.BuildLocationReferencePointLast( coder, points[points.Count - 2])); // build location. location.First = locationReferencePoints[0]; location.Intermediate = new LocationReferencePoint[locationReferencePoints.Count - 2]; for (var idx = 1; idx < locationReferencePoints.Count - 1; idx++) { location.Intermediate[idx - 1] = locationReferencePoints[idx]; } location.Last = locationReferencePoints[locationReferencePoints.Count - 1]; // set offsets. location.PositiveOffsetPercentage = referencedLocation.PositiveOffsetPercentage; location.NegativeOffsetPercentage = referencedLocation.NegativeOffsetPercentage; return(location); } catch (ReferencedEncodingException) { // rethrow referenced encoding exception. throw; } catch (Exception ex) { // unhandled exception! throw new ReferencedEncodingException(referencedLocation, string.Format("Unhandled exception during ReferencedLineEncoder: {0}", ex.ToString()), ex); } }
private MethodAndTypeMetrics GetMethodOfDefiniton(LineLocation location) { lastLocation = location; return metrics.Report.MethodOfLine(location); }
public void EncodeBase64Test() { double delta = 0.0001; // build the location to decode. var location = new LineLocation(); location.First = new LocationReferencePoint(); location.First.Coordinate = new Coordinate() { Latitude = 49.60851, Longitude = 6.12683 }; location.First.DistanceToNext = 10; location.First.FuntionalRoadClass = FunctionalRoadClass.Frc3; location.First.FormOfWay = FormOfWay.MultipleCarriageWay; location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc3; location.First.Bearing = 0; location.Intermediate = new LocationReferencePoint[1]; location.Intermediate[0] = new LocationReferencePoint(); location.Intermediate[0].Coordinate = new Coordinate() { Latitude = 49.60398, Longitude = 6.12838 }; location.Intermediate[0].DistanceToNext = 10; location.Intermediate[0].FuntionalRoadClass = FunctionalRoadClass.Frc3; location.Intermediate[0].FormOfWay = FormOfWay.SingleCarriageWay; location.Intermediate[0].LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc5; location.Intermediate[0].Bearing = 0; location.Last = new LocationReferencePoint(); location.Last.Coordinate = new Coordinate() { Latitude = 49.60305, Longitude = 6.12817 }; location.Last.DistanceToNext = 10; location.Last.FuntionalRoadClass = FunctionalRoadClass.Frc5; location.Last.FormOfWay = FormOfWay.SingleCarriageWay; location.Last.Bearing = 0; // encode. var encoder = new LineEncoder(); var stringData = encoder.Encode(location); // decode again (decoding was tested above). var decoder = new LineLocationDecoder(); var decodedLocation = decoder.Decode(stringData); Assert.IsNotNull(decodedLocation); Assert.IsInstanceOf <LineLocation>(decodedLocation); var lineLocation = (decodedLocation as LineLocation); // check first reference. Assert.IsNotNull(lineLocation.First); Assert.AreEqual(6.12683, lineLocation.First.Coordinate.Longitude, delta); // 6.12683° Assert.AreEqual(49.60851, lineLocation.First.Coordinate.Latitude, delta); // 49.60851° Assert.AreEqual(FunctionalRoadClass.Frc3, lineLocation.First.FuntionalRoadClass); Assert.AreEqual(FormOfWay.MultipleCarriageWay, lineLocation.First.FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc3, lineLocation.First.LowestFunctionalRoadClassToNext); // check intermediates. Assert.IsNotNull(lineLocation.Intermediate); Assert.AreEqual(1, lineLocation.Intermediate.Length); Assert.AreEqual(6.12838, lineLocation.Intermediate[0].Coordinate.Longitude, delta); // 6.12838° Assert.AreEqual(49.60398, lineLocation.Intermediate[0].Coordinate.Latitude, delta); // 49.60398° Assert.AreEqual(FunctionalRoadClass.Frc3, lineLocation.Intermediate[0].FuntionalRoadClass); Assert.AreEqual(FormOfWay.SingleCarriageWay, lineLocation.Intermediate[0].FormOfWay); Assert.AreEqual(FunctionalRoadClass.Frc5, lineLocation.Intermediate[0].LowestFunctionalRoadClassToNext); // check second reference. Assert.IsNotNull(lineLocation.Last); Assert.AreEqual(6.12817, lineLocation.Last.Coordinate.Longitude, delta); // 6.12817° Assert.AreEqual(49.60305, lineLocation.Last.Coordinate.Latitude, delta); // 49.60305° Assert.AreEqual(FunctionalRoadClass.Frc5, lineLocation.Last.FuntionalRoadClass); Assert.AreEqual(FormOfWay.SingleCarriageWay, lineLocation.Last.FormOfWay); // compare again with reference encoded string. var referenceStringData = "CwRbWyNG9BpgAACa/jsboAD/6/+kKwAAAA=="; var referenceDecodedLocation = decoder.Decode(referenceStringData); var referenceBinary = System.Convert.FromBase64String(referenceStringData); var encodedBinary = System.Convert.FromBase64String(stringData); // check first reference. Assert.IsNotNull(lineLocation.First); Assert.AreEqual(referenceDecodedLocation.First.Coordinate.Longitude, lineLocation.First.Coordinate.Longitude, delta); // 6.12829° Assert.AreEqual(referenceDecodedLocation.First.Coordinate.Latitude, lineLocation.First.Coordinate.Latitude, delta); // 49.60597° Assert.AreEqual(referenceDecodedLocation.First.FuntionalRoadClass, lineLocation.First.FuntionalRoadClass); Assert.AreEqual(referenceDecodedLocation.First.FormOfWay, lineLocation.First.FormOfWay); Assert.AreEqual(referenceDecodedLocation.First.LowestFunctionalRoadClassToNext, lineLocation.First.LowestFunctionalRoadClassToNext); Assert.AreEqual(referenceDecodedLocation.First.Bearing.Value, lineLocation.First.Bearing.Value, 11.25); // binary encode loses accuracy for bearing. // check intermediates. Assert.IsNotNull(referenceDecodedLocation.Intermediate); Assert.AreEqual(referenceDecodedLocation.Intermediate.Length, lineLocation.Intermediate.Length); Assert.AreEqual(referenceDecodedLocation.Intermediate[0].Coordinate.Longitude, lineLocation.Intermediate[0].Coordinate.Longitude, delta); // 6.12838° Assert.AreEqual(referenceDecodedLocation.Intermediate[0].Coordinate.Latitude, lineLocation.Intermediate[0].Coordinate.Latitude, delta); // 49.60398° Assert.AreEqual(referenceDecodedLocation.Intermediate[0].FuntionalRoadClass, lineLocation.Intermediate[0].FuntionalRoadClass); Assert.AreEqual(referenceDecodedLocation.Intermediate[0].FormOfWay, lineLocation.Intermediate[0].FormOfWay); Assert.AreEqual(referenceDecodedLocation.Intermediate[0].LowestFunctionalRoadClassToNext, lineLocation.Intermediate[0].LowestFunctionalRoadClassToNext); // check second reference. Assert.IsNotNull(lineLocation.Last); Assert.AreEqual(referenceDecodedLocation.Last.Coordinate.Longitude, lineLocation.Last.Coordinate.Longitude, delta); // 6.12779° Assert.AreEqual(referenceDecodedLocation.Last.Coordinate.Latitude, lineLocation.Last.Coordinate.Latitude, delta); // 49.60521° Assert.AreEqual(referenceDecodedLocation.Last.FuntionalRoadClass, lineLocation.Last.FuntionalRoadClass); Assert.AreEqual(referenceDecodedLocation.Last.FormOfWay, lineLocation.Last.FormOfWay); Assert.AreEqual(referenceDecodedLocation.Last.Bearing.Value, lineLocation.Last.Bearing.Value, 11.25); // binary encode loses accuracy for bearing. }
private void DisplayNoMetricsInfo() { lastLocation = new LineLocation(); Entries.Add(new CurrentEntry { Metric = "no metrics yet, consider compiling", Value = "" }); }
/// <summary> /// Decodes the given location. /// </summary> public static ReferencedLine Decode(LineLocation location, Coder coder) { // get candidate vertices and edges. var candidates = new List <Itinero.Algorithms.Collections.SortedSet <CandidatePathSegment> >(); var lrps = new List <LocationReferencePoint>(); // loop over all lrps. lrps.Add(location.First); candidates.Add(coder.FindCandidatesFor(location.First, true)); if (location.Intermediate != null) { // there are intermediates. for (int idx = 0; idx < location.Intermediate.Length; idx++) { lrps.Add(location.Intermediate[idx]); candidates.Add(coder.FindCandidatesFor(location.Intermediate[idx], true)); } } lrps.Add(location.Last); candidates.Add(coder.FindCandidatesFor(location.Last, false)); // find a route between each pair of sequential points. // start with the last two points and move backwards. var target = lrps[lrps.Count - 1]; var targetCandidates = candidates[candidates.Count - 1]; var lineLocationSegments = new List <ReferencedLine>(); for (int idx = lrps.Count - 2; idx >= 0; idx--) { var source = lrps[idx]; var sourceCandidates = candidates[idx]; // build a list of combined scores. var combinedScoresSet = new Itinero.Algorithms.Collections.SortedSet <CombinedScore>(new CombinedScoreComparer()); foreach (var targetCandidate in targetCandidates) { foreach (var currentCandidate in sourceCandidates) { combinedScoresSet.Add(new CombinedScore() { Source = currentCandidate, Target = targetCandidate }); } } var combinedScores = new List <CombinedScore>(combinedScoresSet); // find the best candidate route. CandidateRoute best = null; CandidatePathSegment bestSource = null; var targetIsLast = idx == lrps.Count - 2; while (combinedScores.Count > 0) { // get the first pair. var combinedScore = combinedScores[0]; combinedScores.RemoveAt(0); // find a route. var candidate = coder.FindCandidateRoute(combinedScore.Source, combinedScore.Target, source.LowestFunctionalRoadClassToNext.Value, targetIsLast); // bring score of from/to also into the mix. candidate.Score = candidate.Score + combinedScore.Score; // verify bearing by adding it to the score. if (candidate != null && candidate.Route != null) { // calculate bearing and compare with reference bearing. // calculate distance and compare with distancetonext. var distance = candidate.Route.GetCoordinates(coder.Router.Db).Length(); var expectedDistance = source.DistanceToNext; // default a perfect score, only compare large distances. var deviation = Score.New(Score.DISTANCE_COMPARISON, "Compares expected location distance with decoded location distance (1=perfect, 0=difference bigger than total distance)", 1, 1); if (expectedDistance > 200 || distance > 200) { // non-perfect score. // don't care about difference smaller than 200m, the binary encoding only handles segments of about 50m. var distanceDiff = System.Math.Max(System.Math.Abs(distance - expectedDistance) - 200, 0); deviation = Score.New(Score.DISTANCE_COMPARISON, "Compares expected location distance with decoded location distance (1=prefect, 0=difference bigger than total distance)", 1 - System.Math.Min(System.Math.Max(distanceDiff / expectedDistance, 0), 1), 1); } // add deviation-score. candidate.Score = candidate.Score * deviation; if ((candidate.Score.Value / candidate.Score.Reference) > coder.Profile.ScoreThreshold) { // check candidate. if (best == null) { // there was no previous candidate or candidate has no route. best = candidate; bestSource = combinedScore.Source; } else if (best.Score.Value < candidate.Score.Value) { // the new candidate is better. best = candidate; bestSource = combinedScore.Source; } else if (best.Score.Value > candidate.Score.Value) { // the current candidate is better. break; } if (best.Score.Value == 1) { // stop search on a perfect scrore! break; } } } } // append the current best. if (best == null || best.Route == null) { // no location reference found between two points. return(null); } if (!targetIsLast) { // strip last edge and vertex, these will overlap with the previous. best.Route.Vertices = best.Route.Vertices.Range(0, best.Route.Vertices.Length - 1); best.Route.Edges = best.Route.Edges.Range(0, best.Route.Edges.Length - 1); } // keep the segment. lineLocationSegments.Insert(0, best.Route); // assign new next. target = source; targetCandidates = new Itinero.Algorithms.Collections.SortedSet <CandidatePathSegment>(); targetCandidates.Add(bestSource); // only the best source can be re-used for the next segment. } // build the line location from the segments. var lineLocation = lineLocationSegments[0]; for (var i = 1; i < lineLocationSegments.Count; i++) { lineLocation.Add(lineLocationSegments[i]); } lineLocation.PositiveOffsetPercentage = (location.PositiveOffsetPercentage == null) ? 0 : location.PositiveOffsetPercentage.Value; lineLocation.NegativeOffsetPercentage = (location.NegativeOffsetPercentage == null) ? 0 : location.NegativeOffsetPercentage.Value; return(lineLocation); }
/// <summary> /// Encodes a point along line location. /// </summary> public static byte[] Encode(LineLocation location) { int size = 18; if (location.Intermediate != null) { // each intermediate adds 7 bytes. size = size + (location.Intermediate.Length * 7); } byte[] data = new byte[size]; var header = new Header(); header.Version = 3; header.HasAttributes = true; header.ArF0 = false; header.IsPoint = false; header.ArF1 = false; HeaderConvertor.Encode(data, 0, header); CoordinateConverter.Encode(location.First.Coordinate, data, 1); FunctionalRoadClassConvertor.Encode(location.First.FuntionalRoadClass.Value, data, 7, 2); FormOfWayConvertor.Encode(location.First.FormOfWay.Value, data, 7, 5); FunctionalRoadClassConvertor.Encode(location.First.LowestFunctionalRoadClassToNext.Value, data, 8, 0); BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(location.First.Bearing.Value), data, 8, 3); data[9] = DistanceToNextConvertor.Encode(location.First.DistanceToNext); // calculate the intermediate points count. var position = 10; var reference = location.First.Coordinate; if (location.Intermediate != null) { for (int idx = 0; idx < location.Intermediate.Length; idx++) { // create an intermediate point. var intermediate = location.Intermediate[idx]; CoordinateConverter.EncodeRelative(reference, intermediate.Coordinate, data, position); reference = intermediate.Coordinate; position = position + 4; FunctionalRoadClassConvertor.Encode(intermediate.FuntionalRoadClass.Value, data, position, 2); FormOfWayConvertor.Encode(intermediate.FormOfWay.Value, data, position, 5); position = position + 1; BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(intermediate.Bearing.Value), data, position, 3); FunctionalRoadClassConvertor.Encode(intermediate.LowestFunctionalRoadClassToNext.Value, data, position, 0); position = position + 1; data[position] = DistanceToNextConvertor.Encode(intermediate.DistanceToNext); position = position + 1; } } CoordinateConverter.EncodeRelative(reference, location.Last.Coordinate, data, position); FunctionalRoadClassConvertor.Encode(location.Last.FuntionalRoadClass.Value, data, position + 4, 2); FormOfWayConvertor.Encode(location.Last.FormOfWay.Value, data, position + 4, 5); BearingConvertor.Encode(BearingConvertor.EncodeAngleToBearing(location.Last.Bearing.Value), data, position + 5, 3); if (location.PositiveOffsetPercentage.HasValue) { // positive offset percentage is present. OffsetConvertor.EncodeFlag(true, data, position + 5, 1); OffsetConvertor.Encode(location.PositiveOffsetPercentage.Value, data, position + 6); } if (location.NegativeOffsetPercentage.HasValue) { // positive offset percentage is present. OffsetConvertor.EncodeFlag(true, data, position + 5, 2); OffsetConvertor.Encode(location.NegativeOffsetPercentage.Value, data, position + 7); } return(data); }
public bool IsSameAs(LineLocation location) { return(location != null && location.File == File && location.Line == Line); }
/// <summary> /// Decodes the given data into a location reference. /// </summary> public static LineLocation Decode(byte[] data) { // decode first location reference point. var first = new LocationReferencePoint(); first.Coordinate = CoordinateConverter.Decode(data, 1); first.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, 7, 2); first.FormOfWay = FormOfWayConvertor.Decode(data, 7, 5); first.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, 8, 0); first.Bearing = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, 8, 3)); first.DistanceToNext = DistanceToNextConvertor.Decode(data[9]); // calculate the intermediate points count. var intermediateList = new List <LocationReferencePoint>(); int intermediates = (data.Length - 16) / 7; int location = 10; var reference = first.Coordinate; // the reference for the relative coordinates. for (int idx = 0; idx < intermediates; idx++) { // create an intermediate point. var intermediate = new LocationReferencePoint(); intermediate.Coordinate = CoordinateConverter.DecodeRelative(reference, data, location); reference = intermediate.Coordinate; location = location + 4; intermediate.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, location, 2); intermediate.FormOfWay = FormOfWayConvertor.Decode(data, location, 5); location = location + 1; intermediate.Bearing = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, location, 3)); intermediate.LowestFunctionalRoadClassToNext = FunctionalRoadClassConvertor.Decode(data, location, 0); location = location + 1; intermediate.DistanceToNext = DistanceToNextConvertor.Decode(data[location]); location = location + 1; intermediateList.Add(intermediate); } // decode last location reference point. var last = new LocationReferencePoint(); last.Coordinate = CoordinateConverter.DecodeRelative(reference, data, location); location = location + 4; last.FuntionalRoadClass = FunctionalRoadClassConvertor.Decode(data, location, 2); last.FormOfWay = FormOfWayConvertor.Decode(data, location, 5); location = location + 1; last.Bearing = BearingConvertor.DecodeAngleFromBearing(BearingConvertor.Decode(data, location, 3)); location = location + 1; // create line location. var lineLocation = new LineLocation(); if (location < data.Length) { // if present. lineLocation.PositiveOffsetPercentage = OffsetConvertor.Decode(data, location); location = location + 1; } if (location < data.Length) { // if present. lineLocation.NegativeOffsetPercentage = OffsetConvertor.Decode(data, location); location = location + 1; } lineLocation.First = first; lineLocation.Intermediate = intermediateList.ToArray(); lineLocation.Last = last; return(lineLocation); }
public static MethodAndTypeMetrics MethodOfLine(this MetricsReport metrics, LineLocation location) { if (metrics == null) return null; return (metrics.GetMethodOfLine(location)).FirstOrDefault(); }
/// <summary> /// Finds the half-edge bounding the <see cref="SubdivisionFace"/> that is nearest to and /// facing the specified coordinates.</summary> /// <param name="q"> /// The <see cref="PointD"/> coordinates to locate.</param> /// <param name="distance"> /// Returns the distance between <paramref name="q"/> and the returned <see /// cref="SubdivisionEdge"/>, if any; otherwise, <see cref="Double.MaxValue"/>.</param> /// <returns><para> /// The <see cref="SubdivisionEdge"/> on any outer or inner boundaries of the <see /// cref="SubdivisionFace"/> with the smallest distance to and facing <paramref name="q"/>. /// </para><para>-or-</para><para> /// A null reference if the <see cref="SubdivisionFace"/> is completely unbounded. /// </para></returns> /// <remarks><para> /// <b>FindNearestEdge</b> traverses the <see cref="OuterEdge"/> boundary and all <see /// cref="InnerEdges"/> boundaries, computing the distance from <paramref name="q"/> to each /// <see cref="SubdivisionEdge"/>. This is an O(n) operation where n is the number of /// half-edges incident on the <see cref="SubdivisionFace"/>. /// </para><para> /// If <paramref name="q"/> is nearest to an edge that belongs to a zero-area protrusion /// into the <see cref="SubdivisionFace"/>, <b>FindNearestEdge</b> returns the twin /// half-edge that faces <paramref name="q"/>, according to its <see /// cref="SubdivisionEdge.Face"/> orientation.</para></remarks> public SubdivisionEdge FindNearestEdge(PointD q, out double distance) { distance = Double.MaxValue; SubdivisionEdge nearestEdge = null; // find smallest distance to any outer cycle edge if (_outerEdge != null) { SubdivisionEdge edge = _outerEdge; do { double d = edge.ToLine().DistanceSquared(q); if (distance > d) { distance = d; if (d == 0) { return(edge); } nearestEdge = edge; } edge = edge._next; } while (edge != _outerEdge); } // find smallest distance to any inner cycle edge if (_innerEdges != null) { for (int i = 0; i < _innerEdges.Count; i++) { SubdivisionEdge innerEdge = _innerEdges[i]; SubdivisionEdge edge = innerEdge; do { double d = edge.ToLine().DistanceSquared(q); if (distance > d) { distance = d; if (d == 0) { return(edge); } nearestEdge = edge; } edge = edge._next; } while (edge != innerEdge); } } if (nearestEdge == null) { return(null); } // check twin in case of zero-area protrusion if (nearestEdge._twin._face == this) { LineLocation location = nearestEdge.ToLine().Locate(q); if (location == LineLocation.Right) { nearestEdge = nearestEdge._twin; } } distance = Math.Sqrt(distance); return(nearestEdge); }
public void DecodeReferencedLineLocation() { // build the location to decode. var location = new LineLocation(); location.First = new LocationReferencePoint(); location.First.Coordinate = new Coordinate() { Latitude = 49.60851, Longitude = 6.12683 }; location.First.DistanceToNext = 517; location.First.FuntionalRoadClass = FunctionalRoadClass.Frc3; location.First.FormOfWay = FormOfWay.MultipleCarriageWay; location.First.LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc3; location.First.Bearing = 0; location.Intermediate = new LocationReferencePoint[1]; location.Intermediate[0] = new LocationReferencePoint(); location.Intermediate[0].Coordinate = new Coordinate() { Latitude = 49.60398, Longitude = 6.12838 }; location.Intermediate[0].DistanceToNext = 104; location.Intermediate[0].FuntionalRoadClass = FunctionalRoadClass.Frc3; location.Intermediate[0].FormOfWay = FormOfWay.SingleCarriageWay; location.Intermediate[0].LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc5; location.Intermediate[0].Bearing = 0; location.Last = new LocationReferencePoint(); location.Last = new LocationReferencePoint(); location.Last.Coordinate = new Coordinate() { Latitude = 49.60305, Longitude = 6.12817 }; location.Last.DistanceToNext = 0; location.Last.FuntionalRoadClass = FunctionalRoadClass.Frc5; location.Last.FormOfWay = FormOfWay.SingleCarriageWay; location.Last.Bearing = 0; // build a graph to decode onto. var tags = new TagsTableCollectionIndex(); var graphDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tags); uint vertex1 = graphDataSource.AddVertex(49.60851f, 6.12683f); uint vertex2 = graphDataSource.AddVertex(49.60398f, 6.12838f); uint vertex3 = graphDataSource.AddVertex(49.60305f, 6.12817f); graphDataSource.AddEdge(vertex1, vertex2, new LiveEdge() { Distance = 517, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex2, vertex1, new LiveEdge() { Distance = 517, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex2, vertex3, new LiveEdge() { Distance = 104, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); graphDataSource.AddEdge(vertex3, vertex2, new LiveEdge() { Distance = 104, Forward = true, Tags = tags.Add(new TagsCollection(Tag.Create("highway", "tertiary"))) }, null); // decode the location var graph = new BasicRouterDataSource <LiveEdge>(graphDataSource); var decoder = new LineLocationDecoder(); var router = new BasicRouter(); var mainDecoder = new ReferencedOsmDecoder(graph, new BinaryDecoder()); var referencedDecoder = new ReferencedLineDecoder(mainDecoder, decoder); var referencedLocation = referencedDecoder.Decode(location); // confirm result. Assert.IsNotNull(referencedLocation); Assert.IsNotNull(referencedLocation.Vertices); Assert.AreEqual(3, referencedLocation.Vertices.Length); Assert.IsNotNull(referencedLocation.Edges); Assert.AreEqual(2, referencedLocation.Edges.Length); }
internal void Push(LineLocation location) { if (pushHandler != null && location != null) pushHandler(location); }
public void DecodeReferencedLineLocation() { // setup a routing network to test against. var routerDb = new RouterDb(); routerDb.LoadTestNetwork( System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( "OpenLR.Test.test_data.networks.network3.geojson")); routerDb.Sort(); routerDb.AddSupportedVehicle(Itinero.Osm.Vehicles.Vehicle.Car); // setup test location and data to verify this. var start = routerDb.Network.GetVertex(7); var end = routerDb.Network.GetVertex(6); var location = new LineLocation() { First = new LocationReferencePoint() { Bearing = 90, Coordinate = new Coordinate() { Latitude = start.Latitude, Longitude = start.Longitude }, DistanceToNext = (int)Itinero.LocalGeo.Coordinate.DistanceEstimateInMeter(start, end), FormOfWay = FormOfWay.SingleCarriageWay, FuntionalRoadClass = FunctionalRoadClass.Frc4, LowestFunctionalRoadClassToNext = FunctionalRoadClass.Frc4 }, Intermediate = new LocationReferencePoint[0], Last = new LocationReferencePoint() { Bearing = 270, Coordinate = new Coordinate() { Latitude = end.Latitude, Longitude = end.Longitude }, DistanceToNext = 0, FormOfWay = FormOfWay.SingleCarriageWay, FuntionalRoadClass = FunctionalRoadClass.Frc4 }, NegativeOffsetPercentage = 0, PositiveOffsetPercentage = 0 }; // decode and verify result. var decoded = ReferencedLineCodec.Decode(location, new Coder(routerDb, new OsmCoderProfile())); Assert.IsNotNull(decoded); Assert.AreEqual(0, decoded.NegativeOffsetPercentage); Assert.AreEqual(0, decoded.PositiveOffsetPercentage); Assert.IsNotNull(decoded.Vertices); Assert.AreEqual(new uint[] { 7, 4, 5, 6 }, decoded.Vertices); Assert.IsNotNull(decoded.Edges); Assert.AreEqual(new long[] { 1, -6, 2 }, decoded.Edges); Assert.IsNotNull(decoded.StartLocation); Assert.IsTrue(Itinero.LocalGeo.Coordinate.DistanceEstimateInMeter( decoded.StartLocation.LocationOnNetwork(routerDb), start) < 1); Assert.IsTrue(Itinero.LocalGeo.Coordinate.DistanceEstimateInMeter( decoded.EndLocation.LocationOnNetwork(routerDb), end) < 1); }
private void DisplayMetricsOfMethodAtDefinition(LineLocation location) { if (lastLocation.IsSameAs(location)) return; DisplayMetrics(metrics != null ? GetMethodOfDefiniton(location) : null); }
/// <summary> /// Constructor /// </summary> /// <param name="startLinePosition">Start line position</param> /// <param name="endLinePosition">End line position</param> public LineLocationSpan(LineLocation startLinePosition, LineLocation endLinePosition) { StartLinePosition = startLinePosition; EndLinePosition = endLinePosition; }
/// <summary> /// Determines whether the specified <see cref="LineLocation"/> value specifies that the /// tested line segment contains the tested point.</summary> /// <param name="location"> /// The <see cref="LineLocation"/> value to examine.</param> /// <returns> /// <c>true</c> if <paramref name="location"/> equals <see cref="LineLocation.Start"/>, <see /// cref="LineLocation.Between"/>, or <see cref="LineLocation.End"/>; otherwise, /// <c>false</c>.</returns> /// <remarks> /// <b>Contains</b> uses a bit mask for efficient testing of the specified <paramref /// name="location"/> for the three acceptable <see cref="LineLocation"/> values.</remarks> public static bool Contains(LineLocation location) { const LineLocation mask = LineLocation.Start | LineLocation.Between | LineLocation.End; return((location & mask) != 0); }