使用SVG路径,我们可以绘制99.99%的圆形并显示出来,但是当它是99.99999999%的圆形时,圆形就不会显示出来。如何解决?
以下SVG路径可以绘制99.99%的圆形:
var paper = Raphael(0, 0, 300, 800);
// Note that there are supposed to be 4 arcs drawn, but you may see only 1, 2, or 3 arcs depending on which browser you use
paper.path("M 100 100 a 50 50 0 1 0 35 85").attr({stroke: "#080", opacity: 1, "stroke-width" : 6}) // this is about 62.5% of a circle, and it shows on most any browsers
paper.path("M 100 210 a 50 50 0 1 0 0.0001 0").attr({stroke: "#080", opacity: 1, "stroke-width" : 6}) // this one won't show anything if it is IE 8's VML, but will show if it is Chrome or Firefox's SVG. On IE 8, it needs to be 0.01 to show
paper.path("M 100 320 a 50 50 0 1 0 0.0000001 0").attr({stroke: "#080", opacity: 1, "stroke-width" : 6}) // this one won't draw anything at all, unless you change the 0.0000001 to 0.0001 on Chrome or Firefox... Safari will show it though...
paper.path("M 100 430 a 50 50 0 1 0 0 0").attr({stroke: "#080", opacity: 1, "stroke-width" : 6}) // this is 100% of a circle... even Safari won't show it
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
M 100 100 a 50 50 0 1 0 0.00001 0
但当它是圆的99.99999999%时,什么也不会显示出来吗?
M 100 100 a 50 50 0 1 0 0.00000001 0
同样的,对于一个圆来说也是如此(它仍然是一段弧线,不是吗,只不过是非常完整的一段弧线)
M 100 100 a 50 50 0 1 0 0 0
如何解决这个问题?原因是我使用了一个函数来画圆弧的百分比,如果我需要"特殊处理"一个99.9999%或100%的圆弧来使用圆形函数,那就有点傻了。
再次声明,上面有一个测试用例(如果在IE 8上是VML,则甚至第二个圆也不会显示...你必须将其更改为0.01)。
更新:
这是因为我们的系统中正在渲染得分的弧线,所以3.3分得到1/3的圆。0.5得到一半的圆,而9.9分得到99%的圆。但是,如果我们的系统中有得分是9.99怎么办?我是否需要检查它是否接近于99.999%的圆,然后相应地使用arc
函数或circle
函数?那么对于得分为9.9987的情况呢?该使用哪一个?需要知道哪些得分将映射到一个“太完整的圆”并切换到圆形函数,以及何时是“某个99.9%的”圆或9.9987的分数,然后使用圆弧函数,这是荒谬的。