Overconstrained:
The Secret Lives of Rectangles
Alex Russell <slightlyoff@google.com>
TXJS, June 14, 2012
@slightlylate
Alex Russell <slightlyoff@google.com>
TXJS, June 14, 2012
@slightlylate
Wikipedia
Stanford
"Maximize Z subject to the following constraints..."
Constraints: Mountain <= 4 Road <= 7 Mountain + Road <= 6 0 <= Mountain, Road, etc. // Not negative! Maximize(Z) = (15 * Mountain) + (10 * Road) // profit
<!doctype html>
<html>
<head>
<style>
body > article {
width: 30%;
min-width: 50px;
max-width: 50em;
}
@media screen and (max-width: 570px) {
body > article { width: 100%; }
}
</style>
</head>
<body>
<article>...</article>
</body>
</html>
Stanford
flickr.com/photos/fdecomite/1423775059
Right = Left + Width Bottom = Top + Height
Top = other.Top + padding Left = other.Left + padding Right = other.Right - padding Bottom = other.Bottom - padding
var left = v(), right = v(), bottom = v(), top = v();
var width = v(), height = v();
constrain( // Not negative
geq(left, 0), geq(right, 0), geq(bottom, 0), geq(top, 0),
geq(width, 0), geq(height, 0)
);
constrain( // The simplest box model ever.
eq(right, plus(left, width)),
eq(bottom, plus(top, height))
);
// Set a position
constrain(eq(left, 50), eq(top, 50));
// Set our width/height
constrain(eq(width, 150), eq(height, 90));
var Box = inherit({
initialize: function(id) {
this.id = id;
this._left = v(); this._right = v();
this._bottom = v(); this._top = v();
this._width = v(); this._height = v();
constrain(
geq(this._left, 0), geq(this._right, 0),
geq(this._bottom, 0), geq(this._top, 0),
geq(this._width, 0), geq(this._height, 0)
eq(this._right, plus(this._left, this._width)),
eq(this._bottom, plus(this._top, this._height))
);
},
set left(v) { constrain(eq(this._left, v)); this.layout(); },
set top(v) { constrain(eq(this._top, v)); this.layout(); },
set width(v) { constrain(eq(this._width, v)); this.layout(); },
set height(v) { constrain(eq(this._height, v)); this.layout(); },
layout: function() { /* Copy styles here */ },
});
var outer = new Box("outer");
outer.left = 50;
outer.top = 50;
outer.width = 150;
outer.height = 90;
var inner = new Box("inner");
inner.left = plus(outer._left, 10);
inner.top = plus(outer._top, 10);
inner.width = 100;
inner.height = 50;
panels.jsvar p = new Panel(); document.body.appendChild(p); p.left = 200; p.top = 150; p.width = 100; p.height = 100; p.debug = true; p.movable = true; var p2 = new Panel(); document.body.appendChild(p2); p.width = 140; p.height = 100; p.rightOf = p2; p.above = p2; p.debug = true; p.movable = true;