SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AGPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // References a street of the city and defines a position in this street
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14 // activitygen module
15 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include "AGPosition.h"
37 #include "AGStreet.h"
38 #include "router/ROEdge.h"
40 #include <iostream>
41 #include <limits>
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  street(&str), position(pos), pos2d(compute2dPosition()) {
49 }
50 
51 
53  street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) {
54 }
55 
56 
57 void
59  std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
60 }
61 
62 
63 bool
65  return pos2d.almostSame(pos.pos2d);
66 }
67 
68 
70 AGPosition::distanceTo(const AGPosition& otherPos) const {
71  return pos2d.distanceTo(otherPos.pos2d);
72 }
73 
74 
76 AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
77  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
78  SUMOReal tempDist;
79  std::list<AGPosition>::const_iterator itt;
80 
81  for (itt = positions.begin(); itt != positions.end(); ++itt) {
82  tempDist = this->distanceTo(*itt);
83  if (tempDist < minDist) {
84  minDist = tempDist;
85  }
86  }
87  return minDist;
88 }
89 
90 
92 AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
93  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
94  SUMOReal tempDist;
95  std::map<int, AGPosition>::const_iterator itt;
96 
97  for (itt = positions.begin(); itt != positions.end(); ++itt) {
98  tempDist = this->distanceTo(itt->second);
99  if (tempDist < minDist) {
100  minDist = tempDist;
101  }
102  }
103  return minDist;
104 }
105 
106 
107 const AGStreet&
109  return *street;
110 }
111 
112 
113 SUMOReal
115  return position;
116 }
117 
118 
119 SUMOReal
121  return RandHelper::rand(0.0, s.getLength());
122 }
123 
124 
125 Position
127  // P = From + pos*(To - From) = pos*To + (1-pos)*From
130  Position position2d(To);
131 
132  position2d.sub(From);
133  position2d.mul(position / street->getLength());
134  position2d.add(From);
135 
136  return position2d;
137 }
138 
139 /****************************************************************************/