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
e9335659
Commit
e9335659
authored
Jul 08, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bulk edit update options to the solver
parent
149a2ca1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
21 deletions
+50
-21
solver.dart
packages/cassowary/lib/solver.dart
+39
-21
cassowary_test.dart
packages/cassowary/test/cassowary_test.dart
+11
-0
No files found.
packages/cassowary/lib/solver.dart
View file @
e9335659
...
...
@@ -18,28 +18,10 @@ class Solver {
/// add any for some reason, a cleanup is attempted so that either all
/// constraints will be added or none.
Result
addConstraints
(
List
<
Constraint
>
constraints
)
{
List
<
Constraint
>
added
=
new
List
<
Constraint
>();
bool
needsCleanup
=
false
;
Result
result
=
Result
.
success
;
for
(
Constraint
constraint
in
constraints
)
{
result
=
addConstraint
(
constraint
);
if
(
result
==
Result
.
success
)
{
added
.
add
(
constraint
);
}
else
{
needsCleanup
=
true
;
break
;
}
}
_SolverBulkUpdate
applier
=
(
Constraint
c
)
=>
addConstraint
(
c
);
_SolverBulkUpdate
undoer
=
(
Constraint
c
)
=>
removeConstraint
(
c
);
if
(
needsCleanup
)
{
for
(
Constraint
constraint
in
added
)
{
removeConstraint
(
constraint
);
}
}
return
result
;
return
_bulkEdit
(
constraints
,
applier
,
undoer
);
}
Result
addConstraint
(
Constraint
constraint
)
{
...
...
@@ -113,6 +95,13 @@ class Solver {
return
_constraints
.
containsKey
(
constraint
);
}
Result
addEditVariables
(
List
<
Variable
>
variables
,
double
priority
)
{
_SolverBulkUpdate
applier
=
(
Variable
v
)
=>
addEditVariable
(
v
,
priority
);
_SolverBulkUpdate
undoer
=
(
Variable
v
)
=>
removeEditVariable
(
v
);
return
_bulkEdit
(
variables
,
applier
,
undoer
);
}
Result
addEditVariable
(
Variable
variable
,
double
priority
)
{
if
(
_edits
.
containsKey
(
variable
))
{
return
Result
.
duplicateEditVariable
;
...
...
@@ -189,6 +178,33 @@ class Solver {
return
updates
;
}
Result
_bulkEdit
(
Iterable
items
,
_SolverBulkUpdate
applier
,
_SolverBulkUpdate
undoer
)
{
List
applied
=
new
List
();
bool
needsCleanup
=
false
;
Result
result
=
Result
.
success
;
for
(
dynamic
item
in
items
)
{
result
=
applier
(
item
);
if
(
result
==
Result
.
success
)
{
applied
.
add
(
item
);
}
else
{
needsCleanup
=
true
;
break
;
}
}
if
(
needsCleanup
)
{
for
(
dynamic
item
in
applied
.
reversed
)
{
undoer
(
item
);
}
}
return
result
;
}
_Symbol
_symbolForVariable
(
Variable
variable
)
{
_Symbol
symbol
=
_vars
[
variable
];
...
...
@@ -617,3 +633,5 @@ class _EditInfo {
bool
_isValidNonRequiredPriority
(
double
priority
)
{
return
(
priority
>=
0.0
&&
priority
<
Priority
.
required
);
}
typedef
Result
_SolverBulkUpdate
(
dynamic
item
);
packages/cassowary/test/cassowary_test.dart
View file @
e9335659
...
...
@@ -592,4 +592,15 @@ void main() {
expect
((
left
==
right
).
runtimeType
,
Constraint
);
});
test
(
'bulk_add_edit_variables'
,
()
{
Solver
s
=
new
Solver
();
var
left
=
new
Param
(
0.0
);
var
right
=
new
Param
(
100.0
);
var
mid
=
new
Param
(
0.0
);
expect
(
s
.
addEditVariables
(
[
left
.
variable
,
right
.
variable
,
mid
.
variable
],
999.0
),
Result
.
success
);
});
}
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