slightlyoff/cassowary-js-refactor — Issue #3: LinearInequality constructor breaks when first argument is LinearExpression
Author: d4tocchini
Created: 2012-02-16 10:03:18+00:00
State: open

it seems that the `c.LinearInequality` doesn't accept a `c.LinearExpression` as subject of the constraint, ie, as first parameter in constructor.

so given the following coffeescript abbreviated setup:

```coffeescript

required = c.Strength.required

x = new c.Variable(10)
w = new c.Variable(10) # width
r = new c.LinearExpression(x).plus(w) # right

```

the following `x >= 20` test works as expected:

```coffeescript

test1.solver.addConstraint new c.LinearInequality(x, c.GEQ, 20)
alert x.value() # expects and gets 20

```

the following `r == 100` test also works as expected:

```coffeescript

test2.solver.addStay w
test2.solver.addConstraint new c.LinearEquation(r, 100, required)
alert x.value() # expects and gets 90

```

but the following `r >= 100` test throws an error:

```coffeescript

test3.solver.addStay w
test3.solver.addConstraint new c.LinearInequality(r, c.GEQ, 100, required)
alert x.value() # expects 90...
# throws error: "Constraint.js:43Uncaught TypeError: Object 1 has no method 'isRequired"

```

i'm assuming, just as we can use expressions and variables on either side of an equation, we should be able to do the same with inequalities...

The error is not just b/c `!constraint.strength.isRequired` in `c.Constraint`, it appears to be the way the arguments are handled in the `C.LinearInequality.initialize` function, but i haven't been able to monkey wrench a solution...