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: 2024-10-24 15:46:30 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-2024 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        14981 :     struct Carriage {
      45              :         Position front;
      46              :         Position back;
      47              :         std::vector<Position> doorPositions;
      48              :         std::vector<Position> unboardingPositions;
      49              :     };
      50              : 
      51         4701 :     MSTrainHelper(const MSVehicle* vehicle, bool reversed = false, bool secondaryShape = false, double exaggeration = 1.0, int vehicleQuality = 3)
      52         4701 :         : myTrain(vehicle) {
      53         4701 :         computeTrainDimensions(exaggeration, vehicleQuality);
      54         4701 :         computeCarriages(reversed, secondaryShape);
      55         4701 :     }
      56              : 
      57         4701 :     ~MSTrainHelper() {
      58        19682 :         for (const Carriage* carriage : myCarriages) {
      59        29962 :             delete carriage;
      60              :         }
      61         4701 :     }
      62              : 
      63              :     inline double getUpscaleLength() const {
      64         8730 :         return myUpscaleLength;
      65              :     }
      66              : 
      67              :     inline double getHalfWidth() const {
      68        13640 :         return myHalfWidth;
      69              :     }
      70              : 
      71              :     inline int getNumCarriages() const {
      72         4701 :         return myNumCarriages;
      73              :     }
      74              : 
      75              :     inline double getCarriageLength() const {
      76         9275 :         return myCarriageLength;
      77              :     }
      78              : 
      79              :     inline double getFirstCarriageLength() const {
      80         8730 :         return myFirstCarriageLength;
      81              :     }
      82              : 
      83              :     inline int getCarriageDoors() const {
      84          336 :         return myCarriageDoors;
      85              :     }
      86              : 
      87              :     inline int getFirstCarriageNo() const {
      88        39120 :         return myFirstCarriageNo;
      89              :     }
      90              : 
      91              :     inline int getFirstPassengerCarriage() const {
      92         4701 :         return myFirstPassengerCarriage;
      93              :     }
      94              : 
      95              :     inline bool isReversed() const {
      96        13640 :         return myIsReversed;
      97              :     }
      98              : 
      99              :     inline const std::vector<Carriage*>& getCarriages() const {
     100              :         return myCarriages;
     101              :     }
     102              : 
     103              :     /// @brief compute door positions on demand and fills the carriage structures
     104              :     /// @remark need to be called before retrieving carriages if door positions needed
     105              :     void computeDoorPositions();
     106              : 
     107              :     /// @brief compute unboarding positions on demand and fills the carriage structures
     108              :     /// @remark need to be called before retrieving carriages if unboarding positions needed
     109              :     void computeUnboardingPositions(double passengerRadius, std::vector<Position>& unboardingPositions);
     110              : 
     111              :     /// @brief return length exaggeration factor (special for long vehicles)
     112              :     static double getUpscaleLength(double upscale, double length, double width, int vehicleQuality);
     113              : 
     114              :     /// @brief average door width used to compute doors positions
     115              :     static const double CARRIAGE_DOOR_WIDTH;
     116              : 
     117              :     /// @brief small extra tolerance used to avoid constraint violations
     118              :     static const double PEDESTRIAN_RADIUS_EXTRA_TOLERANCE;
     119              : 
     120              : private:
     121              :     void computeTrainDimensions(double exaggeration, int vehicleQuality);
     122              :     void computeCarriages(bool reversed, bool secondaryShape);
     123              : 
     124              :     const MSVehicle* myTrain;
     125              :     double myUpscaleLength;
     126              :     double myLocomotiveLength;
     127              :     double myDefaultLength;
     128              :     double myCarriageGap;
     129              :     double myLength;
     130              :     double myHalfWidth;
     131              :     int myNumCarriages;
     132              :     double myCarriageLengthWithGap;
     133              :     double myCarriageLength;
     134              :     double myFirstCarriageLength;
     135              :     int myCarriageDoors;
     136              :     int myFirstCarriageNo;
     137              :     int myFirstPassengerCarriage;
     138              :     bool myIsReversed;
     139              :     std::vector<Carriage*> myCarriages;
     140              : };
        

Generated by: LCOV version 2.0-1