情况如下:
我们有一些通用图形代码用于我们的一个项目。在对代码进行了一些清理之后,似乎有些东西不再起作用(图形输出看起来完全错误)。
我对给出正确输出的最后一个代码版本进行了比较,看起来我们改变了我们的一个函数,如下所示:
static public Rectangle FitRectangleOld(Rectangle rect, Size targetSize)
{
if (rect.Width <= 0 || rect.Height <= 0)
{
rect.Width = targetSize.Width;
rect.Height = targetSize.Height;
}
else if (targetSize.Width * rect.Height >
rect.Width * targetSize.Height)
{
rect.Width = rect.Width * targetSize.Height / rect.Height;
rect.Height = targetSize.Height;
}
else
{
rect.Height = rect.Height * targetSize.Width / rect.Width;
rect.Width = targetSize.Width;
}
return rect;
}
到
static public Rectangle FitRectangle(Rectangle rect, Size targetSize)
{
if (rect.Width <= 0 || rect.Height <= 0)
{
rect.Width = targetSize.Width;
rect.Height = targetSize.Height;
}
else if (targetSize.Width * rect.Height >
rect.Width * targetSize.Height)
{
rect.Width *= targetSize.Height / rect.Height;
rect.Height = targetSize.Height;
}
else
{
rect.Height *= targetSize.Width / rect.Width;
rect.Width = targetSize.Width;
}
return rect;
}
我们所有的单元测试都通过了,除了一些语法快捷方式之外,代码中没有任何变化。但就像我说的,输出是错误的。我们可能只是恢复到旧代码,但我很好奇是否有人知道这里发生了什么。
谢谢。