Replies: 26 comments
-
use but notice that if you add a variable to solver and remove it, |
Beta Was this translation helpful? Give feedback.
-
a >= 5 Another example |
Beta Was this translation helpful? Give feedback.
-
yes, in first case |
Beta Was this translation helpful? Give feedback.
-
So it sounds like |
Beta Was this translation helpful? Give feedback.
-
but I don't have other idea to do that. this API is designed to do this, but to track variable need more cost. do you really need this function? I will think to implement if you really want it. |
Beta Was this translation helpful? Give feedback.
-
Think about it :) The designers in my workplace would love such a feature. Our designers write json like this
Sometimes they forget to constraint all four variables (top, left, width, height) either explicitly or implicitly (using e.g. right, bottom). In a case like this the designer can get confused if he forgets one constraint
Having a warning telling him |
Beta Was this translation helpful? Give feedback.
-
am_isunderconstrained(a) should return TRUE a >= 1 should return TRUE a >= 1
a <= 10 should return FALSE a >= 1
a <= 10
a == 5 !strong should return FALSE a == 5 should return TRUE (nothing) If you are going to look at this I can write tests for you. :) |
Beta Was this translation helpful? Give feedback.
-
why |
Beta Was this translation helpful? Give feedback.
-
I think I am not communicating clearly. Statement is above code (not under) |
Beta Was this translation helpful? Give feedback.
-
So, why |
Beta Was this translation helpful? Give feedback.
-
Sorry, I'll try to communicate more clearly. I'm thinking of underconstrained variables as variables that have a multiple correct answers.
In this case
In this case
In this case
In this case
In this case Let me know if I can explain better. |
Beta Was this translation helpful? Give feedback.
-
So, if and, what if: and then a = 50, is |
Beta Was this translation helpful? Give feedback.
-
Yep, that's what I'm thinking
No, it is not underconstrained. It is sufficiently constrained to be 50 because |
Beta Was this translation helpful? Give feedback.
-
You posed a really good question. I thought maybe I could write something like this public func isUnderconstrained(_ variable: Variable) -> Bool {
do {
let currentValue: Double = try value(variable)
let dummyConstraint: Constraint = variable == currentValue
try add(dummyConstraint)
try remove(dummyConstraint)
return true
} catch let error {
return false
}
} (😬 this will probably be a little bit expensive?) Which makes this test pass func testUnderconstrained() {
let solver = Solver(debug: true)
do {
let v = Variable()
XCTAssertTrue(solver.isUnderconstrained(v))
let constraint = v == 5
try solver.add(constraint)
XCTAssertFalse(solver.isUnderconstrained(v))
try solver.remove(constraint)
XCTAssertTrue(solver.isUnderconstrained(v))
} catch let error as AmoebaError {
switch error {
case .unbound:
break
default:
XCTFail("Didn't expect \(error)")
break
}
} catch let error {
XCTFail("Didn't expect \(error)")
}
} But that doesn't work when using constraints which isn't using func testUnderconstrained2() {
let solver = Solver(debug: true)
do {
let v = Variable()
XCTAssertTrue(solver.isUnderconstrained(v))
let constraint = (v == 5).strong()
try solver.add(constraint)
XCTAssertFalse(solver.isUnderconstrained(v)) // <<< fails
try solver.remove(constraint)
XCTAssertTrue(solver.isUnderconstrained(v))
} catch let error as AmoebaError {
switch error {
case .unbound:
break
default:
XCTFail("Didn't expect \(error)")
break
}
} catch let error {
XCTFail("Didn't expect \(error)")
}
} |
Beta Was this translation helpful? Give feedback.
-
I find the question about underconstraint (its meaning and its influence on the workflow of designers) quite important. Any more thoughts on this? |
Beta Was this translation helpful? Give feedback.
-
I need rethought this thing, because now I changed the API it export. Can you give me some insight about how you will use this function? |
Beta Was this translation helpful? Give feedback.
-
It is only useful at the time of writing constraints. Give the designers feedback on which variables that is not being constrained sufficiently to have a deterministic behavior. ExampleA designer places a textbox on screen. The textbox is placed given the constraints
But then nothing shows up. The designer scratches his head because he is not aware that it is missing a constraint for the width. He should be given a cue (on demand) about how to sufficiently constrain this text box. He could write
Or
in order to be sufficiently constrained. Now the textbox is visible. Having some API to tell our designers of his mistake is what we are asking for – |
Beta Was this translation helpful? Give feedback.
-
But if you don't add width to amoeba, it can't know whether it need under constraint. It's somewhat "business related" in this case. |
Beta Was this translation helpful? Give feedback.
-
For me it's for the same reason as @hfossli described. I understand, that it's not inherently needed for Amoeba, but we might treat this as an optional extension to the Amoeba functionality or even API. So what I'm asking is a built-in support for the possibility to create such an extension. The extension might be also in a form of a flag indicating how the rule evaluation should proceed - we might call it somehow like "a stronger requirement on rules". |
Beta Was this translation helpful? Give feedback.
-
I think I have an idea. It won't be efficient computation wise, but it will probably do the job. I'll try to post next week |
Beta Was this translation helpful? Give feedback.
-
@dumblob this is acceptable I think. can you give some examples or definitions for the plugin interface? |
Beta Was this translation helpful? Give feedback.
-
I've thought about it, but everything I came up with was not good enough. I think we should wait the few days for @hfossli and his new idea and proceed with the discussion afterwards. Should something worth mentioning come to my mind in the mean time, I'll post it here. |
Beta Was this translation helpful? Give feedback.
-
I think my new idea might be flawed after all... :( maybe @kongtomorrow has some ideas? |
Beta Was this translation helpful? Give feedback.
-
My suggestion is to improve one of my earlier suggestions in this thread. Introduce a new function It could do the following:
I'm sure there are edge cases that won't be covered. It might be quite expensive, but it should only be done at the time of writing constraints (oppsoed to consuming). |
Beta Was this translation helpful? Give feedback.
-
@hfossli did you succeed to implement your last proposal? Anything I could take a look at and try it to see what are the caveats of this logic? Any comments @kongtomorrow? |
Beta Was this translation helpful? Give feedback.
-
I ran out of time and that feature was put in backlog unfortunately. I think I made it work the way I described it. I guess it messes up stays and edit variables though. |
Beta Was this translation helpful? Give feedback.
-
I would like to ask the solver wether a variable is underconstrained or not. Maybe I can try to add a constraint for a variable and see if I get an error? Is there better ways?
Beta Was this translation helpful? Give feedback.
All reactions