Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
5288d466
Commit
5288d466
authored
Jun 22, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dry up incremental expression construction from constants, variable, terms and other expressions
parent
a8e6ea06
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
158 deletions
+18
-158
constant_member.dart
packages/cassowary/lib/constant_member.dart
+1
-51
equation_member.dart
packages/cassowary/lib/equation_member.dart
+13
-1
expression.dart
packages/cassowary/lib/expression.dart
+2
-0
term.dart
packages/cassowary/lib/term.dart
+1
-52
variable.dart
packages/cassowary/lib/variable.dart
+1
-54
No files found.
packages/cassowary/lib/constant_member.dart
View file @
5288d466
...
...
@@ -8,57 +8,7 @@ class ConstantMember extends EquationMember {
double
value
=
0.0
;
ConstantMember
(
this
.
value
);
Expression
_asExpression
()
=>
new
Expression
([],
this
.
value
);
Constraint
operator
>=(
EquationMember
m
)
=>
_asExpression
()
>=
m
;
Constraint
operator
<=(
EquationMember
m
)
=>
_asExpression
()
<=
m
;
operator
==(
EquationMember
m
)
=>
_asExpression
()
==
m
;
Expression
operator
+(
EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
return
new
Expression
([],
this
.
value
+
m
.
value
);
}
if
(
m
is
Variable
)
{
return
new
Expression
([
new
Term
(
m
,
1.0
)],
this
.
value
);
}
if
(
m
is
Term
)
{
return
new
Expression
([
m
],
this
.
value
);
}
if
(
m
is
Expression
)
{
return
new
Expression
(
new
List
.
from
(
m
.
terms
),
this
.
value
+
m
.
constant
);
}
assert
(
false
);
return
null
;
}
Expression
operator
-(
EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
return
new
Expression
([],
this
.
value
-
m
.
value
);
}
if
(
m
is
Variable
)
{
return
new
Expression
([
new
Term
(
m
,
-
1.0
)],
this
.
value
);
}
if
(
m
is
Term
)
{
return
new
Expression
([
new
Term
(
m
.
variable
,
-
m
.
coefficient
)],
this
.
value
);
}
if
(
m
is
Expression
)
{
var
negatedTerms
=
m
.
terms
.
fold
(
new
List
<
Term
>(),
(
list
,
term
)
=>
list
..
add
(
new
Term
(
term
.
variable
,
-
term
.
coefficient
)));
return
new
Expression
(
negatedTerms
,
this
.
value
-
m
.
constant
);
}
assert
(
false
);
return
null
;
}
Expression
asExpression
()
=>
new
Expression
([],
this
.
value
);
EquationMember
operator
*(
double
m
)
{
return
new
ConstantMember
(
this
.
value
*
m
);
...
...
packages/cassowary/lib/equation_member.dart
View file @
5288d466
...
...
@@ -4,4 +4,16 @@
part of
cassowary
;
abstract
class
EquationMember
{}
abstract
class
EquationMember
{
Expression
asExpression
();
Constraint
operator
>=(
EquationMember
m
)
=>
asExpression
()
>=
m
;
Constraint
operator
<=(
EquationMember
m
)
=>
asExpression
()
<=
m
;
operator
==(
EquationMember
m
)
=>
asExpression
()
==
m
;
Expression
operator
+(
EquationMember
m
)
=>
asExpression
()
+
m
;
Expression
operator
-(
EquationMember
m
)
=>
asExpression
()
-
m
;
}
packages/cassowary/lib/expression.dart
View file @
5288d466
...
...
@@ -12,6 +12,8 @@ class Expression extends EquationMember {
Expression
(
this
.
terms
,
this
.
constant
);
Expression
asExpression
()
=>
this
;
Constraint
_createConstraint
(
EquationMember
/* rhs */
value
,
Relation
relation
)
{
if
(
value
is
ConstantMember
)
{
...
...
packages/cassowary/lib/term.dart
View file @
5288d466
...
...
@@ -11,60 +11,9 @@ class Term extends EquationMember {
Term
(
this
.
variable
,
this
.
coefficient
);
Expression
_
asExpression
()
=>
Expression
asExpression
()
=>
new
Expression
([
new
Term
(
this
.
variable
,
this
.
coefficient
)],
0.0
);
Constraint
operator
>=(
EquationMember
m
)
=>
_asExpression
()
>=
m
;
Constraint
operator
<=(
EquationMember
m
)
=>
_asExpression
()
<=
m
;
operator
==(
EquationMember
m
)
=>
_asExpression
()
==
m
;
Expression
operator
+(
EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
return
new
Expression
([
this
],
m
.
value
);
}
if
(
m
is
Variable
)
{
return
new
Expression
([
this
,
new
Term
(
m
,
1.0
)],
0.0
);
}
if
(
m
is
Term
)
{
return
new
Expression
([
this
,
m
],
0.0
);
}
if
(
m
is
Expression
)
{
return
new
Expression
(
new
List
.
from
(
m
.
terms
)..
insert
(
0
,
this
),
m
.
constant
);
}
assert
(
false
);
return
null
;
}
Expression
operator
-(
EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
return
new
Expression
([
this
],
-
m
.
value
);
}
if
(
m
is
Variable
)
{
return
new
Expression
([
this
,
new
Term
(
m
,
-
1.0
)],
0.0
);
}
if
(
m
is
Term
)
{
return
new
Expression
([
this
,
new
Term
(
m
.
variable
,
-
m
.
coefficient
)],
0.0
);
}
if
(
m
is
Expression
)
{
var
negatedTerms
=
m
.
terms
.
fold
(
new
List
<
Term
>(),
(
list
,
t
)
=>
list
..
add
(
new
Term
(
t
.
variable
,
-
t
.
coefficient
)));
return
new
Expression
(
negatedTerms
..
insert
(
0
,
this
),
-
m
.
constant
);
}
assert
(
false
);
return
null
;
}
EquationMember
operator
*(
double
m
)
{
return
new
Term
(
this
.
variable
,
this
.
coefficient
*
m
);
}
...
...
packages/cassowary/lib/variable.dart
View file @
5288d466
...
...
@@ -8,60 +8,7 @@ class Variable extends EquationMember {
double
value
=
0.0
;
Variable
(
this
.
value
);
Expression
_asExpression
()
=>
new
Expression
([
new
Term
(
this
,
1.0
)],
0.0
);
Constraint
operator
>=(
EquationMember
m
)
=>
_asExpression
()
>=
m
;
Constraint
operator
<=(
EquationMember
m
)
=>
_asExpression
()
<=
m
;
operator
==(
EquationMember
m
)
=>
_asExpression
()
==
m
;
Expression
operator
+(
EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
return
new
Expression
([
new
Term
(
this
,
1.0
)],
m
.
value
);
}
if
(
m
is
Variable
)
{
return
new
Expression
([
new
Term
(
this
,
1.0
),
new
Term
(
m
,
1.0
)],
0.0
);
}
if
(
m
is
Term
)
{
return
new
Expression
([
new
Term
(
this
,
1.0
),
m
],
0.0
);
}
if
(
m
is
Expression
)
{
return
new
Expression
(
new
List
.
from
(
m
.
terms
)..
insert
(
0
,
new
Term
(
this
,
1.0
)),
m
.
constant
);
}
assert
(
false
);
return
null
;
}
Expression
operator
-(
EquationMember
m
)
{
if
(
m
is
ConstantMember
)
{
return
new
Expression
([
new
Term
(
this
,
1.0
)],
-
m
.
value
);
}
if
(
m
is
Variable
)
{
return
new
Expression
([
new
Term
(
this
,
1.0
),
new
Term
(
m
,
-
1.0
)],
0.0
);
}
if
(
m
is
Term
)
{
return
new
Expression
(
[
new
Term
(
this
,
1.0
),
new
Term
(
m
.
variable
,
-
m
.
coefficient
)],
0.0
);
}
if
(
m
is
Expression
)
{
var
negatedTerms
=
m
.
terms
.
fold
(
new
List
<
Term
>(),
(
list
,
t
)
=>
list
..
add
(
new
Term
(
t
.
variable
,
-
t
.
coefficient
)));
negatedTerms
.
insert
(
0
,
new
Term
(
this
,
1.0
));
return
new
Expression
(
negatedTerms
,
-
m
.
constant
);
}
assert
(
false
);
return
null
;
}
Expression
asExpression
()
=>
new
Expression
([
new
Term
(
this
,
1.0
)],
0.0
);
EquationMember
operator
*(
double
m
)
{
return
new
Term
(
this
,
m
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment