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
0117de40
Unverified
Commit
0117de40
authored
Mar 20, 2023
by
Greg Price
Committed by
GitHub
Mar 20, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give PolynomialFit more docs, and a debug toString (#122333)
Give PolynomialFit more docs, and a debug toString
parent
e0ea39fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
lsq_solver.dart
packages/flutter/lib/src/gestures/lsq_solver.dart
+15
-1
lsq_solver_test.dart
packages/flutter/test/gestures/lsq_solver_test.dart
+8
-0
No files found.
packages/flutter/lib/src/gestures/lsq_solver.dart
View file @
0117de40
...
...
@@ -70,12 +70,26 @@ class PolynomialFit {
PolynomialFit
(
int
degree
)
:
coefficients
=
Float64List
(
degree
+
1
);
/// The polynomial coefficients of the fit.
///
/// For each `i`, the element `coefficients[i]` is the coefficient of
/// the `i`-th power of the variable.
final
List
<
double
>
coefficients
;
/// An indicator of the quality of the fit.
///
/// Larger values indicate greater quality.
/// Larger values indicate greater quality. The value ranges from 0.0 to 1.0.
///
/// The confidence is defined as the fraction of the dataset's variance
/// that is captured by variance in the fit polynomial. In statistics
/// textbooks this is often called "r-squared".
late
double
confidence
;
@override
String
toString
()
{
final
String
coefficientString
=
coefficients
.
map
((
double
c
)
=>
c
.
toStringAsPrecision
(
3
)).
toList
().
toString
();
return
'
${objectRuntimeType(this, 'PolynomialFit')}
(
$coefficientString
, confidence:
${confidence.toStringAsFixed(3)}
)'
;
}
}
/// Uses the least-squares algorithm to fit a polynomial to a set of data.
...
...
packages/flutter/test/gestures/lsq_solver_test.dart
View file @
0117de40
...
...
@@ -69,4 +69,12 @@ void main() {
expect
(
approx
(
fit
.
confidence
,
1.0
),
isTrue
);
});
test
(
'Least-squares fit: toString'
,
()
{
final
PolynomialFit
fit
=
PolynomialFit
(
2
);
fit
.
coefficients
[
0
]
=
123.45
;
fit
.
coefficients
[
1
]
=
54.321
;
fit
.
coefficients
[
2
]
=
1.3579
;
fit
.
confidence
=
0.9876
;
expect
(
fit
.
toString
(),
'PolynomialFit([123, 54.3, 1.36], confidence: 0.988)'
);
});
}
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