LCOV - code coverage report
Current view: top level - src/microsim - MSTrainHelper.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 19 19
Test Date: 2025-11-13 15:38:19 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2014-2025 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MSTrainHelper.h
      15              : /// @author  Benjamin Coueraud
      16              : /// @date    Wed, 07 Fev 2024
      17              : ///
      18              : // A class that helps computing positions of a train's carriages.
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <utils/geom/Position.h>
      24              : #include <utils/geom/PositionVector.h>
      25              : #include "MSVehicleControl.h"
      26              : 
      27              : // ===========================================================================
      28              : // class declarations
      29              : // ===========================================================================
      30              : class MSVehicle;
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // class definitions
      35              : // ===========================================================================
      36              : /**
      37              :  * @class MSTrainHelper
      38              :  * @brief A class that helps computing positions of a train's carriages
      39              :  * and additional structures.
      40              :  *
      41              :  */
      42              : class MSTrainHelper {
      43              : public:
      44        14770 :     struct Carriage {
      45              :         Position front;
      46              :         Position back;
      47              :         std::vector<Position> doorPositions;
      48              :         std::vector<Position> unboardingPositions;
      49              :     };
      50              : 
      51         4648 :     MSTrainHelper(const MSVehicle* vehicle, double scaledLength = -1, bool reversed = false,
      52              :                   bool secondaryShape = false, double exaggeration = 1.0, int vehicleQuality = 3)
      53         4648 :         : myTrain(vehicle) {
      54         4648 :         computeTrainDimensions(exaggeration, secondaryShape, scaledLength < 0 ? myTrain->getLength() : scaledLength, vehicleQuality);
      55         4648 :         computeCarriages(reversed, secondaryShape);
      56         4648 :     }
      57              : 
      58         4648 :     ~MSTrainHelper() {
      59        19418 :         for (const Carriage* carriage : myCarriages) {
      60        29540 :             delete carriage;
      61              :         }
      62         4648 :     }
      63              : 
      64              :     inline double getUpscaleLength() const {
      65         8624 :         return myUpscaleLength;
      66              :     }
      67              : 
      68              :     inline double getHalfWidth() const {
      69        13546 :         return myHalfWidth;
      70              :     }
      71              : 
      72              :     inline int getNumCarriages() const {
      73         4648 :         return myNumCarriages;
      74              :     }
      75              : 
      76              :     inline double getCarriageLength() const {
      77         9234 :         return myCarriageLength;
      78              :     }
      79              : 
      80              :     inline double getFirstCarriageLength() const {
      81         8624 :         return myFirstCarriageLength;
      82              :     }
      83              : 
      84              :     inline int getCarriageDoors() const {
      85          336 :         return myCarriageDoors;
      86              :     }
      87              : 
      88              :     inline int getFirstCarriageNo() const {
      89        38838 :         return myFirstCarriageNo;
      90              :     }
      91              : 
      92              :     inline int getFirstPassengerCarriage() const {
      93         4648 :         return myFirstPassengerCarriage;
      94              :     }
      95              : 
      96              :     inline bool isReversed() const {
      97        13546 :         return myIsReversed;
      98              :     }
      99              : 
     100              :     inline const std::vector<Carriage*>& getCarriages() const {
     101              :         return myCarriages;
     102              :     }
     103              : 
     104              :     /// @brief compute door positions on demand and fills the carriage structures
     105              :     /// @remark need to be called before retrieving carriages if door positions needed
     106              :     void computeDoorPositions();
     107              : 
     108              :     /// @brief compute unboarding positions on demand and fills the carriage structures
     109              :     /// @remark need to be called before retrieving carriages if unboarding positions needed
     110              :     void computeUnboardingPositions(double passengerRadius, std::vector<Position>& unboardingPositions);
     111              : 
     112              :     /// @brief return length exaggeration factor (special for long vehicles)
     113              :     static double getUpscaleLength(double upscale, double length, double width, int vehicleQuality);
     114              : 
     115              :     /// @brief small extra tolerance used to avoid constraint violations
     116              :     static const double PEDESTRIAN_RADIUS_EXTRA_TOLERANCE;
     117              : 
     118              : private:
     119              :     void computeTrainDimensions(double exaggeration, bool secondaryShape, double scaledLength, int vehicleQuality);
     120              :     void computeCarriages(bool reversed, bool secondaryShape);
     121              : 
     122              :     const MSVehicle* myTrain;
     123              :     double myUpscaleLength;
     124              :     double myLocomotiveLength;
     125              :     double myDefaultLength;
     126              :     double myCarriageGap;
     127              :     double myLength;
     128              :     bool myUnscale;
     129              :     double myHalfWidth;
     130              :     int myNumCarriages;
     131              :     double myCarriageLengthWithGap;
     132              :     double myCarriageLength;
     133              :     double myFirstCarriageLength;
     134              :     int myCarriageDoors;
     135              :     int myFirstCarriageNo;
     136              :     int myFirstPassengerCarriage;
     137              :     bool myIsReversed;
     138              :     std::vector<Carriage*> myCarriages;
     139              : };
        

Generated by: LCOV version 2.0-1