-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_methods.dart
87 lines (76 loc) · 2.07 KB
/
helper_methods.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'chart/data_pool.dart';
void main() {
test('test equalsPaths', () {
expect(
HelperMethods.equalsPaths(MockData.path1, MockData.path1Duplicate),
true,
);
expect(HelperMethods.equalsPaths(MockData.path1, MockData.path2), false);
});
}
class HelperMethods {
static bool equalsPaths(Path path1, Path path2) {
final metrics1 = path1.computeMetrics().toList();
final metrics2 = path2.computeMetrics().toList();
if (metrics1.length != metrics2.length) {
return false;
}
for (var i = 0; i < metrics1.length; i++) {
if (metrics1[i].length != metrics2[i].length) {
return false;
}
if (metrics1[i].isClosed != metrics2[i].isClosed) {
return false;
}
if (metrics1[i].contourIndex != metrics2[i].contourIndex) {
return false;
}
final half = metrics1[i].length / 2;
final tangent1 = metrics1[i].getTangentForOffset(half);
final tangent2 = metrics2[i].getTangentForOffset(half);
if (tangent1!.position != tangent2!.position) {
return false;
}
if (tangent1.angle != tangent2.angle) {
return false;
}
if (tangent1.vector != tangent2.vector) {
return false;
}
}
return true;
}
static bool equalsRRects(
RRect rrect1,
RRect rrect2, {
double tolerance = 0.05,
}) {
if ((rrect1.left - rrect2.left).abs() > tolerance) {
return false;
}
if ((rrect1.top - rrect2.top).abs() > tolerance) {
return false;
}
if ((rrect1.right - rrect2.right).abs() > tolerance) {
return false;
}
if ((rrect1.bottom - rrect2.bottom).abs() > tolerance) {
return false;
}
if (rrect1.blRadius != rrect2.blRadius) {
return false;
}
if (rrect1.brRadius != rrect2.brRadius) {
return false;
}
if (rrect1.trRadius != rrect2.trRadius) {
return false;
}
if (rrect1.tlRadius != rrect2.tlRadius) {
return false;
}
return true;
}
}