LCOV - code coverage report
Current view: top level - include/ad/map/restriction - ParametricRangeAttributeOperation.hpp (source / functions) Hit Total Coverage
Test: ad_map_access Lines: 26 29 89.7 %
Date: 2022-10-04 09:48:07 Functions: 5 5 100.0 %
Branches: 24 38 63.2 %

           Branch data     Line data    Source code
       1                 :            : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
       2                 :            : //
       3                 :            : // Copyright (C) 2018-2021 Intel Corporation
       4                 :            : //
       5                 :            : // SPDX-License-Identifier: MIT
       6                 :            : //
       7                 :            : // ----------------- END LICENSE BLOCK -----------------------------------
       8                 :            : /**
       9                 :            :  * @file
      10                 :            :  */
      11                 :            : 
      12                 :            : #pragma once
      13                 :            : 
      14                 :            : #include "ad/map/restriction/SpeedLimit.hpp"
      15                 :            : #include "ad/physics/RangeOperation.hpp"
      16                 :            : 
      17                 :            : /** @brief namespace ad */
      18                 :            : namespace ad {
      19                 :            : /** @brief namespace map */
      20                 :            : namespace map {
      21                 :            : /** @brief namespace restriction */
      22                 :            : namespace restriction {
      23                 :            : 
      24                 :            : /**
      25                 :            :  * @brief Compare two speed limit attributes for equality.
      26                 :            :  * @param[in] left SpeedLimit object.
      27                 :            :  * @param[in] right SpeedLimit object.
      28                 :            :  * @returns true if the attributes of the left SpeedLimit and right SpeedLimit can be considered to be equal.
      29                 :            :  */
      30                 :      11820 : inline bool areAttributesEqual(SpeedLimit const &left, SpeedLimit const &right)
      31                 :            : {
      32                 :      11820 :   return left.speedLimit == right.speedLimit;
      33                 :            : }
      34                 :            : 
      35                 :            : /**
      36                 :            :  * @brief Tries to combine two RangeAttributes into one.
      37                 :            :  * @param[in] left RangeAttributes object.
      38                 :            :  * @param[in] right RangeAttributes object.
      39                 :            :  * @returns true if left RangeAttributes is extended with right one.
      40                 :            :  */
      41                 :      11820 : template <typename RangeAttribute> bool combineRangeAttributes(RangeAttribute &left, RangeAttribute const &right)
      42                 :            : {
      43         [ +  + ]:      11820 :   if (areAttributesEqual(left, right))
      44                 :            :   {
      45                 :      11819 :     return extendRangeWith(left.lanePiece, right.lanePiece);
      46                 :            :   }
      47                 :          1 :   return false;
      48                 :            : }
      49                 :            : 
      50                 :            : /**
      51                 :            :  * @brief Checks if another attribute overlaps any existing element.
      52                 :            :  * @param[in] attributeList attribute list to check for overlap
      53                 :            :  * @param[in] attribute another attribute.
      54                 :            :  * @returns true if another element overlaps any existing element in the attributeList
      55                 :            :  */
      56                 :            : template <typename RangeAttribute>
      57                 :      35258 : bool doesRangeAttributeOverlap(std::vector<RangeAttribute> const &attributeList, RangeAttribute const &attribute)
      58                 :            : {
      59         [ +  + ]:      47077 :   for (auto const &listEntry : attributeList)
      60                 :            :   {
      61         [ +  - ]:      11820 :     if (doRangesOverlap(attribute.lanePiece, listEntry.lanePiece)
      62   [ +  -  +  - ]:      11820 :         && !doesRangePredate(attribute.lanePiece, listEntry.lanePiece)
      63   [ +  -  +  -  :      23640 :         && !doesRangeSucceed(attribute.lanePiece, listEntry.lanePiece))
             +  +  +  + ]
      64                 :            :     {
      65                 :          1 :       return true;
      66                 :            :     }
      67                 :            :   }
      68                 :      35257 :   return false;
      69                 :            : }
      70                 :            : 
      71                 :            : /**
      72                 :            :  * @brief Insert attribute and preserve order.
      73                 :            :  * @param[in] attributeList attribute list
      74                 :            :  * @param[in] attribute attribute to insert
      75                 :            :  */
      76                 :            : template <typename RangeAttribute>
      77                 :      35258 : void insertRangeAttribute(std::vector<RangeAttribute> &attributeList, RangeAttribute const &attribute)
      78                 :            : {
      79         [ +  + ]:      47078 :   for (auto it = attributeList.begin(); it != attributeList.end(); it++)
      80                 :            :   {
      81   [ +  -  -  + ]:      11820 :     if (attribute.lanePiece <= it->lanePiece)
      82                 :            :     {
      83         [ #  # ]:          0 :       attributeList.insert(it, attribute);
      84         [ #  # ]:          0 :       optimizeRangeAttributeList(attributeList);
      85                 :          0 :       return;
      86                 :            :     }
      87                 :            :   }
      88                 :      35258 :   attributeList.push_back(attribute);
      89                 :      35258 :   optimizeRangeAttributeList(attributeList);
      90                 :            : }
      91                 :            : 
      92                 :            : /** @brief Combines multiple elements into one - if possible. */
      93                 :      35258 : template <typename RangeAttribute> void optimizeRangeAttributeList(std::vector<RangeAttribute> &attributeList)
      94                 :            : {
      95         [ +  - ]:      47078 :   for (auto it = attributeList.begin(); it != attributeList.end();)
      96                 :            :   {
      97                 :      47078 :     auto it1 = it + 1;
      98         [ +  + ]:      47078 :     if (it1 == attributeList.end())
      99                 :            :     {
     100                 :      35258 :       return;
     101                 :            :     }
     102   [ +  -  +  + ]:      11820 :     if (combineRangeAttributes(*it, *it1))
     103                 :            :     {
     104         [ +  - ]:      11819 :       attributeList.erase(it1);
     105                 :            :     }
     106                 :            :     else
     107                 :            :     {
     108                 :          1 :       it = it1;
     109                 :            :     }
     110                 :            :   }
     111                 :            : }
     112                 :            : 
     113                 :            : } // namespace restriction
     114                 :            : } // namespace map
     115                 :            : } // namespace ad

Generated by: LCOV version 1.14