Skip to content

Commit becb344

Browse files
committed
mostly happy
1 parent 8cd14d1 commit becb344

Some content is hidden

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

48 files changed

+273
-267
lines changed

analysis_options.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include: package:pedantic/analysis_options.yaml
22

3+
analyzer:
4+
enable-experiment:
5+
- non-nullable
6+
37
linter:
48
rules:
59
- avoid_bool_literals_in_conditional_expressions

benchmark/matrix4_tween_bench.dart

+8-20
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup {
8989

9090
@override
9191
Matrix4 lerp(Matrix4 begin, Matrix4 end, double t) {
92-
if (beginTranslation == null) _lerpInit();
9392
begin.decompose(beginTranslation, beginRotation, beginScale);
9493
end.decompose(endTranslation, endRotation, endScale);
9594
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
@@ -99,25 +98,14 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup {
9998
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
10099
}
101100

102-
// Manually initialized pre-allocated vectors.
103-
static Vector3 beginTranslation;
104-
static Vector3 endTranslation;
105-
static Vector3 lerpTranslation;
106-
static Quaternion beginRotation;
107-
static Quaternion endRotation;
108-
static Vector3 beginScale;
109-
static Vector3 endScale;
110-
static Vector3 lerpScale;
111-
static void _lerpInit() {
112-
beginTranslation = Vector3.zero();
113-
endTranslation = Vector3.zero();
114-
lerpTranslation = Vector3.zero();
115-
beginRotation = Quaternion.identity();
116-
endRotation = Quaternion.identity();
117-
beginScale = Vector3.zero();
118-
endScale = Vector3.zero();
119-
lerpScale = Vector3.zero();
120-
}
101+
late final beginTranslation = Vector3.zero();
102+
late final endTranslation = Vector3.zero();
103+
late final lerpTranslation = Vector3.zero();
104+
late final beginRotation = Quaternion.identity();
105+
late final endRotation = Quaternion.identity();
106+
late final beginScale = Vector3.zero();
107+
late final endScale = Vector3.zero();
108+
late final lerpScale = Vector3.zero();
121109
}
122110

123111
void main() {

bin/mesh_generator.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ library vector_math.mesh_generator;
77
import 'dart:convert';
88
import 'package:vector_math/vector_math_geometry.dart';
99

10-
typedef GenerateFunction = MeshGeometry Function(List<String> args);
10+
typedef GenerateFunction = MeshGeometry? Function(List<String> args);
1111

12-
MeshGeometry generateCube(List<String> args) {
12+
MeshGeometry? generateCube(List<String> args) {
1313
if (args.length != 3) {
1414
return null;
1515
}
@@ -20,7 +20,7 @@ MeshGeometry generateCube(List<String> args) {
2020
return generator.createCube(width, height, depth);
2121
}
2222

23-
MeshGeometry generateSphere(List<String> args) {
23+
MeshGeometry? generateSphere(List<String> args) {
2424
if (args.length != 1) {
2525
return null;
2626
}
@@ -29,7 +29,7 @@ MeshGeometry generateSphere(List<String> args) {
2929
return generator.createSphere(radius);
3030
}
3131

32-
MeshGeometry generateCircle(List<String> args) {
32+
MeshGeometry? generateCircle(List<String> args) {
3333
if (args.length != 1) {
3434
return null;
3535
}
@@ -38,7 +38,7 @@ MeshGeometry generateCircle(List<String> args) {
3838
return generator.createCircle(radius);
3939
}
4040

41-
MeshGeometry generateCylinder(List<String> args) {
41+
MeshGeometry? generateCylinder(List<String> args) {
4242
if (args.length != 3) {
4343
return null;
4444
}
@@ -49,7 +49,7 @@ MeshGeometry generateCylinder(List<String> args) {
4949
return generator.createCylinder(topRadius, bottomRadius, height);
5050
}
5151

52-
MeshGeometry generateRing(List<String> args) {
52+
MeshGeometry? generateRing(List<String> args) {
5353
if (args.length != 2) {
5454
return null;
5555
}

build.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ targets:
88
generate_for:
99
include:
1010
- test/**.dart
11+
exclude:
12+
- test/**vm_test.dart

lib/src/vector_math/aabb2.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ class Aabb2 {
7676
_max.setFrom(other._max);
7777
}
7878

79-
static Vector2 _center;
80-
static Vector2 _halfExtents;
81-
void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(
82-
_center ??= Vector2.zero(),
83-
_halfExtents ??= Vector2.zero(),
84-
);
79+
static late final _center = Vector2.zero();
80+
static late final _halfExtents = Vector2.zero();
81+
void _updateCenterAndHalfExtents() =>
82+
copyCenterAndHalfExtents(_center, _halfExtents);
8583

8684
/// Transform this by the transform [t].
8785
void transform(Matrix3 t) {

lib/src/vector_math/aabb3.dart

+20-22
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,10 @@ class Aabb3 {
203203
_max.setFrom(other._max);
204204
}
205205

206-
static Vector3 _center;
207-
static Vector3 _halfExtents;
208-
void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(
209-
_center ??= Vector3.zero(),
210-
_halfExtents ??= Vector3.zero(),
211-
);
206+
static late final _center = Vector3.zero();
207+
static late final _halfExtents = Vector3.zero();
208+
void _updateCenterAndHalfExtents() =>
209+
copyCenterAndHalfExtents(_center, _halfExtents);
212210

213211
/// Transform this by the transform [t].
214212
void transform(Matrix4 t) {
@@ -394,7 +392,7 @@ class Aabb3 {
394392
/// found, result is modified to contain more details about the type of
395393
/// intersection.
396394
bool intersectsWithTriangle(Triangle other,
397-
{double epsilon = 1e-3, IntersectionResult result}) {
395+
{double epsilon = 1e-3, IntersectionResult? result}) {
398396
double p0, p1, p2, r, len;
399397
double a;
400398

@@ -437,7 +435,7 @@ class Aabb3 {
437435
}
438436

439437
a = math.min(p0, p2) - r;
440-
if (result != null && (result._depth == null || result._depth < a)) {
438+
if (result != null && (result._depth == null || (result._depth!) < a)) {
441439
result._depth = a;
442440
_u0.crossInto(_f0, result.axis);
443441
}
@@ -455,7 +453,7 @@ class Aabb3 {
455453
}
456454

457455
a = math.min(p0, p1) - r;
458-
if (result != null && (result._depth == null || result._depth < a)) {
456+
if (result != null && (result._depth == null || (result._depth!) < a)) {
459457
result._depth = a;
460458
_u0.crossInto(_f1, result.axis);
461459
}
@@ -473,7 +471,7 @@ class Aabb3 {
473471
}
474472

475473
a = math.min(p0, p1) - r;
476-
if (result != null && (result._depth == null || result._depth < a)) {
474+
if (result != null && (result._depth == null || (result._depth!) < a)) {
477475
result._depth = a;
478476
_u0.crossInto(_f2, result.axis);
479477
}
@@ -491,7 +489,7 @@ class Aabb3 {
491489
}
492490

493491
a = math.min(p0, p2) - r;
494-
if (result != null && (result._depth == null || result._depth < a)) {
492+
if (result != null && (result._depth == null || (result._depth!) < a)) {
495493
result._depth = a;
496494
_u1.crossInto(_f0, result.axis);
497495
}
@@ -509,7 +507,7 @@ class Aabb3 {
509507
}
510508

511509
a = math.min(p0, p1) - r;
512-
if (result != null && (result._depth == null || result._depth < a)) {
510+
if (result != null && (result._depth == null || (result._depth!) < a)) {
513511
result._depth = a;
514512
_u1.crossInto(_f1, result.axis);
515513
}
@@ -527,7 +525,7 @@ class Aabb3 {
527525
}
528526

529527
a = math.min(p0, p1) - r;
530-
if (result != null && (result._depth == null || result._depth < a)) {
528+
if (result != null && (result._depth == null || (result._depth!) < a)) {
531529
result._depth = a;
532530
_u1.crossInto(_f2, result.axis);
533531
}
@@ -545,7 +543,7 @@ class Aabb3 {
545543
}
546544

547545
a = math.min(p0, p2) - r;
548-
if (result != null && (result._depth == null || result._depth < a)) {
546+
if (result != null && (result._depth == null || (result._depth!) < a)) {
549547
result._depth = a;
550548
_u2.crossInto(_f0, result.axis);
551549
}
@@ -563,7 +561,7 @@ class Aabb3 {
563561
}
564562

565563
a = math.min(p0, p1) - r;
566-
if (result != null && (result._depth == null || result._depth < a)) {
564+
if (result != null && (result._depth == null || (result._depth!) < a)) {
567565
result._depth = a;
568566
_u2.crossInto(_f1, result.axis);
569567
}
@@ -581,7 +579,7 @@ class Aabb3 {
581579
}
582580

583581
a = math.min(p0, p1) - r;
584-
if (result != null && (result._depth == null || result._depth < a)) {
582+
if (result != null && (result._depth == null || (result._depth!) < a)) {
585583
result._depth = a;
586584
_u2.crossInto(_f2, result.axis);
587585
}
@@ -594,7 +592,7 @@ class Aabb3 {
594592
return false;
595593
}
596594
a = math.min(_v0.x, math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
597-
if (result != null && (result._depth == null || result._depth < a)) {
595+
if (result != null && (result._depth == null || (result._depth!) < a)) {
598596
result._depth = a;
599597
result.axis.setFrom(_u0);
600598
}
@@ -604,7 +602,7 @@ class Aabb3 {
604602
return false;
605603
}
606604
a = math.min(_v0.y, math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
607-
if (result != null && (result._depth == null || result._depth < a)) {
605+
if (result != null && (result._depth == null || (result._depth!) < a)) {
608606
result._depth = a;
609607
result.axis.setFrom(_u1);
610608
}
@@ -614,7 +612,7 @@ class Aabb3 {
614612
return false;
615613
}
616614
a = math.min(_v0.z, math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
617-
if (result != null && (result._depth == null || result._depth < a)) {
615+
if (result != null && (result._depth == null || (result._depth!) < a)) {
618616
result._depth = a;
619617
result.axis.setFrom(_u2);
620618
}
@@ -630,7 +628,7 @@ class Aabb3 {
630628
}
631629

632630
/// Return if this intersects with [other]
633-
bool intersectsWithPlane(Plane other, {IntersectionResult result}) {
631+
bool intersectsWithPlane(Plane other, {IntersectionResult? result}) {
634632
// This line is not necessary with a (center, extents) AABB representation
635633
copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents);
636634

@@ -643,7 +641,7 @@ class Aabb3 {
643641
// Intersection occurs when distance s falls within [-r,+r] interval
644642
if (s.abs() <= r) {
645643
final a = s - r;
646-
if (result != null && (result._depth == null || result._depth < a)) {
644+
if (result != null && (result._depth == null || (result._depth!) < a)) {
647645
result._depth = a;
648646
result.axis.setFrom(other.normal);
649647
}
@@ -662,7 +660,7 @@ class Aabb3 {
662660
/// If [result] is specified and an intersection is
663661
/// found, result is modified to contain more details about the type of
664662
/// intersection.
665-
bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
663+
bool intersectsWithQuad(Quad other, {IntersectionResult? result}) {
666664
other.copyTriangles(_quadTriangle0, _quadTriangle1);
667665

668666
return intersectsWithTriangle(_quadTriangle0, result: result) ||

lib/src/vector_math/colors.dart

+14-14
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ class Colors {
3030

3131
if (fullMatch != null) {
3232
if (fullMatch[4] == null) {
33-
final r = int.parse(fullMatch[1], radix: 16);
34-
final g = int.parse(fullMatch[2], radix: 16);
35-
final b = int.parse(fullMatch[3], radix: 16);
33+
final r = int.parse(fullMatch[1]!, radix: 16);
34+
final g = int.parse(fullMatch[2]!, radix: 16);
35+
final b = int.parse(fullMatch[3]!, radix: 16);
3636

3737
fromRgba(r, g, b, 255, result);
3838
return;
3939
} else {
40-
final a = int.parse(fullMatch[1], radix: 16);
41-
final r = int.parse(fullMatch[2], radix: 16);
42-
final g = int.parse(fullMatch[3], radix: 16);
43-
final b = int.parse(fullMatch[4], radix: 16);
40+
final a = int.parse(fullMatch[1]!, radix: 16);
41+
final r = int.parse(fullMatch[2]!, radix: 16);
42+
final g = int.parse(fullMatch[3]!, radix: 16);
43+
final b = int.parse(fullMatch[4]!, radix: 16);
4444

4545
fromRgba(r, g, b, a, result);
4646
return;
@@ -51,17 +51,17 @@ class Colors {
5151

5252
if (smallMatch != null) {
5353
if (smallMatch[4] == null) {
54-
final r = int.parse(smallMatch[1] + smallMatch[1], radix: 16);
55-
final g = int.parse(smallMatch[2] + smallMatch[2], radix: 16);
56-
final b = int.parse(smallMatch[3] + smallMatch[3], radix: 16);
54+
final r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16);
55+
final g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16);
56+
final b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16);
5757

5858
fromRgba(r, g, b, 255, result);
5959
return;
6060
} else {
61-
final a = int.parse(smallMatch[1] + smallMatch[1], radix: 16);
62-
final r = int.parse(smallMatch[2] + smallMatch[2], radix: 16);
63-
final g = int.parse(smallMatch[3] + smallMatch[3], radix: 16);
64-
final b = int.parse(smallMatch[4] + smallMatch[4], radix: 16);
61+
final a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16);
62+
final r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16);
63+
final g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16);
64+
final b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16);
6565

6666
fromRgba(r, g, b, a, result);
6767
return;

lib/src/vector_math/intersection_result.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ part of vector_math;
55

66
/// Defines a result of an intersection test.
77
class IntersectionResult {
8-
double _depth;
8+
double? _depth;
99

1010
/// The penetration depth of the intersection.
11-
double get depth => _depth;
11+
double? get depth => _depth;
1212

1313
/// The [axis] of the intersection.
1414
final axis = Vector3.zero();

lib/src/vector_math/matrix2.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Matrix2 {
145145

146146
/// Check if two matrices are the same.
147147
@override
148-
bool operator ==(Object other) =>
148+
bool operator ==(Object? other) =>
149149
(other is Matrix2) &&
150150
(_m2storage[0] == other._m2storage[0]) &&
151151
(_m2storage[1] == other._m2storage[1]) &&
@@ -479,7 +479,7 @@ class Matrix2 {
479479
/// Transform a copy of [arg] of type [Vector2] using the transformation
480480
/// defined by this. If a [out] parameter is supplied, the copy is stored in
481481
/// [out].
482-
Vector2 transformed(Vector2 arg, [Vector2 out]) {
482+
Vector2 transformed(Vector2 arg, [Vector2? out]) {
483483
if (out == null) {
484484
out = Vector2.copy(arg);
485485
} else {

lib/src/vector_math/matrix3.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class Matrix3 {
236236

237237
/// Check if two matrices are the same.
238238
@override
239-
bool operator ==(Object other) =>
239+
bool operator ==(Object? other) =>
240240
(other is Matrix3) &&
241241
(_m3storage[0] == other._m3storage[0]) &&
242242
(_m3storage[1] == other._m3storage[1]) &&
@@ -832,7 +832,7 @@ class Matrix3 {
832832
/// Transform a copy of [arg] of type [Vector3] using the transformation
833833
/// defined by this. If a [out] parameter is supplied, the copy is stored in
834834
/// [out].
835-
Vector3 transformed(Vector3 arg, [Vector3 out]) {
835+
Vector3 transformed(Vector3 arg, [Vector3? out]) {
836836
if (out == null) {
837837
out = Vector3.copy(arg);
838838
} else {

0 commit comments

Comments
 (0)