问题描述
我绘制插补曲线正是如此:
I am rendering an interpolation curve thusly:
e.Graphics.DrawLines(new Pen(Color.Red), _interpolationPoints.ToArray());
有时会抛出一个发生OverflowException。
which sometimes throws an OverflowException.
考试的_interpolationPoints阵列显示科学记数法,例如一些非常大的值{X = 0.0 Y = -1.985174E + 10}
Examination of the _interpolationPoints array shows some very large values in scientific notation e.g. {X = 0.0 Y = -1.985174E+10}
我怀疑Y = -1.985174E + 10是一个值,GDI +无法处理。这很好,但什么是最大/最小的X和Y值转换,我可以借鉴,因此限制了数据(并警告用户),而不是捕捉油漆中的溢出异常?是限制文档?
I suspect that Y = -1.985174E+10 is a value that GDI+ cannot handle. That's fine but what are the max/min X and Y values into which I can draw and so constrain the data (and warn the user) rather than catching the overflow exception during paint? Are the limits documented?
例如,我愿做这样的事情:
For example, I would like to do something like this:
if (yVal < float.MinValue || yval > float.MaxValue)
throw new OverflowException("Interpolation value too large to be rendered.");
在_interpolationPoints阵列的人口和停止进程。 (浮点混合/ Max不BTW工作,我仍然可以例外。)
during the population of the _interpolationPoints array and stop the process. (float mix/max does not work btw. i still get the exception.)
推荐答案
确定,我需要知道,所以我测试增量,并提出了这些限制:
OK, I needed to know so I tested incrementally and came up with these limits:
positive: 1,073,741,951
negative: -1,073,741,760
在code我用看起来是这样的:
The code I used looked something like this:
int lastGoodVal = 0;
for (int i = -1073000000; i > -1073832999; i -= 1)
{
g.DrawLine(Pens.Blue, new Point(0,0), new Point(0, i));
lastGoodVal = i;
}
环路上面是最终的测试,由1步,通过一系列由早期的测试建立负值。正如你所看到的,lastGoodVal保持最后的成功画迭代,因此,真正的限制,我会为一个常量使用。
The loop above was the final test, stepping by 1, through a range of negative values established by earlier tests. As you can see, lastGoodVal holds the last successful painting iteration and therefore the real limit which I'll use as a constant.
我试图在.NET元,这些数字与价值,但不能。每次限值为接近2 ^ 30的值,但并不完全就可以了。任何其他有识之士将是非常美联社preciated。
I tried to correlate these numbers to a value in the .NET primitives but couldn't. Each limit is close to the value of 2^30 but is not exactly on it. Any other insight would be much appreciated.
我也只能用DrawLine的方法进行测试。这有可能是不同的限制API中的其他功能存在,但我还没有机会去探索呢。
I also only tested with the DrawLine method. It's possible that different limits exist for other functions in the API but I have not had a chance to explore that yet.
此外,在完成这个实验,然后谷歌搜索的价值1073741951后,我整个来到这篇文章其相关我的发现。我也发现这个的一些单声道code档案排序其中提到近,虽然没有确切的相关性浮动范围。
Also, after finishing this experiment and then Googling for the value 1073741951 I came across this article which correlates my findings. I also found this in a Mono code archive of some sort which mentions a near, though not exact correlation to float limits.
这篇关于什么是GDI +中绘制坐标硬边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!