[whatwg] Canvas - Exception on arc with negative radius

Ian Hickson ian at hixie.ch
Tue Apr 28 17:53:16 PDT 2009

On Fri, 27 Mar 2009, Dirk Schulze wrote:
> why does the spec want an INDEX_SIZE_ERR exception on arc's with a 
> negative radius?

Because it is indicative of a fundamental error. Calculations involving 
radii should never be able to go negative.

> Another example is: 
> http://blahbleh.com/molecools.php?name=1,2%20dimethylcyclopropane
> If you turn the molecule a bit, the circles disappear with a
> INDEX_SIZE_ERR exception.

Why is this sometimes calculating negative radii?

> Isn't it better to just ignore the arc and go on with the drawing, like 
> Firefox does? And perhaps the same for arcTo?

There are three places where there are radii: gradients, arc(), and 

On Fri, 27 Mar 2009, Martin Atkins wrote:
> Assuming that we desire a "do what I mean" approach, it seems sane to me 
> for a negative radius to be normalized to a positive radius with the 
> same magnitude.
> It goes from being the distance from the center to the edge to being the 
> distance from the center to the "opposite" edge.
> You might also like to visualize this as drawing the "back" of the 
> circle.

That's one option.

On Sun, 29 Mar 2009, Dirk Schulze wrote:
> A negative value doesn't mean, that you want an arc. They can happen 
> during the automatic calculation process. There is no reason, that a 
> developers takes negative values and wants to see an arc otherwise he 
> could cut of the sign.

Well then why would there be a negative value?

> I'm just speaking of ignoring negative arcs instead of giving an 
> exception to continue further drawings.

It's unclear why this would be better.

On Sun, 29 Mar 2009, Oliver Hunt wrote:
> I commented to the list on this issue some time ago (and a number of the 
> APIs were updated base don my comments);  in general developers do not 
> expect graphics libraries to throw exceptions, especially for values 
> that are frequently computed.  We've had numerous cases where webkit has 
> had to relax exception logic in canvas (having tightened it to match 
> spec) where the result has been broken sites and widgets (alas the 
> webkit and mozilla canvas implementations do have some edge case where 
> one throws and the other does not), i believe the most consistent 
> approach will be to fail silently when given invalid, but finite 
> arguments to any given API.  The alternative is that certain APIs will 
> relax (regardless of spec), whereas others will not, leading to a more 
> or less random combination of throw vs. no throw on invalid arguments.

Generally most exceptions in the canvas API have been dropped; the only 
ones remaining are for cases where there really doesn't seem to be a good 
reason why you'd ever pass that value.

When faced with negative radii: Gecko throws an exception for arcTo(), 
ignores the call for arc(), and uses the magnitude of the radii for 
createRadialGradient(); Webkit throws for arcTo() and arc() and does 
something I couldn't understand for createRadialGradient(); and Opera 
throws an exception for all three.

I haven't changed the spec, which says to throw an exception for all 
three, since that's the change that results in the fewest changes to 
browser implementations.

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list