Sometimes you need the angles to be represented only between 0..360, you probably seen functions like this one:
Code:
function OLDclamp360(angle: single): single;
begin
Result := angle;
while Result <0> 360 do
Result := Result - 360;
end;
Not only it's a bad code with a lot of branching that gets slower the bigger / smaller the numbers are, but there is a better / proper way:
Code:
function clamp360(angle: single): single;
begin
Result := angle;
if result > 360 then result:= result - (round(result) div 360 * 360);
if result < 0 then result:= 360 + result - (round(result) div 360 * 360);
end;
Bookmarks