ad_rss
VelocityValidInputRange.hpp
Go to the documentation of this file.
1 /*
2  * ----------------- BEGIN LICENSE BLOCK ---------------------------------
3  *
4  * Copyright (C) 2018-2020 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.speedLonMin, logErrors)
46  && withinValidInputRange(input.speedLonMax, logErrors) && withinValidInputRange(input.speedLatMin, logErrors)
47  && withinValidInputRange(input.speedLatMax, 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 = (::ad::physics::Speed(0.) <= input.speedLonMin) && (input.speedLonMin <= input.speedLonMax);
58  if (!inValidInputRange && logErrors)
59  {
60  spdlog::error(
61  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
62  input,
63  input.speedLonMin,
64  ::ad::physics::Speed(0.),
65  input.speedLonMax); // LCOV_EXCL_BR_LINE
66  }
67  }
68 
69  if (inValidInputRange)
70  {
71  inValidInputRange = (input.speedLonMin <= input.speedLonMax) && (input.speedLonMax <= ::ad::physics::Speed(100.));
72  if (!inValidInputRange && logErrors)
73  {
74  spdlog::error(
75  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
76  input,
77  input.speedLonMax,
78  input.speedLonMin,
79  ::ad::physics::Speed(100.)); // LCOV_EXCL_BR_LINE
80  }
81  }
82 
83  if (inValidInputRange)
84  {
85  inValidInputRange = (::ad::physics::Speed(-100.) <= input.speedLatMin) && (input.speedLatMin <= input.speedLatMax);
86  if (!inValidInputRange && logErrors)
87  {
88  spdlog::error(
89  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
90  input,
91  input.speedLatMin,
92  ::ad::physics::Speed(-100.),
93  input.speedLatMax); // LCOV_EXCL_BR_LINE
94  }
95  }
96 
97  if (inValidInputRange)
98  {
99  inValidInputRange = (input.speedLatMin <= input.speedLatMax) && (input.speedLatMax <= ::ad::physics::Speed(100.));
100  if (!inValidInputRange && logErrors)
101  {
102  spdlog::error(
103  "withinValidInputRange(::ad::rss::world::Velocity)>> {} element {} out of valid input range [{}, {}]",
104  input,
105  input.speedLatMax,
106  input.speedLatMin,
107  ::ad::physics::Speed(100.)); // LCOV_EXCL_BR_LINE
108  }
109  }
110 
111  return inValidInputRange;
112 }
Velocity.hpp
ad::rss::world::Velocity::speedLatMax
::ad::physics::Speed speedLatMax
Definition: Velocity.hpp:148
ad::rss::world::Velocity::speedLatMin
::ad::physics::Speed speedLatMin
Definition: Velocity.hpp:141
ad::rss::world::Velocity::speedLonMax
::ad::physics::Speed speedLonMax
Definition: Velocity.hpp:134
ad::rss::world::Velocity::speedLonMin
::ad::physics::Speed speedLonMin
Definition: Velocity.hpp:127
ad::rss::world::Velocity
DataType Velocity.
Definition: Velocity.hpp:47
withinValidInputRange
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