# Re: [css3-flexbox] Updates to Resolving Flexible Sizes

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 30 Apr 2012 11:42:59 -0700
Message-ID: <CAAWBYDB-1Lb9KmM__BGRBxHeBrgkmxsE-6dk7FBsu3bFuS=y4A@mail.gmail.com>
To: Alex Mogilevsky <alexmog@microsoft.com>
```On Wed, Apr 25, 2012 at 7:35 AM, Alex Mogilevsky <alexmog@microsoft.com> wrote:
> Sent: Tuesday, April 24, 2012 6:26 PM
> ±    3. The zero clause only exits if the free space is also zero.
> ±       Previously you could exit with undistributed free space.
>
> How could that happen? At step 3 of the algorithm, we've distributed all available space, total item size must be equal to total available space.
>
> Then at step 4 we've fixed min/max and added up deltas from that. If the total change from fixing min/max is zero, it means total size has not changed, which means it is still equal to available space...
>
> What am I not getting here?
>
> I suppose that can happen when there are no flexible items, but the algorithm should just check that in step 1 and exit (which it doesn't).

We've added an early-exit clause so that the "no flexible items" case
gets caught early.

You're right - I did the math wrong, and you can't get zero violations
and still have free space left over.

> ±    4. Loop begins with determining the sign of the flexibility again.
> ±       This is necessary if freezing violations flips the sign of the
> ±       free space.
>
> I think it is a good change, but then the sizes being added up shouldn't get clamped with min/max. With clamping it will always get the same sign, but I don't think it is what you want.
>
> We came up with the first step for flexibility sign because we were not sure that alternating flexibility will always converge. It was easier to see that it will converge if the sign never changes. But I don't think that fear was justified.
>
> You seem to be OK with alternating sign too, then the sign should be calculated based on current iteration.
>
> A way to prove that the algorithm converges, without guessing flex direction up-front:
> * Each additional iteration is invoked only after one or more items lose flexibility
> * When there is no flexible items left, the algorithm will exit
> (for this proof to be true, 'zero' clause has to either always exit or only proceed if it managed to freeze something)

You're right that the choice of which flexibility to use can't change
in different steps of the algo.  I've made it skip that step when it
resets.

> In step 3, the condition "If the sign of the free space matches the sign of the flexibility," also seems unnecessary. It matches the approach of defining flex sign once per algorithm, but then if flex sign can change within the algorithm, it should be ok that it has effect...

Since the flex sign can't change, I'm keeping that condition.  I'm not
100% sure it's necessary, but it doesn't give wrong results for any of
my testcases.

~TJ
```
Received on Monday, 30 April 2012 18:43:48 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:58 UTC