Skip to content

Add more details to roundRect proposal #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions spec/roundrect.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,39 @@ Proposal
--------

```webidl


interface mixin CanvasPath {
// all doubles are unrestricted.
void roundRect(double x, double y, double w, double h, sequence<double> radius);
void roundRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h, sequence<(unrestricted double or DOMPoint)> radii);
};
```

`radius` specifies the radius of corners. Each corner is represented by a single radius.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

radius has been renamed radii.


If `radius.length == 1` then all 4 corners have the same length.
If `radii.length == 1` then all 4 corners have the same length.

If `radii.length == 2` then the first value applies to the top-left and bottom-right corners, and the second value applies to the top-right and bottom-left corners.

If `radii.length == 3` then the first value applies to the top-left corner, the second value applies to the top-right and bottom-left corners, and the third value applies to the bottom-right corner.

If `radii.length == 4` then each corner is specified, in order: top-left, top-right, bottom-right, bottom-left.

If `w` and `h` are both greater than or equal to 0, or if both are smaller than 0, then the primitive is drawn clockwise. Otherwise, it is drawn conterclockwise.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: double space in "greater.than..or".

Also this [counter]clockwise thing sounds a bit open to interpretation and confusing. Wouldn't reusing a similar prose to the one for rect() be clearer? (defining which points are to be drawn in which order no matter the input's values).
I'm even wondering if I'm not missing the point and instead of just saying it should behave like current rect() it also says the radii order should be determined by this?


When `w` is negative, the rounded rectangle is flipped horizontally, which means that the radius values that apply to the left corners, are actual used on the right and vice versa. Similarly, when `h` is negative, the rounded rect is flipped vertically.

When a value `r` in `radii` is a `DOMPoint`, the corresponding corner(s) are drawn as elliptical arcs whose x and y radii are equal to `r.x` and `r.y`, respecively.

When a value `r` in `radii` is a `double`, the corresponding corner(s) are drawn as circular arcs of radius `r`.

When the sum of the radii of two corners of the same edge is greater than the length of the edge, the all the radii of the rounded rectangle are scaled by a factor of len/(r1+r2). If multiple edges have this property, the scale factor of the edge with the smallest scale factor is used. This is consistent with CSS behaviour.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "the all the radii" -> "then all the radii"


If a value in `radii` is a negative number, then roudRect() throws an `IndexSizeError` DOM Exception.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not in CSS nor even in Skia yet, but what about allowing concave angles? Would that be too much overhead?
As a web-author that sounds to me like something that could be useful, and I must admit I was a bit surprised / disappointed not later than yesterday when I tried to set a negative radius or DOMPoint going inward and saw it didn't work...


If a value in `radii` is a `DOMPoint` whose `x` or `y` attributes are negative numbers, then roundRect() throws an `IndexSizeError` DOM Exception.

If `radius.length == 4` then each corner is specified, in order: top left, top right, bottom right, bottom left.
If any of `x`, `y`, `width` or `height` ar non-finite numbers, or if a value in radii is a non-finite number, or if a value of `radii` is a DOMPoint who `x` or `y` attributes are non-finite numbers, the roundRect aborts without throwing an exception and without adding anything to the current path.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typos:
"ar" -> "are"
"who" -> "whose"

And while we're at typos, l13 also has one "Even thought" -> "Even though"



### Open issues and questions
Expand Down