maliput
RangeValidator< ErrorType > Class Template Reference

Detailed Description

template<typename ErrorType = maliput::common::assertion_error>
class maliput::common::RangeValidator< ErrorType >

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< ErrorType > 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< ErrorType > 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()

static RangeValidator<ErrorType> 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).
Template Parameters
ErrorTypeThe error type to be thrown.
Returns
A RangeValidator instance.
Exceptions
ErrorTypeWhen tolerance is non positive.
ErrorTypeWhen epsilon is not in [0, tolerance].
ErrorTypeWhen min + epsilon > max or max - epsilon < min

◆ GetRelativeEpsilonValidator()

static RangeValidator<ErrorType> 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.
Template Parameters
ErrorTypeThe error type to be thrown.
Returns
A RangeValidator instance.
Exceptions
ErrorTypeWhen tolerance is non positive.
ErrorTypeWhen epsilon is not in [0, tolerance].
ErrorTypeWhen min + epsilon > max or max - epsilon < min

◆ operator()()

double operator() ( double  s) const

Evaluates whether s is in range or not.

Parameters
svalue to check if it is in range.
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.
Exceptions
ErrorTypeif s is out of range.

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