Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 5258a5d0ad98d49c3096d092166a9275f371dadb 1 parent aedf15f
@slightlyoff authored
View
8 demos/css/layout.js
@@ -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);
View
2  demos/panels/cloudy.css
@@ -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 {
View
10 demos/panels/compat.html
@@ -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>
View
18 demos/panels/panels.js
@@ -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);
View
9 demos/panels/popup.html
@@ -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);
View
40 demos/quad/quaddemo.js
@@ -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
22 src/Constraint.js
@@ -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
6 src/Error.js
@@ -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
6 src/Expression.js
@@ -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);
}
View
4 src/SimplexSolver.js
@@ -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);
},
View
38 tests/Constraint-test.js
@@ -9,7 +9,7 @@
doh.add("c.Constraint", [
function equationFromExpression(t) {
var ex = new c.Expression(10);
- var c1 = new c.LinearEquation(ex);
+ var c1 = new c.Equation(ex);
t.is(c1.expression, '10');
},
@@ -23,7 +23,7 @@ doh.add("c.Constraint", [
function equationFromVarAndExpression(t) {
var x = new c.Variable('x', 167);
var cly = new c.Expression(2);
- var eq = new c.LinearEquation(x, cly);
+ var eq = new c.Equation(x, cly);
t.is('2 + -1*[x:167]', eq.expression);
},
@@ -35,14 +35,14 @@ doh.add("c.Constraint", [
var w = new c.Variable("w", 1);
// Default weights.
- var e0 = new c.LinearEquation(x, y);
+ var e0 = new c.Equation(x, y);
solver.addStay(y);
solver.addConstraint(e0);
t.t(c.approx(x, 20));
t.t(c.approx(y, 20));
// Weak.
- var e1 = new c.LinearEquation(x, z, c.Strength.weak);
+ var e1 = new c.Equation(x, z, c.Strength.weak);
solver.addStay(x);
solver.addConstraint(e1);
t.t(c.approx(x, 20));
@@ -50,7 +50,7 @@ doh.add("c.Constraint", [
return;
// Strong.
- var e2 = new c.LinearEquation(z, w, c.Strength.strong);
+ var e2 = new c.Equation(z, w, c.Strength.strong);
solver.addStay(w);
solver.addConstraint(e2);
t.is(w.value(), 1);
@@ -59,14 +59,14 @@ doh.add("c.Constraint", [
function equation_variable_number(t) {
var v = new c.Variable('v', 22);
- var eq = new c.LinearEquation(v, 5);
+ var eq = new c.Equation(v, 5);
t.is(eq.expression, '5 + -1*[v:22]');
},
function equation_expression_variable(t) {
var e = new c.Expression(10);
var v = new c.Variable('v', 22);
- var eq = new c.LinearEquation(e, v);
+ var eq = new c.Equation(e, v);
t.is(eq.expression, '10 + -1*[v:22]');
},
@@ -74,14 +74,14 @@ doh.add("c.Constraint", [
function equation_expression_x2(t) {
var e1 = new c.Expression(10);
var e2 = new c.Expression(new c.Variable('z', 10), 2, 4);
- var eq = new c.LinearEquation(e1, e2);
+ var eq = new c.Equation(e1, e2);
t.is(eq.expression, '6 + -2*[z:10]');
},
function inequality_expression(t) {
var e = new c.Expression(10);
- var ieq = new c.LinearInequality(e);
+ var ieq = new c.Inequality(e);
t.is(ieq.expression, '10');
},
@@ -89,54 +89,54 @@ doh.add("c.Constraint", [
function inequality_var_op_var(t) {
var v1 = new c.Variable('v1', 10);
var v2 = new c.Variable('v2', 5);
- var ieq = new c.LinearInequality(v1, c.GEQ, v2);
+ var ieq = new c.Inequality(v1, c.GEQ, v2);
t.is(ieq.expression, '1*[v1:10] + -1*[v2:5]');
- ieq = new c.LinearInequality(v1, c.LEQ, v2);
+ ieq = new c.Inequality(v1, c.LEQ, v2);
t.is(ieq.expression, '-1*[v1:10] + 1*[v2:5]');
},
function inequality_var_op_num(t) {
var v = new c.Variable('v', 10);
- var ieq = new c.LinearInequality(v, c.GEQ, 5);
+ var ieq = new c.Inequality(v, c.GEQ, 5);
t.is(ieq.expression, '-5 + 1*[v:10]');
- ieq = new c.LinearInequality(v, c.LEQ, 5);
+ ieq = new c.Inequality(v, c.LEQ, 5);
t.is(ieq.expression, '5 + -1*[v:10]');
},
function inequality_expression_x2(t) {
var e1 = new c.Expression(10);
var e2 = new c.Expression(new c.Variable('c', 10), 2, 4);
- var ieq = new c.LinearInequality(e1, c.GEQ, e2);
+ var ieq = new c.Inequality(e1, c.GEQ, e2);
t.is(ieq.expression, '6 + -2*[c:10]');
- ieq = new c.LinearInequality(e1, c.LEQ, e2);
+ ieq = new c.Inequality(e1, c.LEQ, e2);
t.is(ieq.expression, '-6 + 2*[c:10]');
},
function inequality_var_op_exp(t) {
var v = new c.Variable('v', 10);
var e = new c.Expression(new c.Variable('x', 5), 2, 4);
- var ieq = new c.LinearInequality(v, c.GEQ, e);
+ var ieq = new c.Inequality(v, c.GEQ, e);
t.is(ieq.expression, '-4 + 1*[v:10] + -2*[x:5]');
- ieq = new c.LinearInequality(v, c.LEQ, e);
+ ieq = new c.Inequality(v, c.LEQ, e);
t.is(ieq.expression, '4 + -1*[v:10] + 2*[x:5]');
},
function inequality_exp_op_var(t) {
var v = new c.Variable('v', 10);
var e = new c.Expression(new c.Variable('x', 5), 2, 4);
- var ieq = new c.LinearInequality(e, c.GEQ, v);
+ var ieq = new c.Inequality(e, c.GEQ, v);
t.is(ieq.expression, '4 + -1*[v:10] + 2*[x:5]');
- ieq = new c.LinearInequality(e, c.LEQ, v);
+ ieq = new c.Inequality(e, c.LEQ, v);
t.is(ieq.expression, '-4 + 1*[v:10] + -2*[x:5]');
}
]);
View
88 tests/End-To-End-test.js
@@ -15,7 +15,7 @@ doh.add("End-To-End", [
var x = new c.Variable(167);
var y = new c.Variable(2);
- var eq = new c.LinearEquation(x, new c.Expression(y));
+ var eq = new c.Equation(x, new c.Expression(y));
solver.addConstraint(eq);
t.t(x.value() == y.value());
@@ -42,7 +42,7 @@ doh.add("End-To-End", [
var solver = new c.SimplexSolver();
var x = new c.Variable(10);
- var ieq = new c.LinearInequality(x, c.GEQ, 100);
+ var ieq = new c.Inequality(x, c.GEQ, 100);
solver.addConstraint(ieq);
t.is(x.value(), 100);
}
@@ -55,7 +55,7 @@ doh.add("End-To-End", [
var solver = new c.SimplexSolver();
var x = new c.Variable(10);
- var eq = new c.LinearEquation(100, x);
+ var eq = new c.Equation(100, x);
solver.addConstraint(eq);
t.is(x.value(), 100);
}
@@ -68,7 +68,7 @@ doh.add("End-To-End", [
var solver = new c.SimplexSolver();
var x = new c.Variable(10);
- var ieq = new c.LinearInequality(100, c.LEQ, x);
+ var ieq = new c.Inequality(100, c.LEQ, x);
solver.addConstraint(ieq);
t.is(x.value(), 100);
@@ -89,7 +89,7 @@ doh.add("End-To-End", [
// right = x + width
var right = new c.Expression(x).plus(width);
// right >= 100
- var ieq = new c.LinearInequality(right, c.GEQ, 100);
+ var ieq = new c.Inequality(right, c.GEQ, 100);
solver.addStay(width)
solver.addConstraint(ieq);
@@ -108,7 +108,7 @@ doh.add("End-To-End", [
var x = new c.Variable(10);
var width = new c.Variable(10);
var right = new c.Expression(x).plus(width);
- var ieq = new c.LinearInequality(100, c.LEQ, right);
+ var ieq = new c.Inequality(100, c.LEQ, right);
solver.addStay(width)
.addConstraint(ieq);
@@ -129,7 +129,7 @@ doh.add("End-To-End", [
var width = new c.Variable(10);
var rightMin = new c.Variable(100);
var right = new c.Expression(x).plus(width);
- var eq = new c.LinearEquation(right, rightMin);
+ var eq = new c.Equation(right, rightMin);
solver.addStay(width)
.addStay(rightMin)
@@ -151,7 +151,7 @@ doh.add("End-To-End", [
var width = new c.Variable(10);
var rightMin = new c.Variable(100);
var right = new c.Expression(x).plus(width);
- var ieq = new c.LinearInequality(right, c.GEQ, rightMin);
+ var ieq = new c.Inequality(right, c.GEQ, rightMin);
solver.addStay(width)
.addStay(rightMin)
@@ -173,7 +173,7 @@ doh.add("End-To-End", [
var width = new c.Variable(10);
var rightMin = new c.Variable(100);
var right = new c.Expression(x).plus(width);
- var ieq = new c.LinearInequality(rightMin, c.LEQ, right);
+ var ieq = new c.Inequality(rightMin, c.LEQ, right);
solver.addStay(width)
.addStay(rightMin)
.addConstraint(ieq);
@@ -197,7 +197,7 @@ doh.add("End-To-End", [
var width2 = new c.Variable(10);
var right2 = new c.Expression(x2).plus(width2);
- var eq = new c.LinearEquation(right1, right2);
+ var eq = new c.Equation(right1, right2);
solver.addStay(width1)
.addStay(width2)
@@ -225,7 +225,7 @@ doh.add("End-To-End", [
var width2 = new c.Variable(10);
var right2 = new c.Expression(x2).plus(width2);
- var ieq = new c.LinearInequality(right1, c.GEQ, right2);
+ var ieq = new c.Inequality(right1, c.GEQ, right2);
solver.addStay(width1)
.addStay(width2)
@@ -250,7 +250,7 @@ doh.add("End-To-End", [
var x2 = new c.Variable(100);
var width2 = new c.Variable(10);
var right2 = new c.Expression(x2).plus(width2);
- var ieq = new c.LinearInequality(right2, c.LEQ, right1);
+ var ieq = new c.Inequality(right2, c.LEQ, right1);
solver.addStay(width1)
.addStay(width2)
@@ -265,11 +265,11 @@ doh.add("End-To-End", [
function addDelete1(t) {
var solver = new c.SimplexSolver();
var x = new c.Variable("x");
- var cbl = new c.LinearEquation(x, 100, c.Strength.weak);
+ var cbl = new c.Equation(x, 100, c.Strength.weak);
solver.addConstraint(cbl);
- var c10 = new c.LinearInequality(x, c.LEQ, 10.0);
- var c20 = new c.LinearInequality(x, c.LEQ, 20.0);
+ var c10 = new c.Inequality(x, c.LEQ, 10.0);
+ var c20 = new c.Inequality(x, c.LEQ, 20.0);
solver.addConstraint(c10)
.addConstraint(c20);
t.t(c.approx(x, 10.0));
@@ -280,7 +280,7 @@ doh.add("End-To-End", [
solver.removeConstraint(c20);
t.t(c.approx(x, 100.0));
- var c10again = new c.LinearInequality(x, c.LEQ, 10.0);
+ var c10again = new c.Inequality(x, c.LEQ, 10.0);
solver.addConstraint(c10)
.addConstraint(c10again);
t.t(c.approx(x, 10.0));
@@ -297,10 +297,10 @@ doh.add("End-To-End", [
var x = new c.Variable("x");
var y = new c.Variable("y");
- solver.addConstraint(new c.LinearEquation(x, 100.0, c.Strength.weak))
- .addConstraint(new c.LinearEquation(y, 120.0, c.Strength.strong));
- var c10 = new c.LinearInequality(x, c.LEQ, 10.0);
- var c20 = new c.LinearInequality(x, c.LEQ, 20.0);
+ solver.addConstraint(new c.Equation(x, 100.0, c.Strength.weak))
+ .addConstraint(new c.Equation(y, 120.0, c.Strength.strong));
+ var c10 = new c.Inequality(x, c.LEQ, 10.0);
+ var c20 = new c.Inequality(x, c.LEQ, 20.0);
solver.addConstraint(c10)
.addConstraint(c20);
t.t(c.approx(x, 10.0));
@@ -310,7 +310,7 @@ doh.add("End-To-End", [
t.t(c.approx(x, 20.0));
t.t(c.approx(y, 120.0));
- var cxy = new c.LinearEquation(c.Times(2.0, x), y);
+ var cxy = new c.Equation(c.Times(2.0, x), y);
solver.addConstraint(cxy);
t.t(c.approx(x, 20.0));
t.t(c.approx(y, 40.0));
@@ -329,10 +329,10 @@ doh.add("End-To-End", [
var x = new c.Variable("x");
var y = new c.Variable("y");
- solver.addConstraint(new c.LinearInequality(x, c.LEQ, y))
- .addConstraint(new c.LinearEquation(y, c.Plus(x, 3.0)))
- .addConstraint(new c.LinearEquation(x, 10.0, c.Strength.weak))
- .addConstraint(new c.LinearEquation(y, 10.0, c.Strength.weak));
+ solver.addConstraint(new c.Inequality(x, c.LEQ, y))
+ .addConstraint(new c.Equation(y, c.Plus(x, 3.0)))
+ .addConstraint(new c.Equation(x, 10.0, c.Strength.weak))
+ .addConstraint(new c.Equation(y, 10.0, c.Strength.weak));
t.t(
(c.approx(x, 10.0) && c.approx(y, 13.0)) ||
@@ -344,19 +344,19 @@ doh.add("End-To-End", [
var solver = new c.SimplexSolver();
var x = new c.Variable("x");
// x = 10
- solver.addConstraint(new c.LinearEquation(x, 10.0));
+ solver.addConstraint(new c.Equation(x, 10.0));
// x = 5
t.e(c.RequiredFailure, solver, "addConstraint", [
- new c.LinearEquation(x, 5.0)
+ new c.Equation(x, 5.0)
]);
},
function inconsistent2(t) {
var solver = new c.SimplexSolver();
var x = new c.Variable("x");
- solver.addConstraint(new c.LinearInequality(x, c.GEQ, 10.0));
+ solver.addConstraint(new c.Inequality(x, c.GEQ, 10.0));
t.e(c.RequiredFailure, solver, "addConstraint", [
- new c.LinearInequality(x, c.LEQ, 5.0)
+ new c.Inequality(x, c.LEQ, 5.0)
]);
},
@@ -366,13 +366,13 @@ doh.add("End-To-End", [
var x = new c.Variable("x");
var y = new c.Variable("y");
var z = new c.Variable("z");
- solver.addConstraint(new c.LinearInequality(w, c.GEQ, 10.0))
- .addConstraint(new c.LinearInequality(x, c.GEQ, w))
- .addConstraint(new c.LinearInequality(y, c.GEQ, x))
- .addConstraint(new c.LinearInequality(z, c.GEQ, y))
- .addConstraint(new c.LinearInequality(z, c.GEQ, 8.0));
+ solver.addConstraint(new c.Inequality(w, c.GEQ, 10.0))
+ .addConstraint(new c.Inequality(x, c.GEQ, w))
+ .addConstraint(new c.Inequality(y, c.GEQ, x))
+ .addConstraint(new c.Inequality(z, c.GEQ, y))
+ .addConstraint(new c.Inequality(z, c.GEQ, 8.0));
t.e(c.RequiredFailure, solver, "addConstraint", [
- new c.LinearInequality(z, c.LEQ, 4.0)
+ new c.Inequality(z, c.LEQ, 4.0)
]);
},
@@ -381,12 +381,12 @@ doh.add("End-To-End", [
var x = new c.Variable("x");
var y = new c.Variable("y");
// x = 10
- solver.addConstraint(new c.LinearEquation(x, 10.0));
+ solver.addConstraint(new c.Equation(x, 10.0));
// x = y
- solver.addConstraint(new c.LinearEquation(x, y));
+ solver.addConstraint(new c.Equation(x, y));
// y = 5. Should fail.
t.e(c.RequiredFailure, solver, "addConstraint", [
- new c.LinearEquation(y, 5.0)
+ new c.Equation(y, 5.0)
]);
},
@@ -480,7 +480,7 @@ doh.add("End-To-End", [
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 v = {
@@ -554,7 +554,7 @@ doh.add("End-To-End", [
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 x = new c.Variable("x", 100);
@@ -564,16 +564,16 @@ doh.add("End-To-End", [
t.is(y.value(), 200);
t.is(z.value(), 50);
- solver.addConstraint(new c.LinearEquation(z, x, weak))
- .addConstraint(new c.LinearEquation(x, 20, weak))
- .addConstraint(new c.LinearEquation(y, 200, strong));
+ solver.addConstraint(new c.Equation(z, x, weak))
+ .addConstraint(new c.Equation(x, 20, weak))
+ .addConstraint(new c.Equation(y, 200, strong));
t.is(x.value(), 20);
t.is(y.value(), 200);
t.is(z.value(), 20);
solver.addConstraint(
- new c.LinearInequality(c.Plus(z, 150), c.LEQ, y, medium)
+ new c.Inequality(c.Plus(z, 150), c.LEQ, y, medium)
);
t.is(x.value(), 20);
View
14 tests/LinearExpression-test.js → tests/Expression-test.js
@@ -130,7 +130,7 @@ doh.add("c.Expression", [
t.is(e.terms.get(v), 200);
// multiplying two non-constant expressions
- t.e(c.NonlinearExpression, a, 'times', [a]);
+ t.e(c.NonExpression, a, 'times', [a]);
},
function addVariable(t) {
@@ -231,14 +231,14 @@ doh.add("c.Expression", [
var vb = new c.Variable(20);
var a = new c.Expression(va, 20, 2);
- t.e(c.NonlinearExpression, a, 'divide', [0]);
+ t.e(c.NonExpression, a, 'divide', [0]);
var p = a.divide(2);
t.is(p.constant, 1);
t.is(p.terms.get(va), 10);
- t.e(c.NonlinearExpression, a, 'divide', [new c.Expression(vb, 10, 5)]);
- t.e(c.NonlinearExpression, new c.Expression(vb, 10, 5), 'divide', [a]);
+ t.e(c.NonExpression, a, 'divide', [new c.Expression(vb, 10, 5)]);
+ t.e(c.NonExpression, new c.Expression(vb, 10, 5), 'divide', [a]);
p = a.divide(new c.Expression(2));
t.is(p.constant, 1);
@@ -364,7 +364,7 @@ doh.add("c.Expression", [
t.is(c.Times(2, 3), '6');
t.is(c.Times(x, 2), '2*[x:167]');
t.is(c.Times(3, x), '3*[x:167]');
- t.e(c.NonlinearExpression, c, 'Times', [x, y]);
+ t.e(c.NonExpression, c, 'Times', [x, y]);
},
function Divide(t) {
@@ -373,7 +373,7 @@ doh.add("c.Expression", [
t.is(c.Divide(4, 2), '2');
t.is(c.Divide(x, 2), '0.5*[x:167]');
- t.e(c.NonlinearExpression, c, 'Divide', [4, x]);
- t.e(c.NonlinearExpression, c, 'Divide', [x, y]);
+ t.e(c.NonExpression, c, 'Divide', [4, x]);
+ t.e(c.NonExpression, c, 'Divide', [x, y]);
}
]);
View
8 tests/PerfTest.js
@@ -39,9 +39,9 @@ var PerfTest = c.inherit({
expr.addExpression(c.Times(rgpclv[iclv], coeff));
}
if (this.UniformRandomDiscretized() < ineqProb) {
- rgpcns[j] = new c.LinearInequality(expr);
+ rgpcns[j] = new c.Inequality(expr);
} else {
- rgpcns[j] = new c.LinearEquation(expr);
+ rgpcns[j] = new c.Equation(expr);
}
if (c.trace) c.traceprint("Constraint " + j + " is " + rgpcns[j]);
}
@@ -158,9 +158,9 @@ var PerfTest = c.inherit({
expr.addExpression(c.Times(rgpclv[iclv], coeff));
}
if (this.UniformRandomDiscretized() < ineqProb) {
- rgpcns[j] = new c.LinearInequality(expr);
+ rgpcns[j] = new c.Inequality(expr);
} else {
- rgpcns[j] = new c.LinearEquation(expr);
+ rgpcns[j] = new c.Equation(expr);
}
if (this.trace) this.traceprint("Constraint " + j + " is " + rgpcns[j]);
}
View
8 tests/Strength-test.js
@@ -34,8 +34,8 @@ doh.add("c.Strength", [
var y = new c.Variable("y");
var z = new c.Variable("z");
- s.addConstraint(new c.LinearEquation(z, x, c.Strength.weak))
- .addConstraint(new c.LinearEquation(z, y, c.Strength.strong));
+ s.addConstraint(new c.Equation(z, x, c.Strength.weak))
+ .addConstraint(new c.Equation(z, y, c.Strength.strong));
s.addStay(x)
.addStay(y)
@@ -57,8 +57,8 @@ doh.add("c.Strength", [
var y = new c.Variable("y");
var z = new c.Variable("z");
- s.addConstraint(new c.LinearEquation(z, x, c.Strength.weak))
- .addConstraint(new c.LinearEquation(z, y, c.Strength.strong));
+ s.addConstraint(new c.Equation(z, x, c.Strength.weak))
+ .addConstraint(new c.Equation(z, y, c.Strength.strong));
s.addStay(x)
.addStay(y)
View
2  tests/test.js
@@ -28,7 +28,7 @@ c.verbose = false;
doh.squelch = false;
load("Constraint-test.js");
-load("LinearExpression-test.js");
+load("Expression-test.js");
load("Point-test.js");
load("SimplexSolver-test.js");
load("Strength-test.js");
View
3  tests/unittests.html
@@ -53,6 +53,7 @@
<script src="../src/Point.js"></script>
<script src="../src/Expression.js"></script>
<script src="../src/Constraint.js"></script>
+ <script src="../src/Constraint.js"></script>
<script src="../src/EditInfo.js"></script>
<script src="../src/Tableau.js"></script>
<script src="../src/SimplexSolver.js"></script>
@@ -61,7 +62,7 @@
<script src="../util/doh/runner.js"></script>
<script>doh.squelch = false;</script>
<script src="Constraint-test.js"></script>
- <script src="LinearExpression-test.js"></script>
+ <script src="Expression-test.js"></script>
<script src="Point-test.js"></script>
<script src="SimplexSolver-test.js"></script>
<script src="Strength-test.js"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.