Skip to content

Commit

Permalink
chore(api): Incorporate hints from Hamish about Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmth committed Dec 12, 2023
1 parent 486d89b commit 11e28a3
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions files/en-us/web/api/canvasrenderingcontext2d/arcto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ browser-compat: api.CanvasRenderingContext2D.arcTo

{{APIRef}}

The
**`CanvasRenderingContext2D.arcTo()`**
method of the Canvas 2D API adds a circular arc to the current sub-path, using the given
control points and radius. The arc is automatically connected to the path's latest point
with a straight line, if necessary for the specified parameters.
The **`CanvasRenderingContext2D.arcTo()`** method of the Canvas 2D API adds a circular arc to the current sub-path, using the given control points and radius.
The arc is automatically connected to the path's latest point with a straight line if necessary, for example if the control points are in a line.

This method is commonly used for making rounded corners.

> **Note:** Be aware that you may get unexpected results when using a
> **Note:** You may get unexpected results when using a
> relatively large radius: the arc's connecting line will go in whatever direction it
> must to meet the specified radius.
Expand All @@ -43,31 +40,11 @@ arcTo(x1, y1, x2, y2, radius)

None ({{jsxref("undefined")}}).

### Usage notes
### Exceptions

There are some special cases to consider when describing the action of
`arcTo()`. Let <em>P<sub>0</sub></em> be the current point on the path when
`arcTo()` is called, <em>P<sub>1</sub></em> = (x1, y1), and
<em>P<sub>2</sub></em> = (x2, y2) be the first and second control points
respectively, and _r_ = radius be the `radius` specified in the call.
- `IndexSizeError` {{domxref("DOMException")}}

- If _r_ is negative, it is an error, and an `IndexSizeError` [DOMException](/en-US/docs/Web/API/DOMException) is raised.

- If _r_ is 0, `arcTo()` behaves as if <em>P<sub>0</sub></em>,
<em>P<sub>1</sub></em>, and <em>P<sub>2</sub></em> are collinear (in a line).

- In the case of all of the points being collinear, a line from
<em>P<sub>0</sub></em> to <em>P<sub>1</sub></em> is drawn
unless the points <em>P<sub>0</sub></em> and <em>P<sub>1</sub></em> are
coincident (on top of each other), in which case nothing is drawn.

For the usual case of _r_ being positive and <em>P<sub>0</sub></em>,
<em>P<sub>1</sub></em>, and <em>P<sub>2</sub></em> not being collinear,
drawing always consists of an arc and possibly a line connecting the current
position on the path to that arc.
To visualize how this works, an interactive demo shows the
construction of the path generated by `arcTo()` in
[Construction of `arcTo()` path](#construction_of_arcto_path).
- : Thrown if `radius` is a negative value.

## Examples

Expand Down Expand Up @@ -207,15 +184,22 @@ ctx.stroke();

{{ EmbedLiveSample('Result_of_a_large_radius', 315, 165) }}

### Construction of arcTo() path
### Constructing an arcTo() path

The demo shows the semi-infinite lines and circle with center _C_ tangent
to the lines at <em>T<sub>1</sub></em> and <em>T<sub>2</sub></em> used to
determine the path rendered by `arcTo()`. Besides being able to set the arc radius with
the slider, the initial point <em>P<sub>0</sub></em> and control points
<em>P<sub>1</sub></em> and <em>P<sub>2</sub></em> can be moved by
dragging them with the mouse with the left button down. The numeric values can also
be edited, and the arrow keys can be used to change an underlined element that is in focus.
determine the path rendered by `arcTo()`.

Note that `arcTo` will create a straight line when <em>P<sub>1</sub></em>
and <em>P<sub>2</sub></em> are in a line. Additionally, nothing is drawn by
`arcTo` if <em>P<sub>1</sub></em> and <em>P<sub>2</sub></em> have the same
coordinates.

Besides being able to set the arc radius with the slider, the initial point
<em>P<sub>0</sub></em> and control points <em>P<sub>1</sub></em> and
<em>P<sub>2</sub></em> can be moved by dragging them with the mouse with the
left button down. The numeric values can also be edited, and the arrow keys
can be used to change an underlined element that is in focus.

```html hidden
<div>
Expand Down Expand Up @@ -997,7 +981,7 @@ label {
}
```

{{ EmbedLiveSample("Construction of arcTo() path", 350, 450) }}
{{ EmbedLiveSample("constructing_an_arcto_path", 350, 450) }}

### Animating `arcTo()` drawing

Expand Down Expand Up @@ -1072,7 +1056,7 @@ loop(0);

#### Result

{{EmbedLiveSample('Live_demo', 315, 200) }}
{{EmbedLiveSample('animating_arcto_drawing', 315, 200) }}

## Specifications

Expand Down

0 comments on commit 11e28a3

Please sign in to comment.