Suggestion: Template specialisation for CRange<CRadians>
Posted: Thu Jun 14, 2012 3:07 pm
Hi All,
I've come across a problem in ARGoS that I am going to make a patch for, however I would like to get some feedback first.
The patch will create a specialised version of the CRange template for types CRadians and CDegrees. Consider the following scenario to understand my motivation for this.
I would like to specify a range that is plus-minus an offset angle from an variable angle as an input. Creating the object using ARGoS libraries would look like this:
Now If I choose to represent angles from 0-->2pi, I have a problem such that if; InputAngle < OFFSET_ANGLE_CONST the lower bound will wrap around. This causes one of two problems, firstly the lower bound is greater than the upperbound, or secondly if the bounds were switched around, we would be actually talking about the exterior range instead of the interior range that was the target interval.
I propose that I fix this problem using template specialisation. A well known use of template specialisation is the std::vector specialisation for the type bool. Using template specialisation I can build the intelligence into CRange for the types CRange<CRadians> and CRange<CDegrees> such that we fix this problem.
Cheers,
I've come across a problem in ARGoS that I am going to make a patch for, however I would like to get some feedback first.
The patch will create a specialised version of the CRange template for types CRadians and CDegrees. Consider the following scenario to understand my motivation for this.
I would like to specify a range that is plus-minus an offset angle from an variable angle as an input. Creating the object using ARGoS libraries would look like this:
Code: Select all
CRange<CRadians> MyRange( InputAngle - OFFSET_ANGLE_CONST, InputAngle + OFFSET_ANGLE_CONST)
I propose that I fix this problem using template specialisation. A well known use of template specialisation is the std::vector specialisation for the type bool. Using template specialisation I can build the intelligence into CRange for the types CRange<CRadians> and CRange<CDegrees> such that we fix this problem.
Cheers,