我正在编写一个简单的旋转例程,它将物体的旋转归一化为0到360度之间。我的 C# 代码似乎可以工作,但我并不完全满意。有人能够改进下面的代码,使其更加稳健吗?
public void Rotate(int degrees)
{
this.orientation += degrees;
if (this.orientation < 0)
{
while (this.orientation < 0)
{
this.orientation += 360;
}
}
else if (this.orientation >= 360)
{
while (this.orientation >= 360)
{
this.orientation -= 360;
}
}
}
if
语句可以先去掉。 - user16217248