2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_BOUNDSCHECKING
|
|
|
|
#define OSG_BOUNDSCHECKING 1
|
|
|
|
|
|
|
|
#include <osg/Notify>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** If value is greater than or equal to minValue do nothing - legal value,
|
|
|
|
* Otherwise set value to minValue, and warn that valueName was clamped.
|
|
|
|
* Note this is effectively A=max(A,B). */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampGEQUAL(T& value,const T minValue,const char* valueName)
|
|
|
|
{
|
|
|
|
if (value<minValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value = minValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** If value is less than or equal to maxValue do nothing - legal value,
|
|
|
|
* Otherwise set value to maxValue, and warn that valueName was clamped.
|
|
|
|
* Note this is effectively A=min(A,B). */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampLEQUAL(T& value,const T maxValue,const char* valueName)
|
|
|
|
{
|
|
|
|
if (value>maxValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value = maxValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** If value is between or equal to minValue and maxValue do nothing - legal
|
|
|
|
* value, Otherwise clamp value to specified range and warn that valueName
|
2015-06-01 21:40:20 +08:00
|
|
|
* was clamped. Equivalent to calling
|
2004-09-07 18:07:11 +08:00
|
|
|
* clampGEQUAL( value, minValue, valueName );
|
|
|
|
* clampLEQUAL( value, maxValue, valueName ); */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampBetweenRange(T& value,const T minValue,const T maxValue,const char* valueName)
|
|
|
|
{
|
|
|
|
if (value<minValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value = minValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (value>maxValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value = maxValue;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** If value[i] is greater than or equal to minValue do nothing - legal value,
|
|
|
|
* Otherwise set value[i] to minValue, and warn that valueName[i] was clamped.
|
|
|
|
* Note this is effectively A[i]=max(A[i],B). */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void clampArrayElementGEQUAL(A& value,unsigned int i,const T minValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
if (value[i]<minValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value[i] = minValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** If value[i] is less than or equal to maxValue do nothing - legal value,
|
|
|
|
* Otherwise set value[i] to maxValue, and warn that valueName[i] was clamped.
|
|
|
|
* Note this is effectively A[i]=min(A[i],B). */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void clampArrayElementLEQUAL(A& value,unsigned int i,const T maxValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
if (value[i]>maxValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value = maxValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** If value[i] is between or equal to minValue and maxValue do nothing - legal
|
|
|
|
* value, Otherwise clamp value[i] to specified range and warn that
|
2015-06-01 21:40:20 +08:00
|
|
|
* valueName[i] was clamped. Equivalent to calling
|
2004-09-07 18:07:11 +08:00
|
|
|
* clampArrayElementGEQUAL( value, i, minValue, valueName );
|
|
|
|
* clampArrayElementLEQUAL( value, i, maxValue, valueName ); */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void clampArrayElementBetweenRange(A& value,unsigned int i,const T minValue,const T maxValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
if (value[i]<minValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clamping to "<<minValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value[i] = minValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (value[i]>maxValue)
|
|
|
|
{
|
2015-07-21 21:42:22 +08:00
|
|
|
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clamping to "<<maxValue<<"."<< std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
value[i] = maxValue;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of value[] in the range (first,last), if the element is
|
|
|
|
* greater than or equal to minValue do nothing - legal value, Otherwise
|
|
|
|
* clamp the element to minValue, and warn that valueName[i] was clamped. */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void clampArrayElementsGEQUAL(A& value,unsigned int first,unsigned int last,const T minValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
for(unsigned int i=first;i<=last;++i)
|
|
|
|
clampArrayElementGEQUAL(value,i,minValue,valueName);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of value[] in the range (first,last), if the element is
|
|
|
|
* less than or equal to maxValue do nothing - legal value, Otherwise clamp
|
|
|
|
* the element to maxValue, and warn that valueName[i] was clamped. */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void clampArrayElementsLEQUAL(A& value,unsigned int first,unsigned int last,const T maxValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
for(unsigned int i=first;i<=last;++i)
|
|
|
|
clampArrayElementLEQUAL(value,i,maxValue,valueName);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of value[] in the range (first,last), if the element is
|
|
|
|
* between or equal to minValue and maxValue do nothing - legal value,
|
|
|
|
* Otherwise clamp the element to the range and warn that valueName[i] was
|
|
|
|
* clamped. Equivalent to calling
|
|
|
|
* clampArrayElementsGEQUAL( value, first, last, minValue, valueName);
|
|
|
|
* clampArrayElementsLEQUAL( value, first, last, maxValue, valueName); */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void clampArrayElementsBetweenRange(A& value,unsigned int first,unsigned int last,const T minValue,const T maxValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
for(unsigned int i=first;i<=last;++i)
|
2012-03-22 01:36:20 +08:00
|
|
|
clampArrayElementBetweenRange(value,i,minValue,maxValue,valueName);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of the three-element array value[], if the element is
|
|
|
|
* greater than or equal to minValue do nothing - legal value, Otherwise
|
|
|
|
* clamp the element to minValue, and warn that valueName[i] was clamped. */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampArray3GEQUAL(A& value,const T minValue,const char* valueName)
|
|
|
|
{
|
|
|
|
clampArrayElementsGEQUAL(value,0u,2u,minValue,valueName);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of the three-element array value[], if the element is
|
|
|
|
* less than or equal to maxValue do nothing - legal value, Otherwise clamp
|
|
|
|
* the element to maxValue, and warn that valueName[i] was clamped. */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampArray3LEQUAL(A& value,const T maxValue,const char* valueName)
|
|
|
|
{
|
|
|
|
clampArrayElementsLEQUAL(value,0u,2u,maxValue,valueName);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of the three-element array value[], if the element is
|
|
|
|
* between or equal to minValue and maxValue do nothing - legal value,
|
|
|
|
* Otherwise clamp the element to the range and warn that valueName[i] was
|
|
|
|
* clamped. Equivalent to calling
|
|
|
|
* clampArray3GEQUAL( value, minValue, valueName);
|
|
|
|
* clampArray3LEQUAL( value, maxValue, valueName); */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampArray3BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
|
|
|
|
{
|
|
|
|
clampArrayElementsBetweenRange(value,0u,2u,minValue,maxValue,valueName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of the four-element array value[], if the element is
|
|
|
|
* greater than or equal to minValue do nothing - legal value, Otherwise
|
|
|
|
* clamp the element to minValue, and warn that valueName[i] was clamped. */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampArray4GEQUAL(A& value,const T minValue,const char* valueName)
|
|
|
|
{
|
|
|
|
clampArrayElementsGEQUAL(value,0u,3u,minValue,valueName);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of the four-element array value[], if the element is
|
|
|
|
* less than or equal to maxValue do nothing - legal value, Otherwise clamp
|
|
|
|
* the element to maxValue, and warn that valueName[i] was clamped. */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2004-09-07 18:31:30 +08:00
|
|
|
inline void clampArray4LEQUAL(A& value,const T maxValue,const char* valueName)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
clampArrayElementsLEQUAL(value,0u,3u,maxValue,valueName);
|
|
|
|
}
|
|
|
|
|
2004-09-07 18:07:11 +08:00
|
|
|
/** For each element of the four-element array value[], if the element is
|
|
|
|
* between or equal to minValue and maxValue do nothing - legal value,
|
|
|
|
* Otherwise clamp the element to the range and warn that valueName[i] was
|
|
|
|
* clamped. Equivalent to calling
|
|
|
|
* clampArray4GEQUAL( value, minValue, valueName);
|
|
|
|
* clampArray4LEQUAL( value, maxValue, valueName); */
|
2005-01-27 19:18:33 +08:00
|
|
|
template <typename A, typename T>
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void clampArray4BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
|
|
|
|
{
|
|
|
|
clampArrayElementsBetweenRange(value,0u,3u,minValue,maxValue,valueName);
|
|
|
|
}
|
|
|
|
|
2002-02-23 01:12:10 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|