slightlyoff / cassowary.js

Cassowary/JS, better, faster, future-ready
Other
1.69k stars 107 forks source link

Am I missing something? #82

Open GalloglyP opened 6 years ago

GalloglyP commented 6 years ago

After running the quad demo. I tried adding a horizontal distance constraint to an edge .

cle = c.Expression.fromConstant(db[0].x).plus(15);
cleq = new c.Equation(db[1].x, cle);

Which generated this error.

Constraint.js:219 Uncaught Bad initializer to c.Equation

So I Modified Expression.plus similarly to Expression.times

    plus: function(expr /*c.Expression*/) {
      if (typeof expr == 'number') {
        return (this.clone()).addMe(expr);
      } else {
        if (expr instanceof c.Expression) {
          return this.clone().addExpression(expr, 1);
        } else if (expr instanceof c.Variable) {
          return this.clone().addVariable(expr, 1);
        }
      }
    },

And added this addMe method similar to multiplyMe

  addMe: function(x /*double*/) {
    this.constant += x;
    var t = this.terms;
    t.each(function(clv, coeff) { t.set(clv, coeff + x); });
    return this;
  },

Are these basic expressions not developed or am I missing something? This does generate a valid result.