ad_rss
VelocityValidInputRange.hpp
Go to the documentation of this file.
1 /*
2  * ----------------- BEGIN LICENSE BLOCK ---------------------------------
3  *
4  * Copyright (C) 2018-2022 Intel Corporation
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only
7  *
8  * ----------------- END LICENSE BLOCK -----------------------------------
9  */
10 
18 #pragma once
19 
20 #include <cmath>
21 #include <limits>
22 #include "ad/physics/SpeedValidInputRange.hpp"
24 #include "spdlog/fmt/ostr.h"
25 #include "spdlog/spdlog.h"
26 
41 inline bool withinValidInputRange(::ad::rss::world::Velocity const &input, bool const logErrors = true)
42 {
43  // check for generic member input ranges
44  bool inValidInputRange = true;
45  inValidInputRange = withinValidInputRange(input.speed_lon_min, logErrors)
46  && withinValidInputRange(input.speed_lon_max, logErrors) && withinValidInputRange(input.speed_lat_min, logErrors)
47  && withinValidInputRange(input.speed_lat_max, logErrors);
48  if (!inValidInputRange && logErrors)
49  {
50  spdlog::error("withinValidInputRange(::ad::rss::world::Velocity)>> {} has invalid member",
51  input); // LCOV_EXCL_BR_LINE
52  }
53 
54  // check for individual input ranges
55  if (inValidInputRange)
56  {
57  inValidInputRange
58  = (::ad::physics::Speed(0.) <= input.speed_lon_min) && (input.speed_lon_min <= input.speed_lon_max);
59  if (!inValidInputRange && logErrors)
60  {
61  spdlog::error(
62  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
63  input,
64  input.speed_lon_min,
65  ::ad::physics::Speed(0.),
66  input.speed_lon_max); // LCOV_EXCL_BR_LINE
67  }
68  }
69 
70  if (inValidInputRange)
71  {
72  inValidInputRange
73  = (input.speed_lon_min <= input.speed_lon_max) && (input.speed_lon_max <= ::ad::physics::Speed(100.));
74  if (!inValidInputRange && logErrors)
75  {
76  spdlog::error(
77  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
78  input,
79  input.speed_lon_max,
80  input.speed_lon_min,
81  ::ad::physics::Speed(100.)); // LCOV_EXCL_BR_LINE
82  }
83  }
84 
85  if (inValidInputRange)
86  {
87  inValidInputRange
88  = (::ad::physics::Speed(-100.) <= input.speed_lat_min) && (input.speed_lat_min <= input.speed_lat_max);
89  if (!inValidInputRange && logErrors)
90  {
91  spdlog::error(
92  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
93  input,
94  input.speed_lat_min,
95  ::ad::physics::Speed(-100.),
96  input.speed_lat_max); // LCOV_EXCL_BR_LINE
97  }
98  }
99 
100  if (inValidInputRange)
101  {
102  inValidInputRange
103  = (input.speed_lat_min <= input.speed_lat_max) && (input.speed_lat_max <= ::ad::physics::Speed(100.));
104  if (!inValidInputRange && logErrors)
105  {
106  spdlog::error(
107  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
108  input,
109  input.speed_lat_max,
110  input.speed_lat_min,
111  ::ad::physics::Speed(100.)); // LCOV_EXCL_BR_LINE
112  }
113  }
114 
115  return inValidInputRange;
116 }
bool withinValidInputRange(::ad::rss::world::Velocity const &input, bool const logErrors=true)
check if the given Velocity is within valid input range
Definition: VelocityValidInputRange.hpp:41
DataType Velocity.
Definition: Velocity.hpp:48
::ad::physics::Speed speed_lon_max
Definition: Velocity.hpp:134
::ad::physics::Speed speed_lat_max
Definition: Velocity.hpp:148
::ad::physics::Speed speed_lon_min
Definition: Velocity.hpp:127
::ad::physics::Speed speed_lat_min
Definition: Velocity.hpp:141