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
20908034
Commit
20908034
authored
Jun 25, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make constraint priority setup more expressive
parent
2f3e5aa7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
20 deletions
+37
-20
cassowary.dart
packages/cassowary/lib/cassowary.dart
+3
-0
constraint.dart
packages/cassowary/lib/constraint.dart
+4
-14
priority.dart
packages/cassowary/lib/priority.dart
+24
-0
row.dart
packages/cassowary/lib/row.dart
+2
-2
solver.dart
packages/cassowary/lib/solver.dart
+3
-3
variable.dart
packages/cassowary/lib/variable.dart
+1
-1
No files found.
packages/cassowary/lib/cassowary.dart
View file @
20908034
...
...
@@ -4,6 +4,8 @@
library
cassowary
;
import
'dart:math'
;
part
'constraint.dart'
;
part
'expression.dart'
;
part
'term.dart'
;
...
...
@@ -17,3 +19,4 @@ part 'utils.dart';
part
'result.dart'
;
part
'parser_exception.dart'
;
part
'param.dart'
;
part
'priority.dart'
;
packages/cassowary/lib/constraint.dart
View file @
20908034
...
...
@@ -9,19 +9,9 @@ enum Relation { equalTo, lessThanOrEqualTo, greaterThanOrEqualTo, }
class
Constraint
{
final
Relation
relation
;
final
Expression
expression
;
final
bool
required
;
double
priority
=
Priority
.
required
;
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
(
this
.
expression
,
this
.
relation
);
Constraint
operator
|(
double
p
)
=>
this
..
priority
=
p
;
...
...
@@ -31,7 +21,7 @@ class Constraint {
switch
(
relation
)
{
case
Relation
.
equalTo
:
buffer
.
write
(
"
<
= 0 "
);
buffer
.
write
(
"
=
= 0 "
);
break
;
case
Relation
.
greaterThanOrEqualTo
:
buffer
.
write
(
" >= 0 "
);
...
...
@@ -43,7 +33,7 @@ class Constraint {
buffer
.
write
(
" | priority =
${priority}
"
);
if
(
required
)
{
if
(
priority
==
Priority
.
required
)
{
buffer
.
write
(
" (required)"
);
}
...
...
packages/cassowary/lib/priority.dart
0 → 100644
View file @
20908034
// 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
Priority
{
static
final
double
required
=
create
(
1
e3
,
1
e3
,
1
e3
);
static
final
double
strong
=
create
(
1.0
,
0.0
,
0.0
);
static
final
double
medium
=
create
(
0.0
,
1.0
,
0.0
);
static
final
double
weak
=
create
(
0.0
,
0.0
,
1.0
);
static
double
create
(
double
a
,
double
b
,
double
c
)
{
double
result
=
0.0
;
result
+=
max
(
0.0
,
min
(
1
e3
,
a
))
*
1
e6
;
result
+=
max
(
0.0
,
min
(
1
e3
,
b
))
*
1
e3
;
result
+=
max
(
0.0
,
min
(
1
e3
,
c
));
return
result
;
}
static
double
clamp
(
double
value
)
{
return
max
(
0.0
,
min
(
required
,
value
));
}
}
packages/cassowary/lib/row.dart
View file @
20908034
...
...
@@ -16,9 +16,9 @@ class _Row {
double
add
(
double
value
)
=>
constant
+=
value
;
void
insertSymbol
(
_Symbol
symbol
,
[
double
coefficient
=
1.0
])
{
double
val
=
_elvis
(
cells
[
symbol
],
0.0
)
+
coefficient
;
double
val
=
_elvis
(
cells
[
symbol
],
0.0
);
if
(
_nearZero
(
val
))
{
if
(
_nearZero
(
val
+
coefficient
))
{
cells
.
remove
(
symbol
);
}
else
{
cells
[
symbol
]
=
val
+
coefficient
;
...
...
packages/cassowary/lib/solver.dart
View file @
20908034
...
...
@@ -221,7 +221,7 @@ class Solver {
tag
.
marker
=
slack
;
row
.
insertSymbol
(
slack
,
coefficient
);
if
(
!
constraint
.
required
)
{
if
(
constraint
.
priority
<
Priority
.
required
)
{
_Symbol
error
=
new
_Symbol
(
_SymbolType
.
error
,
tick
++);
tag
.
other
=
error
;
row
.
insertSymbol
(
error
,
-
coefficient
);
...
...
@@ -230,7 +230,7 @@ class Solver {
}
break
;
case
Relation
.
equalTo
:
if
(
!
constraint
.
required
)
{
if
(
constraint
.
priority
<
Priority
.
required
)
{
_Symbol
errPlus
=
new
_Symbol
(
_SymbolType
.
error
,
tick
++);
_Symbol
errMinus
=
new
_Symbol
(
_SymbolType
.
error
,
tick
++);
tag
.
marker
=
errPlus
;
...
...
@@ -605,5 +605,5 @@ class _EditInfo {
}
bool
_isValidNonRequiredPriority
(
double
priority
)
{
return
(
priority
>=
0.0
&&
priority
<
Constraint
.
requiredPriority
);
return
(
priority
>=
0.0
&&
priority
<
Priority
.
required
);
}
packages/cassowary/lib/variable.dart
View file @
20908034
...
...
@@ -17,5 +17,5 @@ class Variable {
String
get
debugName
=>
_elvis
(
name
,
"variable
${_tick}
"
);
String
toString
()
=>
"
${debugName}
(=
${value}
)"
;
String
toString
()
=>
debugName
;
}
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