ad_map_access
ParametricRangeAttributeOperation.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2018-2021 Intel Corporation
4 //
5 // SPDX-License-Identifier: MIT
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
12 #pragma once
13 
15 #include "ad/physics/RangeOperation.hpp"
16 
18 namespace ad {
20 namespace map {
22 namespace restriction {
23 
30 inline bool areAttributesEqual(SpeedLimit const &left, SpeedLimit const &right)
31 {
32  return left.speedLimit == right.speedLimit;
33 }
34 
41 template <typename RangeAttribute> bool combineRangeAttributes(RangeAttribute &left, RangeAttribute const &right)
42 {
43  if (areAttributesEqual(left, right))
44  {
45  return extendRangeWith(left.lanePiece, right.lanePiece);
46  }
47  return false;
48 }
49 
56 template <typename RangeAttribute>
57 bool doesRangeAttributeOverlap(std::vector<RangeAttribute> const &attributeList, RangeAttribute const &attribute)
58 {
59  for (auto const &listEntry : attributeList)
60  {
61  if (doRangesOverlap(attribute.lanePiece, listEntry.lanePiece)
62  && !doesRangePredate(attribute.lanePiece, listEntry.lanePiece)
63  && !doesRangeSucceed(attribute.lanePiece, listEntry.lanePiece))
64  {
65  return true;
66  }
67  }
68  return false;
69 }
70 
76 template <typename RangeAttribute>
77 void insertRangeAttribute(std::vector<RangeAttribute> &attributeList, RangeAttribute const &attribute)
78 {
79  for (auto it = attributeList.begin(); it != attributeList.end(); it++)
80  {
81  if (attribute.lanePiece <= it->lanePiece)
82  {
83  attributeList.insert(it, attribute);
84  optimizeRangeAttributeList(attributeList);
85  return;
86  }
87  }
88  attributeList.push_back(attribute);
89  optimizeRangeAttributeList(attributeList);
90 }
91 
93 template <typename RangeAttribute> void optimizeRangeAttributeList(std::vector<RangeAttribute> &attributeList)
94 {
95  for (auto it = attributeList.begin(); it != attributeList.end();)
96  {
97  auto it1 = it + 1;
98  if (it1 == attributeList.end())
99  {
100  return;
101  }
102  if (combineRangeAttributes(*it, *it1))
103  {
104  attributeList.erase(it1);
105  }
106  else
107  {
108  it = it1;
109  }
110  }
111 }
112 
113 } // namespace restriction
114 } // namespace map
115 } // namespace ad
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
ad::map::restriction::combineRangeAttributes
bool combineRangeAttributes(RangeAttribute &left, RangeAttribute const &right)
Tries to combine two RangeAttributes into one.
Definition: ParametricRangeAttributeOperation.hpp:41
ad::map::restriction::optimizeRangeAttributeList
void optimizeRangeAttributeList(std::vector< RangeAttribute > &attributeList)
Combines multiple elements into one - if possible.
Definition: ParametricRangeAttributeOperation.hpp:93
ad::map::restriction::insertRangeAttribute
void insertRangeAttribute(std::vector< RangeAttribute > &attributeList, RangeAttribute const &attribute)
Insert attribute and preserve order.
Definition: ParametricRangeAttributeOperation.hpp:77
ad::map::restriction::SpeedLimit
DataType SpeedLimit.
Definition: SpeedLimit.hpp:44
SpeedLimit.hpp
ad::map::restriction::areAttributesEqual
bool areAttributesEqual(SpeedLimit const &left, SpeedLimit const &right)
Compare two speed limit attributes for equality.
Definition: ParametricRangeAttributeOperation.hpp:30
ad::map::restriction::doesRangeAttributeOverlap
bool doesRangeAttributeOverlap(std::vector< RangeAttribute > const &attributeList, RangeAttribute const &attribute)
Checks if another attribute overlaps any existing element.
Definition: ParametricRangeAttributeOperation.hpp:57