-
Notifications
You must be signed in to change notification settings - Fork 258
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
Add weak constraints to make rects closer to each other in size #395
Conversation
71f04ee
to
94724b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know this a bit unrelated, but this change causes some side-effects, please test against #404 with this change applied, see #370 (comment) for more context
The main blocker for this PR right now is that it results in non-deterministic splits more often, which is makes it difficult to reason about how space will be allocated for users. |
I did some testing with this and wrote a integer optimization program (in Julia) to simulate "ideal" behavior to compare. I think we are never going to be able to guarantee that there won't be gaps with cassowary. For example, take a constraints I implemented this using integer variables in Julia and I get a solution that we would expect, i.e. area = Rect(0, 0, 100, 1)
constraints = [Percent(33), Percent(33), Percent(33)]
r1, r2, r3 = split(Horizontal(constraints), area; kwargs...)
@test r1.width == 33
@test r2.width == 34
@test r3.width == 33 Unfortunately, this behavior is not guaranteed with cassowary because cassowary uses floating point values. |
Adding the weak constraints to make the widths (or heights) similar did have the intended effect (imo). Take this test for example: area = Rect(0, 0, 100, 1)
constraints = [Percent(50), HardMin(10), Percent(50)]
r1, r2, r3 = split(Horizontal(constraints), area; kwargs...)
@test r1.width == 45
@test r2.width == 10
@test r3.width == 45 Without the weak constraints, I was getting results like this: area = Rect(0, 0, 100, 1)
constraints = [Percent(50), HardMin(10), Percent(50)]
r1, r2, r3 = split(Horizontal(constraints), area; kwargs...)
@test r1.width == 50
@test r2.width == 10
@test r3.width == 40 |
The approach that makes this round without gaps is to use the left/right position rather than the widths to work out how to round. This works pretty nicely as far as I can tell and is my intended change as soon as the refactor in #405 lands. See #408 for the change. |
Interesting idea! I think there are some corner cases there as well (I'll have to test to come up with examples), but maybe fewer issues than what we have at the moment, so it should be good! |
Perhaps something that evaluates to (positions): |
94724b4
to
2d7792d
Compare
Codecov Report
@@ Coverage Diff @@
## main #395 +/- ##
==========================================
+ Coverage 86.28% 86.41% +0.12%
==========================================
Files 40 40
Lines 9343 9432 +89
==========================================
+ Hits 8062 8151 +89
Misses 1281 1281
|
2d7792d
to
1a7eb71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code looks good to me, though it would probably be great to also have some tests for Max
and Length
to ensure they are not somehow heigher / lower than what they should be
36a9864
to
ea18fd1
Compare
389cb87
to
17790b7
Compare
77cff61
to
6bdc8b2
Compare
@hasezoey I had to fix some tests after #404 was merged and after I rebased on top of it. |
eb4a0b5
to
d0257fe
Compare
I renamed it to |
d0257fe
to
2a995a4
Compare
I pushed a rebase on the fix in #419 - happy for this to be approved and merged now @kdheepak. We can work out the public name for the API at some point later. I lean towards using |
I did the rebase locally as well but you are faster than me :) I'll discard my changes. Yes, let's merge and figure out the right names for it later. I'm not tied to any names here. |
2a995a4
to
23af050
Compare
Also make `Max` and `Min` constraints MEDIUM strength for higher priority over equal chunks
23af050
to
29bd834
Compare
This PR introduces a
SegmentSize
enum
that will allow adding the following constraints optionally:This makes chunks similar in size to each other if other constraints are satisfied.
This PR also changes the implementation of
Max
andMin
by adding aMEDIUM
equality constraint instead of aWEAK
equality constraint.It should result in the same layouts for us though, because there were no other
MEDIUM
constraints used.