maliput
RangeValidator Class Reference

Detailed Description

Functor to validate if a number is within [min, max] and considering assuming a tolerance.

This tolerance extends the range to be [min - tolerance, max + tolerance]. The functor not only validates that number is within the range, but also adapts it to be in the interval (min, max) where the difference between the close and open range is epsilon. This functor is motivated to wrap MALIPUT_VALIDATE() calls plus a std::clamp() to avoid throws for numerical errors.

#include <include/maliput/common/range_validator.h>

Public Member Functions

 RangeValidator ()=delete
 
double operator() (double s) const
 Evaluates whether s is in range or not. More...
 

Static Public Member Functions

static RangeValidator GetRelativeEpsilonValidator (double min, double max, double tolerance, double epsilon)
 Creates a RangeValidator instance that uses a relative epsilon to validate the values. More...
 
static RangeValidator GetAbsoluteEpsilonValidator (double min, double max, double tolerance, double epsilon)
 Creates a RangeValidator instance that uses a epsilon as the absolute epsilon to validate the values. More...
 

Constructor & Destructor Documentation

◆ RangeValidator()

RangeValidator ( )
delete

Member Function Documentation

◆ GetAbsoluteEpsilonValidator()

RangeValidator GetAbsoluteEpsilonValidator ( double  min,
double  max,
double  tolerance,
double  epsilon 
)
static

Creates a RangeValidator instance that uses a epsilon as the absolute epsilon to validate the values.

Parameters
minlower extreme of the range.
maxupper extreme of the range.
toleranceis the range extension to be accepted.
epsilonis minimum difference that separates a number within the range to be distinct from range extremes (min and max).
Returns
A RangeValidator instance.
Exceptions
maliput::common::assertion_errorWhen tolerance is non positive.
maliput::common::assertion_errorWhen epsilon is not in [0, tolerance].
maliput::common::assertion_errorWhen min + epsilon > max or max - epsilon < min

◆ GetRelativeEpsilonValidator()

RangeValidator GetRelativeEpsilonValidator ( double  min,
double  max,
double  tolerance,
double  epsilon 
)
static

Creates a RangeValidator instance that uses a relative epsilon to validate the values.

This relative epsilon is computed by multiplying epsilon by the range.

Parameters
minlower extreme of the range.
maxupper extreme of the range.
toleranceis the range extension to be accepted.
epsilonis the relative minimum difference that separates a number within range to be distinct from extremes. It is relative to the range.
Returns
A RangeValidator instance.
Exceptions
maliput::common::assertion_errorWhen tolerance is non positive.
maliput::common::assertion_errorWhen epsilon is not in [0, tolerance].
maliput::common::assertion_errorWhen min + epsilon > max or max - epsilon < min

◆ operator()()

double operator() ( double  s) const

Evaluates whether s is in range or not.

Returns
s when it is within the open range. If s is equal to either range extremes or the difference to them is less or equal to tolerance, it returns the closest open range value. Otherwise, it
Exceptions
maliput::common::assertion_error.

The documentation for this class was generated from the following files: