1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2016 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.
import 'equation_member.dart';
import 'expression.dart';
import 'term.dart';
class Variable {
static int _total = 0;
Variable(this.value) : _tick = _total++;
final int _tick;
double value;
String name;
Param get owner => _owner;
Param _owner;
bool applyUpdate(double updated) {
bool res = updated != value;
value = updated;
return res;
}
String get debugName => name ?? 'variable$_tick';
@override
String toString() => debugName;
}
class Param extends EquationMember {
Param([double value = 0.0]) : variable = new Variable(value) {
variable._owner = this;
}
Param.withContext(dynamic context, [double value = 0.0])
: variable = new Variable(value),
context = context {
variable._owner = this;
}
final Variable variable;
dynamic context;
@override
Expression asExpression() => new Expression(<Term>[new Term(variable, 1.0)], 0.0);
@override
bool get isConstant => false;
@override
double get value => variable.value;
String get name => variable.name;
void set name(String name) { variable.name = name; }
}