Skip to content

Commit 6c0460b

Browse files
Merge pull request #182 from lexaknyazev/strong-mode
Strong mode and linter updates
2 parents 0930a2d + 808300b commit 6c0460b

File tree

92 files changed

+4431
-4165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4431
-4165
lines changed

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
analyzer:
2+
strong-mode:
3+
implicit-dynamic: False
4+
implicit-casts: False

benchmark/matrix_bench.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MatrixMultiplyBenchmark extends BenchmarkBase {
1919
new MatrixMultiplyBenchmark().report();
2020
}
2121

22+
@override
2223
void run() {
2324
for (int i = 0; i < 200; i++) {
2425
Matrix44Operations.multiply(C, 0, A, 0, B, 0);
@@ -36,6 +37,7 @@ class SIMDMatrixMultiplyBenchmark extends BenchmarkBase {
3637
new SIMDMatrixMultiplyBenchmark().report();
3738
}
3839

40+
@override
3941
void run() {
4042
for (int i = 0; i < 200; i++) {
4143
Matrix44SIMDOperations.multiply(C, 0, A, 0, B, 0);
@@ -53,6 +55,7 @@ class VectorTransformBenchmark extends BenchmarkBase {
5355
new VectorTransformBenchmark().report();
5456
}
5557

58+
@override
5659
void run() {
5760
for (int i = 0; i < 200; i++) {
5861
Matrix44Operations.transform4(C, 0, A, 0, B, 0);
@@ -70,6 +73,7 @@ class SIMDVectorTransformBenchmark extends BenchmarkBase {
7073
new SIMDVectorTransformBenchmark().report();
7174
}
7275

76+
@override
7377
void run() {
7478
for (int i = 0; i < 200; i++) {
7579
Matrix44SIMDOperations.transform4(C, 0, A, 0, B, 0);
@@ -89,14 +93,15 @@ class ViewMatrixBenchmark extends BenchmarkBase {
8993
new ViewMatrixBenchmark().report();
9094
}
9195

96+
@override
9297
void run() {
9398
for (int i = 0; i < 100; i++) {
9499
setViewMatrix(M, P, F, U);
95100
}
96101
}
97102
}
98103

99-
main() {
104+
void main() {
100105
MatrixMultiplyBenchmark.main();
101106
SIMDMatrixMultiplyBenchmark.main();
102107
VectorTransformBenchmark.main();

bin/mesh_generator.dart

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,70 @@ library vector_math.mesh_generator;
77
import 'dart:convert';
88
import 'package:vector_math/vector_math_geometry.dart';
99

10+
typedef MeshGeometry GenerateFunction(List<String> args);
11+
1012
MeshGeometry generateCube(List<String> args) {
1113
if (args.length != 3) {
1214
return null;
1315
}
14-
num width = double.parse(args[0]);
15-
num height = double.parse(args[1]);
16-
num depth = double.parse(args[2]);
17-
var generator = new CubeGenerator();
18-
MeshGeometry geometry = generator.createCube(width, height, depth);
19-
return geometry;
16+
final double width = double.parse(args[0]);
17+
final double height = double.parse(args[1]);
18+
final double depth = double.parse(args[2]);
19+
final CubeGenerator generator = new CubeGenerator();
20+
return generator.createCube(width, height, depth);
2021
}
2122

2223
MeshGeometry generateSphere(List<String> args) {
2324
if (args.length != 1) {
2425
return null;
2526
}
26-
num radius = double.parse(args[0]);
27-
var generator = new SphereGenerator();
28-
MeshGeometry geometry = generator.createSphere(radius);
29-
return geometry;
27+
final double radius = double.parse(args[0]);
28+
final SphereGenerator generator = new SphereGenerator();
29+
return generator.createSphere(radius);
3030
}
3131

3232
MeshGeometry generateCircle(List<String> args) {
3333
if (args.length != 1) {
3434
return null;
3535
}
36-
num radius = double.parse(args[0]);
37-
var generator = new CircleGenerator();
38-
MeshGeometry geometry = generator.createCircle(radius);
39-
return geometry;
36+
final double radius = double.parse(args[0]);
37+
final CircleGenerator generator = new CircleGenerator();
38+
return generator.createCircle(radius);
4039
}
4140

4241
MeshGeometry generateCylinder(List<String> args) {
4342
if (args.length != 3) {
4443
return null;
4544
}
46-
num topRadius = double.parse(args[0]);
47-
num bottomRadius = double.parse(args[1]);
48-
num height = double.parse(args[2]);
49-
var generator = new CylinderGenerator();
50-
MeshGeometry geometry =
51-
generator.createCylinder(topRadius, bottomRadius, height);
52-
return geometry;
45+
final double topRadius = double.parse(args[0]);
46+
final double bottomRadius = double.parse(args[1]);
47+
final double height = double.parse(args[2]);
48+
final CylinderGenerator generator = new CylinderGenerator();
49+
return generator.createCylinder(topRadius, bottomRadius, height);
5350
}
5451

5552
MeshGeometry generateRing(List<String> args) {
5653
if (args.length != 2) {
5754
return null;
5855
}
59-
num innerRadius = double.parse(args[0]);
60-
num outerRadius = double.parse(args[1]);
61-
var generator = new RingGenerator();
62-
MeshGeometry geometry = generator.createRing(innerRadius, outerRadius);
63-
return geometry;
56+
final double innerRadius = double.parse(args[0]);
57+
final double outerRadius = double.parse(args[1]);
58+
final RingGenerator generator = new RingGenerator();
59+
return generator.createRing(innerRadius, outerRadius);
6460
}
6561

66-
Map<String, Function> generators = {
62+
Map<String, GenerateFunction> generators = <String, GenerateFunction>{
6763
'cube': generateCube,
6864
'sphere': generateSphere,
6965
'circle': generateCircle,
7066
'cylinder': generateCylinder,
7167
'ring': generateRing
7268
};
7369

74-
main(List<String> args_) {
75-
List<String> args = new List.from(args_, growable: true);
70+
void main(List<String> args_) {
71+
final List<String> args = new List<String>.from(args_, growable: true);
7672

77-
if (args.length == 0) {
73+
if (args.isEmpty) {
7874
print('mesh_generator.dart <type> [<arg0> ... <argN>]');
7975
print('');
8076
print('<type> = cube, sphere, cylinder');
@@ -86,13 +82,13 @@ main(List<String> args_) {
8682
print('');
8783
return;
8884
}
89-
var type = args.removeAt(0);
90-
var generator = generators[type];
85+
final String type = args.removeAt(0);
86+
final GenerateFunction generator = generators[type];
9187
if (generator == null) {
9288
print('Could not find generator for $type');
9389
return;
9490
}
95-
MeshGeometry geometry = generator(args);
91+
final MeshGeometry geometry = generator(args);
9692
if (geometry == null) {
9793
print('Error generating geometry for $type');
9894
return;

lib/hash.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// All rights reserved. Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
/**
6-
* Generates a hash code for multiple [objects].
7-
*/
8-
int hashObjects(Iterable objects) =>
9-
_finish(objects.fold(0, (h, i) => _combine(h, i.hashCode)));
5+
///
6+
/// Generates a hash code for multiple [objects].
7+
///
8+
int hashObjects(Iterable<Object> objects) =>
9+
_finish(objects.fold<int>(0, (int h, Object i) => _combine(h, i.hashCode)));
1010

1111
// Jenkins hash functions
1212
int _combine(int hash, int value) {

lib/src/vector_math/aabb2.dart

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class Aabb2 {
7878

7979
/// Transform [this] by the transform [t].
8080
void transform(Matrix3 t) {
81-
final center = new Vector2.zero();
82-
final halfExtents = new Vector2.zero();
81+
final Vector2 center = new Vector2.zero();
82+
final Vector2 halfExtents = new Vector2.zero();
8383
copyCenterAndHalfExtents(center, halfExtents);
8484
t
8585
..transform2(center)
@@ -94,8 +94,8 @@ class Aabb2 {
9494

9595
/// Rotate [this] by the rotation matrix [t].
9696
void rotate(Matrix3 t) {
97-
final center = new Vector2.zero();
98-
final halfExtents = new Vector2.zero();
97+
final Vector2 center = new Vector2.zero();
98+
final Vector2 halfExtents = new Vector2.zero();
9999
copyCenterAndHalfExtents(center, halfExtents);
100100
t.absoluteRotate2(halfExtents);
101101
_min
@@ -133,8 +133,8 @@ class Aabb2 {
133133

134134
/// Return if [this] contains [other].
135135
bool containsAabb2(Aabb2 other) {
136-
final otherMax = other._max;
137-
final otherMin = other._min;
136+
final Vector2 otherMax = other._max;
137+
final Vector2 otherMin = other._min;
138138

139139
return (_min.x < otherMin.x) &&
140140
(_min.y < otherMin.y) &&
@@ -143,17 +143,16 @@ class Aabb2 {
143143
}
144144

145145
/// Return if [this] contains [other].
146-
bool containsVector2(Vector2 other) {
147-
return (_min.x < other.x) &&
148-
(_min.y < other.y) &&
149-
(_max.x > other.x) &&
150-
(_max.y > other.y);
151-
}
146+
bool containsVector2(Vector2 other) =>
147+
(_min.x < other.x) &&
148+
(_min.y < other.y) &&
149+
(_max.x > other.x) &&
150+
(_max.y > other.y);
152151

153152
/// Return if [this] intersects with [other].
154153
bool intersectsWithAabb2(Aabb2 other) {
155-
final otherMax = other._max;
156-
final otherMin = other._min;
154+
final Vector2 otherMax = other._max;
155+
final Vector2 otherMin = other._min;
157156

158157
return (_min.x <= otherMax.x) &&
159158
(_min.y <= otherMax.y) &&
@@ -162,10 +161,9 @@ class Aabb2 {
162161
}
163162

164163
/// Return if [this] intersects with [other].
165-
bool intersectsWithVector2(Vector2 other) {
166-
return (_min.x <= other.x) &&
167-
(_min.y <= other.y) &&
168-
(_max.x >= other.x) &&
169-
(_max.y >= other.y);
170-
}
164+
bool intersectsWithVector2(Vector2 other) =>
165+
(_min.x <= other.x) &&
166+
(_min.y <= other.y) &&
167+
(_max.x >= other.x) &&
168+
(_max.y >= other.y);
171169
}

0 commit comments

Comments
 (0)