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
530700a8
Commit
530700a8
authored
Jun 23, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement row.dart and some other minor utility methods
parent
306c795c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
0 deletions
+100
-0
cassowary.dart
packages/cassowary/lib/cassowary.dart
+2
-0
row.dart
packages/cassowary/lib/row.dart
+62
-0
solver.dart
packages/cassowary/lib/solver.dart
+21
-0
utils.dart
packages/cassowary/lib/utils.dart
+15
-0
No files found.
packages/cassowary/lib/cassowary.dart
View file @
530700a8
...
...
@@ -12,3 +12,5 @@ part 'equation_member.dart';
part
'constant_member.dart'
;
part
'solver.dart'
;
part
'symbol.dart'
;
part
'row.dart'
;
part
'utils.dart'
;
packages/cassowary/lib/row.dart
0 → 100644
View file @
530700a8
// 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
;
class
Row
{
final
Map
<
Symbol
,
double
>
_cells
=
new
Map
<
Symbol
,
double
>();
double
_constant
=
0.0
;
double
get
constant
=>
_constant
;
Map
<
Symbol
,
double
>
get
cells
=>
_cells
;
double
add
(
double
value
)
=>
_constant
+=
value
;
void
insertSymbol
(
Symbol
symbol
,
[
double
coefficient
=
1.0
])
{
double
val
=
_elvis
(
_cells
[
symbol
],
0.0
)
+
coefficient
;
if
(
_nearZero
(
val
))
{
_cells
.
remove
(
symbol
);
}
else
{
_cells
[
symbol
]
=
val
+
coefficient
;
}
}
void
insertRow
(
Row
other
,
[
double
coefficient
=
1.0
])
{
_constant
+=
other
.
constant
*
coefficient
;
other
.
cells
.
forEach
((
s
,
v
)
=>
insertSymbol
(
s
,
v
*
coefficient
));
}
void
removeSymbol
(
Symbol
symbol
)
{
_cells
.
remove
(
symbol
);
}
void
reverseSign
()
=>
_cells
.
forEach
((
s
,
v
)
=>
_cells
[
s
]
=
-
v
);
void
solveForSymbol
(
Symbol
symbol
)
{
assert
(
_cells
.
containsKey
(
symbol
));
double
coefficient
=
-
1.0
/
_cells
[
symbol
];
_cells
.
remove
(
symbol
);
_constant
*=
coefficient
;
_cells
.
forEach
((
s
,
v
)
=>
_cells
[
s
]
=
v
*
coefficient
);
}
void
solveForSymbols
(
Symbol
lhs
,
Symbol
rhs
)
{
insertSymbol
(
lhs
,
-
1.0
);
solveForSymbol
(
rhs
);
}
double
coefficientForSymbol
(
Symbol
symbol
)
=>
_elvis
(
_cells
[
symbol
],
0.0
);
void
substitute
(
Symbol
symbol
,
Row
row
)
{
double
coefficient
=
_cells
[
symbol
];
if
(
coefficient
==
null
)
{
return
;
}
_cells
.
remove
(
symbol
);
insertRow
(
row
,
coefficient
);
}
}
packages/cassowary/lib/solver.dart
View file @
530700a8
...
...
@@ -5,6 +5,14 @@
part of
cassowary
;
class
Solver
{
final
Map
<
Constraint
,
Tag
>
_constraints
=
new
Map
<
Constraint
,
Tag
>();
final
Map
<
Symbol
,
Row
>
_rows
=
new
Map
<
Symbol
,
Row
>();
final
Map
<
Variable
,
Symbol
>
_vars
=
new
Map
<
Variable
,
Symbol
>();
final
Map
<
Variable
,
EditInfo
>
_edits
=
new
Map
<
Variable
,
EditInfo
>();
final
List
<
Symbol
>
_infeasibleRows
=
new
List
<
Symbol
>();
final
Row
_objective
=
new
Row
();
final
Row
_artificial
=
new
Row
();
bool
addConstraint
(
Constraint
c
)
{
return
false
;
}
...
...
@@ -37,3 +45,16 @@ class Solver {
Solver
operator
<<(
Constraint
c
)
=>
this
..
addConstraint
(
c
);
}
class
Tag
{
Symbol
marker
;
Symbol
other
;
Tag
(
this
.
marker
,
this
.
other
);
}
class
EditInfo
{
Tag
tag
;
Constraint
constraint
;
double
constant
;
}
packages/cassowary/lib/utils.dart
0 → 100644
View file @
530700a8
// 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
;
bool
_nearZero
(
double
value
)
{
const
double
epsilon
=
1.0e-8
;
return
value
<
0.0
?
-
value
<
epsilon
:
value
<
epsilon
;
}
// Workaround for the lack of a null coalescing operator. Uses a ternary
// instead. Sadly, due the lack of generic types on functions, we have to use
// dynamic instead.
_elvis
(
a
,
b
)
=>
a
!=
null
?
a
:
b
;
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