Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 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 412 : AGPosition::AGPosition(const AGStreet& str, double pos) : 39 412 : street(&str), position(pos), pos2d(compute2dPosition()) { 40 412 : } 41 : 42 : 43 8551 : AGPosition::AGPosition(const AGStreet& str) : 44 8551 : street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) { 45 8551 : } 46 : 47 : 48 : void 49 0 : AGPosition::print() const { 50 0 : std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl; 51 0 : } 52 : 53 : 54 : bool 55 15511 : AGPosition::operator==(const AGPosition& pos) const { 56 15511 : return pos2d.almostSame(pos.pos2d); 57 : } 58 : 59 : 60 : double 61 350699 : AGPosition::distanceTo(const AGPosition& otherPos) const { 62 350699 : return pos2d.distanceTo(otherPos.pos2d); 63 : } 64 : 65 : 66 : double 67 0 : 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 0 : for (itt = positions.begin(); itt != positions.end(); ++itt) { 73 0 : tempDist = this->distanceTo(*itt); 74 0 : if (tempDist < minDist) { 75 : minDist = tempDist; 76 : } 77 : } 78 0 : return minDist; 79 : } 80 : 81 : 82 : double 83 11282 : 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 349198 : for (itt = positions.begin(); itt != positions.end(); ++itt) { 89 337916 : tempDist = this->distanceTo(itt->second); 90 337916 : if (tempDist < minDist) { 91 : minDist = tempDist; 92 : } 93 : } 94 11282 : return minDist; 95 : } 96 : 97 : 98 : const AGStreet& 99 13506 : AGPosition::getStreet() const { 100 13506 : return *street; 101 : } 102 : 103 : 104 : double 105 7896 : AGPosition::getPosition() const { 106 7896 : return position; 107 : } 108 : 109 : 110 : double 111 8551 : AGPosition::randomPositionInStreet(const AGStreet& s) { 112 8551 : return RandHelper::rand(0.0, s.getLength()); 113 : } 114 : 115 : 116 : Position 117 8963 : AGPosition::compute2dPosition() const { 118 : // P = From + pos*(To - From) = pos*To + (1-pos)*From 119 8963 : Position From = street->getFromJunction()->getPosition(); 120 8963 : Position To = street->getToJunction()->getPosition(); 121 : Position position2d(To); 122 : 123 : position2d.sub(From); 124 8963 : position2d.mul(position / street->getLength()); 125 : position2d.add(From); 126 : 127 8963 : return position2d; 128 : } 129 : 130 : 131 : /****************************************************************************/