Chrome 中的画布半圆错误解决方法

发布于 2024-12-19 10:02:25 字数 396 浏览 3 评论 0原文

看起来有人确实在 Chromium 论坛上提到了这个错误,但没有解决方案,所以我想知道是否有人知道解决方法。

问题是尝试使用 canvas 元素在 Chrome 中逆时针渲染半圆。相反,这会呈现一个完整的圆圈:

var ctx = document.getElementById('can').getContext('2d');
ctx.beginPath();
ctx.arc(50,50,50,0,Math.PI*3,true);
ctx.fill();
ctx.closePath();

这是一个小提琴,在非 chrome 中查看,然后在 chrome 中查看: fiddle

It looks like someone did mention this bug to the Chromium forums but there was no resolution so I'm wondering if anyone simply knows a workaround.

The issue is trying to render a half circle counter-clockwise in Chrome, using the canvas element. Instead this renders a full circle:

var ctx = document.getElementById('can').getContext('2d');
ctx.beginPath();
ctx.arc(50,50,50,0,Math.PI*3,true);
ctx.fill();
ctx.closePath();

Here is a fiddle, view in non-chrome, then in chrome: fiddle

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

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

发布评论

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

评论(1

記憶穿過時間隧道 2024-12-26 10:02:25

该错误可能源于 规范的这一部分

如果逆时针参数被省略或为 false 并且
endAngle-startAngle 等于或大于 2π,或者,如果
逆时针参数为 true 并且 startAngle-endAngle 等于或
大于2π,那么弧就是这个圆周的全周
圆圈。

Chrome 似乎不尊重该声明的第二部分(即,当逆时针true 时)。

为什么不标准化你的终点呢?

var end = 3 * Math.PI;
while (end > 2 * Math.PI) {
    end -= 2 * Math.PI;
}

The bug probably stems from this part of the spec:

If the anticlockwise argument is omitted or false and
endAngle-startAngle is equal to or greater than 2π, or, if the
anticlockwise argument is true and startAngle-endAngle is equal to or
greater than 2π, then the arc is the whole circumference of this
circle.

Chrome does not appear to respect the second part of that statement (i.e. when anticlockwise is true).

Why not normalize your end-point?

var end = 3 * Math.PI;
while (end > 2 * Math.PI) {
    end -= 2 * Math.PI;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文