Minor: Add stubs for the symbol and solver

This commit is contained in:
Chinmay Garde
2015-06-23 09:50:52 -07:00
parent e788fe538f
commit 306c795c21
6 changed files with 51 additions and 2 deletions

View File

@@ -11,3 +11,4 @@ part 'variable.dart';
part 'equation_member.dart';
part 'constant_member.dart';
part 'solver.dart';
part 'symbol.dart';

View File

@@ -6,6 +6,7 @@ part of cassowary;
class ConstantMember extends EquationMember {
double value = 0.0;
ConstantMember(this.value);
Expression asExpression() => new Expression([], this.value);

View File

@@ -9,9 +9,19 @@ enum Relation { equalTo, lessThanOrEqualTo, greaterThanOrEqualTo, }
class Constraint {
final Relation relation;
final Expression expression;
double priority = 1000.0;
final bool required;
Constraint(this.expression, this.relation);
static const double requiredPriority = 1000.0;
double _priority = requiredPriority - 1.0;
Constraint(this.expression, this.relation) : this.required = false;
Constraint.Required(this.expression, this.relation) : this.required = true {
this.priority = requiredPriority;
}
double get priority => required ? requiredPriority : _priority;
set priority(double p) => _priority =
required ? requiredPriority : p.clamp(0.0, requiredPriority - 1.0);
Constraint operator |(double p) => this..priority = p;
}

View File

@@ -13,5 +13,27 @@ class Solver {
return false;
}
bool hasConstraint(Constraint c) {
return false;
}
bool addEditVariable(Variable v, double priority) {
return false;
}
bool removeEditVariable(Variable v) {
return false;
}
bool hasEditVariable(Variable v) {
return false;
}
bool suggestVariable(Variable v, double value) {
return false;
}
void updateVariable() {}
Solver operator <<(Constraint c) => this..addConstraint(c);
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of cassowary;
enum SymbolType { invalid, external, slack, error, dummy, }
class Symbol {
SymbolType type;
Symbol(this.type);
}

View File

@@ -280,6 +280,8 @@ void main() {
var c1 = right - left >= CM(200.0);
var c2 = right + left >= CM(0.0);
expect((right >= left) is Constraint, true);
// TODO: Add assertions for this
s << c1 << c2;
});