Skip to content

Am I missing something? #82

Description

@GalloglyP

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions