Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/city/AGPosition.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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 are made available under the
7
// terms of the Eclipse Public License 2.0 which is available at
8
// https://www.eclipse.org/legal/epl-2.0/
9
// This Source Code may also be made available under the following Secondary
10
// Licenses when the conditions for such availability set forth in the Eclipse
11
// Public License 2.0 are satisfied: GNU General Public License, version 2
12
// or later which is available at
13
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15
/****************************************************************************/
16
/// @file AGPosition.cpp
17
/// @author Piotr Woznica
18
/// @author Walter Bamberger
19
/// @author Daniel Krajzewicz
20
/// @author Michael Behrisch
21
/// @date July 2010
22
///
23
// References a street of the city and defines a position in this street
24
/****************************************************************************/
25
#include <config.h>
26
27
#include "AGPosition.h"
28
#include "AGStreet.h"
29
#include "router/ROEdge.h"
30
#include "utils/common/RandHelper.h"
31
#include <iostream>
32
#include <limits>
33
34
35
// ===========================================================================
36
// method definitions
37
// ===========================================================================
38
AGPosition::AGPosition(const AGStreet& str, double pos) :
39
street(&str), position(pos), pos2d(compute2dPosition()) {
40
}
41
42
43
AGPosition::AGPosition(const AGStreet& str) :
44
street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) {
45
}
46
47
48
void
49
AGPosition::print() const {
50
std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
51
}
52
53
54
bool
55
AGPosition::operator==(const AGPosition& pos) const {
56
return pos2d.almostSame(pos.pos2d);
57
}
58
59
60
double
61
AGPosition::distanceTo(const AGPosition& otherPos) const {
62
return pos2d.distanceTo(otherPos.pos2d);
63
}
64
65
66
double
67
AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
68
double minDist = std::numeric_limits<double>::infinity();
69
double tempDist;
70
std::list<AGPosition>::const_iterator itt;
71
72
for (itt = positions.begin(); itt != positions.end(); ++itt) {
73
tempDist = this->distanceTo(*itt);
74
if (tempDist < minDist) {
75
minDist = tempDist;
76
}
77
}
78
return minDist;
79
}
80
81
82
double
83
AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
84
double minDist = std::numeric_limits<double>::infinity();
85
double tempDist;
86
std::map<int, AGPosition>::const_iterator itt;
87
88
for (itt = positions.begin(); itt != positions.end(); ++itt) {
89
tempDist = this->distanceTo(itt->second);
90
if (tempDist < minDist) {
91
minDist = tempDist;
92
}
93
}
94
return minDist;
95
}
96
97
98
const AGStreet&
99
AGPosition::getStreet() const {
100
return *street;
101
}
102
103
104
double
105
AGPosition::getPosition() const {
106
return position;
107
}
108
109
110
double
111
AGPosition::randomPositionInStreet(const AGStreet& s) {
112
return RandHelper::rand(0.0, s.getLength());
113
}
114
115
116
Position
117
AGPosition::compute2dPosition() const {
118
// P = From + pos*(To - From) = pos*To + (1-pos)*From
119
Position From = street->getFromJunction()->getPosition();
120
Position To = street->getToJunction()->getPosition();
121
Position position2d(To);
122
123
position2d.sub(From);
124
position2d.mul(position / street->getLength());
125
position2d.add(From);
126
127
return position2d;
128
}
129
130
131
/****************************************************************************/
132
133