Scalar-inl.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_MATH_SCALAR_INL_H
17 #define SURGSIM_MATH_SCALAR_INL_H
18 
20 
21 namespace SurgSim
22 {
23 namespace Math
24 {
25 
26 template <class T>
27 T clamp(T value, T min, T max, T epsilon)
28 {
29  return (value >= (max - epsilon) ? max : (value <= (min + epsilon) ? min : value));
30 }
31 
32 template <typename T>
33 const T clampOperator<T>::operator()(const T& x) const
34 {
35  return clamp(x, m_min, m_max, m_epsilon);
36 }
37 
38 };
39 };
40 
41 #endif // SURGSIM_MATH_SCALAR_INL_H
42 
SurgSim::Math::clamp
T clamp(T value, T min, T max, T epsilon)
Clamp any values within an epsilon window to a maximum or minimum value.
Definition: Scalar-inl.h:27
Assert.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Math::clampOperator::operator()
const T operator()(const T &x) const
Execute the clamp operator.
Definition: Scalar-inl.h:33