Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm/Utils.cs @ 8308

Last change on this file since 8308 was 8308, checked in by spimming, 12 years ago

#1894:

  • get neighbors for specific node
  • method to calculate weight between two nodes
  • interface for router
  • Dijkstra algorithm initial commit
  • Utils methods added
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Problems.RoutePlanning.Osm {
5  public static class Utils {
6    public static double Distance(PointD p1, PointD p2) {
7      double dx = p2.X - p1.X;
8      double dy = p2.Y - p1.Y;
9      return Math.Sqrt(dx * dx + dy * dy);
10    }
11
12    public static double PathLength(IList<PointD> points) {
13      double length = 0;
14      for (int i = 1; i < points.Count; i++) {
15        length += Distance((PointD)points[i - 1], (PointD)points[i]);
16      }
17      return length;
18    }
19
20    public static RectangleD FindBox(IList<PointD> points) {
21      double minX = double.MaxValue;
22      double maxX = double.MinValue;
23      double minY = double.MaxValue;
24      double maxY = double.MinValue;
25
26      foreach (PointD p in points) {
27        if (p.X < minX)
28          minX = p.X;
29        if (p.X > maxX)
30          maxX = p.X;
31
32        if (p.Y < minY)
33          minY = p.Y;
34        if (p.Y > maxY)
35          maxY = p.Y;
36      }
37      return new RectangleD(minX, minY, maxX - minX, maxY - minY);
38    }
39
40    public static double PathDistance(IList<PointD> path1, IList<PointD> path2) {
41      double distance = 0;
42      for (int i = 0; i < path1.Count; i++) {
43        distance += Distance((PointD)path1[i], (PointD)path2[i]);
44      }
45      return distance / path1.Count;
46    }
47  }
48}
49
Note: See TracBrowser for help on using the repository browser.