Permalink
Browse files

LinearEquation -> Equation, LinearInequality -> Equality. Fixes #21

  • Loading branch information...
1 parent aedf15f commit 5258a5d0ad98d49c3096d092166a9275f371dadb @slightlyoff committed Jun 29, 2012
View
@@ -41,11 +41,11 @@ var strong = c.Strength.strong;
var required = c.Strength.required;
var eq = function(a1, a2, strength, w) {
- return new c.LinearEquation(a1, a2, strength || weak, w||0);
+ return new c.Equation(a1, a2, strength || weak, w||0);
};
-var neq = function(a1, a2, a3) { return new c.LinearInequality(a1, a2, a3); };
-var geq = function(a1, a2, str, w) { return new c.LinearInequality(a1, c.GEQ, a2, str, w); };
-var leq = function(a1, a2, str, w) { return new c.LinearInequality(a1, c.LEQ, a2, str, w); };
+var neq = function(a1, a2, a3) { return new c.Inequality(a1, a2, a3); };
+var geq = function(a1, a2, str, w) { return new c.Inequality(a1, c.GEQ, a2, str, w); };
+var leq = function(a1, a2, str, w) { return new c.Inequality(a1, c.LEQ, a2, str, w); };
var stay = function(v, strength, weight) {
return new c.StayConstraint(v, strength || weak, weight || 1.0);
@@ -167,7 +167,7 @@
border-right: 1px solid #DDD;
border-radius: 3px 0px 0px 3px;
background: #EEE;
- background: -webkit-gradient(linear, left top, left bottom, from(#EEE), to(white));
+ background: -webkit-gradient(, left top, left bottom, from(#EEE), to(white));
}
#inputto {
@@ -21,22 +21,22 @@
<script src="http://www.badros.com/greg/cassowary/js/ClStrength.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/ClVariable.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/ClPoint.js"></script>
- <script src="http://www.badros.com/greg/cassowary/js/ClLinearExpression.js"></script>
+ <script src="http://www.badros.com/greg/cassowary/js/ClExpression.js"></script>
+ <script src="http://www.badros.com/greg/cassowary/js/ClConstraint.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/ClConstraint.js"></script>
- <script src="http://www.badros.com/greg/cassowary/js/ClLinearConstraint.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/ClEditInfo.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/ClTableau.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/ClSimplexSolver.js"></script>
<script src="http://www.badros.com/greg/cassowary/js/CL.js"></script>
<script>
c.SimplexSolver = ClSimplexSolver;
- c.LinearInequality = ClLinearInequality;
+ c.Inequality = ClInequality;
c.GEQ = CL.GEQ;
c.LEQ = CL.LEQ;
- c.LinearEquation = ClLinearEquation;
+ c.Equation = ClEquation;
c.Strength = ClStrength;
c.StayConstraint = ClStayConstraint;
- c.Expression = ClLinearExpression;
+ c.Expression = ClExpression;
c.Variable = ClVariable;
c.Plus = CL.Plus;
</script>
@@ -74,7 +74,7 @@ var listSetter = function(l, name, own, relativeTo, oper, strength, weight) {
}
this.remove.apply(this, this[ln]);
this[ln] = toArray(l).map(function(v) {
- return new c.LinearInequality(this.v[own],
+ return new c.Inequality(this.v[own],
oper,
this._panelOrVariable(v, relativeTo),
strength||weak,
@@ -110,11 +110,11 @@ var valueSetter = function(item, varOrValue, oper, strength, weight) {
if (oper && oper != "=") {
if (oper == ">=") oper = c.GEQ;
if (oper == "<=") oper = c.LEQ;
- // this[slot] = new c.LinearInequality(this.v[item], oper, varOrValue, strength||weak, weight||1);
- this[slot] = new c.LinearInequality(this.v[item], oper, varOrValue, strength);
+ // this[slot] = new c.Inequality(this.v[item], oper, varOrValue, strength||weak, weight||1);
+ this[slot] = new c.Inequality(this.v[item], oper, varOrValue, strength);
} else {
- // this[slot] = new c.LinearEquation(this.v[item], varOrValue, strength||weak, weight||1);
- this[slot] = new c.LinearEquation(this.v[item], varOrValue, strength);
+ // this[slot] = new c.Equation(this.v[item], varOrValue, strength||weak, weight||1);
+ this[slot] = new c.Equation(this.v[item], varOrValue, strength);
}
this.add(this[slot]);
};
@@ -130,11 +130,11 @@ var strong = c.Strength.strong;
var required = c.Strength.required;
var eq = function(a1, a2, strength, w) {
- return new c.LinearEquation(a1, a2, strength || weak, w||0);
+ return new c.Equation(a1, a2, strength || weak, w||0);
};
-var neq = function(a1, a2, a3) { return new c.LinearInequality(a1, a2, a3); };
-var geq = function(a1, a2, str, w) { return new c.LinearInequality(a1, c.GEQ, a2, str, w); };
-var leq = function(a1, a2, str, w) { return new c.LinearInequality(a1, c.LEQ, a2, str, w); };
+var neq = function(a1, a2, a3) { return new c.Inequality(a1, a2, a3); };
+var geq = function(a1, a2, str, w) { return new c.Inequality(a1, c.GEQ, a2, str, w); };
+var leq = function(a1, a2, str, w) { return new c.Inequality(a1, c.LEQ, a2, str, w); };
var stay = function(v, strength, weight) {
return new c.StayConstraint(v, strength || weak, weight || 1.0);
@@ -22,6 +22,7 @@
<script defer="defer" src="../../src/Point.js"></script>
<script defer="defer" src="../../src/Expression.js"></script>
<script defer="defer" src="../../src/Constraint.js"></script>
+ <script defer="defer" src="../../src/Constraint.js"></script>
<script defer="defer" src="../../src/EditInfo.js"></script>
<script defer="defer" src="../../src/Tableau.js"></script>
<script defer="defer" src="../../src/SimplexSolver.js"></script>
@@ -45,11 +46,11 @@
var required = c.Strength.required;
var eq = function(a1, a2, strength, w) {
- return new c.LinearEquation(a1, a2, strength || weak, w||0);
+ return new c.Equation(a1, a2, strength || weak, w||0);
};
- var neq = function(a1, a2, a3) { return new c.LinearInequality(a1, a2, a3); };
- var geq = function(a1, a2, str, w) { return new c.LinearInequality(a1, c.GEQ, a2, str, w); };
- var leq = function(a1, a2, str, w) { return new c.LinearInequality(a1, c.LEQ, a2, str, w); };
+ var neq = function(a1, a2, a3) { return new c.Inequality(a1, a2, a3); };
+ var geq = function(a1, a2, str, w) { return new c.Inequality(a1, c.GEQ, a2, str, w); };
+ var leq = function(a1, a2, str, w) { return new c.Inequality(a1, c.LEQ, a2, str, w); };
var stay = function(v, strength, weight) {
return new c.StayConstraint(v, strength || weak, weight || 1.0);
@@ -109,78 +109,78 @@ var QuadDemo = c.inherit({
// Add constraints to keep midpoints at line midpoints
cle = new c.Expression(db[0].X());
cle = (cle.plus(db[1].X())).divide(2);
- cleq = new c.LinearEquation(mp[0].X(), cle);
+ cleq = new c.Equation(mp[0].X(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[0].Y());
cle = (cle.plus(db[1].Y())).divide(2);
- cleq = new c.LinearEquation(mp[0].Y(), cle);
+ cleq = new c.Equation(mp[0].Y(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[1].X());
cle = (cle.plus(db[2].X())).divide(2);
- cleq = new c.LinearEquation(mp[1].X(), cle);
+ cleq = new c.Equation(mp[1].X(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[1].Y());
cle = (cle.plus(db[2].Y())).divide(2);
- cleq = new c.LinearEquation(mp[1].Y(), cle);
+ cleq = new c.Equation(mp[1].Y(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[2].X());
cle = (cle.plus(db[3].X())).divide(2);
- cleq = new c.LinearEquation(mp[2].X(), cle);
+ cleq = new c.Equation(mp[2].X(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[2].Y());
cle = (cle.plus(db[3].Y())).divide(2);
- cleq = new c.LinearEquation(mp[2].Y(), cle);
+ cleq = new c.Equation(mp[2].Y(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[3].X());
cle = (cle.plus(db[0].X())).divide(2);
- cleq = new c.LinearEquation(mp[3].X(), cle);
+ cleq = new c.Equation(mp[3].X(), cle);
solver.addConstraint(cleq);
cle = new c.Expression(db[3].Y());
cle = (cle.plus(db[0].Y())).divide(2);
- cleq = new c.LinearEquation(mp[3].Y(), cle);
+ cleq = new c.Equation(mp[3].Y(), cle);
solver.addConstraint(cleq);
cle = c.Plus(db[0].X(), 20);
- solver.addConstraint(new c.LinearInequality(cle, c.LEQ, db[2].X()))
- .addConstraint(new c.LinearInequality(cle, c.LEQ, db[3].X()));
+ solver.addConstraint(new c.Inequality(cle, c.LEQ, db[2].X()))
+ .addConstraint(new c.Inequality(cle, c.LEQ, db[3].X()));
cle = c.Plus(db[1].X(), 20);
- solver.addConstraint(new c.LinearInequality(cle, c.LEQ, db[2].X()))
- .addConstraint(new c.LinearInequality(cle, c.LEQ, db[3].X()));
+ solver.addConstraint(new c.Inequality(cle, c.LEQ, db[2].X()))
+ .addConstraint(new c.Inequality(cle, c.LEQ, db[3].X()));
cle = c.Plus(db[0].Y(), 20);
- solver.addConstraint(new c.LinearInequality(cle, c.LEQ, db[1].Y()))
- .addConstraint(new c.LinearInequality(cle, c.LEQ, db[2].Y()));
+ solver.addConstraint(new c.Inequality(cle, c.LEQ, db[1].Y()))
+ .addConstraint(new c.Inequality(cle, c.LEQ, db[2].Y()));
cle = c.Plus(db[3].Y(), 20);
- solver.addConstraint(new c.LinearInequality(cle, c.LEQ, db[1].Y()))
- .addConstraint(new c.LinearInequality(cle, c.LEQ, db[2].Y()));
+ solver.addConstraint(new c.Inequality(cle, c.LEQ, db[1].Y()))
+ .addConstraint(new c.Inequality(cle, c.LEQ, db[2].Y()));
// Add constraints to keep points inside window
db.forEach(function(p) {
- solver.addConstraint(new c.LinearInequality(p.X(), c.GEQ, 10));
- solver.addConstraint(new c.LinearInequality(p.Y(), c.GEQ, 10));
+ solver.addConstraint(new c.Inequality(p.X(), c.GEQ, 10));
+ solver.addConstraint(new c.Inequality(p.Y(), c.GEQ, 10));
- solver.addConstraint(new c.LinearInequality(p.X(), c.LEQ, this.cwidth - 10));
- solver.addConstraint(new c.LinearInequality(p.Y(), c.LEQ, this.cheight - 10));
+ solver.addConstraint(new c.Inequality(p.X(), c.LEQ, this.cwidth - 10));
+ solver.addConstraint(new c.Inequality(p.Y(), c.LEQ, this.cheight - 10));
}, this);
// } catch (e) {
View
@@ -60,7 +60,7 @@ c.Constraint = c.inherit({
},
});
-c.LinearInequality = c.inherit({
+c.Inequality = c.inherit({
extends: c.Constraint,
_cloneOrNewCle: function(cle) {
@@ -74,7 +74,7 @@ c.LinearInequality = c.inherit({
initialize: function(a1, a2, a3, a4, a5) {
// FIXME(slightlyoff): what a disgusting mess. Should at least add docs.
- // console.log("c.LinearInequality.initialize(", a1, a2, a3, a4, a5, ")");
+ // console.log("c.Inequality.initialize(", a1, a2, a3, a4, a5, ")");
//
// (cle || number), op, clv
var a1IsExp, a3IsExp, a1IsNum, a3IsNum, a1IsVar, a3IsVar;
@@ -94,7 +94,7 @@ c.LinearInequality = c.inherit({
} else if (op == c.GEQ) {
this.expression.addVariable(clv, -1);
} else {
- throw new c.InternalError("Invalid operator in ClLinearInequality constructor");
+ throw new c.InternalError("Invalid operator in ClInequality constructor");
}
// clv, op, (cle || number)
} else if (a1IsVar && (a3IsExp || a3IsNum)) {
@@ -106,7 +106,7 @@ c.LinearInequality = c.inherit({
} else if (op == c.LEQ) {
this.expression.addVariable(clv, -1);
} else {
- throw new c.InternalError("Invalid operator in ClLinearInequality constructor");
+ throw new c.InternalError("Invalid operator in ClInequality constructor");
}
// cle, op, num
} else if (a1IsExp && a3IsNum) {
@@ -118,7 +118,7 @@ c.LinearInequality = c.inherit({
} else if (op == c.GEQ) {
this.expression.addExpression(this._cloneOrNewCle(cle2), -1);
} else {
- throw new c.InternalError("Invalid operator in ClLinearInequality constructor");
+ throw new c.InternalError("Invalid operator in ClInequality constructor");
}
return this
// num, op, cle
@@ -131,7 +131,7 @@ c.LinearInequality = c.inherit({
} else if (op == c.LEQ) {
this.expression.addExpression(this._cloneOrNewCle(cle2), -1);
} else {
- throw new c.InternalError("Invalid operator in ClLinearInequality constructor");
+ throw new c.InternalError("Invalid operator in ClInequality constructor");
}
return this
// cle op cle
@@ -144,7 +144,7 @@ c.LinearInequality = c.inherit({
} else if (op == c.LEQ) {
this.expression.addExpression(this._cloneOrNewCle(cle1), -1);
} else {
- throw new c.InternalError("Invalid operator in ClLinearInequality constructor");
+ throw new c.InternalError("Invalid operator in ClInequality constructor");
}
// cle
} else if (a1IsExp) {
@@ -160,21 +160,21 @@ c.LinearInequality = c.inherit({
this.expression.addVariable(a1,-1);
// error
} else {
- throw new c.InternalError("Invalid operator in ClLinearInequality constructor");
+ throw new c.InternalError("Invalid operator in ClInequality constructor");
}
},
isInequality: true,
toString: function() {
- // return "c.LinearInequality: " + this.hashCode();
+ // return "c.Inequality: " + this.hashCode();
return c.Constraint.prototype.toString.call(this) + " >= 0 ) id: " + this.hash_code;
},
});
var lc = c.Constraint;
-c.LinearEquation = c.inherit({
+c.Equation = c.inherit({
extends: c.Constraint,
initialize: function(a1, a2, a3, a4) {
// FIXME(slightlyoff): this is just a huge mess.
@@ -212,7 +212,7 @@ c.LinearEquation = c.inherit({
lc.call(this, a1, a3, a4);
this.expression.addExpression(a2, -1);
} else {
- throw "Bad initializer to ClLinearEquation";
+ throw "Bad initializer to ClEquation";
}
c.Assert(this.strength instanceof c.Strength, "_strength not set");
},
View
@@ -33,9 +33,9 @@
c.InternalError =
errorType("c.InternalError");
- c.NonlinearExpression =
- errorType("c.NonlinearExpression",
- "The resulting expression would be nonlinear");
+ c.NonExpression =
+ errorType("c.NonExpression",
+ "The resulting expression would be non");
c.NotEnoughStays =
errorType("c.NotEnoughStays",
View
@@ -72,7 +72,7 @@ c.Expression = c.inherit({
} else if (x.isConstant()) {
return this.times(x.constant);
} else {
- throw new c.NonlinearExpression();
+ throw new c.NonExpression();
}
}
},
@@ -96,12 +96,12 @@ c.Expression = c.inherit({
divide: function(x) {
if (typeof x == 'number') {
if (c.approx(x, 0)) {
- throw new c.NonlinearExpression();
+ throw new c.NonExpression();
}
return this.times(1 / x);
} else if (x instanceof c.Expression) {
if (!x.isConstant()) {
- throw new c.NonlinearExpression();
+ throw new c.NonExpression();
}
return this.times(1 / x.constant);
}
@@ -42,12 +42,12 @@ c.SimplexSolver = c.inherit({
},
addLowerBound: function(v /*c.AbstractVariable*/, lower /*double*/) {
- var cn = new c.LinearInequality(v, c.GEQ, new c.Expression(lower));
+ var cn = new c.Inequality(v, c.GEQ, new c.Expression(lower));
return this.addConstraint(cn);
},
addUpperBound: function(v /*c.AbstractVariable*/, upper /*double*/) {
- var cn = new c.LinearInequality(v, c.LEQ, new c.Expression(upper));
+ var cn = new c.Inequality(v, c.LEQ, new c.Expression(upper));
return this.addConstraint(cn);
},
Oops, something went wrong.

0 comments on commit 5258a5d

Please sign in to comment.