| OLD | NEW |
| (Empty) |
| 1 // dynamic is not a subtype of dart.core::int (DeltaBlue.dart:139:16) | |
| 2 library; | |
| 3 import self as self; | |
| 4 import "dart:core" as core; | |
| 5 | |
| 6 class DeltaBlue extends core::Object { | |
| 7 constructor •() → void | |
| 8 : super core::Object::•() | |
| 9 ; | |
| 10 method run() → void { | |
| 11 self::chainTest(100); | |
| 12 self::projectionTest(100); | |
| 13 } | |
| 14 } | |
| 15 class Strength extends core::Object { | |
| 16 final field core::int value; | |
| 17 final field core::String name; | |
| 18 const constructor •(core::int value, core::String name) → void | |
| 19 : self::Strength::value = value, self::Strength::name = name, super core::Ob
ject::•() | |
| 20 ; | |
| 21 method nextWeaker() → self::Strength | |
| 22 return const <self::Strength>[self::STRONG_PREFERRED, self::PREFERRED, self:
:STRONG_DEFAULT, self::NORMAL, self::WEAK_DEFAULT, self::WEAKEST].{core::List::[
]}(this.{self::Strength::value}); | |
| 23 static method stronger(self::Strength s1, self::Strength s2) → core::bool { | |
| 24 return s1.{self::Strength::value}.{core::num::<}(s2.{self::Strength::value})
; | |
| 25 } | |
| 26 static method weaker(self::Strength s1, self::Strength s2) → core::bool { | |
| 27 return s1.{self::Strength::value}.{core::num::>}(s2.{self::Strength::value})
; | |
| 28 } | |
| 29 static method weakest(self::Strength s1, self::Strength s2) → self::Strength { | |
| 30 return self::Strength::weaker(s1, s2) ? s1 : s2; | |
| 31 } | |
| 32 } | |
| 33 abstract class Constraint extends core::Object { | |
| 34 final field self::Strength strength; | |
| 35 const constructor •(self::Strength strength) → void | |
| 36 : self::Constraint::strength = strength, super core::Object::•() | |
| 37 ; | |
| 38 abstract method isSatisfied() → core::bool; | |
| 39 abstract method markUnsatisfied() → void; | |
| 40 abstract method addToGraph() → void; | |
| 41 abstract method removeFromGraph() → void; | |
| 42 abstract method chooseMethod(core::int mark) → void; | |
| 43 abstract method markInputs(core::int mark) → void; | |
| 44 abstract method inputsKnown(core::int mark) → core::bool; | |
| 45 abstract method output() → self::Variable; | |
| 46 abstract method execute() → void; | |
| 47 abstract method recalculate() → void; | |
| 48 method addConstraint() → void { | |
| 49 this.{self::Constraint::addToGraph}(); | |
| 50 self::planner.{self::Planner::incrementalAdd}(this); | |
| 51 } | |
| 52 method satisfy(dynamic mark) → self::Constraint { | |
| 53 this.{self::Constraint::chooseMethod}(mark as core::int); | |
| 54 if(!this.{self::Constraint::isSatisfied}()) { | |
| 55 if(this.{self::Constraint::strength}.{core::Object::==}(self::REQUIRED)) { | |
| 56 core::print("Could not satisfy a required constraint!"); | |
| 57 } | |
| 58 return null; | |
| 59 } | |
| 60 this.{self::Constraint::markInputs}(mark as core::int); | |
| 61 self::Variable out = this.{self::Constraint::output}(); | |
| 62 self::Constraint overridden = out.{self::Variable::determinedBy}; | |
| 63 if(!overridden.{core::Object::==}(null)) | |
| 64 overridden.{self::Constraint::markUnsatisfied}(); | |
| 65 out.{self::Variable::determinedBy} = this; | |
| 66 if(!self::planner.{self::Planner::addPropagate}(this, mark as core::int)) | |
| 67 core::print("Cycle encountered"); | |
| 68 out.{self::Variable::mark} = mark; | |
| 69 return overridden; | |
| 70 } | |
| 71 method destroyConstraint() → void { | |
| 72 if(this.{self::Constraint::isSatisfied}()) | |
| 73 self::planner.{self::Planner::incrementalRemove}(this); | |
| 74 this.{self::Constraint::removeFromGraph}(); | |
| 75 } | |
| 76 method isInput() → core::bool | |
| 77 return false; | |
| 78 } | |
| 79 abstract class UnaryConstraint extends self::Constraint { | |
| 80 final field self::Variable myOutput; | |
| 81 field core::bool satisfied = false; | |
| 82 constructor •(self::Variable myOutput, self::Strength strength) → void | |
| 83 : self::UnaryConstraint::myOutput = myOutput, super self::Constraint::•(stre
ngth) { | |
| 84 this.{self::Constraint::addConstraint}(); | |
| 85 } | |
| 86 method addToGraph() → void { | |
| 87 this.{self::UnaryConstraint::myOutput}.{self::Variable::addConstraint}(this)
; | |
| 88 this.{self::UnaryConstraint::satisfied} = false; | |
| 89 } | |
| 90 method chooseMethod(core::int mark) → void { | |
| 91 this.{self::UnaryConstraint::satisfied} = !this.{self::UnaryConstraint::myOu
tput}.{self::Variable::mark}.{core::num::==}(mark) && self::Strength::stronger(t
his.{self::Constraint::strength}, this.{self::UnaryConstraint::myOutput}.{self::
Variable::walkStrength}); | |
| 92 } | |
| 93 method isSatisfied() → core::bool | |
| 94 return this.{self::UnaryConstraint::satisfied}; | |
| 95 method markInputs(core::int mark) → void {} | |
| 96 method output() → self::Variable | |
| 97 return this.{self::UnaryConstraint::myOutput}; | |
| 98 method recalculate() → void { | |
| 99 this.{self::UnaryConstraint::myOutput}.{self::Variable::walkStrength} = this
.{self::Constraint::strength}; | |
| 100 this.{self::UnaryConstraint::myOutput}.{self::Variable::stay} = !this.{self:
:Constraint::isInput}(); | |
| 101 if(this.{self::UnaryConstraint::myOutput}.{self::Variable::stay}) | |
| 102 this.{self::Constraint::execute}(); | |
| 103 } | |
| 104 method markUnsatisfied() → void { | |
| 105 this.{self::UnaryConstraint::satisfied} = false; | |
| 106 } | |
| 107 method inputsKnown(core::int mark) → core::bool | |
| 108 return true; | |
| 109 method removeFromGraph() → void { | |
| 110 if(!this.{self::UnaryConstraint::myOutput}.{core::Object::==}(null)) | |
| 111 this.{self::UnaryConstraint::myOutput}.{self::Variable::removeConstraint}(
this); | |
| 112 this.{self::UnaryConstraint::satisfied} = false; | |
| 113 } | |
| 114 } | |
| 115 class StayConstraint extends self::UnaryConstraint { | |
| 116 constructor •(self::Variable v, self::Strength str) → void | |
| 117 : super self::UnaryConstraint::•(v, str) | |
| 118 ; | |
| 119 method execute() → void {} | |
| 120 } | |
| 121 class EditConstraint extends self::UnaryConstraint { | |
| 122 constructor •(self::Variable v, self::Strength str) → void | |
| 123 : super self::UnaryConstraint::•(v, str) | |
| 124 ; | |
| 125 method isInput() → core::bool | |
| 126 return true; | |
| 127 method execute() → void {} | |
| 128 } | |
| 129 abstract class BinaryConstraint extends self::Constraint { | |
| 130 field self::Variable v1; | |
| 131 field self::Variable v2; | |
| 132 field core::int direction = self::NONE; | |
| 133 constructor •(self::Variable v1, self::Variable v2, self::Strength strength) →
void | |
| 134 : self::BinaryConstraint::v1 = v1, self::BinaryConstraint::v2 = v2, super se
lf::Constraint::•(strength) { | |
| 135 this.{self::Constraint::addConstraint}(); | |
| 136 } | |
| 137 method chooseMethod(core::int mark) → void { | |
| 138 if(this.{self::BinaryConstraint::v1}.{self::Variable::mark}.{core::num::==}(
mark)) { | |
| 139 this.{self::BinaryConstraint::direction} = !this.{self::BinaryConstraint::
v2}.{self::Variable::mark}.{core::num::==}(mark) && self::Strength::stronger(thi
s.{self::Constraint::strength}, this.{self::BinaryConstraint::v2}.{self::Variabl
e::walkStrength}) ? self::FORWARD : self::NONE; | |
| 140 } | |
| 141 if(this.{self::BinaryConstraint::v2}.{self::Variable::mark}.{core::num::==}(
mark)) { | |
| 142 this.{self::BinaryConstraint::direction} = !this.{self::BinaryConstraint::
v1}.{self::Variable::mark}.{core::num::==}(mark) && self::Strength::stronger(thi
s.{self::Constraint::strength}, this.{self::BinaryConstraint::v1}.{self::Variabl
e::walkStrength}) ? self::BACKWARD : self::NONE; | |
| 143 } | |
| 144 if(self::Strength::weaker(this.{self::BinaryConstraint::v1}.{self::Variable:
:walkStrength}, this.{self::BinaryConstraint::v2}.{self::Variable::walkStrength}
)) { | |
| 145 this.{self::BinaryConstraint::direction} = self::Strength::stronger(this.{
self::Constraint::strength}, this.{self::BinaryConstraint::v1}.{self::Variable::
walkStrength}) ? self::BACKWARD : self::NONE; | |
| 146 } | |
| 147 else { | |
| 148 this.{self::BinaryConstraint::direction} = self::Strength::stronger(this.{
self::Constraint::strength}, this.{self::BinaryConstraint::v2}.{self::Variable::
walkStrength}) ? self::FORWARD : self::BACKWARD; | |
| 149 } | |
| 150 } | |
| 151 method addToGraph() → void { | |
| 152 this.{self::BinaryConstraint::v1}.{self::Variable::addConstraint}(this); | |
| 153 this.{self::BinaryConstraint::v2}.{self::Variable::addConstraint}(this); | |
| 154 this.{self::BinaryConstraint::direction} = self::NONE; | |
| 155 } | |
| 156 method isSatisfied() → core::bool | |
| 157 return !this.{self::BinaryConstraint::direction}.{core::num::==}(self::NONE)
; | |
| 158 method markInputs(core::int mark) → void { | |
| 159 this.{self::BinaryConstraint::input}().{self::Variable::mark} = mark; | |
| 160 } | |
| 161 method input() → self::Variable | |
| 162 return this.{self::BinaryConstraint::direction}.{core::num::==}(self::FORWAR
D) ? this.{self::BinaryConstraint::v1} : this.{self::BinaryConstraint::v2}; | |
| 163 method output() → self::Variable | |
| 164 return this.{self::BinaryConstraint::direction}.{core::num::==}(self::FORWAR
D) ? this.{self::BinaryConstraint::v2} : this.{self::BinaryConstraint::v1}; | |
| 165 method recalculate() → void { | |
| 166 self::Variable ihn = this.{self::BinaryConstraint::input}(); | |
| 167 self::Variable out = this.{self::BinaryConstraint::output}(); | |
| 168 out.{self::Variable::walkStrength} = self::Strength::weakest(this.{self::Con
straint::strength}, ihn.{self::Variable::walkStrength}); | |
| 169 out.{self::Variable::stay} = ihn.{self::Variable::stay}; | |
| 170 if(out.{self::Variable::stay}) | |
| 171 this.{self::Constraint::execute}(); | |
| 172 } | |
| 173 method markUnsatisfied() → void { | |
| 174 this.{self::BinaryConstraint::direction} = self::NONE; | |
| 175 } | |
| 176 method inputsKnown(core::int mark) → core::bool { | |
| 177 self::Variable i = this.{self::BinaryConstraint::input}(); | |
| 178 return i.{self::Variable::mark}.{core::num::==}(mark) || i.{self::Variable::
stay} || i.{self::Variable::determinedBy}.{core::Object::==}(null); | |
| 179 } | |
| 180 method removeFromGraph() → void { | |
| 181 if(!this.{self::BinaryConstraint::v1}.{core::Object::==}(null)) | |
| 182 this.{self::BinaryConstraint::v1}.{self::Variable::removeConstraint}(this)
; | |
| 183 if(!this.{self::BinaryConstraint::v2}.{core::Object::==}(null)) | |
| 184 this.{self::BinaryConstraint::v2}.{self::Variable::removeConstraint}(this)
; | |
| 185 this.{self::BinaryConstraint::direction} = self::NONE; | |
| 186 } | |
| 187 } | |
| 188 class ScaleConstraint extends self::BinaryConstraint { | |
| 189 final field self::Variable scale; | |
| 190 final field self::Variable offset; | |
| 191 constructor •(self::Variable src, self::Variable scale, self::Variable offset,
self::Variable dest, self::Strength strength) → void | |
| 192 : self::ScaleConstraint::scale = scale, self::ScaleConstraint::offset = offs
et, super self::BinaryConstraint::•(src, dest, strength) | |
| 193 ; | |
| 194 method addToGraph() → void { | |
| 195 this.{=self::BinaryConstraint::addToGraph}(); | |
| 196 this.{self::ScaleConstraint::scale}.{self::Variable::addConstraint}(this); | |
| 197 this.{self::ScaleConstraint::offset}.{self::Variable::addConstraint}(this); | |
| 198 } | |
| 199 method removeFromGraph() → void { | |
| 200 this.{=self::BinaryConstraint::removeFromGraph}(); | |
| 201 if(!this.{self::ScaleConstraint::scale}.{core::Object::==}(null)) | |
| 202 this.{self::ScaleConstraint::scale}.{self::Variable::removeConstraint}(thi
s); | |
| 203 if(!this.{self::ScaleConstraint::offset}.{core::Object::==}(null)) | |
| 204 this.{self::ScaleConstraint::offset}.{self::Variable::removeConstraint}(th
is); | |
| 205 } | |
| 206 method markInputs(core::int mark) → void { | |
| 207 this.{=self::BinaryConstraint::markInputs}(mark); | |
| 208 this.{self::ScaleConstraint::scale}.{self::Variable::mark} = this.{self::Sca
leConstraint::offset}.{self::Variable::mark} = mark; | |
| 209 } | |
| 210 method execute() → void { | |
| 211 if(this.{self::BinaryConstraint::direction}.{core::num::==}(self::FORWARD))
{ | |
| 212 this.{self::BinaryConstraint::v2}.{self::Variable::value} = this.{self::Bi
naryConstraint::v1}.{self::Variable::value}.{core::num::*}(this.{self::ScaleCons
traint::scale}.{self::Variable::value}).{core::num::+}(this.{self::ScaleConstrai
nt::offset}.{self::Variable::value}); | |
| 213 } | |
| 214 else { | |
| 215 this.{self::BinaryConstraint::v1}.{self::Variable::value} = this.{self::Bi
naryConstraint::v2}.{self::Variable::value}.{core::num::-}(this.{self::ScaleCons
traint::offset}.{self::Variable::value}).{core::num::~/}(this.{self::ScaleConstr
aint::scale}.{self::Variable::value}); | |
| 216 } | |
| 217 } | |
| 218 method recalculate() → void { | |
| 219 self::Variable ihn = this.{self::BinaryConstraint::input}(); | |
| 220 self::Variable out = this.{self::BinaryConstraint::output}(); | |
| 221 out.{self::Variable::walkStrength} = self::Strength::weakest(this.{self::Con
straint::strength}, ihn.{self::Variable::walkStrength}); | |
| 222 out.{self::Variable::stay} = ihn.{self::Variable::stay} && this.{self::Scale
Constraint::scale}.{self::Variable::stay} && this.{self::ScaleConstraint::offset
}.{self::Variable::stay}; | |
| 223 if(out.{self::Variable::stay}) | |
| 224 this.{self::ScaleConstraint::execute}(); | |
| 225 } | |
| 226 } | |
| 227 class EqualityConstraint extends self::BinaryConstraint { | |
| 228 constructor •(self::Variable v1, self::Variable v2, self::Strength strength) →
void | |
| 229 : super self::BinaryConstraint::•(v1, v2, strength) | |
| 230 ; | |
| 231 method execute() → void { | |
| 232 this.{self::BinaryConstraint::output}().{self::Variable::value} = this.{self
::BinaryConstraint::input}().{self::Variable::value}; | |
| 233 } | |
| 234 } | |
| 235 class Variable extends core::Object { | |
| 236 field core::List<self::Constraint> constraints = <self::Constraint>[]; | |
| 237 field self::Constraint determinedBy = null; | |
| 238 field core::int mark = 0; | |
| 239 field self::Strength walkStrength = self::WEAKEST; | |
| 240 field core::bool stay = true; | |
| 241 field core::int value; | |
| 242 final field core::String name; | |
| 243 constructor •(core::String name, core::int value) → void | |
| 244 : self::Variable::name = name, self::Variable::value = value, super core::Ob
ject::•() | |
| 245 ; | |
| 246 method addConstraint(self::Constraint c) → void { | |
| 247 this.{self::Variable::constraints}.{core::List::add$cc}(c); | |
| 248 } | |
| 249 method removeConstraint(self::Constraint c) → void { | |
| 250 this.{self::Variable::constraints}.{core::List::remove}(c); | |
| 251 if(this.{self::Variable::determinedBy}.{core::Object::==}(c)) | |
| 252 this.{self::Variable::determinedBy} = null; | |
| 253 } | |
| 254 } | |
| 255 class Planner extends core::Object { | |
| 256 field core::int currentMark = 0; | |
| 257 constructor •() → void | |
| 258 : super core::Object::•() | |
| 259 ; | |
| 260 method incrementalAdd(self::Constraint c) → void { | |
| 261 core::int mark = this.{self::Planner::newMark}(); | |
| 262 for (self::Constraint overridden = c.{self::Constraint::satisfy}(mark); !ove
rridden.{core::Object::==}(null); overridden = overridden.{self::Constraint::sat
isfy}(mark)) | |
| 263 ; | |
| 264 } | |
| 265 method incrementalRemove(self::Constraint c) → void { | |
| 266 self::Variable out = c.{self::Constraint::output}(); | |
| 267 c.{self::Constraint::markUnsatisfied}(); | |
| 268 c.{self::Constraint::removeFromGraph}(); | |
| 269 core::List<self::Constraint> unsatisfied = this.{self::Planner::removePropag
ateFrom}(out); | |
| 270 self::Strength strength = self::REQUIRED; | |
| 271 do { | |
| 272 for (core::int i = 0; i.{core::num::<}(unsatisfied.{core::List::length});
i = i.{core::num::+}(1)) { | |
| 273 self::Constraint u = unsatisfied.{core::List::[]}(i); | |
| 274 if(u.{self::Constraint::strength}.{core::Object::==}(strength)) | |
| 275 this.{self::Planner::incrementalAdd}(u); | |
| 276 } | |
| 277 strength = strength.{self::Strength::nextWeaker}(); | |
| 278 } | |
| 279 while (!strength.{core::Object::==}(self::WEAKEST)) | |
| 280 } | |
| 281 method newMark() → core::int | |
| 282 return this.{self::Planner::currentMark} = this.{self::Planner::currentMark}
.{core::num::+}(1); | |
| 283 method makePlan(core::List<self::Constraint> sources) → self::Plan { | |
| 284 core::int mark = this.{self::Planner::newMark}(); | |
| 285 self::Plan plan = new self::Plan::•(); | |
| 286 core::List<self::Constraint> todo = sources; | |
| 287 while (todo.{core::List::length}.{core::num::>}(0)) { | |
| 288 self::Constraint c = todo.{core::List::removeLast}(); | |
| 289 if(!c.{self::Constraint::output}().{self::Variable::mark}.{core::num::==}(
mark) && c.{self::Constraint::inputsKnown}(mark)) { | |
| 290 plan.{self::Plan::addConstraint}(c); | |
| 291 c.{self::Constraint::output}().{self::Variable::mark} = mark; | |
| 292 this.{self::Planner::addConstraintsConsumingTo}(c.{self::Constraint::out
put}(), todo); | |
| 293 } | |
| 294 } | |
| 295 return plan; | |
| 296 } | |
| 297 method extractPlanFromConstraints(core::List<self::Constraint> constraints) →
self::Plan { | |
| 298 core::List<self::Constraint> sources = <self::Constraint>[]; | |
| 299 for (core::int i = 0; i.{core::num::<}(constraints.{core::List::length}); i
= i.{core::num::+}(1)) { | |
| 300 self::Constraint c = constraints.{core::List::[]}(i); | |
| 301 if(c.{self::Constraint::isInput}() && c.{self::Constraint::isSatisfied}()) | |
| 302 sources.{core::List::add$cc}(c); | |
| 303 } | |
| 304 return this.{self::Planner::makePlan}(sources); | |
| 305 } | |
| 306 method addPropagate(self::Constraint c, core::int mark) → core::bool { | |
| 307 core::List<self::Constraint> todo = <self::Constraint>[c]; | |
| 308 while (todo.{core::List::length}.{core::num::>}(0)) { | |
| 309 self::Constraint d = todo.{core::List::removeLast}(); | |
| 310 if(d.{self::Constraint::output}().{self::Variable::mark}.{core::num::==}(m
ark)) { | |
| 311 this.{self::Planner::incrementalRemove}(c); | |
| 312 return false; | |
| 313 } | |
| 314 d.{self::Constraint::recalculate}(); | |
| 315 this.{self::Planner::addConstraintsConsumingTo}(d.{self::Constraint::outpu
t}(), todo); | |
| 316 } | |
| 317 return true; | |
| 318 } | |
| 319 method removePropagateFrom(self::Variable out) → core::List<self::Constraint>
{ | |
| 320 out.{self::Variable::determinedBy} = null; | |
| 321 out.{self::Variable::walkStrength} = self::WEAKEST; | |
| 322 out.{self::Variable::stay} = true; | |
| 323 core::List<self::Constraint> unsatisfied = <self::Constraint>[]; | |
| 324 core::List<self::Variable> todo = <self::Variable>[out]; | |
| 325 while (todo.{core::List::length}.{core::num::>}(0)) { | |
| 326 self::Variable v = todo.{core::List::removeLast}(); | |
| 327 for (core::int i = 0; i.{core::num::<}(v.{self::Variable::constraints}.{co
re::List::length}); i = i.{core::num::+}(1)) { | |
| 328 self::Constraint c = v.{self::Variable::constraints}.{core::List::[]}(i)
; | |
| 329 if(!c.{self::Constraint::isSatisfied}()) | |
| 330 unsatisfied.{core::List::add$cc}(c); | |
| 331 } | |
| 332 self::Constraint determining = v.{self::Variable::determinedBy}; | |
| 333 for (core::int i = 0; i.{core::num::<}(v.{self::Variable::constraints}.{co
re::List::length}); i = i.{core::num::+}(1)) { | |
| 334 self::Constraint next = v.{self::Variable::constraints}.{core::List::[]}
(i); | |
| 335 if(!next.{core::Object::==}(determining) && next.{self::Constraint::isSa
tisfied}()) { | |
| 336 next.{self::Constraint::recalculate}(); | |
| 337 todo.{core::List::add}(next.{self::Constraint::output}()); | |
| 338 } | |
| 339 } | |
| 340 } | |
| 341 return unsatisfied; | |
| 342 } | |
| 343 method addConstraintsConsumingTo(self::Variable v, core::List<self::Constraint
> coll) → void { | |
| 344 self::Constraint determining = v.{self::Variable::determinedBy}; | |
| 345 for (core::int i = 0; i.{core::num::<}(v.{self::Variable::constraints}.{core
::List::length}); i = i.{core::num::+}(1)) { | |
| 346 self::Constraint c = v.{self::Variable::constraints}.{core::List::[]}(i); | |
| 347 if(!c.{core::Object::==}(determining) && c.{self::Constraint::isSatisfied}
()) | |
| 348 coll.{core::List::add$cc}(c); | |
| 349 } | |
| 350 } | |
| 351 } | |
| 352 class Plan extends core::Object { | |
| 353 field core::List<self::Constraint> list = <self::Constraint>[]; | |
| 354 constructor •() → void | |
| 355 : super core::Object::•() | |
| 356 ; | |
| 357 method addConstraint(self::Constraint c) → void { | |
| 358 this.{self::Plan::list}.{core::List::add$cc}(c); | |
| 359 } | |
| 360 method execute() → void { | |
| 361 for (core::int i = 0; i.{core::num::<}(this.{self::Plan::list}.{core::List::
length}); i = i.{core::num::+}(1)) { | |
| 362 this.{self::Plan::list}.{core::List::[]}(i).{self::Constraint::execute}(); | |
| 363 } | |
| 364 } | |
| 365 } | |
| 366 static const field self::Strength REQUIRED = const self::Strength::•(0, "require
d"); | |
| 367 static const field self::Strength STRONG_PREFERRED = const self::Strength::•(1,
"strongPreferred"); | |
| 368 static const field self::Strength PREFERRED = const self::Strength::•(2, "prefer
red"); | |
| 369 static const field self::Strength STRONG_DEFAULT = const self::Strength::•(3, "s
trongDefault"); | |
| 370 static const field self::Strength NORMAL = const self::Strength::•(4, "normal"); | |
| 371 static const field self::Strength WEAK_DEFAULT = const self::Strength::•(5, "wea
kDefault"); | |
| 372 static const field self::Strength WEAKEST = const self::Strength::•(6, "weakest"
); | |
| 373 static const field core::int NONE = 1; | |
| 374 static const field core::int FORWARD = 2; | |
| 375 static const field core::int BACKWARD = 0; | |
| 376 static field self::Planner planner = null; | |
| 377 static method main() → dynamic { | |
| 378 new self::DeltaBlue::•().{self::DeltaBlue::run}(); | |
| 379 } | |
| 380 static method chainTest(core::int n) → void { | |
| 381 self::planner = new self::Planner::•(); | |
| 382 self::Variable prev = null; | |
| 383 self::Variable first = null; | |
| 384 self::Variable last = null; | |
| 385 for (core::int i = 0; i.{core::num::<=}(n); i = i.{core::num::+}(1)) { | |
| 386 self::Variable v = new self::Variable::•("v${i}", 0); | |
| 387 if(!prev.{core::Object::==}(null)) | |
| 388 new self::EqualityConstraint::•(prev, v, self::REQUIRED); | |
| 389 if(i.{core::num::==}(0)) | |
| 390 first = v; | |
| 391 if(i.{core::num::==}(n)) | |
| 392 last = v; | |
| 393 prev = v; | |
| 394 } | |
| 395 new self::StayConstraint::•(last, self::STRONG_DEFAULT); | |
| 396 self::EditConstraint edit = new self::EditConstraint::•(first, self::PREFERRED
); | |
| 397 self::Plan plan = self::planner.{self::Planner::extractPlanFromConstraints}(<s
elf::Constraint>[edit]); | |
| 398 for (core::int i = 0; i.{core::num::<}(100); i = i.{core::num::+}(1)) { | |
| 399 first.{self::Variable::value} = i; | |
| 400 plan.{self::Plan::execute}(); | |
| 401 if(!last.{self::Variable::value}.{core::num::==}(i)) { | |
| 402 core::print("Chain test failed:"); | |
| 403 core::print("Expected last value to be ${i} but it was ${last.{self::Varia
ble::value}}."); | |
| 404 } | |
| 405 } | |
| 406 } | |
| 407 static method projectionTest(core::int n) → void { | |
| 408 self::planner = new self::Planner::•(); | |
| 409 self::Variable scale = new self::Variable::•("scale", 10); | |
| 410 self::Variable offset = new self::Variable::•("offset", 1000); | |
| 411 self::Variable src = null; | |
| 412 self::Variable dst = null; | |
| 413 core::List<self::Variable> dests = <self::Variable>[]; | |
| 414 for (core::int i = 0; i.{core::num::<}(n); i = i.{core::num::+}(1)) { | |
| 415 src = new self::Variable::•("src", i); | |
| 416 dst = new self::Variable::•("dst", i); | |
| 417 dests.{core::List::add}(dst); | |
| 418 new self::StayConstraint::•(src, self::NORMAL); | |
| 419 new self::ScaleConstraint::•(src, scale, offset, dst, self::REQUIRED); | |
| 420 } | |
| 421 self::change(src, 17); | |
| 422 if(!dst.{self::Variable::value}.{core::num::==}(1170)) | |
| 423 core::print("Projection 1 failed"); | |
| 424 self::change(dst, 1050); | |
| 425 if(!src.{self::Variable::value}.{core::num::==}(5)) | |
| 426 core::print("Projection 2 failed"); | |
| 427 self::change(scale, 5); | |
| 428 for (core::int i = 0; i.{core::num::<}(n.{core::num::-}(1)); i = i.{core::num:
:+}(1)) { | |
| 429 if(!dests.{core::List::[]}(i).{self::Variable::value}.{core::num::==}(i.{cor
e::num::*}(5).{core::num::+}(1000))) | |
| 430 core::print("Projection 3 failed"); | |
| 431 } | |
| 432 self::change(offset, 2000); | |
| 433 for (core::int i = 0; i.{core::num::<}(n.{core::num::-}(1)); i = i.{core::num:
:+}(1)) { | |
| 434 if(!dests.{core::List::[]}(i).{self::Variable::value}.{core::num::==}(i.{cor
e::num::*}(5).{core::num::+}(2000))) | |
| 435 core::print("Projection 4 failed"); | |
| 436 } | |
| 437 } | |
| 438 static method change(self::Variable v, core::int newValue) → void { | |
| 439 self::EditConstraint edit = new self::EditConstraint::•(v, self::PREFERRED); | |
| 440 self::Plan plan = self::planner.{self::Planner::extractPlanFromConstraints}(<s
elf::EditConstraint>[edit]); | |
| 441 for (core::int i = 0; i.{core::num::<}(10); i = i.{core::num::+}(1)) { | |
| 442 v.{self::Variable::value} = newValue; | |
| 443 plan.{self::Plan::execute}(); | |
| 444 } | |
| 445 edit.{self::Constraint::destroyConstraint}(); | |
| 446 } | |
| OLD | NEW |