MCPcopy Create free account
hub / github.com/davisking/dlib / put_in_range

Function put_in_range

dlib/algs.h:536–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534
535 template <typename T>
536 T put_in_range (
537 const T& a,
538 const T& b,
539 const T& val
540 )
541 /*!
542 requires
543 - T is a type that looks like double, float, int, or so forth
544 ensures
545 - if (val is within the range [a,b]) then
546 - returns val
547 - else
548 - returns the end of the range [a,b] that is closest to val
549 !*/
550 {
551 if (a < b)
552 {
553 if (val < a)
554 return a;
555 else if (val > b)
556 return b;
557 }
558 else
559 {
560 if (val < b)
561 return b;
562 else if (val > a)
563 return a;
564 }
565
566 return val;
567 }
568
569 // overload for double
570 inline double put_in_range(const double& a, const double& b, const double& val)

Callers 15

save_imageFunction · 0.85
solve_linear_mpcMethod · 0.85
angle_between_linesFunction · 0.85
poly_min_extrapFunction · 0.85
line_searchFunction · 0.85
backtracking_line_searchFunction · 0.85
perform_testMethod · 0.85
make_simple_test_dataFunction · 0.85
colormap_heatFunction · 0.85

Calls

no outgoing calls

Tested by 2

perform_testMethod · 0.68
make_simple_test_dataFunction · 0.68