Created
December 5, 2011 16:12
-
-
Save lynaghk/1434117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cl.errors.Error | |
description: -> "An error has occurred in Cassowary Coffee" | |
toString: -> @description() | |
class Cl.errors.ConstraintNotFound extends Cl.errors.Error | |
description: -> "Tried to remove a constraint never added to the tableau" | |
class Cl.errors.NonlinearExpression extends Cl.errors.Error | |
description: -> "The resulting expression would be nonlinear" | |
class Cl.errors.NotEnoughStays extends Cl.errors.Error | |
description: -> "There are not enough stays to give specific values to every variable" | |
class Cl.errors.RequiredFailure extends Cl.errors.Error | |
description: -> "A required constraint cannot be satisfied" | |
class Cl.errors.TooDifficult extends Cl.errors.Error | |
description: -> "The constraints are too difficult to solve" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cl.LinearExpression | |
constructor: (clv, value, constant) -> | |
@val = clv | |
@_constant = constant || 0 | |
@_terms = new Hashtable() | |
if clv instanceof AbstractVariable | |
@_terms.put clv, value || 1 | |
else if typeof(clv) == "number" | |
@_constant = clv | |
initializeFromHash: (@_constant, terms) -> | |
@_terms = terms.clone() | |
return this | |
clone: -> new Cl.LinearExpression().initializeFromHash @_constant, @_terms | |
multiplyMe: (x) -> | |
@_constant *= x | |
@_terms.each (clv, coeff) => @_terms.put clv, coeff*x | |
return this | |
times: (x) -> | |
if typeof(x) == "number" | |
@clone().multiplyMe x | |
else | |
expr = x | |
if @isConstant() | |
expr.times @_constant | |
else if expr.isConstant() | |
@times expr._constant | |
else | |
throw new Cl.errors.NonlinearExpression() | |
plus: (expr) -> | |
@val + expr | |
# if expr instanceof LinearExpression | |
# this.clone().addExpression expr, 1.0 | |
# else if expr instanceof Variable | |
# this.clone().addVariable expr, 1.0 | |
goog.exportSymbol "LinearExpression", Cl.LinearExpression | |
goog.exportSymbol "LinearExpression.prototype.plus", Cl.LinearExpression.prototype.plus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
OUT=out | |
#Clean output folder | |
rm -rfd $OUT | |
mkdir $OUT | |
#Compile CoffeeScript | |
find src/coffee -name '*.coffee' | xargs cat > out/out.coffee | |
vendor/coffee-script/bin/coffee \ | |
--google \ | |
--compile \ | |
--output $OUT \ | |
$OUT/out.coffee | |
#Run Closure Compiler | |
java -jar vendor/closure-compiler.jar \ | |
--js vendor/base.js \ | |
--js vendor/jshashtable.js \ | |
--js $OUT/out.js \ | |
--js_output_file $OUT/compiled.js \ | |
--compilation_level ADVANCED_OPTIMIZATIONS \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment