Re: [csswg-drafts] [css-backgrounds] The shape of box-shadow should be a circle for a box with border-radius:50% and big spread (#7103)

The CSS Working Group just discussed `Border Radius Spread`.

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> Topic: Border Radius Spread<br>
&lt;TabAtkins> github: https://github.com/w3c/csswg-drafts/issues/7103<br>
&lt;TabAtkins> fantasai: I think we should have demos before we discuss this<br>
&lt;TabAtkins> Rossen_: oriol made those an hour ago<br>
&lt;TabAtkins> oriol: you can see a comparison of the different algos<br>
&lt;TabAtkins> oriol: i didn't find an algo that works perfectly for all<br>
&lt;TabAtkins> oriol: but maybe i'm leaning towards the last one in the demo<br>
&lt;bramus> https://people.igalia.com/obrufau/testcases/shadow-radius/<br>
&lt;TabAtkins> oriol: [demos]<br>
&lt;TabAtkins> oriol: first is no polyfill at all, browser does different things<br>
&lt;TabAtkins> oriol: this is chromium<br>
&lt;TabAtkins> oriol: here's current spec, where a ciruclar element is a non-ciruclar shadow'<br>
&lt;TabAtkins> oriol: here's another showing that same, with an ellipse<br>
&lt;TabAtkins> oriol: another algo is ot increase radius by spread<br>
&lt;TabAtkins> oriol: similar to firefox, but ff has a special case for 0 radius that isn't continuous<br>
&lt;TabAtkins> oriol: otherwise i'd say it's not a bad algo<br>
&lt;TabAtkins> oriol: there are some variant algos that take the border radius, express it as a percentage, then apply the same % to the shadow<br>
&lt;TabAtkins> oriol: good in some cases, but in this ellipse case it gets flat edges<br>
&lt;TabAtkins> oriol: using the maximum axis improves some cases but not all<br>
&lt;TabAtkins> oriol: ellipse is still flat<br>
&lt;TabAtkins> oriol: then my original proposal is each % is taken independently per axis<br>
&lt;Rossen_> q?<br>
&lt;TabAtkins> oriol: this works good i'd say, but has problem shown in this long roundrect,<br>
&lt;TabAtkins> oriol: where the shadow gets an elliptical corner when the original element was circular corner<br>
&lt;TabAtkins> oriol: so final variant, finds %s in each axis, then tries to, for each corner, if the radius has changed its aspect ratio relative to the element, it tries to increase one component to hit the same aspect-ratio<br>
&lt;TabAtkins> oriol: with the limitation that it prevents the radius from going to [???]<br>
&lt;TabAtkins> oriol: we have a restriction that the x component of top-left and top-right radius shouldn't exceed the width; the spec has an adjustment for that<br>
&lt;TabAtkins> oriol: so the constraint we apply here is we increase one component to restore the aspect ratio, without breaking this constraint<br>
&lt;TabAtkins> oriol: I think this is the best I could find<br>
&lt;TabAtkins> oriol: 0 radius gives square shadow, 1px gives mostly-square shadow<br>
&lt;TabAtkins> oriol: circle and ellipse are still pretty round<br>
&lt;lea> would be nice if one could input their own dimension/spread/radius values to see the result with the different algorithms<br>
&lt;TabAtkins> oriol: circular corners stay circular on the shadow even with long rects<br>
&lt;TabAtkins> oriol: in this example (a "cup" shape) the shadow looks like it becomes thinner, but it is the same arc in both the shape and the shadow<br>
&lt;TabAtkins> oriol: So this is the best idea I could find<br>
&lt;TabAtkins> oriol: if people want to play with this they can look at the source, it's a standalone page<br>
&lt;TabAtkins> oriol: [explains how to modify the demo]<br>
&lt;TabAtkins> Rossen_: fantastic, thansk fo rputting in the time for this<br>
&lt;lea> but yes, so great to have a demo! thanks oriol!<br>
&lt;TabAtkins> dbaron: I was looking at the cases where you said your preferred algo wasn't great<br>
&lt;TabAtkins> dbaron: I agree it's not that great, like the 3rd fro mthe end case<br>
&lt;TabAtkins> dbaron: it seems what the algo is doing wrong is producing too large a radius<br>
&lt;TabAtkins> dbaron: don't know why<br>
&lt;TabAtkins> dbaron: the problem there is the radius we're ending up with seems larger than it should be<br>
&lt;TabAtkins> oriol: both arcs are circular<br>
&lt;TabAtkins> oriol: inner element has border-radius of 39/39<br>
&lt;TabAtkins> oriol: shadow has border radius of 107/107<br>
&lt;TabAtkins> oriol: so x and y components are equal<br>
&lt;Rossen_> a/fo rputting/for putting/<br>
&lt;TabAtkins> oriol: almost no radius in the top left, and the shadow similarly has almost no radius there<br>
&lt;vmpstr> q+<br>
&lt;Rossen_> ack dbaron<br>
&lt;Rossen_> ack fantasai<br>
&lt;TabAtkins> fantasai: last time we discussed this i wanted to ask if it's posibble alternative...<br>
&lt;TabAtkins> fantasai: we have a formula in the spec, and the original proposal that's to use the same %s<br>
&lt;TabAtkins> fantasai: so, should we decide which formula to use based on whether the original radius was expressed in lengths or %s?<br>
&lt;TabAtkins> fantasai: so if you have oval that's 50%, the spread would also be 50%<br>
&lt;TabAtkins> fantasai: whereas if it was 200px/100px, we'd use the old formula<br>
&lt;vmpstr> q-<br>
&lt;TabAtkins> fantasai: So rather than just doing math on the absolute value, carry over the initial intent<br>
&lt;TabAtkins> fantasai: looking at these tests, the ones that look bad in the old formula are the ones where the length of the straight part of the border are 0 or close<br>
&lt;TabAtkins> fantasai: whereas the bad ones for %s are where the straight side is pretty long<br>
&lt;TabAtkins> fantasai: so we could have two different formulas, using one when the straight side is 0 or the other when large<br>
&lt;TabAtkins> fantasai: and between the two for some distance, such as radius = straight side to 0, we interpolate the formulas<br>
&lt;TabAtkins> oriol: re: the first thing, choosing the algo depending on whether the author specified length or %<br>
&lt;TabAtkins> oriol: I didn't consider that<br>
&lt;TabAtkins> oriol: issue is you can get the same shape in either way<br>
&lt;TabAtkins> oriol: seems strange to have two equivalent shapes for th eleemnet can produce different shadows<br>
&lt;Rossen_> q<br>
&lt;TabAtkins> fantasai: yeah but consider i have an element that's short, and the border-radius makes a semicircle, i might want that becuase i want a pillshaped box<br>
&lt;lea> q?<br>
&lt;lea> q+<br>
&lt;TabAtkins> fantasai: *or* it might be a consequence of this box being short, and i have a set of boxes with rounded corners and straight sides, so i'd prefer the shadow generally to have straight sides<br>
&lt;TabAtkins> fantasai: dunno if it's a great idea. authors might not think about their intent, and isntead just shove in numbers that get a result<br>
&lt;TabAtkins> oriol: could be a possibility<br>
&lt;TabAtkins> oriol: didn't consider it, to have it differentiate would have to [missed]<br>
&lt;TabAtkins> oriol: re: the other thing about combining algos<br>
&lt;TabAtkins> oriol: you were mentioning the old algo, what browsers used to do and firefox still does<br>
&lt;TabAtkins> fantasai: my understanding is chrome updated to current spec and realized there were problems<br>
&lt;TabAtkins> fantasai: the cases that work poorly are those where you want to get a round shape<br>
&lt;TabAtkins> fantasai: in those %s work great<br>
&lt;TabAtkins> fantasai: but they work bad for rounded corners on a rectangular shape, that's where current spec works well<br>
&lt;TabAtkins> fantasai: so using both formulas and interpolating might be a way to get good results in more cases<br>
&lt;TabAtkins> oriol: but then how do you do this interpolation?<br>
&lt;TabAtkins> fantasai: you look at the straight side, if it's 0 you use % formula. if it's longer than the radius, use the old formula. between those two, you do linear interp<br>
&lt;TabAtkins> lea: not super confident since this is the first time iv'e seen this<br>
&lt;TabAtkins> lea: but looking thru these algos<br>
&lt;TabAtkins> lea: as an author, anything with a % produces surprising results in some cases<br>
&lt;TabAtkins> lea: the one that produces th eleast surprise, to me at least, is to increase radius by spread<br>
&lt;TabAtkins> lea: except that it produces round from 0 radius<br>
&lt;TabAtkins> lea: this was chrome's behavior before they changed?<br>
&lt;TabAtkins> oriol: yes, firefox has a discontinuity at 0<br>
&lt;TabAtkins> lea: so maybe bc i was used to previous behavior, this makes sense to me<br>
&lt;TabAtkins> lea: is discontinuity acceptable?<br>
&lt;TabAtkins> oriol: another possibility is adding another initial value like "none" which keeps the shadow straight<br>
&lt;emilio> q+<br>
&lt;TabAtkins> fantasai: if you think about this in terms of being a drop shadow, instaed of a way to get a rounded corner outline, th eresults of "increase radius by spread" the results are clearly pretty unreasonable<br>
&lt;TabAtkins> fantasai: If you switch to current spec it looks a little more like an actual shadow<br>
&lt;TabAtkins> fantasai: the problem with current spec is the case with circles and ovals<br>
&lt;TabAtkins> lea: so you're proposing neither of these<br>
&lt;TabAtkins> fantasai: I'm proposing using current spec for first three cases, % of side in the next two, and some interp in the rest<br>
&lt;TabAtkins> fantasai: so formula i'm suggesting would be... 5th and 6th case would be current spec<br>
&lt;TabAtkins> fantasai: 7th case would get you a combo, one axis would use each<br>
&lt;TabAtkins> fantasai: second to last would be %<br>
&lt;TabAtkins> lea: I think it's hard to picture how it looks<br>
&lt;Rossen_> q<br>
&lt;TabAtkins> fantasai: yeah i can code it up<br>
&lt;TabAtkins> lea: I think we should definitely avoid that if you ahve a fully curved shape, the sahdow should have any straight edges<br>
&lt;TabAtkins> fantasai: right, that's the issue we're trying to solve<br>
&lt;TabAtkins> emilio: the othe rplace where this pops up is outlines<br>
&lt;TabAtkins> emilio: do you propose to change both?<br>
&lt;TabAtkins> fantasai: both seems reasonable<br>
&lt;Rossen_> ack emilio<br>
&lt;TabAtkins> emilio: you're right that firefox's behavior for second case doesn't make sense for shadows, but i think it makes sense for an outline<br>
&lt;TabAtkins> TabAtkins: right i think outline is like a border<br>
&lt;TabAtkins> emilio: so right now outline works like a border<br>
&lt;TabAtkins> fantasai: so there's a discontinuity at zero<br>
&lt;TabAtkins> Rossen_: spec has a cubic interpolation<br>
&lt;TabAtkins> fantasai: been in spec for a long time, chrome just implemented it and discovered problems<br>
&lt;TabAtkins> fantasai: so i think using whateer we end up for spread readius would probably look good, but i think having continuous behavior generally is also pretty good<br>
&lt;TabAtkins> fantasai: so might want to use same for both<br>
&lt;Rossen_> ack dbaron<br>
&lt;TabAtkins> dbaron: first to emilio, i'm in favor of having a single algo in CSS for expanding a rounded rect<br>
&lt;TabAtkins> dbaron: that is the direction i was pushing when i code-reviewed the patch that led to this in the first place<br>
&lt;emilio> +1 to have a single algorithm<br>
&lt;TabAtkins> dbaron: I'd like us to be consistent in inflation<br>
&lt;TabAtkins> dbaron: the othe rpoint about inflating rounded rects, is you always start fro mthe border edge and do a single inflation<br>
&lt;TabAtkins> dbaron: you never do it from another algo<br>
&lt;TabAtkins> dbaron: because inflate(10)+inflate(10) might be different than inflate(20), and certainly inflate(10)+inflate(-10) is definitely not the identity<br>
&lt;TabAtkins> dbaron: can avoid problems by starting from the border edge always<br>
&lt;fantasai> DBaron Principle of Rounded Rectangle Flation<br>
&lt;TabAtkins> dbaron: one reason to keep these consistent is people might have both at the same time<br>
&lt;TabAtkins> dbaron: if outline and shadow use different algos, that'll look bad<br>
&lt;TabAtkins> dbaron: i think we'll be okay with a single algo<br>
&lt;Rossen_> q<br>
&lt;TabAtkins> dbaron: looking thru oriol's demos, i think the best results generally come from option 2 or 3<br>
&lt;TabAtkins> dbaron: while i understand the goal was to find the right compromise between 2 and 3, i think the % options din't really work out<br>
&lt;TabAtkins> dbaron: i think the goal should be to find the right way to compromise between those two<br>
&lt;TabAtkins> dbaron: there's also the 2-variant that is what browsers did before, which has the 0 discontinuity<br>
&lt;TabAtkins> dbaron: so maybe a comp between 2v and 3<br>
&lt;fantasai> TabAtkins: next steps, code up fantasai's idea<br>
&lt;fantasai> TabAtkins: anyone with other ideas, put them in the demo as well<br>
&lt;fantasai> TabAtkins: revisit in 2 weeks to decide?<br>
&lt;TabAtkins> Rossen_: again, thanks to oriol for the demo<br>
&lt;emilio> oriol++<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7103#issuecomment-1204355391 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 3 August 2022 18:56:50 UTC