SUMO - Simulation of Urban MObility
AGPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
20 // References a street of the city and defines a position in this street
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include "AGPosition.h"
30 #include "AGStreet.h"
31 #include "router/ROEdge.h"
33 #include <iostream>
34 #include <limits>
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 AGPosition::AGPosition(const AGStreet& str, double pos) :
41  street(&str), position(pos), pos2d(compute2dPosition()) {
42 }
43 
44 
47 }
48 
49 
50 void
52  std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
53 }
54 
55 
56 bool
58  return pos2d.almostSame(pos.pos2d);
59 }
60 
61 
62 double
63 AGPosition::distanceTo(const AGPosition& otherPos) const {
64  return pos2d.distanceTo(otherPos.pos2d);
65 }
66 
67 
68 double
69 AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
70  double minDist = std::numeric_limits<double>::infinity();
71  double tempDist;
72  std::list<AGPosition>::const_iterator itt;
73 
74  for (itt = positions.begin(); itt != positions.end(); ++itt) {
75  tempDist = this->distanceTo(*itt);
76  if (tempDist < minDist) {
77  minDist = tempDist;
78  }
79  }
80  return minDist;
81 }
82 
83 
84 double
85 AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
86  double minDist = std::numeric_limits<double>::infinity();
87  double tempDist;
88  std::map<int, AGPosition>::const_iterator itt;
89 
90  for (itt = positions.begin(); itt != positions.end(); ++itt) {
91  tempDist = this->distanceTo(itt->second);
92  if (tempDist < minDist) {
93  minDist = tempDist;
94  }
95  }
96  return minDist;
97 }
98 
99 
100 const AGStreet&
102  return *street;
103 }
104 
105 
106 double
108  return position;
109 }
110 
111 
112 double
114  return RandHelper::rand(0.0, s.getLength());
115 }
116 
117 
118 Position
120  // P = From + pos*(To - From) = pos*To + (1-pos)*From
123  Position position2d(To);
124 
125  position2d.sub(From);
126  position2d.mul(position / street->getLength());
127  position2d.add(From);
128 
129  return position2d;
130 }
131 
132 /****************************************************************************/
bool almostSame(const Position &p2, double maxDiv=POSITION_EPS) const
check if two position is almost the sme as other
Definition: Position.h:229
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:67
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
Position compute2dPosition() const
Definition: AGPosition.cpp:119
static double randomPositionInStreet(const AGStreet &street)
Determines a random relative position on a street.
Definition: AGPosition.cpp:113
const RONode * getFromJunction() const
Definition: ROEdge.h:460
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:56
A model of the street in the city.
Definition: AGStreet.h:53
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:199
const RONode * getToJunction() const
Definition: ROEdge.h:464
bool operator==(const AGPosition &pos) const
Tests whether two positions are at the same place.
Definition: AGPosition.cpp:57
AGPosition(const AGStreet &str, double pos)
Constructs an AGPosition at a certain point on a street.
Definition: AGPosition.cpp:40
double minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
Definition: AGPosition.cpp:69
const AGStreet & getStreet() const
Provides the street this AGPosition is located on.
Definition: AGPosition.cpp:101
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
Definition: AGPosition.cpp:63
Position pos2d
Definition: AGPosition.h:137
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
void print() const
Prints out a summary of the properties of this class on standard output.
Definition: AGPosition.cpp:51
void mul(double val)
Multiplies both positions with the given value.
Definition: Position.h:107
double getPosition() const
Provides the relative position of this AGPosition on the street.
Definition: AGPosition.cpp:107
double position
Definition: AGPosition.h:136
const AGStreet * street
Definition: AGPosition.h:135
void sub(double dx, double dy)
Substracts the given position from this one.
Definition: Position.h:147