为什么我应该使用浮动?

发布于 2024-08-31 11:09:33 字数 54 浏览 3 评论 0原文

我的意思是,对于像素位置、大小等。我不会制作一个 100 个半像素高的矩形。这些也可能是整数。

I mean, for pixel position, sizes, etc. It's not like I'll be making a rectangle that's 100 and a half pixels high. These might as well be integers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

默嘫て 2024-09-07 11:09:33

如果您绘制抗锯齿几何图形,则需要分数坐标。

如果底层 API 可能会重新调整您的几何图形以在各种屏幕上显示,则您需要分数坐标。

如果您希望能够告诉 API 旋转、缩放或剪切几何体,您需要分数坐标。

如果您希望能够将从 A 到 C 的一条线分成从 A 到 B 的一段和从 B 到 C 的一段,并将它们连接起来看起来就像原始线一样,那么您需要分数坐标。

如果您希望获得独立于底层显示硬件的低精度细节的几何图形的高精度内部表示,则需要分数坐标。

如果您的 API 现在不执行这些操作,但您需要它在下一版本中支持这些操作而不破坏兼容性,那么您需要分数坐标。

If you draw anti-aliased geometry, you need fractional coordinates.

If your geometry might be rescaled by the underlying API to display on a variety of screens you need fractional coordinates.

If you want to be able to tell the API to rotate, scale or shear your geometry you need fractional coordinates.

If you want to be able to break a line from A to C into a piece from A to B and a piece from B to C, and have them join up to look just like the original line, then you need fractional coordinates.

If you want to have a high precision internal representation of your geometry that's independent of the low precision details of the underlying display hardware, you need fractional coordinates.

If your API doesn't do these things now, but you need it to support these things in the next version without breaking compatibility, then you need fractional coordinates.

南烟 2024-09-07 11:09:33

也许你还不会。但随着更多分辨率的增加,苹果以自己的单位而不是像素来测量屏幕的事实可能会变得更加有用。

Not yet you won't, perhaps. But as more resolutions are added, the fact that Apple measure screens in their own units rather than pixels could become more useful in time.

花伊自在美 2024-09-07 11:09:33

对于简单的图形、窗口位置等,你是对的,你不需要它们。

对于更复杂的图形,它们是必要的,因为屏幕分辨率可能不够精细,无法正确显示您要显示的内容。将理想化的、部分的世界视图转变为具有有限数量像素的屏幕可以显示的东西被称为 光栅化,这是一个相当大的话题。

我始终将其视为模型-视图-控制器的一个极端示例:将您尝试绘制的内容与其在屏幕上绘制的方式解耦。

For simple graphics, window positions, etc, you're right, you don't need them.

For more complicated graphics, they're necessary because the screen resolution might not be fine enough to do justice to what you're trying to display. Turning an idealised, fractional view of the world into something that a screen with a finite number of pixels can display is known as rasterisation, and it's a pretty big topic.

I always see this as an extreme example of model-view-controller: decoupling what you're trying to draw from how it's being drawn on the screen.

网名女生简单气质 2024-09-07 11:09:33

某些坐标系统通过近似具有不同阴影的两个像素之间的位置来解释浮动坐标,以实现更平滑的动画并消除锯齿状边缘。

Some coordinate systems interpret float coordinates by approximating the location between two pixels with different shades to enable smoother animation and eliminate jagged edges.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文