Merge branch 'master' into null_safety
diff --git a/analysis_options.yaml b/analysis_options.yaml
index bf1d5fc..e08c7c9 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,10 +1,8 @@
include: package:pedantic/analysis_options.yaml
analyzer:
-# strong-mode:
-# implicit-casts: false
- errors:
- omit_local_variable_types: ignore #1929 cases
+ enable-experiment:
+ - non-nullable
linter:
rules:
@@ -67,6 +65,7 @@
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_null_aware_assignments
+ - unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_statements
- unnecessary_string_interpolations
diff --git a/benchmark/matrix4_tween_bench.dart b/benchmark/matrix4_tween_bench.dart
index b95e417..7a08cef 100644
--- a/benchmark/matrix4_tween_bench.dart
+++ b/benchmark/matrix4_tween_bench.dart
@@ -14,7 +14,7 @@
Vector3(1.0, 1.0, 1.0),
);
- final Matrix4 endTransform = Matrix4.compose(
+ final endTransform = Matrix4.compose(
Vector3(5.0, 260.0, 1.0),
Quaternion.euler(0.0, 1.0, -0.7),
Vector3(0.6, 0.6, 0.6),
@@ -43,19 +43,18 @@
@override
Matrix4 lerp(Matrix4 begin, Matrix4 end, double t) {
- final Vector3 beginTranslation = Vector3.zero();
- final Vector3 endTranslation = Vector3.zero();
- final Quaternion beginRotation = Quaternion.identity();
- final Quaternion endRotation = Quaternion.identity();
- final Vector3 beginScale = Vector3.zero();
- final Vector3 endScale = Vector3.zero();
+ final beginTranslation = Vector3.zero();
+ final endTranslation = Vector3.zero();
+ final beginRotation = Quaternion.identity();
+ final endRotation = Quaternion.identity();
+ final beginScale = Vector3.zero();
+ final endScale = Vector3.zero();
begin.decompose(beginTranslation, beginRotation, beginScale);
end.decompose(endTranslation, endRotation, endScale);
- final Vector3 lerpTranslation =
- beginTranslation * (1.0 - t) + endTranslation * t;
- final Quaternion lerpRotation =
+ final lerpTranslation = beginTranslation * (1.0 - t) + endTranslation * t;
+ final lerpRotation =
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
- final Vector3 lerpScale = beginScale * (1.0 - t) + endScale * t;
+ final lerpScale = beginScale * (1.0 - t) + endScale * t;
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
}
}
@@ -68,21 +67,21 @@
begin.decompose(beginTranslation, beginRotation, beginScale);
end.decompose(endTranslation, endRotation, endScale);
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
- final Quaternion lerpRotation =
+ final lerpRotation =
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
Vector3.mix(beginScale, endScale, t, lerpScale);
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
}
// Pre-allocated vectors.
- static final Vector3 beginTranslation = Vector3.zero();
- static final Vector3 endTranslation = Vector3.zero();
- static final Vector3 lerpTranslation = Vector3.zero();
- static final Quaternion beginRotation = Quaternion.identity();
- static final Quaternion endRotation = Quaternion.identity();
- static final Vector3 beginScale = Vector3.zero();
- static final Vector3 endScale = Vector3.zero();
- static final Vector3 lerpScale = Vector3.zero();
+ static final beginTranslation = Vector3.zero();
+ static final endTranslation = Vector3.zero();
+ static final lerpTranslation = Vector3.zero();
+ static final beginRotation = Quaternion.identity();
+ static final endRotation = Quaternion.identity();
+ static final beginScale = Vector3.zero();
+ static final endScale = Vector3.zero();
+ static final lerpScale = Vector3.zero();
}
class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup {
@@ -90,35 +89,23 @@
@override
Matrix4 lerp(Matrix4 begin, Matrix4 end, double t) {
- if (beginTranslation == null) _lerpInit();
begin.decompose(beginTranslation, beginRotation, beginScale);
end.decompose(endTranslation, endRotation, endScale);
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
- final Quaternion lerpRotation =
+ final lerpRotation =
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
Vector3.mix(beginScale, endScale, t, lerpScale);
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
}
- // Manually initialized pre-allocated vectors.
- static Vector3 beginTranslation;
- static Vector3 endTranslation;
- static Vector3 lerpTranslation;
- static Quaternion beginRotation;
- static Quaternion endRotation;
- static Vector3 beginScale;
- static Vector3 endScale;
- static Vector3 lerpScale;
- static void _lerpInit() {
- beginTranslation = Vector3.zero();
- endTranslation = Vector3.zero();
- lerpTranslation = Vector3.zero();
- beginRotation = Quaternion.identity();
- endRotation = Quaternion.identity();
- beginScale = Vector3.zero();
- endScale = Vector3.zero();
- lerpScale = Vector3.zero();
- }
+ late final beginTranslation = Vector3.zero();
+ late final endTranslation = Vector3.zero();
+ late final lerpTranslation = Vector3.zero();
+ late final beginRotation = Quaternion.identity();
+ late final endRotation = Quaternion.identity();
+ late final beginScale = Vector3.zero();
+ late final endScale = Vector3.zero();
+ late final lerpScale = Vector3.zero();
}
void main() {
diff --git a/benchmark/matrix_bench.dart b/benchmark/matrix_bench.dart
index 6cc87bc..20e15ad 100644
--- a/benchmark/matrix_bench.dart
+++ b/benchmark/matrix_bench.dart
@@ -12,9 +12,9 @@
class MatrixMultiplyBenchmark extends BenchmarkBase {
MatrixMultiplyBenchmark() : super('MatrixMultiply');
- final Float32List A = Float32List(16);
- final Float32List B = Float32List(16);
- final Float32List C = Float32List(16);
+ final A = Float32List(16);
+ final B = Float32List(16);
+ final C = Float32List(16);
static void main() {
MatrixMultiplyBenchmark().report();
@@ -30,9 +30,9 @@
class SIMDMatrixMultiplyBenchmark extends BenchmarkBase {
SIMDMatrixMultiplyBenchmark() : super('SIMDMatrixMultiply');
- final Float32x4List A = Float32x4List(4);
- final Float32x4List B = Float32x4List(4);
- final Float32x4List C = Float32x4List(4);
+ final A = Float32x4List(4);
+ final B = Float32x4List(4);
+ final C = Float32x4List(4);
static void main() {
SIMDMatrixMultiplyBenchmark().report();
@@ -48,9 +48,9 @@
class VectorTransformBenchmark extends BenchmarkBase {
VectorTransformBenchmark() : super('VectorTransform');
- final Float32List A = Float32List(16);
- final Float32List B = Float32List(4);
- final Float32List C = Float32List(4);
+ final A = Float32List(16);
+ final B = Float32List(4);
+ final C = Float32List(4);
static void main() {
VectorTransformBenchmark().report();
@@ -66,9 +66,9 @@
class SIMDVectorTransformBenchmark extends BenchmarkBase {
SIMDVectorTransformBenchmark() : super('SIMDVectorTransform');
- final Float32x4List A = Float32x4List(4);
- final Float32x4List B = Float32x4List(1);
- final Float32x4List C = Float32x4List(1);
+ final A = Float32x4List(4);
+ final B = Float32x4List(1);
+ final C = Float32x4List(1);
static void main() {
SIMDVectorTransformBenchmark().report();
@@ -85,10 +85,10 @@
class ViewMatrixBenchmark extends BenchmarkBase {
ViewMatrixBenchmark() : super('setViewMatrix');
- final Matrix4 M = Matrix4.zero();
- final Vector3 P = Vector3.zero();
- final Vector3 F = Vector3.zero();
- final Vector3 U = Vector3.zero();
+ final M = Matrix4.zero();
+ final P = Vector3.zero();
+ final F = Vector3.zero();
+ final U = Vector3.zero();
static void main() {
ViewMatrixBenchmark().report();
@@ -105,14 +105,14 @@
class Aabb2TransformBenchmark extends BenchmarkBase {
Aabb2TransformBenchmark() : super('aabb2Transform');
- static final Matrix3 M = Matrix3.rotationZ(math.pi / 4);
- static final Vector2 P1 = Vector2(10.0, 10.0);
- static final Vector2 P2 = Vector2(20.0, 30.0);
- static final Vector2 P3 = Vector2(100.0, 50.0);
- static final Aabb2 B1 = Aabb2.minMax(P1, P2);
- static final Aabb2 B2 = Aabb2.minMax(P1, P3);
- static final Aabb2 B3 = Aabb2.minMax(P2, P3);
- static final Aabb2 temp = Aabb2();
+ static final M = Matrix3.rotationZ(math.pi / 4);
+ static final P1 = Vector2(10.0, 10.0);
+ static final P2 = Vector2(20.0, 30.0);
+ static final P3 = Vector2(100.0, 50.0);
+ static final B1 = Aabb2.minMax(P1, P2);
+ static final B2 = Aabb2.minMax(P1, P3);
+ static final B3 = Aabb2.minMax(P2, P3);
+ static final temp = Aabb2();
static void main() {
Aabb2TransformBenchmark().report();
@@ -134,14 +134,14 @@
class Aabb2RotateBenchmark extends BenchmarkBase {
Aabb2RotateBenchmark() : super('aabb2Rotate');
- static final Matrix3 M = Matrix3.rotationZ(math.pi / 4);
- static final Vector2 P1 = Vector2(10.0, 10.0);
- static final Vector2 P2 = Vector2(20.0, 30.0);
- static final Vector2 P3 = Vector2(100.0, 50.0);
- static final Aabb2 B1 = Aabb2.minMax(P1, P2);
- static final Aabb2 B2 = Aabb2.minMax(P1, P3);
- static final Aabb2 B3 = Aabb2.minMax(P2, P3);
- static final Aabb2 temp = Aabb2();
+ static final M = Matrix3.rotationZ(math.pi / 4);
+ static final P1 = Vector2(10.0, 10.0);
+ static final P2 = Vector2(20.0, 30.0);
+ static final P3 = Vector2(100.0, 50.0);
+ static final B1 = Aabb2.minMax(P1, P2);
+ static final B2 = Aabb2.minMax(P1, P3);
+ static final B3 = Aabb2.minMax(P2, P3);
+ static final temp = Aabb2();
static void main() {
Aabb2RotateBenchmark().report();
@@ -163,14 +163,14 @@
class Aabb3TransformBenchmark extends BenchmarkBase {
Aabb3TransformBenchmark() : super('aabb3Transform');
- static final Matrix4 M = Matrix4.rotationZ(math.pi / 4);
- static final Vector3 P1 = Vector3(10.0, 10.0, 0.0);
- static final Vector3 P2 = Vector3(20.0, 30.0, 1.0);
- static final Vector3 P3 = Vector3(100.0, 50.0, 10.0);
- static final Aabb3 B1 = Aabb3.minMax(P1, P2);
- static final Aabb3 B2 = Aabb3.minMax(P1, P3);
- static final Aabb3 B3 = Aabb3.minMax(P2, P3);
- static final Aabb3 temp = Aabb3();
+ static final M = Matrix4.rotationZ(math.pi / 4);
+ static final P1 = Vector3(10.0, 10.0, 0.0);
+ static final P2 = Vector3(20.0, 30.0, 1.0);
+ static final P3 = Vector3(100.0, 50.0, 10.0);
+ static final B1 = Aabb3.minMax(P1, P2);
+ static final B2 = Aabb3.minMax(P1, P3);
+ static final B3 = Aabb3.minMax(P2, P3);
+ static final temp = Aabb3();
static void main() {
Aabb3TransformBenchmark().report();
@@ -192,14 +192,14 @@
class Aabb3RotateBenchmark extends BenchmarkBase {
Aabb3RotateBenchmark() : super('aabb3Rotate');
- static final Matrix4 M = Matrix4.rotationZ(math.pi / 4);
- static final Vector3 P1 = Vector3(10.0, 10.0, 0.0);
- static final Vector3 P2 = Vector3(20.0, 30.0, 1.0);
- static final Vector3 P3 = Vector3(100.0, 50.0, 10.0);
- static final Aabb3 B1 = Aabb3.minMax(P1, P2);
- static final Aabb3 B2 = Aabb3.minMax(P1, P3);
- static final Aabb3 B3 = Aabb3.minMax(P2, P3);
- static final Aabb3 temp = Aabb3();
+ static final M = Matrix4.rotationZ(math.pi / 4);
+ static final P1 = Vector3(10.0, 10.0, 0.0);
+ static final P2 = Vector3(20.0, 30.0, 1.0);
+ static final P3 = Vector3(100.0, 50.0, 10.0);
+ static final B1 = Aabb3.minMax(P1, P2);
+ static final B2 = Aabb3.minMax(P1, P3);
+ static final B3 = Aabb3.minMax(P2, P3);
+ static final temp = Aabb3();
static void main() {
Aabb3RotateBenchmark().report();
@@ -221,9 +221,9 @@
class Matrix3DeterminantBenchmark extends BenchmarkBase {
Matrix3DeterminantBenchmark() : super('Matrix3.determinant');
- final Matrix3 MX = Matrix3.rotationX(math.pi / 4);
- final Matrix3 MY = Matrix3.rotationY(math.pi / 4);
- final Matrix3 MZ = Matrix3.rotationZ(math.pi / 4);
+ final MX = Matrix3.rotationX(math.pi / 4);
+ final MY = Matrix3.rotationY(math.pi / 4);
+ final MZ = Matrix3.rotationZ(math.pi / 4);
static void main() {
Matrix3DeterminantBenchmark().report();
@@ -242,12 +242,12 @@
class Matrix3TransformVector3Benchmark extends BenchmarkBase {
Matrix3TransformVector3Benchmark() : super('Matrix3.transform(Vector3)');
- final Matrix3 MX = Matrix3.rotationX(math.pi / 4);
- final Matrix3 MY = Matrix3.rotationY(math.pi / 4);
- final Matrix3 MZ = Matrix3.rotationZ(math.pi / 4);
- final Vector3 V1 = Vector3(10.0, 20.0, 1.0);
- final Vector3 V2 = Vector3(-10.0, 20.0, 1.0);
- final Vector3 V3 = Vector3(10.0, -20.0, 1.0);
+ final MX = Matrix3.rotationX(math.pi / 4);
+ final MY = Matrix3.rotationY(math.pi / 4);
+ final MZ = Matrix3.rotationZ(math.pi / 4);
+ final V1 = Vector3(10.0, 20.0, 1.0);
+ final V2 = Vector3(-10.0, 20.0, 1.0);
+ final V3 = Vector3(10.0, -20.0, 1.0);
static void main() {
Matrix3TransformVector3Benchmark().report();
@@ -272,12 +272,12 @@
class Matrix3TransformVector2Benchmark extends BenchmarkBase {
Matrix3TransformVector2Benchmark() : super('Matrix3.transform(Vector2)');
- final Matrix3 MX = Matrix3.rotationX(math.pi / 4);
- final Matrix3 MY = Matrix3.rotationY(math.pi / 4);
- final Matrix3 MZ = Matrix3.rotationZ(math.pi / 4);
- final Vector2 V1 = Vector2(10.0, 20.0);
- final Vector2 V2 = Vector2(-10.0, 20.0);
- final Vector2 V3 = Vector2(10.0, -20.0);
+ final MX = Matrix3.rotationX(math.pi / 4);
+ final MY = Matrix3.rotationY(math.pi / 4);
+ final MZ = Matrix3.rotationZ(math.pi / 4);
+ final V1 = Vector2(10.0, 20.0);
+ final V2 = Vector2(-10.0, 20.0);
+ final V3 = Vector2(10.0, -20.0);
static void main() {
Matrix3TransformVector2Benchmark().report();
@@ -302,10 +302,10 @@
class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase {
Matrix3TransposeMultiplyBenchmark() : super('Matrix3.transposeMultiply');
- final Matrix3 MX = Matrix3.rotationX(math.pi / 4);
- final Matrix3 MY = Matrix3.rotationY(math.pi / 4);
- final Matrix3 MZ = Matrix3.rotationZ(math.pi / 4);
- final Matrix3 temp = Matrix3.zero();
+ final MX = Matrix3.rotationX(math.pi / 4);
+ final MY = Matrix3.rotationY(math.pi / 4);
+ final MZ = Matrix3.rotationZ(math.pi / 4);
+ final temp = Matrix3.zero();
static void main() {
Matrix3TransposeMultiplyBenchmark().report();
diff --git a/bin/mesh_generator.dart b/bin/mesh_generator.dart
index 04d2917..7159680 100644
--- a/bin/mesh_generator.dart
+++ b/bin/mesh_generator.dart
@@ -7,55 +7,55 @@
import 'dart:convert';
import 'package:vector_math/vector_math_geometry.dart';
-typedef GenerateFunction = MeshGeometry Function(List<String> args);
+typedef GenerateFunction = MeshGeometry? Function(List<String> args);
-MeshGeometry generateCube(List<String> args) {
+MeshGeometry? generateCube(List<String> args) {
if (args.length != 3) {
return null;
}
- final double width = double.parse(args[0]);
- final double height = double.parse(args[1]);
- final double depth = double.parse(args[2]);
- final CubeGenerator generator = CubeGenerator();
+ final width = double.parse(args[0]);
+ final height = double.parse(args[1]);
+ final depth = double.parse(args[2]);
+ final generator = CubeGenerator();
return generator.createCube(width, height, depth);
}
-MeshGeometry generateSphere(List<String> args) {
+MeshGeometry? generateSphere(List<String> args) {
if (args.length != 1) {
return null;
}
- final double radius = double.parse(args[0]);
- final SphereGenerator generator = SphereGenerator();
+ final radius = double.parse(args[0]);
+ final generator = SphereGenerator();
return generator.createSphere(radius);
}
-MeshGeometry generateCircle(List<String> args) {
+MeshGeometry? generateCircle(List<String> args) {
if (args.length != 1) {
return null;
}
- final double radius = double.parse(args[0]);
- final CircleGenerator generator = CircleGenerator();
+ final radius = double.parse(args[0]);
+ final generator = CircleGenerator();
return generator.createCircle(radius);
}
-MeshGeometry generateCylinder(List<String> args) {
+MeshGeometry? generateCylinder(List<String> args) {
if (args.length != 3) {
return null;
}
- final double topRadius = double.parse(args[0]);
- final double bottomRadius = double.parse(args[1]);
- final double height = double.parse(args[2]);
- final CylinderGenerator generator = CylinderGenerator();
+ final topRadius = double.parse(args[0]);
+ final bottomRadius = double.parse(args[1]);
+ final height = double.parse(args[2]);
+ final generator = CylinderGenerator();
return generator.createCylinder(topRadius, bottomRadius, height);
}
-MeshGeometry generateRing(List<String> args) {
+MeshGeometry? generateRing(List<String> args) {
if (args.length != 2) {
return null;
}
- final double innerRadius = double.parse(args[0]);
- final double outerRadius = double.parse(args[1]);
- final RingGenerator generator = RingGenerator();
+ final innerRadius = double.parse(args[0]);
+ final outerRadius = double.parse(args[1]);
+ final generator = RingGenerator();
return generator.createRing(innerRadius, outerRadius);
}
@@ -68,7 +68,7 @@
};
void main(List<String> args) {
- final List<String> fixedArgs = List<String>.unmodifiable(args);
+ final fixedArgs = List<String>.unmodifiable(args);
if (fixedArgs.isEmpty) {
print('mesh_generator.dart <type> [<arg0> ... <argN>]');
@@ -82,13 +82,13 @@
print('');
return;
}
- final String type = fixedArgs.removeAt(0);
- final GenerateFunction generator = generators[type];
+ final type = fixedArgs.removeAt(0);
+ final generator = generators[type];
if (generator == null) {
print('Could not find generator for $type');
return;
}
- final MeshGeometry geometry = generator(fixedArgs);
+ final geometry = generator(fixedArgs);
if (geometry == null) {
print('Error generating geometry for $type');
return;
diff --git a/build.yaml b/build.yaml
new file mode 100644
index 0000000..a6af680
--- /dev/null
+++ b/build.yaml
@@ -0,0 +1,12 @@
+# See https://github.com/dart-lang/build/tree/master/build_web_compilers#configuration
+# Matches previous configuration in pubspec.yaml - transformers - $dart2js
+targets:
+ $default:
+ builders:
+ build_web_compilers|entrypoint:
+ # These are globs for the entrypoints you want to compile.
+ generate_for:
+ include:
+ - test/**.dart
+ exclude:
+ - test/**vm_test.dart
diff --git a/lib/src/vector_math/aabb2.dart b/lib/src/vector_math/aabb2.dart
index 1e9d71c..2222c3d 100644
--- a/lib/src/vector_math/aabb2.dart
+++ b/lib/src/vector_math/aabb2.dart
@@ -76,12 +76,10 @@
_max.setFrom(other._max);
}
- static Vector2 _center;
- static Vector2 _halfExtents;
- void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(
- _center ??= Vector2.zero(),
- _halfExtents ??= Vector2.zero(),
- );
+ static late final _center = Vector2.zero();
+ static late final _halfExtents = Vector2.zero();
+ void _updateCenterAndHalfExtents() =>
+ copyCenterAndHalfExtents(_center, _halfExtents);
/// Transform this by the transform [t].
void transform(Matrix3 t) {
@@ -136,8 +134,8 @@
/// Return if this contains [other].
bool containsAabb2(Aabb2 other) {
- final Vector2 otherMax = other._max;
- final Vector2 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -154,8 +152,8 @@
/// Return if this intersects with [other].
bool intersectsWithAabb2(Aabb2 other) {
- final Vector2 otherMax = other._max;
- final Vector2 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
diff --git a/lib/src/vector_math/aabb3.dart b/lib/src/vector_math/aabb3.dart
index f3f21b1..6c58e14 100644
--- a/lib/src/vector_math/aabb3.dart
+++ b/lib/src/vector_math/aabb3.dart
@@ -125,7 +125,7 @@
/// Set the AABB to enclose a [obb].
void setObb3(Obb3 obb) {
- final Vector3 corner = Vector3.zero();
+ final corner = Vector3.zero();
obb.copyCorner(0, corner);
_min.setFrom(corner);
@@ -159,19 +159,19 @@
ray..copyAt(_min, limitMin)..copyAt(_max, limitMax);
if (_max.x < _min.x) {
- final double temp = _max.x;
+ final temp = _max.x;
_max.x = _min.x;
_min.x = temp;
}
if (_max.y < _min.y) {
- final double temp = _max.y;
+ final temp = _max.y;
_max.y = _min.y;
_min.y = temp;
}
if (_max.z < _min.z) {
- final double temp = _max.z;
+ final temp = _max.z;
_max.z = _min.z;
_min.z = temp;
}
@@ -203,12 +203,10 @@
_max.setFrom(other._max);
}
- static Vector3 _center;
- static Vector3 _halfExtents;
- void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(
- _center ??= Vector3.zero(),
- _halfExtents ??= Vector3.zero(),
- );
+ static late final _center = Vector3.zero();
+ static late final _halfExtents = Vector3.zero();
+ void _updateCenterAndHalfExtents() =>
+ copyCenterAndHalfExtents(_center, _halfExtents);
/// Transform this by the transform [t].
void transform(Matrix4 t) {
@@ -289,8 +287,8 @@
/// Return if this contains [other].
bool containsAabb3(Aabb3 other) {
- final Vector3 otherMax = other._max;
- final Vector3 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -302,9 +300,8 @@
/// Return if this contains [other].
bool containsSphere(Sphere other) {
- final Vector3 boxExtends = Vector3.all(other.radius);
- final Aabb3 sphereBox =
- Aabb3.centerAndHalfExtents(other._center, boxExtends);
+ final boxExtends = Vector3.all(other.radius);
+ final sphereBox = Aabb3.centerAndHalfExtents(other._center, boxExtends);
return containsAabb3(sphereBox);
}
@@ -326,8 +323,8 @@
/// Return if this intersects with [other].
bool intersectsWithAabb3(Aabb3 other) {
- final Vector3 otherMax = other._max;
- final Vector3 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
@@ -339,8 +336,8 @@
/// Return if this intersects with [other].
bool intersectsWithSphere(Sphere other) {
- final Vector3 center = other._center;
- final double radius = other.radius;
+ final center = other._center;
+ final radius = other.radius;
var d = 0.0;
var e = 0.0;
@@ -375,19 +372,19 @@
(_max.z >= other.z);
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Vector3 _aabbCenter = Vector3.zero();
- static final Vector3 _aabbHalfExtents = Vector3.zero();
- static final Vector3 _v0 = Vector3.zero();
- static final Vector3 _v1 = Vector3.zero();
- static final Vector3 _v2 = Vector3.zero();
- static final Vector3 _f0 = Vector3.zero();
- static final Vector3 _f1 = Vector3.zero();
- static final Vector3 _f2 = Vector3.zero();
- static final Plane _trianglePlane = Plane();
+ static final _aabbCenter = Vector3.zero();
+ static final _aabbHalfExtents = Vector3.zero();
+ static final _v0 = Vector3.zero();
+ static final _v1 = Vector3.zero();
+ static final _v2 = Vector3.zero();
+ static final _f0 = Vector3.zero();
+ static final _f1 = Vector3.zero();
+ static final _f2 = Vector3.zero();
+ static final _trianglePlane = Plane();
- static final Vector3 _u0 = Vector3(1.0, 0.0, 0.0);
- static final Vector3 _u1 = Vector3(0.0, 1.0, 0.0);
- static final Vector3 _u2 = Vector3(0.0, 0.0, 1.0);
+ static final _u0 = Vector3(1.0, 0.0, 0.0);
+ static final _u1 = Vector3(0.0, 1.0, 0.0);
+ static final _u2 = Vector3(0.0, 0.0, 1.0);
/// Return if this intersects with [other].
/// [epsilon] allows the caller to specify a custum eplsilon value that should
@@ -395,7 +392,7 @@
/// found, result is modified to contain more details about the type of
/// intersection.
bool intersectsWithTriangle(Triangle other,
- {double epsilon = 1e-3, IntersectionResult result}) {
+ {double epsilon = 1e-3, IntersectionResult? result}) {
double p0, p1, p2, r, len;
double a;
@@ -438,7 +435,7 @@
}
a = math.min(p0, p2) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u0.crossInto(_f0, result.axis);
}
@@ -456,7 +453,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u0.crossInto(_f1, result.axis);
}
@@ -474,7 +471,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u0.crossInto(_f2, result.axis);
}
@@ -492,7 +489,7 @@
}
a = math.min(p0, p2) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u1.crossInto(_f0, result.axis);
}
@@ -510,7 +507,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u1.crossInto(_f1, result.axis);
}
@@ -528,7 +525,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u1.crossInto(_f2, result.axis);
}
@@ -546,7 +543,7 @@
}
a = math.min(p0, p2) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u2.crossInto(_f0, result.axis);
}
@@ -564,7 +561,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u2.crossInto(_f1, result.axis);
}
@@ -582,7 +579,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u2.crossInto(_f2, result.axis);
}
@@ -595,7 +592,7 @@
return false;
}
a = math.min(_v0.x, math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(_u0);
}
@@ -605,7 +602,7 @@
return false;
}
a = math.min(_v0.y, math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(_u1);
}
@@ -615,7 +612,7 @@
return false;
}
a = math.min(_v0.z, math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(_u2);
}
@@ -631,20 +628,20 @@
}
/// Return if this intersects with [other]
- bool intersectsWithPlane(Plane other, {IntersectionResult result}) {
+ bool intersectsWithPlane(Plane other, {IntersectionResult? result}) {
// This line is not necessary with a (center, extents) AABB representation
copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents);
// Compute the projection interval radius of b onto L(t) = b.c + t * p.n
- final double r = _aabbHalfExtents[0] * other.normal[0].abs() +
+ final r = _aabbHalfExtents[0] * other.normal[0].abs() +
_aabbHalfExtents[1] * other.normal[1].abs() +
_aabbHalfExtents[2] * other.normal[2].abs();
// Compute distance of box center from plane
- final double s = other.normal.dot(_aabbCenter) - other.constant;
+ final s = other.normal.dot(_aabbCenter) - other.constant;
// Intersection occurs when distance s falls within [-r,+r] interval
if (s.abs() <= r) {
- final double a = s - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ final a = s - r;
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(other.normal);
}
@@ -655,15 +652,15 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Triangle _quadTriangle0 = Triangle();
- static final Triangle _quadTriangle1 = Triangle();
+ static final _quadTriangle0 = Triangle();
+ static final _quadTriangle1 = Triangle();
/// Return `true` if this intersects with [other].
///
/// If [result] is specified and an intersection is
/// found, result is modified to contain more details about the type of
/// intersection.
- bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
+ bool intersectsWithQuad(Quad other, {IntersectionResult? result}) {
other.copyTriangles(_quadTriangle0, _quadTriangle1);
return intersectsWithTriangle(_quadTriangle0, result: result) ||
diff --git a/lib/src/vector_math/colors.dart b/lib/src/vector_math/colors.dart
index bbb14e4..b35a5bc 100644
--- a/lib/src/vector_math/colors.dart
+++ b/lib/src/vector_math/colors.dart
@@ -8,10 +8,10 @@
/// manipulating colors. In addition to that, some known colors can be accessed
/// for fast prototyping.
class Colors {
- static final RegExp _hexStringFullRegex = RegExp(
+ static final _hexStringFullRegex = RegExp(
r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?',
caseSensitive: false);
- static final RegExp _hexStringSmallRegex = RegExp(
+ static final _hexStringSmallRegex = RegExp(
r'\#?([0-9a-f])([0-9a-f])([0-9a-f])(?:([0-9a-f]))?',
caseSensitive: false);
@@ -26,42 +26,42 @@
/// corresponding color value and store it in [result]. The first group is
/// treated as the alpha channel if a [value] with four groups is passed.
static void fromHexString(String value, Vector4 result) {
- final Match fullMatch = _hexStringFullRegex.matchAsPrefix(value);
+ final fullMatch = _hexStringFullRegex.matchAsPrefix(value);
if (fullMatch != null) {
if (fullMatch[4] == null) {
- final int r = int.parse(fullMatch[1], radix: 16);
- final int g = int.parse(fullMatch[2], radix: 16);
- final int b = int.parse(fullMatch[3], radix: 16);
+ final r = int.parse(fullMatch[1]!, radix: 16);
+ final g = int.parse(fullMatch[2]!, radix: 16);
+ final b = int.parse(fullMatch[3]!, radix: 16);
fromRgba(r, g, b, 255, result);
return;
} else {
- final int a = int.parse(fullMatch[1], radix: 16);
- final int r = int.parse(fullMatch[2], radix: 16);
- final int g = int.parse(fullMatch[3], radix: 16);
- final int b = int.parse(fullMatch[4], radix: 16);
+ final a = int.parse(fullMatch[1]!, radix: 16);
+ final r = int.parse(fullMatch[2]!, radix: 16);
+ final g = int.parse(fullMatch[3]!, radix: 16);
+ final b = int.parse(fullMatch[4]!, radix: 16);
fromRgba(r, g, b, a, result);
return;
}
}
- final Match smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
+ final smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
if (smallMatch != null) {
if (smallMatch[4] == null) {
- final int r = int.parse(smallMatch[1] + smallMatch[1], radix: 16);
- final int g = int.parse(smallMatch[2] + smallMatch[2], radix: 16);
- final int b = int.parse(smallMatch[3] + smallMatch[3], radix: 16);
+ final r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16);
+ final g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16);
+ final b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16);
fromRgba(r, g, b, 255, result);
return;
} else {
- final int a = int.parse(smallMatch[1] + smallMatch[1], radix: 16);
- final int r = int.parse(smallMatch[2] + smallMatch[2], radix: 16);
- final int g = int.parse(smallMatch[3] + smallMatch[3], radix: 16);
- final int b = int.parse(smallMatch[4] + smallMatch[4], radix: 16);
+ final a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16);
+ final r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16);
+ final g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16);
+ final b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16);
fromRgba(r, g, b, a, result);
return;
@@ -77,25 +77,25 @@
/// (default false).
static String toHexString(Vector4 input,
{bool alpha = false, bool short = false}) {
- final int r = (input.r * 0xFF).floor() & 0xFF;
- final int g = (input.g * 0xFF).floor() & 0xFF;
- final int b = (input.b * 0xFF).floor() & 0xFF;
- final int a = (input.a * 0xFF).floor() & 0xFF;
+ final r = (input.r * 0xFF).floor() & 0xFF;
+ final g = (input.g * 0xFF).floor() & 0xFF;
+ final b = (input.b * 0xFF).floor() & 0xFF;
+ final a = (input.a * 0xFF).floor() & 0xFF;
- final bool isShort = short &&
+ final isShort = short &&
((r >> 4) == (r & 0xF)) &&
((g >> 4) == (g & 0xF)) &&
((b >> 4) == (b & 0xF)) &&
(!alpha || (a >> 4) == (a & 0xF));
if (isShort) {
- final String rgb = (r & 0xF).toRadixString(16) +
+ final rgb = (r & 0xF).toRadixString(16) +
(g & 0xF).toRadixString(16) +
(b & 0xF).toRadixString(16);
return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb;
} else {
- final String rgb = r.toRadixString(16).padLeft(2, '0') +
+ final rgb = r.toRadixString(16).padLeft(2, '0') +
g.toRadixString(16).padLeft(2, '0') +
b.toRadixString(16).padLeft(2, '0');
@@ -107,16 +107,16 @@
/// in [result].
static void alphaBlend(
Vector4 foreground, Vector4 background, Vector4 result) {
- final double a = foreground.a + (1.0 - foreground.a) * background.a;
- final double factor = 1.0 / a;
+ final a = foreground.a + (1.0 - foreground.a) * background.a;
+ final factor = 1.0 / a;
- final double r = factor *
+ final r = factor *
(foreground.a * foreground.r +
(1.0 - foreground.a) * background.a * background.r);
- final double g = factor *
+ final g = factor *
(foreground.a * foreground.g +
(1.0 - foreground.a) * background.a * background.g);
- final double b = factor *
+ final b = factor *
(foreground.a * foreground.b +
(1.0 - foreground.a) * background.a * background.b);
@@ -125,7 +125,7 @@
/// Convert a [input] color to a gray scaled color and store it in [result].
static void toGrayscale(Vector4 input, Vector4 result) {
- final double value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
+ final value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
result
..r = value
@@ -139,7 +139,7 @@
/// the default value is 2.2.
static void linearToGamma(Vector4 linearColor, Vector4 gammaColor,
[double gamma = 2.2]) {
- final double exponent = 1.0 / gamma;
+ final exponent = 1.0 / gamma;
gammaColor
..r = math.pow(linearColor.r, exponent).toDouble()
@@ -163,11 +163,11 @@
/// Convert [rgbColor] from rgb color model to the hue, saturation, and value
/// (HSV) color model and store it in [hsvColor].
static void rgbToHsv(Vector4 rgbColor, Vector4 hsvColor) {
- final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
- final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
- final double d = max - min;
- final double v = max;
- final double s = max == 0.0 ? 0.0 : d / max;
+ final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
+ final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
+ final d = max - min;
+ final v = max;
+ final s = max == 0.0 ? 0.0 : d / max;
var h = 0.0;
if (max != min) {
@@ -189,11 +189,11 @@
/// Convert [hsvColor] from hue, saturation, and value (HSV) color model to
/// the RGB color model and store it in [rgbColor].
static void hsvToRgb(Vector4 hsvColor, Vector4 rgbColor) {
- final int i = (hsvColor.x * 6.0).floor();
- final double f = hsvColor.x * 6.0 - i.toDouble();
- final double p = hsvColor.z * (1.0 - hsvColor.y);
- final double q = hsvColor.z * (1.0 - f * hsvColor.y);
- final double t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y);
+ final i = (hsvColor.x * 6.0).floor();
+ final f = hsvColor.x * 6.0 - i.toDouble();
+ final p = hsvColor.z * (1.0 - hsvColor.y);
+ final q = hsvColor.z * (1.0 - f * hsvColor.y);
+ final t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y);
switch (i % 6) {
case 0:
@@ -220,14 +220,14 @@
/// Convert [rgbColor] from rgb color model to the hue, saturation, and
/// lightness (HSL) color model and store it in [hslColor].
static void rgbToHsl(Vector4 rgbColor, Vector4 hslColor) {
- final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
- final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
- final double l = (max + min) / 2.0;
+ final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
+ final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
+ final l = (max + min) / 2.0;
var h = 0.0;
var s = 0.0;
if (max != min) {
- final double d = max - min;
+ final d = max - min;
s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min);
@@ -252,14 +252,14 @@
if (hslColor.y == 0.0) {
rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a);
} else {
- final double q = hslColor.z < 0.5
+ final q = hslColor.z < 0.5
? hslColor.z * (1.0 + hslColor.y)
: hslColor.z + hslColor.y - hslColor.z * hslColor.y;
- final double p = 2.0 * hslColor.z - q;
+ final p = 2.0 * hslColor.z - q;
- final double r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0);
- final double g = _hueToRgb(p, q, hslColor.x);
- final double b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0);
+ final r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0);
+ final g = _hueToRgb(p, q, hslColor.x);
+ final b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0);
rgbColor.setValues(r, g, b, hslColor.a);
}
diff --git a/lib/src/vector_math/error_helpers.dart b/lib/src/vector_math/error_helpers.dart
index f57ba9d..3739f05 100644
--- a/lib/src/vector_math/error_helpers.dart
+++ b/lib/src/vector_math/error_helpers.dart
@@ -9,7 +9,7 @@
/// be any vector, matrix, or quaternion.
double relativeError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- final double diff = (calculated - correct).abs().toDouble();
+ final diff = (calculated - correct).abs().toDouble();
return diff / correct;
}
// ignore: return_of_invalid_type
@@ -21,7 +21,7 @@
/// be any vector, matrix, or quaternion.
double absoluteError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- final double diff = (calculated - correct).abs().toDouble();
+ final diff = (calculated - correct).abs().toDouble();
return diff;
}
// ignore: return_of_invalid_type
diff --git a/lib/src/vector_math/frustum.dart b/lib/src/vector_math/frustum.dart
index 616ce5e..b5d5577 100644
--- a/lib/src/vector_math/frustum.dart
+++ b/lib/src/vector_math/frustum.dart
@@ -58,11 +58,11 @@
/// Set this from [matrix].
void setFromMatrix(Matrix4 matrix) {
- final Float32List me = matrix.storage;
- final double me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
- final double me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
- final double me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
- final double me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
+ final me = matrix.storage;
+ final me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
+ final me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
+ final me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
+ final me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
_plane0
..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12)
@@ -144,8 +144,8 @@
/// Check if this intersects with [sphere].
bool intersectsWithSphere(Sphere sphere) {
- final double negativeRadius = -sphere.radius;
- final Vector3 center = sphere.center;
+ final negativeRadius = -sphere.radius;
+ final center = sphere.center;
if (_plane0.distanceToVector3(center) < negativeRadius) {
return false;
@@ -222,11 +222,11 @@
outNz = aabb.min.z;
}
- final double d1 = plane._normal.x * outPx +
+ final d1 = plane._normal.x * outPx +
plane._normal.y * outPy +
plane._normal.z * outPz +
plane.constant;
- final double d2 = plane._normal.x * outNx +
+ final d2 = plane._normal.x * outNx +
plane._normal.y * outNy +
plane._normal.z * outNz +
plane.constant;
diff --git a/lib/src/vector_math/intersection_result.dart b/lib/src/vector_math/intersection_result.dart
index afbd699..75b56a1 100644
--- a/lib/src/vector_math/intersection_result.dart
+++ b/lib/src/vector_math/intersection_result.dart
@@ -5,13 +5,13 @@
/// Defines a result of an intersection test.
class IntersectionResult {
- double _depth;
+ double? _depth;
/// The penetration depth of the intersection.
- double get depth => _depth;
+ double? get depth => _depth;
/// The [axis] of the intersection.
- final Vector3 axis = Vector3.zero();
+ final axis = Vector3.zero();
IntersectionResult();
}
diff --git a/lib/src/vector_math/matrix2.dart b/lib/src/vector_math/matrix2.dart
index e823b90..51f73b6 100644
--- a/lib/src/vector_math/matrix2.dart
+++ b/lib/src/vector_math/matrix2.dart
@@ -14,12 +14,12 @@
/// Solve [A] * [x] = [b].
static void solve(Matrix2 A, Vector2 x, Vector2 b) {
- final double a11 = A.entry(0, 0);
- final double a12 = A.entry(0, 1);
- final double a21 = A.entry(1, 0);
- final double a22 = A.entry(1, 1);
- final double bx = b.x;
- final double by = b.y;
+ final a11 = A.entry(0, 0);
+ final a12 = A.entry(0, 1);
+ final a21 = A.entry(1, 0);
+ final a22 = A.entry(1, 1);
+ final bx = b.x;
+ final by = b.y;
var det = a11 * a22 - a12 * a21;
if (det != 0.0) {
@@ -88,8 +88,8 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector2 arg0, Vector2 arg1) {
- final Float32List arg0Storage = arg0._v2storage;
- final Float32List arg1Storage = arg1._v2storage;
+ final arg0Storage = arg0._v2storage;
+ final arg1Storage = arg1._v2storage;
_m2storage[0] = arg0Storage[0];
_m2storage[1] = arg0Storage[1];
_m2storage[2] = arg1Storage[0];
@@ -98,7 +98,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix2 arg) {
- final Float32List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
_m2storage[3] = argStorage[3];
_m2storage[2] = argStorage[2];
_m2storage[1] = argStorage[1];
@@ -107,8 +107,8 @@
/// Set this to the outer product of [u] and [v].
void setOuter(Vector2 u, Vector2 v) {
- final Float32List uStorage = u._v2storage;
- final Float32List vStorage = v._v2storage;
+ final uStorage = u._v2storage;
+ final vStorage = v._v2storage;
_m2storage[0] = uStorage[0] * vStorage[0];
_m2storage[1] = uStorage[0] * vStorage[1];
_m2storage[2] = uStorage[1] * vStorage[0];
@@ -123,7 +123,7 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_m2storage[0] = argStorage[0];
_m2storage[3] = argStorage[1];
}
@@ -145,7 +145,7 @@
/// Check if two matrices are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Matrix2) &&
(_m2storage[0] == other._m2storage[0]) &&
(_m2storage[1] == other._m2storage[1]) &&
@@ -169,15 +169,15 @@
/// Sets [row] of the matrix to values in [arg]
void setRow(int row, Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_m2storage[index(row, 0)] = argStorage[0];
_m2storage[index(row, 1)] = argStorage[1];
}
/// Gets the [row] of the matrix
Vector2 getRow(int row) {
- final Vector2 r = Vector2.zero();
- final Float32List rStorage = r._v2storage;
+ final r = Vector2.zero();
+ final rStorage = r._v2storage;
rStorage[0] = _m2storage[index(row, 0)];
rStorage[1] = _m2storage[index(row, 1)];
return r;
@@ -185,17 +185,17 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
- final int entry = column * 2;
+ final argStorage = arg._v2storage;
+ final entry = column * 2;
_m2storage[entry + 1] = argStorage[1];
_m2storage[entry + 0] = argStorage[0];
}
/// Gets the [column] of the matrix
Vector2 getColumn(int column) {
- final Vector2 r = Vector2.zero();
- final int entry = column * 2;
- final Float32List rStorage = r._v2storage;
+ final r = Vector2.zero();
+ final entry = column * 2;
+ final rStorage = r._v2storage;
rStorage[1] = _m2storage[entry + 1];
rStorage[0] = _m2storage[entry + 0];
return r;
@@ -206,7 +206,7 @@
/// Copy this into [arg].
Matrix2 copyInto(Matrix2 arg) {
- final Float32List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
argStorage[0] = _m2storage[0];
argStorage[1] = _m2storage[1];
argStorage[2] = _m2storage[2];
@@ -257,15 +257,15 @@
Matrix2 transposed() => clone()..transpose();
void transpose() {
- final double temp = _m2storage[2];
+ final temp = _m2storage[2];
_m2storage[2] = _m2storage[1];
_m2storage[1] = temp;
}
/// Returns the component wise absolute value of this.
Matrix2 absolute() {
- final Matrix2 r = Matrix2.zero();
- final Float32List rStorage = r._m2storage;
+ final r = Matrix2.zero();
+ final rStorage = r._m2storage;
rStorage[0] = _m2storage[0].abs();
rStorage[1] = _m2storage[1].abs();
rStorage[2] = _m2storage[2].abs();
@@ -279,13 +279,13 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector2 v) {
- final Float32List vStorage = v._v2storage;
+ final vStorage = v._v2storage;
return _m2storage[i] * vStorage[0] + _m2storage[2 + i] * vStorage[1];
}
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector2 v) {
- final Float32List vStorage = v._v2storage;
+ final vStorage = v._v2storage;
return _m2storage[j * 2] * vStorage[0] +
_m2storage[(j * 2) + 1] * vStorage[1];
}
@@ -318,28 +318,28 @@
/// Returns relative error between this and [correct]
double relativeError(Matrix2 correct) {
- final Matrix2 diff = correct - this;
- final double correctNorm = correct.infinityNorm();
- final double diff_norm = diff.infinityNorm();
+ final diff = correct - this;
+ final correctNorm = correct.infinityNorm();
+ final diff_norm = diff.infinityNorm();
return diff_norm / correctNorm;
}
/// Returns absolute error between this and [correct]
double absoluteError(Matrix2 correct) {
- final double this_norm = infinityNorm();
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = (this_norm - correct_norm).abs();
+ final this_norm = infinityNorm();
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Invert the matrix. Returns the determinant.
double invert() {
- final double det = determinant();
+ final det = determinant();
if (det == 0.0) {
return 0.0;
}
- final double invDet = 1.0 / det;
- final double temp = _m2storage[0];
+ final invDet = 1.0 / det;
+ final temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * invDet;
_m2storage[1] = -_m2storage[1] * invDet;
_m2storage[2] = -_m2storage[2] * invDet;
@@ -349,13 +349,13 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix2 arg) {
- final double det = arg.determinant();
+ final det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final double invDet = 1.0 / det;
- final Float32List argStorage = arg._m2storage;
+ final invDet = 1.0 / det;
+ final argStorage = arg._m2storage;
_m2storage[0] = argStorage[3] * invDet;
_m2storage[1] = -argStorage[1] * invDet;
_m2storage[2] = -argStorage[2] * invDet;
@@ -365,8 +365,8 @@
/// Turns the matrix into a rotation of [radians]
void setRotation(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m2storage[0] = c;
_m2storage[1] = s;
_m2storage[2] = -s;
@@ -375,7 +375,7 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- final double temp = _m2storage[0];
+ final temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * scale;
_m2storage[2] = -_m2storage[2] * scale;
_m2storage[1] = -_m2storage[1] * scale;
@@ -395,7 +395,7 @@
/// Add [o] to this.
void add(Matrix2 o) {
- final Float32List oStorage = o._m2storage;
+ final oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] + oStorage[0];
_m2storage[1] = _m2storage[1] + oStorage[1];
_m2storage[2] = _m2storage[2] + oStorage[2];
@@ -404,7 +404,7 @@
/// Subtract [o] from this.
void sub(Matrix2 o) {
- final Float32List oStorage = o._m2storage;
+ final oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] - oStorage[0];
_m2storage[1] = _m2storage[1] - oStorage[1];
_m2storage[2] = _m2storage[2] - oStorage[2];
@@ -421,15 +421,15 @@
/// Multiply this with [arg] and store it in this.
void multiply(Matrix2 arg) {
- final double m00 = _m2storage[0];
- final double m01 = _m2storage[2];
- final double m10 = _m2storage[1];
- final double m11 = _m2storage[3];
- final Float32List argStorage = arg._m2storage;
- final double n00 = argStorage[0];
- final double n01 = argStorage[2];
- final double n10 = argStorage[1];
- final double n11 = argStorage[3];
+ final m00 = _m2storage[0];
+ final m01 = _m2storage[2];
+ final m10 = _m2storage[1];
+ final m11 = _m2storage[3];
+ final argStorage = arg._m2storage;
+ final n00 = argStorage[0];
+ final n01 = argStorage[2];
+ final n10 = argStorage[1];
+ final n11 = argStorage[3];
_m2storage[0] = (m00 * n00) + (m01 * n10);
_m2storage[2] = (m00 * n01) + (m01 * n11);
_m2storage[1] = (m10 * n00) + (m11 * n10);
@@ -441,11 +441,11 @@
/// Multiply a transposed this with [arg].
void transposeMultiply(Matrix2 arg) {
- final double m00 = _m2storage[0];
- final double m01 = _m2storage[1];
- final double m10 = _m2storage[2];
- final double m11 = _m2storage[3];
- final Float32List argStorage = arg._m2storage;
+ final m00 = _m2storage[0];
+ final m01 = _m2storage[1];
+ final m10 = _m2storage[2];
+ final m11 = _m2storage[3];
+ final argStorage = arg._m2storage;
_m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]);
_m2storage[2] = (m00 * argStorage[2]) + (m01 * argStorage[3]);
_m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[1]);
@@ -454,11 +454,11 @@
/// Multiply this with a transposed [arg].
void multiplyTranspose(Matrix2 arg) {
- final double m00 = _m2storage[0];
- final double m01 = _m2storage[2];
- final double m10 = _m2storage[1];
- final double m11 = _m2storage[3];
- final Float32List argStorage = arg._m2storage;
+ final m00 = _m2storage[0];
+ final m01 = _m2storage[2];
+ final m10 = _m2storage[1];
+ final m11 = _m2storage[3];
+ final argStorage = arg._m2storage;
_m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[2]);
_m2storage[2] = (m00 * argStorage[1]) + (m01 * argStorage[3]);
_m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[2]);
@@ -468,11 +468,9 @@
/// Transform [arg] of type [Vector2] using the transformation defined by
/// this.
Vector2 transform(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
- final double x =
- (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]);
- final double y =
- (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]);
+ final argStorage = arg._v2storage;
+ final x = (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]);
+ final y = (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]);
argStorage[0] = x;
argStorage[1] = y;
return arg;
@@ -481,7 +479,7 @@
/// Transform a copy of [arg] of type [Vector2] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector2 transformed(Vector2 arg, [Vector2 out]) {
+ Vector2 transformed(Vector2 arg, [Vector2? out]) {
if (out == null) {
out = Vector2.copy(arg);
} else {
@@ -492,7 +490,7 @@
/// Copies this into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
array[i + 3] = _m2storage[3];
array[i + 2] = _m2storage[2];
array[i + 1] = _m2storage[1];
@@ -501,7 +499,7 @@
/// Copies elements from [array] into this starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
_m2storage[3] = array[i + 3];
_m2storage[2] = array[i + 2];
_m2storage[1] = array[i + 1];
diff --git a/lib/src/vector_math/matrix3.dart b/lib/src/vector_math/matrix3.dart
index aacbb73..9d11107 100644
--- a/lib/src/vector_math/matrix3.dart
+++ b/lib/src/vector_math/matrix3.dart
@@ -14,12 +14,12 @@
/// Solve [A] * [x] = [b].
static void solve2(Matrix3 A, Vector2 x, Vector2 b) {
- final double a11 = A.entry(0, 0);
- final double a12 = A.entry(0, 1);
- final double a21 = A.entry(1, 0);
- final double a22 = A.entry(1, 1);
- final double bx = b.x - A.storage[6];
- final double by = b.y - A.storage[7];
+ final a11 = A.entry(0, 0);
+ final a12 = A.entry(0, 1);
+ final a21 = A.entry(1, 0);
+ final a22 = A.entry(1, 1);
+ final bx = b.x - A.storage[6];
+ final by = b.y - A.storage[7];
var det = a11 * a22 - a12 * a21;
if (det != 0.0) {
@@ -33,15 +33,15 @@
/// Solve [A] * [x] = [b].
static void solve(Matrix3 A, Vector3 x, Vector3 b) {
- final double A0x = A.entry(0, 0);
- final double A0y = A.entry(1, 0);
- final double A0z = A.entry(2, 0);
- final double A1x = A.entry(0, 1);
- final double A1y = A.entry(1, 1);
- final double A1z = A.entry(2, 1);
- final double A2x = A.entry(0, 2);
- final double A2y = A.entry(1, 2);
- final double A2z = A.entry(2, 2);
+ final A0x = A.entry(0, 0);
+ final A0y = A.entry(1, 0);
+ final A0z = A.entry(2, 0);
+ final A1x = A.entry(0, 1);
+ final A1y = A.entry(1, 1);
+ final A1z = A.entry(2, 1);
+ final A2x = A.entry(0, 2);
+ final A2y = A.entry(1, 2);
+ final A2z = A.entry(2, 2);
double rx, ry, rz;
double det;
@@ -57,21 +57,21 @@
}
// b dot [Column1 cross Column 2]
- final double x_ = det * (b.x * rx + b.y * ry + b.z * rz);
+ final x_ = det * (b.x * rx + b.y * ry + b.z * rz);
// Column2 cross b
rx = -(A2y * b.z - A2z * b.y);
ry = -(A2z * b.x - A2x * b.z);
rz = -(A2x * b.y - A2y * b.x);
// Column0 dot -[Column2 cross b (Column3)]
- final double y_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final y_ = det * (A0x * rx + A0y * ry + A0z * rz);
// b cross Column 1
rx = -(b.y * A1z - b.z * A1y);
ry = -(b.z * A1x - b.x * A1z);
rz = -(b.x * A1y - b.y * A1x);
// Column0 dot -[b cross Column 1]
- final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final z_ = det * (A0x * rx + A0y * ry + A0z * rz);
x
..x = x_
@@ -153,9 +153,9 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector3 arg0, Vector3 arg1, Vector3 arg2) {
- final Float32List arg0Storage = arg0._v3storage;
- final Float32List arg1Storage = arg1._v3storage;
- final Float32List arg2Storage = arg2._v3storage;
+ final arg0Storage = arg0._v3storage;
+ final arg1Storage = arg1._v3storage;
+ final arg2Storage = arg2._v3storage;
_m3storage[0] = arg0Storage[0];
_m3storage[1] = arg0Storage[1];
_m3storage[2] = arg0Storage[2];
@@ -169,7 +169,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix3 arg) {
- final Float32List argStorage = arg._m3storage;
+ final argStorage = arg._m3storage;
_m3storage[8] = argStorage[8];
_m3storage[7] = argStorage[7];
_m3storage[6] = argStorage[6];
@@ -183,8 +183,8 @@
/// Set this to the outer product of [u] and [v].
void setOuter(Vector3 u, Vector3 v) {
- final Float32List uStorage = u._v3storage;
- final Float32List vStorage = v._v3storage;
+ final uStorage = u._v3storage;
+ final vStorage = v._v3storage;
_m3storage[0] = uStorage[0] * vStorage[0];
_m3storage[1] = uStorage[0] * vStorage[1];
_m3storage[2] = uStorage[0] * vStorage[2];
@@ -212,7 +212,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final Float32List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
_m3storage[0] = argStorage[0];
_m3storage[1] = argStorage[1];
_m3storage[3] = argStorage[2];
@@ -236,7 +236,7 @@
/// Check if two matrices are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Matrix3) &&
(_m3storage[0] == other._m3storage[0]) &&
(_m3storage[1] == other._m3storage[1]) &&
@@ -271,7 +271,7 @@
/// Assigns the [row] of to [arg].
void setRow(int row, Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_m3storage[index(row, 0)] = argStorage[0];
_m3storage[index(row, 1)] = argStorage[1];
_m3storage[index(row, 2)] = argStorage[2];
@@ -279,8 +279,8 @@
/// Gets the [row] of the matrix
Vector3 getRow(int row) {
- final Vector3 r = Vector3.zero();
- final Float32List rStorage = r._v3storage;
+ final r = Vector3.zero();
+ final rStorage = r._v3storage;
rStorage[0] = _m3storage[index(row, 0)];
rStorage[1] = _m3storage[index(row, 1)];
rStorage[2] = _m3storage[index(row, 2)];
@@ -289,8 +289,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
- final int entry = column * 3;
+ final argStorage = arg._v3storage;
+ final entry = column * 3;
_m3storage[entry + 2] = argStorage[2];
_m3storage[entry + 1] = argStorage[1];
_m3storage[entry + 0] = argStorage[0];
@@ -298,9 +298,9 @@
/// Gets the [column] of the matrix
Vector3 getColumn(int column) {
- final Vector3 r = Vector3.zero();
- final Float32List rStorage = r._v3storage;
- final int entry = column * 3;
+ final r = Vector3.zero();
+ final rStorage = r._v3storage;
+ final entry = column * 3;
rStorage[2] = _m3storage[entry + 2];
rStorage[1] = _m3storage[entry + 1];
rStorage[0] = _m3storage[entry + 0];
@@ -312,7 +312,7 @@
/// Copy this into [arg].
Matrix3 copyInto(Matrix3 arg) {
- final Float32List argStorage = arg._m3storage;
+ final argStorage = arg._m3storage;
argStorage[0] = _m3storage[0];
argStorage[1] = _m3storage[1];
argStorage[2] = _m3storage[2];
@@ -393,8 +393,8 @@
/// Returns the component wise absolute value of this.
Matrix3 absolute() {
- final Matrix3 r = Matrix3.zero();
- final Float32List rStorage = r._m3storage;
+ final r = Matrix3.zero();
+ final rStorage = r._m3storage;
rStorage[0] = _m3storage[0].abs();
rStorage[1] = _m3storage[1].abs();
rStorage[2] = _m3storage[2].abs();
@@ -409,18 +409,18 @@
/// Returns the determinant of this matrix.
double determinant() {
- final double x = _m3storage[0] *
+ final x = _m3storage[0] *
((_m3storage[4] * _m3storage[8]) - (_m3storage[5] * _m3storage[7]));
- final double y = _m3storage[1] *
+ final y = _m3storage[1] *
((_m3storage[3] * _m3storage[8]) - (_m3storage[5] * _m3storage[6]));
- final double z = _m3storage[2] *
+ final z = _m3storage[2] *
((_m3storage[3] * _m3storage[7]) - (_m3storage[4] * _m3storage[6]));
return x - y + z;
}
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector3 v) {
- final Float32List vStorage = v._v3storage;
+ final vStorage = v._v3storage;
return _m3storage[i] * vStorage[0] +
_m3storage[3 + i] * vStorage[1] +
_m3storage[6 + i] * vStorage[2];
@@ -428,7 +428,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector3 v) {
- final Float32List vStorage = v._v3storage;
+ final vStorage = v._v3storage;
return _m3storage[j * 3] * vStorage[0] +
_m3storage[j * 3 + 1] * vStorage[1] +
_m3storage[j * 3 + 2] * vStorage[2];
@@ -473,17 +473,17 @@
/// Returns relative error between this and [correct]
double relativeError(Matrix3 correct) {
- final Matrix3 diff = correct - this;
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = diff.infinityNorm();
+ final diff = correct - this;
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between this and [correct]
double absoluteError(Matrix3 correct) {
- final double this_norm = infinityNorm();
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = (this_norm - correct_norm).abs();
+ final this_norm = infinityNorm();
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
@@ -492,30 +492,30 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix3 arg) {
- final double det = arg.determinant();
+ final det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final double invDet = 1.0 / det;
- final Float32List argStorage = arg._m3storage;
- final double ix = invDet *
+ final invDet = 1.0 / det;
+ final argStorage = arg._m3storage;
+ final ix = invDet *
(argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]);
- final double iy = invDet *
+ final iy = invDet *
(argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]);
- final double iz = invDet *
+ final iz = invDet *
(argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]);
- final double jx = invDet *
+ final jx = invDet *
(argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]);
- final double jy = invDet *
+ final jy = invDet *
(argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]);
- final double jz = invDet *
+ final jz = invDet *
(argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]);
- final double kx = invDet *
+ final kx = invDet *
(argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]);
- final double ky = invDet *
+ final ky = invDet *
(argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]);
- final double kz = invDet *
+ final kz = invDet *
(argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]);
_m3storage[0] = ix;
_m3storage[1] = iy;
@@ -537,8 +537,8 @@
/// Turns the matrix into a rotation of [radians] around X
void setRotationX(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m3storage[0] = 1.0;
_m3storage[1] = 0.0;
_m3storage[2] = 0.0;
@@ -552,8 +552,8 @@
/// Turns the matrix into a rotation of [radians] around Y
void setRotationY(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = 0.0;
_m3storage[2] = s;
@@ -567,8 +567,8 @@
/// Turns the matrix into a rotation of [radians] around Z
void setRotationZ(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = s;
_m3storage[2] = 0.0;
@@ -582,15 +582,15 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[3];
- final double m02 = _m3storage[6];
- final double m10 = _m3storage[1];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[7];
- final double m20 = _m3storage[2];
- final double m21 = _m3storage[5];
- final double m22 = _m3storage[8];
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[3];
+ final m02 = _m3storage[6];
+ final m10 = _m3storage[1];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[7];
+ final m20 = _m3storage[2];
+ final m21 = _m3storage[5];
+ final m22 = _m3storage[8];
_m3storage[0] = (m11 * m22 - m12 * m21) * scale;
_m3storage[1] = (m12 * m20 - m10 * m22) * scale;
_m3storage[2] = (m10 * m21 - m11 * m20) * scale;
@@ -606,19 +606,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- final double m00 = _m3storage[0].abs();
- final double m01 = _m3storage[3].abs();
- final double m02 = _m3storage[6].abs();
- final double m10 = _m3storage[1].abs();
- final double m11 = _m3storage[4].abs();
- final double m12 = _m3storage[7].abs();
- final double m20 = _m3storage[2].abs();
- final double m21 = _m3storage[5].abs();
- final double m22 = _m3storage[8].abs();
- final Float32List argStorage = arg._v3storage;
- final double x = argStorage[0];
- final double y = argStorage[1];
- final double z = argStorage[2];
+ final m00 = _m3storage[0].abs();
+ final m01 = _m3storage[3].abs();
+ final m02 = _m3storage[6].abs();
+ final m10 = _m3storage[1].abs();
+ final m11 = _m3storage[4].abs();
+ final m12 = _m3storage[7].abs();
+ final m20 = _m3storage[2].abs();
+ final m21 = _m3storage[5].abs();
+ final m22 = _m3storage[8].abs();
+ final argStorage = arg._v3storage;
+ final x = argStorage[0];
+ final y = argStorage[1];
+ final z = argStorage[2];
argStorage[0] = x * m00 + y * m01 + z * m02;
argStorage[1] = x * m10 + y * m11 + z * m12;
argStorage[2] = x * m20 + y * m21 + z * m22;
@@ -629,13 +629,13 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector2 absoluteRotate2(Vector2 arg) {
- final double m00 = _m3storage[0].abs();
- final double m01 = _m3storage[3].abs();
- final double m10 = _m3storage[1].abs();
- final double m11 = _m3storage[4].abs();
- final Float32List argStorage = arg._v2storage;
- final double x = argStorage[0];
- final double y = argStorage[1];
+ final m00 = _m3storage[0].abs();
+ final m01 = _m3storage[3].abs();
+ final m10 = _m3storage[1].abs();
+ final m11 = _m3storage[4].abs();
+ final argStorage = arg._v2storage;
+ final x = argStorage[0];
+ final y = argStorage[1];
argStorage[0] = x * m00 + y * m01;
argStorage[1] = x * m10 + y * m11;
return arg;
@@ -643,11 +643,11 @@
/// Transforms [arg] with this.
Vector2 transform2(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
- final double x_ = (_m3storage[0] * argStorage[0]) +
+ final argStorage = arg._v2storage;
+ final x_ = (_m3storage[0] * argStorage[0]) +
(_m3storage[3] * argStorage[1]) +
_m3storage[6];
- final double y_ = (_m3storage[1] * argStorage[0]) +
+ final y_ = (_m3storage[1] * argStorage[0]) +
(_m3storage[4] * argStorage[1]) +
_m3storage[7];
argStorage[0] = x_;
@@ -673,7 +673,7 @@
/// Add [o] to this.
void add(Matrix3 o) {
- final Float32List oStorage = o._m3storage;
+ final oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] + oStorage[0];
_m3storage[1] = _m3storage[1] + oStorage[1];
_m3storage[2] = _m3storage[2] + oStorage[2];
@@ -687,7 +687,7 @@
/// Subtract [o] from this.
void sub(Matrix3 o) {
- final Float32List oStorage = o._m3storage;
+ final oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] - oStorage[0];
_m3storage[1] = _m3storage[1] - oStorage[1];
_m3storage[2] = _m3storage[2] - oStorage[2];
@@ -714,25 +714,25 @@
/// Multiply this by [arg].
void multiply(Matrix3 arg) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[3];
- final double m02 = _m3storage[6];
- final double m10 = _m3storage[1];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[7];
- final double m20 = _m3storage[2];
- final double m21 = _m3storage[5];
- final double m22 = _m3storage[8];
- final Float32List argStorage = arg._m3storage;
- final double n00 = argStorage[0];
- final double n01 = argStorage[3];
- final double n02 = argStorage[6];
- final double n10 = argStorage[1];
- final double n11 = argStorage[4];
- final double n12 = argStorage[7];
- final double n20 = argStorage[2];
- final double n21 = argStorage[5];
- final double n22 = argStorage[8];
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[3];
+ final m02 = _m3storage[6];
+ final m10 = _m3storage[1];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[7];
+ final m20 = _m3storage[2];
+ final m21 = _m3storage[5];
+ final m22 = _m3storage[8];
+ final argStorage = arg._m3storage;
+ final n00 = argStorage[0];
+ final n01 = argStorage[3];
+ final n02 = argStorage[6];
+ final n10 = argStorage[1];
+ final n11 = argStorage[4];
+ final n12 = argStorage[7];
+ final n20 = argStorage[2];
+ final n21 = argStorage[5];
+ final n22 = argStorage[8];
_m3storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20);
_m3storage[3] = (m00 * n01) + (m01 * n11) + (m02 * n21);
_m3storage[6] = (m00 * n02) + (m01 * n12) + (m02 * n22);
@@ -748,16 +748,16 @@
Matrix3 multiplied(Matrix3 arg) => clone()..multiply(arg);
void transposeMultiply(Matrix3 arg) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[1];
- final double m02 = _m3storage[2];
- final double m10 = _m3storage[3];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[5];
- final double m20 = _m3storage[6];
- final double m21 = _m3storage[7];
- final double m22 = _m3storage[8];
- final Float32List argStorage = arg._m3storage;
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[1];
+ final m02 = _m3storage[2];
+ final m10 = _m3storage[3];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[5];
+ final m20 = _m3storage[6];
+ final m21 = _m3storage[7];
+ final m22 = _m3storage[8];
+ final argStorage = arg._m3storage;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * argStorage[1]) + (m02 * argStorage[2]);
_m3storage[3] =
@@ -779,16 +779,16 @@
}
void multiplyTranspose(Matrix3 arg) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[3];
- final double m02 = _m3storage[6];
- final double m10 = _m3storage[1];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[7];
- final double m20 = _m3storage[2];
- final double m21 = _m3storage[5];
- final double m22 = _m3storage[8];
- final Float32List argStorage = arg._m3storage;
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[3];
+ final m02 = _m3storage[6];
+ final m10 = _m3storage[1];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[7];
+ final m20 = _m3storage[2];
+ final m21 = _m3storage[5];
+ final m22 = _m3storage[8];
+ final argStorage = arg._m3storage;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * argStorage[3]) + (m02 * argStorage[6]);
_m3storage[3] =
@@ -812,14 +812,14 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// this.
Vector3 transform(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
- final double x_ = (_m3storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m3storage[0] * argStorage[0]) +
(_m3storage[3] * argStorage[1]) +
(_m3storage[6] * argStorage[2]);
- final double y_ = (_m3storage[1] * argStorage[0]) +
+ final y_ = (_m3storage[1] * argStorage[0]) +
(_m3storage[4] * argStorage[1]) +
(_m3storage[7] * argStorage[2]);
- final double z_ = (_m3storage[2] * argStorage[0]) +
+ final z_ = (_m3storage[2] * argStorage[0]) +
(_m3storage[5] * argStorage[1]) +
(_m3storage[8] * argStorage[2]);
arg
@@ -832,7 +832,7 @@
/// Transform a copy of [arg] of type [Vector3] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector3 transformed(Vector3 arg, [Vector3 out]) {
+ Vector3 transformed(Vector3 arg, [Vector3? out]) {
if (out == null) {
out = Vector3.copy(arg);
} else {
@@ -843,7 +843,7 @@
/// Copies this into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
array[i + 8] = _m3storage[8];
array[i + 7] = _m3storage[7];
array[i + 6] = _m3storage[6];
@@ -857,7 +857,7 @@
/// Copies elements from [array] into this starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
_m3storage[8] = array[i + 8];
_m3storage[7] = array[i + 7];
_m3storage[6] = array[i + 6];
@@ -871,8 +871,8 @@
/// Multiply this to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final Vector3 v = Vector3.array(array, j)..applyMatrix3(this);
+ for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final v = Vector3.array(array, j)..applyMatrix3(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -882,23 +882,23 @@
}
Vector3 get right {
- final double x = _m3storage[0];
- final double y = _m3storage[1];
- final double z = _m3storage[2];
+ final x = _m3storage[0];
+ final y = _m3storage[1];
+ final z = _m3storage[2];
return Vector3(x, y, z);
}
Vector3 get up {
- final double x = _m3storage[3];
- final double y = _m3storage[4];
- final double z = _m3storage[5];
+ final x = _m3storage[3];
+ final y = _m3storage[4];
+ final z = _m3storage[5];
return Vector3(x, y, z);
}
Vector3 get forward {
- final double x = _m3storage[6];
- final double y = _m3storage[7];
- final double z = _m3storage[8];
+ final x = _m3storage[6];
+ final y = _m3storage[7];
+ final z = _m3storage[8];
return Vector3(x, y, z);
}
diff --git a/lib/src/vector_math/matrix4.dart b/lib/src/vector_math/matrix4.dart
index 9759d69..3ae0f0d 100644
--- a/lib/src/vector_math/matrix4.dart
+++ b/lib/src/vector_math/matrix4.dart
@@ -14,12 +14,12 @@
/// Solve [A] * [x] = [b].
static void solve2(Matrix4 A, Vector2 x, Vector2 b) {
- final double a11 = A.entry(0, 0);
- final double a12 = A.entry(0, 1);
- final double a21 = A.entry(1, 0);
- final double a22 = A.entry(1, 1);
- final double bx = b.x - A._m4storage[8];
- final double by = b.y - A._m4storage[9];
+ final a11 = A.entry(0, 0);
+ final a12 = A.entry(0, 1);
+ final a21 = A.entry(1, 0);
+ final a22 = A.entry(1, 1);
+ final bx = b.x - A._m4storage[8];
+ final by = b.y - A._m4storage[9];
var det = a11 * a22 - a12 * a21;
if (det != 0.0) {
@@ -33,18 +33,18 @@
/// Solve [A] * [x] = [b].
static void solve3(Matrix4 A, Vector3 x, Vector3 b) {
- final double A0x = A.entry(0, 0);
- final double A0y = A.entry(1, 0);
- final double A0z = A.entry(2, 0);
- final double A1x = A.entry(0, 1);
- final double A1y = A.entry(1, 1);
- final double A1z = A.entry(2, 1);
- final double A2x = A.entry(0, 2);
- final double A2y = A.entry(1, 2);
- final double A2z = A.entry(2, 2);
- final double bx = b.x - A._m4storage[12];
- final double by = b.y - A._m4storage[13];
- final double bz = b.z - A._m4storage[14];
+ final A0x = A.entry(0, 0);
+ final A0y = A.entry(1, 0);
+ final A0z = A.entry(2, 0);
+ final A1x = A.entry(0, 1);
+ final A1y = A.entry(1, 1);
+ final A1z = A.entry(2, 1);
+ final A2x = A.entry(0, 2);
+ final A2y = A.entry(1, 2);
+ final A2z = A.entry(2, 2);
+ final bx = b.x - A._m4storage[12];
+ final by = b.y - A._m4storage[13];
+ final bz = b.z - A._m4storage[14];
double rx, ry, rz;
double det;
@@ -60,21 +60,21 @@
}
// b dot [Column1 cross Column 2]
- final double x_ = det * (bx * rx + by * ry + bz * rz);
+ final x_ = det * (bx * rx + by * ry + bz * rz);
// Column2 cross b
rx = -(A2y * bz - A2z * by);
ry = -(A2z * bx - A2x * bz);
rz = -(A2x * by - A2y * bx);
// Column0 dot -[Column2 cross b (Column3)]
- final double y_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final y_ = det * (A0x * rx + A0y * ry + A0z * rz);
// b cross Column 1
rx = -(by * A1z - bz * A1y);
ry = -(bz * A1x - bx * A1z);
rz = -(bx * A1y - by * A1x);
// Column0 dot -[b cross Column 1]
- final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final z_ = det * (A0x * rx + A0y * ry + A0z * rz);
x
..x = x_
@@ -84,39 +84,39 @@
/// Solve [A] * [x] = [b].
static void solve(Matrix4 A, Vector4 x, Vector4 b) {
- final double a00 = A._m4storage[0];
- final double a01 = A._m4storage[1];
- final double a02 = A._m4storage[2];
- final double a03 = A._m4storage[3];
- final double a10 = A._m4storage[4];
- final double a11 = A._m4storage[5];
- final double a12 = A._m4storage[6];
- final double a13 = A._m4storage[7];
- final double a20 = A._m4storage[8];
- final double a21 = A._m4storage[9];
- final double a22 = A._m4storage[10];
- final double a23 = A._m4storage[11];
- final double a30 = A._m4storage[12];
- final double a31 = A._m4storage[13];
- final double a32 = A._m4storage[14];
- final double a33 = A._m4storage[15];
- final double b00 = a00 * a11 - a01 * a10;
- final double b01 = a00 * a12 - a02 * a10;
- final double b02 = a00 * a13 - a03 * a10;
- final double b03 = a01 * a12 - a02 * a11;
- final double b04 = a01 * a13 - a03 * a11;
- final double b05 = a02 * a13 - a03 * a12;
- final double b06 = a20 * a31 - a21 * a30;
- final double b07 = a20 * a32 - a22 * a30;
- final double b08 = a20 * a33 - a23 * a30;
- final double b09 = a21 * a32 - a22 * a31;
- final double b10 = a21 * a33 - a23 * a31;
- final double b11 = a22 * a33 - a23 * a32;
+ final a00 = A._m4storage[0];
+ final a01 = A._m4storage[1];
+ final a02 = A._m4storage[2];
+ final a03 = A._m4storage[3];
+ final a10 = A._m4storage[4];
+ final a11 = A._m4storage[5];
+ final a12 = A._m4storage[6];
+ final a13 = A._m4storage[7];
+ final a20 = A._m4storage[8];
+ final a21 = A._m4storage[9];
+ final a22 = A._m4storage[10];
+ final a23 = A._m4storage[11];
+ final a30 = A._m4storage[12];
+ final a31 = A._m4storage[13];
+ final a32 = A._m4storage[14];
+ final a33 = A._m4storage[15];
+ final b00 = a00 * a11 - a01 * a10;
+ final b01 = a00 * a12 - a02 * a10;
+ final b02 = a00 * a13 - a03 * a10;
+ final b03 = a01 * a12 - a02 * a11;
+ final b04 = a01 * a13 - a03 * a11;
+ final b05 = a02 * a13 - a03 * a12;
+ final b06 = a20 * a31 - a21 * a30;
+ final b07 = a20 * a32 - a22 * a30;
+ final b08 = a20 * a33 - a23 * a30;
+ final b09 = a21 * a32 - a22 * a31;
+ final b10 = a21 * a33 - a23 * a31;
+ final b11 = a22 * a33 - a23 * a32;
- final double bX = b.storage[0];
- final double bY = b.storage[1];
- final double bZ = b.storage[2];
- final double bW = b.storage[3];
+ final bX = b.storage[0];
+ final bY = b.storage[1];
+ final bZ = b.storage[2];
+ final bW = b.storage[3];
var det =
b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
@@ -150,9 +150,9 @@
/// Returns a matrix that is the inverse of [other] if [other] is invertible,
/// otherwise `null`.
- static Matrix4 tryInvert(Matrix4 other) {
- final Matrix4 r = Matrix4.zero();
- final double determinant = r.copyInverse(other);
+ static Matrix4? tryInvert(Matrix4 other) {
+ final r = Matrix4.zero();
+ final determinant = r.copyInverse(other);
if (determinant == 0.0) {
return null;
}
@@ -231,8 +231,8 @@
/// Constructs a matrix that is the inverse of [other].
factory Matrix4.inverted(Matrix4 other) {
- final Matrix4 r = Matrix4.zero();
- final double determinant = r.copyInverse(other);
+ final r = Matrix4.zero();
+ final determinant = r.copyInverse(other);
if (determinant == 0.0) {
throw ArgumentError.value(other, 'other', 'Matrix cannot be inverted');
}
@@ -275,9 +275,9 @@
/// Scale matrix.
factory Matrix4.diagonal3(Vector3 scale) {
- final Matrix4 m = Matrix4.zero();
- final Float32List mStorage = m._m4storage;
- final Float32List scaleStorage = scale._v3storage;
+ final m = Matrix4.zero();
+ final mStorage = m._m4storage;
+ final scaleStorage = scale._v3storage;
mStorage[15] = 1.0;
mStorage[10] = scaleStorage[2];
mStorage[5] = scaleStorage[1];
@@ -295,21 +295,21 @@
/// Skew matrix around X axis
factory Matrix4.skewX(double alpha) {
- final Matrix4 m = Matrix4.identity();
+ final m = Matrix4.identity();
m._m4storage[4] = math.tan(alpha);
return m;
}
/// Skew matrix around Y axis.
factory Matrix4.skewY(double beta) {
- final Matrix4 m = Matrix4.identity();
+ final m = Matrix4.identity();
m._m4storage[1] = math.tan(beta);
return m;
}
/// Skew matrix around X axis (alpha) and Y axis (beta).
factory Matrix4.skew(double alpha, double beta) {
- final Matrix4 m = Matrix4.identity();
+ final m = Matrix4.identity();
m._m4storage[1] = math.tan(beta);
m._m4storage[4] = math.tan(alpha);
return m;
@@ -375,10 +375,10 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) {
- final Float32List arg0Storage = arg0._v4storage;
- final Float32List arg1Storage = arg1._v4storage;
- final Float32List arg2Storage = arg2._v4storage;
- final Float32List arg3Storage = arg3._v4storage;
+ final arg0Storage = arg0._v4storage;
+ final arg1Storage = arg1._v4storage;
+ final arg2Storage = arg2._v4storage;
+ final arg3Storage = arg3._v4storage;
_m4storage[0] = arg0Storage[0];
_m4storage[1] = arg0Storage[1];
_m4storage[2] = arg0Storage[2];
@@ -399,7 +399,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix4 arg) {
- final Float32List argStorage = arg._m4storage;
+ final argStorage = arg._m4storage;
_m4storage[15] = argStorage[15];
_m4storage[14] = argStorage[14];
_m4storage[13] = argStorage[13];
@@ -420,25 +420,25 @@
/// Sets the matrix from translation [arg0] and rotation [arg1].
void setFromTranslationRotation(Vector3 arg0, Quaternion arg1) {
- final Float32List arg1Storage = arg1._qStorage;
- final double x = arg1Storage[0];
- final double y = arg1Storage[1];
- final double z = arg1Storage[2];
- final double w = arg1Storage[3];
- final double x2 = x + x;
- final double y2 = y + y;
- final double z2 = z + z;
- final double xx = x * x2;
- final double xy = x * y2;
- final double xz = x * z2;
- final double yy = y * y2;
- final double yz = y * z2;
- final double zz = z * z2;
- final double wx = w * x2;
- final double wy = w * y2;
- final double wz = w * z2;
+ final arg1Storage = arg1._qStorage;
+ final x = arg1Storage[0];
+ final y = arg1Storage[1];
+ final z = arg1Storage[2];
+ final w = arg1Storage[3];
+ final x2 = x + x;
+ final y2 = y + y;
+ final z2 = z + z;
+ final xx = x * x2;
+ final xy = x * y2;
+ final xz = x * z2;
+ final yy = y * y2;
+ final yz = y * z2;
+ final zz = z * z2;
+ final wx = w * x2;
+ final wy = w * y2;
+ final wz = w * z2;
- final Float32List arg0Storage = arg0._v3storage;
+ final arg0Storage = arg0._v3storage;
_m4storage[0] = 1.0 - (yy + zz);
_m4storage[1] = xy + wz;
_m4storage[2] = xz - wy;
@@ -466,7 +466,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final Float32List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
_m4storage[0] = argStorage[0];
_m4storage[1] = argStorage[1];
_m4storage[4] = argStorage[2];
@@ -475,7 +475,7 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_m4storage[0] = argStorage[0];
_m4storage[5] = argStorage[1];
_m4storage[10] = argStorage[2];
@@ -483,8 +483,8 @@
}
void setOuter(Vector4 u, Vector4 v) {
- final Float32List uStorage = u._v4storage;
- final Float32List vStorage = v._v4storage;
+ final uStorage = u._v4storage;
+ final vStorage = v._v4storage;
_m4storage[0] = uStorage[0] * vStorage[0];
_m4storage[1] = uStorage[0] * vStorage[1];
_m4storage[2] = uStorage[0] * vStorage[2];
@@ -521,7 +521,7 @@
/// Check if two matrices are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Matrix4) &&
(_m4storage[0] == other._m4storage[0]) &&
(_m4storage[1] == other._m4storage[1]) &&
@@ -569,7 +569,7 @@
/// Assigns the [row] of the matrix [arg]
void setRow(int row, Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_m4storage[index(row, 0)] = argStorage[0];
_m4storage[index(row, 1)] = argStorage[1];
_m4storage[index(row, 2)] = argStorage[2];
@@ -578,8 +578,8 @@
/// Gets the [row] of the matrix
Vector4 getRow(int row) {
- final Vector4 r = Vector4.zero();
- final Float32List rStorage = r._v4storage;
+ final r = Vector4.zero();
+ final rStorage = r._v4storage;
rStorage[0] = _m4storage[index(row, 0)];
rStorage[1] = _m4storage[index(row, 1)];
rStorage[2] = _m4storage[index(row, 2)];
@@ -589,8 +589,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector4 arg) {
- final int entry = column * 4;
- final Float32List argStorage = arg._v4storage;
+ final entry = column * 4;
+ final argStorage = arg._v4storage;
_m4storage[entry + 3] = argStorage[3];
_m4storage[entry + 2] = argStorage[2];
_m4storage[entry + 1] = argStorage[1];
@@ -599,9 +599,9 @@
/// Gets the [column] of the matrix
Vector4 getColumn(int column) {
- final Vector4 r = Vector4.zero();
- final Float32List rStorage = r._v4storage;
- final int entry = column * 4;
+ final r = Vector4.zero();
+ final rStorage = r._v4storage;
+ final entry = column * 4;
rStorage[3] = _m4storage[entry + 3];
rStorage[2] = _m4storage[entry + 2];
rStorage[1] = _m4storage[entry + 1];
@@ -614,7 +614,7 @@
/// Copy into [arg].
Matrix4 copyInto(Matrix4 arg) {
- final Float32List argStorage = arg._m4storage;
+ final argStorage = arg._m4storage;
argStorage[0] = _m4storage[0];
argStorage[1] = _m4storage[1];
argStorage[2] = _m4storage[2];
@@ -665,7 +665,7 @@
double tx;
double ty;
double tz;
- final double tw = x is Vector4 ? x.w : 1.0;
+ final tw = x is Vector4 ? x.w : 1.0;
if (x is Vector3) {
tx = x.x;
ty = x.y;
@@ -678,20 +678,22 @@
tx = x;
ty = y;
tz = z;
+ } else {
+ throw UnimplementedError();
}
- final double t1 = _m4storage[0] * tx +
+ final t1 = _m4storage[0] * tx +
_m4storage[4] * ty +
_m4storage[8] * tz +
_m4storage[12] * tw;
- final double t2 = _m4storage[1] * tx +
+ final t2 = _m4storage[1] * tx +
_m4storage[5] * ty +
_m4storage[9] * tz +
_m4storage[13] * tw;
- final double t3 = _m4storage[2] * tx +
+ final t3 = _m4storage[2] * tx +
_m4storage[6] * ty +
_m4storage[10] * tz +
_m4storage[14] * tw;
- final double t4 = _m4storage[3] * tx +
+ final t4 = _m4storage[3] * tx +
_m4storage[7] * ty +
_m4storage[11] * tz +
_m4storage[15] * tw;
@@ -707,7 +709,7 @@
double tx;
double ty;
double tz;
- final double tw = x is Vector4 ? x.w : 1.0;
+ final tw = x is Vector4 ? x.w : 1.0;
if (x is Vector3) {
tx = x.x;
ty = x.y;
@@ -720,6 +722,8 @@
tx = x;
ty = y;
tz = z;
+ } else {
+ throw UnimplementedError();
}
// Column 1
@@ -749,46 +753,36 @@
/// Rotate this [angle] radians around [axis]
void rotate(Vector3 axis, double angle) {
- final double len = axis.length;
- final Float32List axisStorage = axis._v3storage;
- final double x = axisStorage[0] / len;
- final double y = axisStorage[1] / len;
- final double z = axisStorage[2] / len;
- final double c = math.cos(angle);
- final double s = math.sin(angle);
- final double C = 1.0 - c;
- final double m11 = x * x * C + c;
- final double m12 = x * y * C - z * s;
- final double m13 = x * z * C + y * s;
- final double m21 = y * x * C + z * s;
- final double m22 = y * y * C + c;
- final double m23 = y * z * C - x * s;
- final double m31 = z * x * C - y * s;
- final double m32 = z * y * C + x * s;
- final double m33 = z * z * C + c;
- final double t1 =
- _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31;
- final double t2 =
- _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31;
- final double t3 =
- _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31;
- final double t4 =
- _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31;
- final double t5 =
- _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32;
- final double t6 =
- _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32;
- final double t7 =
- _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32;
- final double t8 =
- _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32;
- final double t9 =
- _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33;
- final double t10 =
- _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33;
- final double t11 =
+ final len = axis.length;
+ final axisStorage = axis._v3storage;
+ final x = axisStorage[0] / len;
+ final y = axisStorage[1] / len;
+ final z = axisStorage[2] / len;
+ final c = math.cos(angle);
+ final s = math.sin(angle);
+ final C = 1.0 - c;
+ final m11 = x * x * C + c;
+ final m12 = x * y * C - z * s;
+ final m13 = x * z * C + y * s;
+ final m21 = y * x * C + z * s;
+ final m22 = y * y * C + c;
+ final m23 = y * z * C - x * s;
+ final m31 = z * x * C - y * s;
+ final m32 = z * y * C + x * s;
+ final m33 = z * z * C + c;
+ final t1 = _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31;
+ final t2 = _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31;
+ final t3 = _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31;
+ final t4 = _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31;
+ final t5 = _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32;
+ final t6 = _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32;
+ final t7 = _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32;
+ final t8 = _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32;
+ final t9 = _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33;
+ final t10 = _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33;
+ final t11 =
_m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33;
- final double t12 =
+ final t12 =
_m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33;
_m4storage[0] = t1;
_m4storage[1] = t2;
@@ -806,16 +800,16 @@
/// Rotate this [angle] radians around X
void rotateX(double angle) {
- final double cosAngle = math.cos(angle);
- final double sinAngle = math.sin(angle);
- final double t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle;
- final double t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle;
- final double t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle;
- final double t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle;
- final double t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle;
- final double t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle;
- final double t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle;
- final double t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle;
+ final cosAngle = math.cos(angle);
+ final sinAngle = math.sin(angle);
+ final t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle;
+ final t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle;
+ final t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle;
+ final t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle;
+ final t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle;
+ final t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle;
+ final t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle;
+ final t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle;
_m4storage[4] = t1;
_m4storage[5] = t2;
_m4storage[6] = t3;
@@ -828,16 +822,16 @@
/// Rotate this matrix [angle] radians around Y
void rotateY(double angle) {
- final double cosAngle = math.cos(angle);
- final double sinAngle = math.sin(angle);
- final double t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle;
- final double t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle;
- final double t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle;
- final double t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle;
- final double t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle;
- final double t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle;
- final double t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle;
- final double t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle;
+ final cosAngle = math.cos(angle);
+ final sinAngle = math.sin(angle);
+ final t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle;
+ final t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle;
+ final t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle;
+ final t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle;
+ final t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle;
+ final t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle;
+ final t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle;
+ final t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -850,16 +844,16 @@
/// Rotate this matrix [angle] radians around Z
void rotateZ(double angle) {
- final double cosAngle = math.cos(angle);
- final double sinAngle = math.sin(angle);
- final double t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle;
- final double t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle;
- final double t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle;
- final double t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle;
- final double t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle;
- final double t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle;
- final double t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle;
- final double t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle;
+ final cosAngle = math.cos(angle);
+ final sinAngle = math.sin(angle);
+ final t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle;
+ final t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle;
+ final t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle;
+ final t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle;
+ final t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle;
+ final t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle;
+ final t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle;
+ final t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -871,11 +865,11 @@
}
/// Scale this matrix by a [Vector3], [Vector4], or x,y,z
- void scale(dynamic x, [double y, double z]) {
+ void scale(dynamic x, [double? y, double? z]) {
double sx;
double sy;
double sz;
- final double sw = x is Vector4 ? x.w : 1.0;
+ final sw = x is Vector4 ? x.w : 1.0;
if (x is Vector3) {
sx = x.x;
sy = x.y;
@@ -888,6 +882,8 @@
sx = x;
sy = y ?? x;
sz = z ?? x;
+ } else {
+ throw UnimplementedError();
}
_m4storage[0] *= sx;
_m4storage[1] *= sx;
@@ -909,7 +905,7 @@
/// Create a copy of this scaled by a [Vector3], [Vector4] or [x],[y], and
/// [z].
- Matrix4 scaled(dynamic x, [double y, double z]) => clone()..scale(x, y, z);
+ Matrix4 scaled(dynamic x, [double? y, double? z]) => clone()..scale(x, y, z);
/// Zeros this.
void setZero() {
@@ -978,8 +974,8 @@
/// Returns the component wise absolute value of this.
Matrix4 absolute() {
- final Matrix4 r = Matrix4.zero();
- final Float32List rStorage = r._m4storage;
+ final r = Matrix4.zero();
+ final rStorage = r._m4storage;
rStorage[0] = _m4storage[0].abs();
rStorage[1] = _m4storage[1].abs();
rStorage[2] = _m4storage[2].abs();
@@ -1001,28 +997,28 @@
/// Returns the determinant of this matrix.
double determinant() {
- final double det2_01_01 =
+ final det2_01_01 =
_m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4];
- final double det2_01_02 =
+ final det2_01_02 =
_m4storage[0] * _m4storage[6] - _m4storage[2] * _m4storage[4];
- final double det2_01_03 =
+ final det2_01_03 =
_m4storage[0] * _m4storage[7] - _m4storage[3] * _m4storage[4];
- final double det2_01_12 =
+ final det2_01_12 =
_m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5];
- final double det2_01_13 =
+ final det2_01_13 =
_m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5];
- final double det2_01_23 =
+ final det2_01_23 =
_m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6];
- final double det3_201_012 = _m4storage[8] * det2_01_12 -
+ final det3_201_012 = _m4storage[8] * det2_01_12 -
_m4storage[9] * det2_01_02 +
_m4storage[10] * det2_01_01;
- final double det3_201_013 = _m4storage[8] * det2_01_13 -
+ final det3_201_013 = _m4storage[8] * det2_01_13 -
_m4storage[9] * det2_01_03 +
_m4storage[11] * det2_01_01;
- final double det3_201_023 = _m4storage[8] * det2_01_23 -
+ final det3_201_023 = _m4storage[8] * det2_01_23 -
_m4storage[10] * det2_01_03 +
_m4storage[11] * det2_01_02;
- final double det3_201_123 = _m4storage[9] * det2_01_23 -
+ final det3_201_123 = _m4storage[9] * det2_01_23 -
_m4storage[10] * det2_01_13 +
_m4storage[11] * det2_01_12;
return -det3_201_123 * _m4storage[12] +
@@ -1033,7 +1029,7 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector4 v) {
- final Float32List vStorage = v._v4storage;
+ final vStorage = v._v4storage;
return _m4storage[i] * vStorage[0] +
_m4storage[4 + i] * vStorage[1] +
_m4storage[8 + i] * vStorage[2] +
@@ -1042,7 +1038,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector4 v) {
- final Float32List vStorage = v._v4storage;
+ final vStorage = v._v4storage;
return _m4storage[j * 4] * vStorage[0] +
_m4storage[j * 4 + 1] * vStorage[1] +
_m4storage[j * 4 + 2] * vStorage[2] +
@@ -1100,34 +1096,34 @@
/// Returns relative error between this and [correct]
double relativeError(Matrix4 correct) {
- final Matrix4 diff = correct - this;
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = diff.infinityNorm();
+ final diff = correct - this;
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between this and [correct]
double absoluteError(Matrix4 correct) {
- final double this_norm = infinityNorm();
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = (this_norm - correct_norm).abs();
+ final this_norm = infinityNorm();
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Returns the translation vector from this homogeneous transformation matrix.
Vector3 getTranslation() {
- final double z = _m4storage[14];
- final double y = _m4storage[13];
- final double x = _m4storage[12];
+ final z = _m4storage[14];
+ final y = _m4storage[13];
+ final x = _m4storage[12];
return Vector3(x, y, z);
}
/// Sets the translation vector in this homogeneous transformation matrix.
void setTranslation(Vector3 t) {
- final Float32List tStorage = t._v3storage;
- final double z = tStorage[2];
- final double y = tStorage[1];
- final double x = tStorage[0];
+ final tStorage = t._v3storage;
+ final z = tStorage[2];
+ final y = tStorage[1];
+ final x = tStorage[0];
_m4storage[14] = z;
_m4storage[13] = y;
_m4storage[12] = x;
@@ -1142,7 +1138,7 @@
/// Returns the rotation matrix from this homogeneous transformation matrix.
Matrix3 getRotation() {
- final Matrix3 r = Matrix3.zero();
+ final r = Matrix3.zero();
copyRotation(r);
return r;
}
@@ -1150,7 +1146,7 @@
/// Copies the rotation matrix from this homogeneous transformation matrix
/// into [rotation].
void copyRotation(Matrix3 rotation) {
- final Float32List rStorage = rotation._m3storage;
+ final rStorage = rotation._m3storage;
rStorage[0] = _m4storage[0];
rStorage[1] = _m4storage[1];
rStorage[2] = _m4storage[2];
@@ -1164,7 +1160,7 @@
/// Sets the rotation matrix in this homogeneous transformation matrix.
void setRotation(Matrix3 r) {
- final Float32List rStorage = r._m3storage;
+ final rStorage = r._m3storage;
_m4storage[0] = rStorage[0];
_m4storage[1] = rStorage[1];
_m4storage[2] = rStorage[2];
@@ -1182,13 +1178,13 @@
/// Returns the max scale value of the 3 axes.
double getMaxScaleOnAxis() {
- final double scaleXSq = _m4storage[0] * _m4storage[0] +
+ final scaleXSq = _m4storage[0] * _m4storage[0] +
_m4storage[1] * _m4storage[1] +
_m4storage[2] * _m4storage[2];
- final double scaleYSq = _m4storage[4] * _m4storage[4] +
+ final scaleYSq = _m4storage[4] * _m4storage[4] +
_m4storage[5] * _m4storage[5] +
_m4storage[6] * _m4storage[6];
- final double scaleZSq = _m4storage[8] * _m4storage[8] +
+ final scaleZSq = _m4storage[8] * _m4storage[8] +
_m4storage[9] * _m4storage[9] +
_m4storage[10] * _m4storage[10];
return math.sqrt(math.max(scaleXSq, math.max(scaleYSq, scaleZSq)));
@@ -1222,42 +1218,42 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix4 arg) {
- final Float32List argStorage = arg._m4storage;
- final double a00 = argStorage[0];
- final double a01 = argStorage[1];
- final double a02 = argStorage[2];
- final double a03 = argStorage[3];
- final double a10 = argStorage[4];
- final double a11 = argStorage[5];
- final double a12 = argStorage[6];
- final double a13 = argStorage[7];
- final double a20 = argStorage[8];
- final double a21 = argStorage[9];
- final double a22 = argStorage[10];
- final double a23 = argStorage[11];
- final double a30 = argStorage[12];
- final double a31 = argStorage[13];
- final double a32 = argStorage[14];
- final double a33 = argStorage[15];
- final double b00 = a00 * a11 - a01 * a10;
- final double b01 = a00 * a12 - a02 * a10;
- final double b02 = a00 * a13 - a03 * a10;
- final double b03 = a01 * a12 - a02 * a11;
- final double b04 = a01 * a13 - a03 * a11;
- final double b05 = a02 * a13 - a03 * a12;
- final double b06 = a20 * a31 - a21 * a30;
- final double b07 = a20 * a32 - a22 * a30;
- final double b08 = a20 * a33 - a23 * a30;
- final double b09 = a21 * a32 - a22 * a31;
- final double b10 = a21 * a33 - a23 * a31;
- final double b11 = a22 * a33 - a23 * a32;
- final double det =
+ final argStorage = arg._m4storage;
+ final a00 = argStorage[0];
+ final a01 = argStorage[1];
+ final a02 = argStorage[2];
+ final a03 = argStorage[3];
+ final a10 = argStorage[4];
+ final a11 = argStorage[5];
+ final a12 = argStorage[6];
+ final a13 = argStorage[7];
+ final a20 = argStorage[8];
+ final a21 = argStorage[9];
+ final a22 = argStorage[10];
+ final a23 = argStorage[11];
+ final a30 = argStorage[12];
+ final a31 = argStorage[13];
+ final a32 = argStorage[14];
+ final a33 = argStorage[15];
+ final b00 = a00 * a11 - a01 * a10;
+ final b01 = a00 * a12 - a02 * a10;
+ final b02 = a00 * a13 - a03 * a10;
+ final b03 = a01 * a12 - a02 * a11;
+ final b04 = a01 * a13 - a03 * a11;
+ final b05 = a02 * a13 - a03 * a12;
+ final b06 = a20 * a31 - a21 * a30;
+ final b07 = a20 * a32 - a22 * a30;
+ final b08 = a20 * a33 - a23 * a30;
+ final b09 = a21 * a32 - a22 * a31;
+ final b10 = a21 * a33 - a23 * a31;
+ final b11 = a22 * a33 - a23 * a32;
+ final det =
b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final double invDet = 1.0 / det;
+ final invDet = 1.0 / det;
_m4storage[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
_m4storage[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
_m4storage[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet;
@@ -1278,11 +1274,11 @@
}
double invertRotation() {
- final double det = determinant();
+ final det = determinant();
if (det == 0.0) {
return 0.0;
}
- final double invDet = 1.0 / det;
+ final invDet = 1.0 / det;
double ix;
double iy;
double iz;
@@ -1324,8 +1320,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around X
void setRotationX(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m4storage[0] = 1.0;
_m4storage[1] = 0.0;
_m4storage[2] = 0.0;
@@ -1342,8 +1338,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Y
void setRotationY(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = 0.0;
_m4storage[2] = -s;
@@ -1360,8 +1356,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Z
void setRotationZ(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = s;
_m4storage[2] = 0.0;
@@ -1379,22 +1375,22 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
// Adapted from code by Richard Carling.
- final double a1 = _m4storage[0];
- final double b1 = _m4storage[4];
- final double c1 = _m4storage[8];
- final double d1 = _m4storage[12];
- final double a2 = _m4storage[1];
- final double b2 = _m4storage[5];
- final double c2 = _m4storage[9];
- final double d2 = _m4storage[13];
- final double a3 = _m4storage[2];
- final double b3 = _m4storage[6];
- final double c3 = _m4storage[10];
- final double d3 = _m4storage[14];
- final double a4 = _m4storage[3];
- final double b4 = _m4storage[7];
- final double c4 = _m4storage[11];
- final double d4 = _m4storage[15];
+ final a1 = _m4storage[0];
+ final b1 = _m4storage[4];
+ final c1 = _m4storage[8];
+ final d1 = _m4storage[12];
+ final a2 = _m4storage[1];
+ final b2 = _m4storage[5];
+ final c2 = _m4storage[9];
+ final d2 = _m4storage[13];
+ final a3 = _m4storage[2];
+ final b3 = _m4storage[6];
+ final c3 = _m4storage[10];
+ final d3 = _m4storage[14];
+ final a4 = _m4storage[3];
+ final b4 = _m4storage[7];
+ final c4 = _m4storage[11];
+ final d4 = _m4storage[15];
_m4storage[0] = (b2 * (c3 * d4 - c4 * d3) -
c2 * (b3 * d4 - b4 * d3) +
d2 * (b3 * c4 - b4 * c3)) *
@@ -1465,19 +1461,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- final double m00 = _m4storage[0].abs();
- final double m01 = _m4storage[4].abs();
- final double m02 = _m4storage[8].abs();
- final double m10 = _m4storage[1].abs();
- final double m11 = _m4storage[5].abs();
- final double m12 = _m4storage[9].abs();
- final double m20 = _m4storage[2].abs();
- final double m21 = _m4storage[6].abs();
- final double m22 = _m4storage[10].abs();
- final Float32List argStorage = arg._v3storage;
- final double x = argStorage[0];
- final double y = argStorage[1];
- final double z = argStorage[2];
+ final m00 = _m4storage[0].abs();
+ final m01 = _m4storage[4].abs();
+ final m02 = _m4storage[8].abs();
+ final m10 = _m4storage[1].abs();
+ final m11 = _m4storage[5].abs();
+ final m12 = _m4storage[9].abs();
+ final m20 = _m4storage[2].abs();
+ final m21 = _m4storage[6].abs();
+ final m22 = _m4storage[10].abs();
+ final argStorage = arg._v3storage;
+ final x = argStorage[0];
+ final y = argStorage[1];
+ final z = argStorage[2];
argStorage[0] = x * m00 + y * m01 + z * m02 + 0.0 * 0.0;
argStorage[1] = x * m10 + y * m11 + z * m12 + 0.0 * 0.0;
argStorage[2] = x * m20 + y * m21 + z * m22 + 0.0 * 0.0;
@@ -1486,7 +1482,7 @@
/// Adds [o] to this.
void add(Matrix4 o) {
- final Float32List oStorage = o._m4storage;
+ final oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] + oStorage[0];
_m4storage[1] = _m4storage[1] + oStorage[1];
_m4storage[2] = _m4storage[2] + oStorage[2];
@@ -1507,7 +1503,7 @@
/// Subtracts [o] from this.
void sub(Matrix4 o) {
- final Float32List oStorage = o._m4storage;
+ final oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] - oStorage[0];
_m4storage[1] = _m4storage[1] - oStorage[1];
_m4storage[2] = _m4storage[2] - oStorage[2];
@@ -1548,39 +1544,39 @@
/// Multiply this by [arg].
void multiply(Matrix4 arg) {
- final double m00 = _m4storage[0];
- final double m01 = _m4storage[4];
- final double m02 = _m4storage[8];
- final double m03 = _m4storage[12];
- final double m10 = _m4storage[1];
- final double m11 = _m4storage[5];
- final double m12 = _m4storage[9];
- final double m13 = _m4storage[13];
- final double m20 = _m4storage[2];
- final double m21 = _m4storage[6];
- final double m22 = _m4storage[10];
- final double m23 = _m4storage[14];
- final double m30 = _m4storage[3];
- final double m31 = _m4storage[7];
- final double m32 = _m4storage[11];
- final double m33 = _m4storage[15];
- final Float32List argStorage = arg._m4storage;
- final double n00 = argStorage[0];
- final double n01 = argStorage[4];
- final double n02 = argStorage[8];
- final double n03 = argStorage[12];
- final double n10 = argStorage[1];
- final double n11 = argStorage[5];
- final double n12 = argStorage[9];
- final double n13 = argStorage[13];
- final double n20 = argStorage[2];
- final double n21 = argStorage[6];
- final double n22 = argStorage[10];
- final double n23 = argStorage[14];
- final double n30 = argStorage[3];
- final double n31 = argStorage[7];
- final double n32 = argStorage[11];
- final double n33 = argStorage[15];
+ final m00 = _m4storage[0];
+ final m01 = _m4storage[4];
+ final m02 = _m4storage[8];
+ final m03 = _m4storage[12];
+ final m10 = _m4storage[1];
+ final m11 = _m4storage[5];
+ final m12 = _m4storage[9];
+ final m13 = _m4storage[13];
+ final m20 = _m4storage[2];
+ final m21 = _m4storage[6];
+ final m22 = _m4storage[10];
+ final m23 = _m4storage[14];
+ final m30 = _m4storage[3];
+ final m31 = _m4storage[7];
+ final m32 = _m4storage[11];
+ final m33 = _m4storage[15];
+ final argStorage = arg._m4storage;
+ final n00 = argStorage[0];
+ final n01 = argStorage[4];
+ final n02 = argStorage[8];
+ final n03 = argStorage[12];
+ final n10 = argStorage[1];
+ final n11 = argStorage[5];
+ final n12 = argStorage[9];
+ final n13 = argStorage[13];
+ final n20 = argStorage[2];
+ final n21 = argStorage[6];
+ final n22 = argStorage[10];
+ final n23 = argStorage[14];
+ final n30 = argStorage[3];
+ final n31 = argStorage[7];
+ final n32 = argStorage[11];
+ final n33 = argStorage[15];
_m4storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30);
_m4storage[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31);
_m4storage[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32);
@@ -1604,23 +1600,23 @@
/// Multiply a transposed this with [arg].
void transposeMultiply(Matrix4 arg) {
- final double m00 = _m4storage[0];
- final double m01 = _m4storage[1];
- final double m02 = _m4storage[2];
- final double m03 = _m4storage[3];
- final double m10 = _m4storage[4];
- final double m11 = _m4storage[5];
- final double m12 = _m4storage[6];
- final double m13 = _m4storage[7];
- final double m20 = _m4storage[8];
- final double m21 = _m4storage[9];
- final double m22 = _m4storage[10];
- final double m23 = _m4storage[11];
- final double m30 = _m4storage[12];
- final double m31 = _m4storage[13];
- final double m32 = _m4storage[14];
- final double m33 = _m4storage[15];
- final Float32List argStorage = arg._m4storage;
+ final m00 = _m4storage[0];
+ final m01 = _m4storage[1];
+ final m02 = _m4storage[2];
+ final m03 = _m4storage[3];
+ final m10 = _m4storage[4];
+ final m11 = _m4storage[5];
+ final m12 = _m4storage[6];
+ final m13 = _m4storage[7];
+ final m20 = _m4storage[8];
+ final m21 = _m4storage[9];
+ final m22 = _m4storage[10];
+ final m23 = _m4storage[11];
+ final m30 = _m4storage[12];
+ final m31 = _m4storage[13];
+ final m32 = _m4storage[14];
+ final m33 = _m4storage[15];
+ final argStorage = arg._m4storage;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[1]) +
(m02 * argStorage[2]) +
@@ -1689,23 +1685,23 @@
/// Multiply this with a transposed [arg].
void multiplyTranspose(Matrix4 arg) {
- final double m00 = _m4storage[0];
- final double m01 = _m4storage[4];
- final double m02 = _m4storage[8];
- final double m03 = _m4storage[12];
- final double m10 = _m4storage[1];
- final double m11 = _m4storage[5];
- final double m12 = _m4storage[9];
- final double m13 = _m4storage[13];
- final double m20 = _m4storage[2];
- final double m21 = _m4storage[6];
- final double m22 = _m4storage[10];
- final double m23 = _m4storage[14];
- final double m30 = _m4storage[3];
- final double m31 = _m4storage[7];
- final double m32 = _m4storage[11];
- final double m33 = _m4storage[15];
- final Float32List argStorage = arg._m4storage;
+ final m00 = _m4storage[0];
+ final m01 = _m4storage[4];
+ final m02 = _m4storage[8];
+ final m03 = _m4storage[12];
+ final m10 = _m4storage[1];
+ final m11 = _m4storage[5];
+ final m12 = _m4storage[9];
+ final m13 = _m4storage[13];
+ final m20 = _m4storage[2];
+ final m21 = _m4storage[6];
+ final m22 = _m4storage[10];
+ final m23 = _m4storage[14];
+ final m30 = _m4storage[3];
+ final m31 = _m4storage[7];
+ final m32 = _m4storage[11];
+ final m33 = _m4storage[15];
+ final argStorage = arg._m4storage;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[4]) +
(m02 * argStorage[8]) +
@@ -1774,11 +1770,11 @@
/// Decomposes this into [translation], [rotation] and [scale] components.
void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) {
- final Vector3 v = _decomposeV ??= Vector3.zero();
+ final v = _decomposeV ??= Vector3.zero();
var sx = (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
- final double sy =
+ final sy =
(v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
- final double sz =
+ final sz =
(v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length;
if (determinant() < 0) {
@@ -1789,11 +1785,11 @@
translation._v3storage[1] = _m4storage[13];
translation._v3storage[2] = _m4storage[14];
- final double invSX = 1.0 / sx;
- final double invSY = 1.0 / sy;
- final double invSZ = 1.0 / sz;
+ final invSX = 1.0 / sx;
+ final invSY = 1.0 / sy;
+ final invSZ = 1.0 / sz;
- final Matrix4 m = _decomposeM ??= Matrix4.zero();
+ final m = _decomposeM ??= Matrix4.zero();
m.setFrom(this);
m._m4storage[0] *= invSX;
m._m4storage[1] *= invSX;
@@ -1805,7 +1801,7 @@
m._m4storage[9] *= invSZ;
m._m4storage[10] *= invSZ;
- final Matrix3 r = _decomposeR ??= Matrix3.zero();
+ final r = _decomposeR ??= Matrix3.zero();
m.copyRotation(r);
rotation.setFromRotation(r);
@@ -1814,20 +1810,20 @@
scale._v3storage[2] = sz;
}
- static Vector3 _decomposeV;
- static Matrix4 _decomposeM;
- static Matrix3 _decomposeR;
+ static Vector3? _decomposeV;
+ static Matrix4? _decomposeM;
+ static Matrix3? _decomposeR;
/// Rotate [arg] of type [Vector3] using the rotation defined by this.
Vector3 rotate3(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]);
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]);
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]);
argStorage[0] = x_;
@@ -1838,7 +1834,7 @@
/// Rotate a copy of [arg] of type [Vector3] using the rotation defined by
/// this. If a [out] parameter is supplied, the copy is stored in [out].
- Vector3 rotated3(Vector3 arg, [Vector3 out]) {
+ Vector3 rotated3(Vector3 arg, [Vector3? out]) {
if (out == null) {
out = Vector3.copy(arg);
} else {
@@ -1850,16 +1846,16 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// this.
Vector3 transform3(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
@@ -1872,7 +1868,7 @@
/// Transform a copy of [arg] of type [Vector3] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector3 transformed3(Vector3 arg, [Vector3 out]) {
+ Vector3 transformed3(Vector3 arg, [Vector3? out]) {
if (out == null) {
out = Vector3.copy(arg);
} else {
@@ -1884,20 +1880,20 @@
/// Transform [arg] of type [Vector4] using the transformation defined by
/// this.
Vector4 transform(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v4storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
(_m4storage[12] * argStorage[3]);
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
(_m4storage[13] * argStorage[3]);
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
(_m4storage[14] * argStorage[3]);
- final double w_ = (_m4storage[3] * argStorage[0]) +
+ final w_ = (_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
(_m4storage[15] * argStorage[3]);
@@ -1911,20 +1907,20 @@
/// Transform [arg] of type [Vector3] using the perspective transformation
/// defined by this.
Vector3 perspectiveTransform(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
- final double w_ = 1.0 /
+ final w_ = 1.0 /
((_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
@@ -1938,7 +1934,7 @@
/// Transform a copy of [arg] of type [Vector4] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector4 transformed(Vector4 arg, [Vector4 out]) {
+ Vector4 transformed(Vector4 arg, [Vector4? out]) {
if (out == null) {
out = Vector4.copy(arg);
} else {
@@ -1949,7 +1945,7 @@
/// Copies this into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
array[i + 15] = _m4storage[15];
array[i + 14] = _m4storage[14];
array[i + 13] = _m4storage[13];
@@ -1970,7 +1966,7 @@
/// Copies elements from [array] into this starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
_m4storage[15] = array[i + 15];
_m4storage[14] = array[i + 14];
_m4storage[13] = array[i + 13];
@@ -1991,8 +1987,8 @@
/// Multiply this to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final Vector3 v = Vector3.array(array, j)..applyMatrix4(this);
+ for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final v = Vector3.array(array, j)..applyMatrix4(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -2002,23 +1998,23 @@
}
Vector3 get right {
- final double x = _m4storage[0];
- final double y = _m4storage[1];
- final double z = _m4storage[2];
+ final x = _m4storage[0];
+ final y = _m4storage[1];
+ final z = _m4storage[2];
return Vector3(x, y, z);
}
Vector3 get up {
- final double x = _m4storage[4];
- final double y = _m4storage[5];
- final double z = _m4storage[6];
+ final x = _m4storage[4];
+ final y = _m4storage[5];
+ final z = _m4storage[6];
return Vector3(x, y, z);
}
Vector3 get forward {
- final double x = _m4storage[8];
- final double y = _m4storage[9];
- final double z = _m4storage[10];
+ final x = _m4storage[8];
+ final y = _m4storage[9];
+ final z = _m4storage[10];
return Vector3(x, y, z);
}
diff --git a/lib/src/vector_math/obb3.dart b/lib/src/vector_math/obb3.dart
index e80b345..876685f 100644
--- a/lib/src/vector_math/obb3.dart
+++ b/lib/src/vector_math/obb3.dart
@@ -169,7 +169,7 @@
/// Find the closest point [q] on the OBB to the point [p] and store it in [q].
void closestPointTo(Vector3 p, Vector3 q) {
- final Vector3 d = p - _center;
+ final d = p - _center;
q.setFrom(_center);
@@ -187,9 +187,9 @@
}
// Avoid allocating these instance on every call to intersectsWithObb3
- static final Matrix3 _r = Matrix3.zero();
- static final Matrix3 _absR = Matrix3.zero();
- static final Vector3 _t = Vector3.zero();
+ static final _r = Matrix3.zero();
+ static final _absR = Matrix3.zero();
+ static final _t = Vector3.zero();
/// Check for intersection between this and [other].
bool intersectsWithObb3(Obb3 other, [double epsilon = 1e-3]) {
@@ -339,12 +339,12 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Triangle _triangle = Triangle();
- static final Aabb3 _aabb3 = Aabb3();
- static final Vector3 _zeroVector = Vector3.zero();
+ static final _triangle = Triangle();
+ static final _aabb3 = Aabb3();
+ static final _zeroVector = Vector3.zero();
/// Return if this intersects with [other]
- bool intersectsWithTriangle(Triangle other, {IntersectionResult result}) {
+ bool intersectsWithTriangle(Triangle other, {IntersectionResult? result}) {
_triangle.copyFrom(other);
_triangle.point0
@@ -366,7 +366,7 @@
}
// Avoid allocating these instance on every call to intersectsWithVector3
- static final Vector3 _vector = Vector3.zero();
+ static final _vector = Vector3.zero();
/// Return if this intersects with [other]
bool intersectsWithVector3(Vector3 other) {
@@ -381,11 +381,11 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Triangle _quadTriangle0 = Triangle();
- static final Triangle _quadTriangle1 = Triangle();
+ static final _quadTriangle0 = Triangle();
+ static final _quadTriangle1 = Triangle();
/// Return if this intersects with [other]
- bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
+ bool intersectsWithQuad(Quad other, {IntersectionResult? result}) {
other.copyTriangles(_quadTriangle0, _quadTriangle1);
return intersectsWithTriangle(_quadTriangle0, result: result) ||
diff --git a/lib/src/vector_math/opengl.dart b/lib/src/vector_math/opengl.dart
index d5565e8..26e5df3 100644
--- a/lib/src/vector_math/opengl.dart
+++ b/lib/src/vector_math/opengl.dart
@@ -56,10 +56,10 @@
/// [tx],[ty],[tz] specifies the position of the object.
void setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection,
Vector3 upDirection, double tx, double ty, double tz) {
- final Vector3 right = forwardDirection.cross(upDirection)..normalize();
- final Vector3 c1 = right;
- final Vector3 c2 = upDirection;
- final Vector3 c3 = -forwardDirection;
+ final right = forwardDirection.cross(upDirection)..normalize();
+ final c1 = right;
+ final c2 = upDirection;
+ final c3 = -forwardDirection;
modelMatrix.setValues(c1[0], c1[1], c1[2], 0.0, c2[0], c2[1], c2[2], 0.0,
c3[0], c3[1], c3[2], 0.0, tx, ty, tz, 1.0);
}
@@ -74,13 +74,13 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition,
Vector3 cameraFocusPosition, Vector3 upDirection) {
- final Vector3 z = (cameraPosition - cameraFocusPosition)..normalize();
- final Vector3 x = upDirection.cross(z)..normalize();
- final Vector3 y = z.cross(x)..normalize();
+ final z = (cameraPosition - cameraFocusPosition)..normalize();
+ final x = upDirection.cross(z)..normalize();
+ final y = z.cross(x)..normalize();
- final double rotatedEyeX = -x.dot(cameraPosition);
- final double rotatedEyeY = -y.dot(cameraPosition);
- final double rotatedEyeZ = -z.dot(cameraPosition);
+ final rotatedEyeX = -x.dot(cameraPosition);
+ final rotatedEyeY = -y.dot(cameraPosition);
+ final rotatedEyeZ = -z.dot(cameraPosition);
viewMatrix.setValues(x[0], y[0], z[0], 0.0, x[1], y[1], z[1], 0.0, x[2], y[2],
z[2], 0.0, rotatedEyeX, rotatedEyeY, rotatedEyeZ, 1.0);
@@ -93,7 +93,7 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
Matrix4 makeViewMatrix(
Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setViewMatrix(r, cameraPosition, cameraFocusPosition, upDirection);
return r;
}
@@ -110,9 +110,9 @@
/// (always positive).
void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians,
double aspectRatio, double zNear, double zFar) {
- final double height = math.tan(fovYRadians * 0.5);
- final double width = height * aspectRatio;
- final double near_minus_far = zNear - zFar;
+ final height = math.tan(fovYRadians * 0.5);
+ final width = height * aspectRatio;
+ final near_minus_far = zNear - zFar;
perspectiveMatrix
..setZero()
@@ -135,7 +135,7 @@
/// (always positive).
Matrix4 makePerspectiveMatrix(
double fovYRadians, double aspectRatio, double zNear, double zFar) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setPerspectiveMatrix(r, fovYRadians, aspectRatio, zNear, zFar);
return r;
}
@@ -149,8 +149,8 @@
/// (always positive).
void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians,
double aspectRatio, double zNear) {
- final double height = math.tan(fovYRadians * 0.5);
- final double width = height * aspectRatio;
+ final height = math.tan(fovYRadians * 0.5);
+ final width = height * aspectRatio;
infiniteMatrix
..setZero()
@@ -171,7 +171,7 @@
/// (always positive).
Matrix4 makeInfiniteMatrix(
double fovYRadians, double aspectRatio, double zNear) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setInfiniteMatrix(r, fovYRadians, aspectRatio, zNear);
return r;
}
@@ -186,10 +186,10 @@
/// planes.
void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right,
double bottom, double top, double near, double far) {
- final double two_near = 2.0 * near;
- final double right_minus_left = right - left;
- final double top_minus_bottom = top - bottom;
- final double far_minus_near = far - near;
+ final two_near = 2.0 * near;
+ final right_minus_left = right - left;
+ final top_minus_bottom = top - bottom;
+ final far_minus_near = far - near;
perspectiveMatrix
..setZero()
..setEntry(0, 0, two_near / right_minus_left)
@@ -211,7 +211,7 @@
/// planes.
Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top,
double near, double far) {
- final Matrix4 view = Matrix4.zero();
+ final view = Matrix4.zero();
setFrustumMatrix(view, left, right, bottom, top, near, far);
return view;
}
@@ -226,12 +226,12 @@
/// planes.
void setOrthographicMatrix(Matrix4 orthographicMatrix, double left,
double right, double bottom, double top, double near, double far) {
- final double rml = right - left;
- final double rpl = right + left;
- final double tmb = top - bottom;
- final double tpb = top + bottom;
- final double fmn = far - near;
- final double fpn = far + near;
+ final rml = right - left;
+ final rpl = right + left;
+ final tmb = top - bottom;
+ final tpb = top + bottom;
+ final fmn = far - near;
+ final fpn = far + near;
orthographicMatrix
..setZero()
..setEntry(0, 0, 2.0 / rml)
@@ -253,7 +253,7 @@
/// planes.
Matrix4 makeOrthographicMatrix(double left, double right, double bottom,
double top, double near, double far) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setOrthographicMatrix(r, left, right, bottom, top, near, far);
return r;
}
@@ -261,14 +261,13 @@
/// Returns a transformation matrix that transforms points onto
/// the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) {
- final Vector4 v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- final Matrix4 outer = Matrix4.outer(v, v);
+ final outer = Matrix4.outer(v, v);
var r = Matrix4.zero();
r = r - outer;
- final Vector3 scaledNormal =
- planeNormal.scaled(dot3(planePoint, planeNormal));
- final Vector4 T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
+ final scaledNormal = planeNormal.scaled(dot3(planePoint, planeNormal));
+ final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
@@ -277,14 +276,14 @@
/// Returns a transformation matrix that transforms points by reflecting
/// them through the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
- final Vector4 v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- final Matrix4 outer = Matrix4.outer(v, v)..scale(2.0);
+ final outer = Matrix4.outer(v, v)..scale(2.0);
var r = Matrix4.zero();
r = r - outer;
- final double scale = 2.0 * planePoint.dot(planeNormal);
- final Vector3 scaledNormal = planeNormal.scaled(scale);
- final Vector4 T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
+ final scale = 2.0 * planePoint.dot(planeNormal);
+ final scaledNormal = planeNormal.scaled(scale);
+ final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
@@ -334,17 +333,16 @@
}
// Copy camera matrix.
- final Matrix4 invertedCameraMatrix = Matrix4.copy(cameraMatrix);
+ final invertedCameraMatrix = Matrix4.copy(cameraMatrix);
// Invert the camera matrix.
invertedCameraMatrix.invert();
// Determine intersection point.
- final Vector4 v =
- Vector4(pickX.toDouble(), pickY.toDouble(), pickZ.toDouble(), 1.0);
+ final v = Vector4(pickX.toDouble(), pickY.toDouble(), pickZ.toDouble(), 1.0);
invertedCameraMatrix.transform(v);
if (v.w == 0.0) {
return false;
}
- final double invW = 1.0 / v.w;
+ final invW = 1.0 / v.w;
pickWorld
..x = v.x * invW
..y = v.y * invW
diff --git a/lib/src/vector_math/plane.dart b/lib/src/vector_math/plane.dart
index 0008e70..c8d9b61 100644
--- a/lib/src/vector_math/plane.dart
+++ b/lib/src/vector_math/plane.dart
@@ -11,21 +11,21 @@
/// Find the intersection point between the three planes [a], [b] and [c] and
/// copy it into [result].
static void intersection(Plane a, Plane b, Plane c, Vector3 result) {
- final Vector3 cross = Vector3.zero();
+ final cross = Vector3.zero();
b.normal.crossInto(c.normal, cross);
- final double f = -a.normal.dot(cross);
+ final f = -a.normal.dot(cross);
- final Vector3 v1 = cross.scaled(a.constant);
+ final v1 = cross.scaled(a.constant);
c.normal.crossInto(a.normal, cross);
- final Vector3 v2 = cross.scaled(b.constant);
+ final v2 = cross.scaled(b.constant);
a.normal.crossInto(b.normal, cross);
- final Vector3 v3 = cross.scaled(c.constant);
+ final v3 = cross.scaled(c.constant);
result
..x = (v1.x + v2.x + v3.x) / f
@@ -60,7 +60,7 @@
}
void normalize() {
- final double inverseLength = 1.0 / normal.length;
+ final inverseLength = 1.0 / normal.length;
_normal.scale(inverseLength);
constant *= inverseLength;
}
diff --git a/lib/src/vector_math/quad.dart b/lib/src/vector_math/quad.dart
index 263f7e4..723e9f3 100644
--- a/lib/src/vector_math/quad.dart
+++ b/lib/src/vector_math/quad.dart
@@ -54,7 +54,7 @@
/// Copy the normal of this into [normal].
void copyNormalInto(Vector3 normal) {
- final Vector3 v0 = _point0.clone()..sub(_point1);
+ final v0 = _point0.clone()..sub(_point1);
normal
..setFrom(_point2)
..sub(_point1)
diff --git a/lib/src/vector_math/quaternion.dart b/lib/src/vector_math/quaternion.dart
index cd942d6..7f134ff 100644
--- a/lib/src/vector_math/quaternion.dart
+++ b/lib/src/vector_math/quaternion.dart
@@ -92,7 +92,7 @@
/// Copy [source] into this.
void setFrom(Quaternion source) {
- final Float32List sourceStorage = source._qStorage;
+ final sourceStorage = source._qStorage;
_qStorage[0] = sourceStorage[0];
_qStorage[1] = sourceStorage[1];
_qStorage[2] = sourceStorage[2];
@@ -109,12 +109,12 @@
/// Set the quaternion with rotation of [radians] around [axis].
void setAxisAngle(Vector3 axis, double radians) {
- final double len = axis.length;
+ final len = axis.length;
if (len == 0.0) {
return;
}
- final double halfSin = math.sin(radians * 0.5) / len;
- final Float32List axisStorage = axis.storage;
+ final halfSin = math.sin(radians * 0.5) / len;
+ final axisStorage = axis.storage;
_qStorage[0] = axisStorage[0] * halfSin;
_qStorage[1] = axisStorage[1] * halfSin;
_qStorage[2] = axisStorage[2] * halfSin;
@@ -123,8 +123,8 @@
/// Set the quaternion with rotation from a rotation matrix [rotationMatrix].
void setFromRotation(Matrix3 rotationMatrix) {
- final Float32List rotationMatrixStorage = rotationMatrix.storage;
- final double trace = rotationMatrix.trace();
+ final rotationMatrixStorage = rotationMatrix.storage;
+ final trace = rotationMatrix.trace();
if (trace > 0.0) {
var s = math.sqrt(trace + 1.0);
_qStorage[3] = s * 0.5;
@@ -133,11 +133,11 @@
_qStorage[1] = (rotationMatrixStorage[6] - rotationMatrixStorage[2]) * s;
_qStorage[2] = (rotationMatrixStorage[1] - rotationMatrixStorage[3]) * s;
} else {
- final int i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
+ final i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1)
: (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0);
- final int j = (i + 1) % 3;
- final int k = (i + 2) % 3;
+ final j = (i + 1) % 3;
+ final k = (i + 2) % 3;
var s = math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] -
rotationMatrixStorage[rotationMatrix.index(j, j)] -
rotationMatrixStorage[rotationMatrix.index(k, k)] +
@@ -157,10 +157,10 @@
}
void setFromTwoVectors(Vector3 a, Vector3 b) {
- final Vector3 v1 = a.normalized();
- final Vector3 v2 = b.normalized();
+ final v1 = a.normalized();
+ final v2 = b.normalized();
- final double c = v1.dot(v2);
+ final c = v1.dot(v2);
var angle = math.acos(c);
var axis = v1.cross(v2);
@@ -192,15 +192,15 @@
void setRandom(math.Random rn) {
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// pg. 124-132.
- final double x0 = rn.nextDouble();
- final double r1 = math.sqrt(1.0 - x0);
- final double r2 = math.sqrt(x0);
- final double t1 = math.pi * 2.0 * rn.nextDouble();
- final double t2 = math.pi * 2.0 * rn.nextDouble();
- final double c1 = math.cos(t1);
- final double s1 = math.sin(t1);
- final double c2 = math.cos(t2);
- final double s2 = math.sin(t2);
+ final x0 = rn.nextDouble();
+ final r1 = math.sqrt(1.0 - x0);
+ final r2 = math.sqrt(x0);
+ final t1 = math.pi * 2.0 * rn.nextDouble();
+ final t2 = math.pi * 2.0 * rn.nextDouble();
+ final c1 = math.cos(t1);
+ final s1 = math.sin(t1);
+ final c2 = math.cos(t2);
+ final s2 = math.sin(t2);
_qStorage[0] = s1 * r1;
_qStorage[1] = c1 * r1;
_qStorage[2] = s2 * r2;
@@ -210,19 +210,19 @@
/// Set the quaternion to the time derivative of [q] with angular velocity
/// [omega].
void setDQ(Quaternion q, Vector3 omega) {
- final Float32List qStorage = q._qStorage;
- final Float32List omegaStorage = omega.storage;
- final double qx = qStorage[0];
- final double qy = qStorage[1];
- final double qz = qStorage[2];
- final double qw = qStorage[3];
- final double ox = omegaStorage[0];
- final double oy = omegaStorage[1];
- final double oz = omegaStorage[2];
- final double _x = ox * qw + oy * qz - oz * qy;
- final double _y = oy * qw + oz * qx - ox * qz;
- final double _z = oz * qw + ox * qy - oy * qx;
- final double _w = -ox * qx - oy * qy - oz * qz;
+ final qStorage = q._qStorage;
+ final omegaStorage = omega.storage;
+ final qx = qStorage[0];
+ final qy = qStorage[1];
+ final qz = qStorage[2];
+ final qw = qStorage[3];
+ final ox = omegaStorage[0];
+ final oy = omegaStorage[1];
+ final oz = omegaStorage[2];
+ final _x = ox * qw + oy * qz - oz * qy;
+ final _y = oy * qw + oz * qx - ox * qz;
+ final _z = oz * qw + ox * qy - oy * qx;
+ final _w = -ox * qx - oy * qy - oz * qz;
_qStorage[0] = _x * 0.5;
_qStorage[1] = _y * 0.5;
_qStorage[2] = _z * 0.5;
@@ -231,15 +231,15 @@
/// Set quaternion with rotation of [yaw], [pitch] and [roll].
void setEuler(double yaw, double pitch, double roll) {
- final double halfYaw = yaw * 0.5;
- final double halfPitch = pitch * 0.5;
- final double halfRoll = roll * 0.5;
- final double cosYaw = math.cos(halfYaw);
- final double sinYaw = math.sin(halfYaw);
- final double cosPitch = math.cos(halfPitch);
- final double sinPitch = math.sin(halfPitch);
- final double cosRoll = math.cos(halfRoll);
- final double sinRoll = math.sin(halfRoll);
+ final halfYaw = yaw * 0.5;
+ final halfPitch = pitch * 0.5;
+ final halfRoll = roll * 0.5;
+ final cosYaw = math.cos(halfYaw);
+ final sinYaw = math.sin(halfYaw);
+ final cosPitch = math.cos(halfPitch);
+ final sinPitch = math.sin(halfPitch);
+ final cosRoll = math.cos(halfRoll);
+ final sinRoll = math.sin(halfRoll);
_qStorage[0] = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw;
_qStorage[1] = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw;
_qStorage[2] = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw;
@@ -248,11 +248,11 @@
/// Normalize this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_qStorage[0] *= d;
_qStorage[1] *= d;
_qStorage[2] *= d;
@@ -269,7 +269,7 @@
/// Invert this.
void inverse() {
- final double l = 1.0 / length2;
+ final l = 1.0 / length2;
_qStorage[3] = _qStorage[3] * l;
_qStorage[2] = -_qStorage[2] * l;
_qStorage[1] = -_qStorage[1] * l;
@@ -290,23 +290,23 @@
/// [axis] of rotation.
Vector3 get axis {
- final double den = 1.0 - (_qStorage[3] * _qStorage[3]);
+ final den = 1.0 - (_qStorage[3] * _qStorage[3]);
if (den < 0.0005) {
// 0-angle rotation, so axis does not matter
return Vector3.zero();
}
- final double scale = 1.0 / math.sqrt(den);
+ final scale = 1.0 / math.sqrt(den);
return Vector3(
_qStorage[0] * scale, _qStorage[1] * scale, _qStorage[2] * scale);
}
/// Length squared.
double get length2 {
- final double x = _qStorage[0];
- final double y = _qStorage[1];
- final double z = _qStorage[2];
- final double w = _qStorage[3];
+ final x = _qStorage[0];
+ final y = _qStorage[1];
+ final z = _qStorage[2];
+ final w = _qStorage[3];
return (x * x) + (y * y) + (z * z) + (w * w);
}
@@ -315,7 +315,7 @@
/// Returns a copy of [v] rotated by quaternion.
Vector3 rotated(Vector3 v) {
- final Vector3 out = v.clone();
+ final out = v.clone();
rotate(out);
return out;
}
@@ -323,22 +323,22 @@
/// Rotates [v] by this.
Vector3 rotate(Vector3 v) {
// conjugate(this) * [v,0] * this
- final double _w = _qStorage[3];
- final double _z = _qStorage[2];
- final double _y = _qStorage[1];
- final double _x = _qStorage[0];
- final double tiw = _w;
- final double tiz = -_z;
- final double tiy = -_y;
- final double tix = -_x;
- final double tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y;
- final double ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z;
- final double tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x;
- final double tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z;
- final double result_x = tw * _x + tx * _w + ty * _z - tz * _y;
- final double result_y = tw * _y + ty * _w + tz * _x - tx * _z;
- final double result_z = tw * _z + tz * _w + tx * _y - ty * _x;
- final Float32List vStorage = v.storage;
+ final _w = _qStorage[3];
+ final _z = _qStorage[2];
+ final _y = _qStorage[1];
+ final _x = _qStorage[0];
+ final tiw = _w;
+ final tiz = -_z;
+ final tiy = -_y;
+ final tix = -_x;
+ final tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y;
+ final ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z;
+ final tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x;
+ final tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z;
+ final result_x = tw * _x + tx * _w + ty * _z - tz * _y;
+ final result_y = tw * _y + ty * _w + tz * _x - tx * _z;
+ final result_z = tw * _z + tz * _w + tx * _y - ty * _x;
+ final vStorage = v.storage;
vStorage[2] = result_z;
vStorage[1] = result_y;
vStorage[0] = result_x;
@@ -347,7 +347,7 @@
/// Add [arg] to this.
void add(Quaternion arg) {
- final Float32List argStorage = arg._qStorage;
+ final argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] + argStorage[0];
_qStorage[1] = _qStorage[1] + argStorage[1];
_qStorage[2] = _qStorage[2] + argStorage[2];
@@ -356,7 +356,7 @@
/// Subtracts [arg] from this.
void sub(Quaternion arg) {
- final Float32List argStorage = arg._qStorage;
+ final argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] - argStorage[0];
_qStorage[1] = _qStorage[1] - argStorage[1];
_qStorage[2] = _qStorage[2] - argStorage[2];
@@ -376,15 +376,15 @@
/// this rotated by [other].
Quaternion operator *(Quaternion other) {
- final double _w = _qStorage[3];
- final double _z = _qStorage[2];
- final double _y = _qStorage[1];
- final double _x = _qStorage[0];
- final Float32List otherStorage = other._qStorage;
- final double ow = otherStorage[3];
- final double oz = otherStorage[2];
- final double oy = otherStorage[1];
- final double ox = otherStorage[0];
+ final _w = _qStorage[3];
+ final _z = _qStorage[2];
+ final _y = _qStorage[1];
+ final _x = _qStorage[0];
+ final otherStorage = other._qStorage;
+ final ow = otherStorage[3];
+ final oz = otherStorage[2];
+ final oy = otherStorage[1];
+ final ox = otherStorage[0];
return Quaternion(
_w * ox + _x * ow + _y * oz - _z * oy,
_w * oy + _y * ow + _z * ox - _x * oz,
@@ -415,32 +415,32 @@
/// Set [rotationMatrix] to a rotation matrix containing the same rotation as
/// this.
Matrix3 copyRotationInto(Matrix3 rotationMatrix) {
- final double d = length2;
+ final d = length2;
assert(d != 0.0);
- final double s = 2.0 / d;
+ final s = 2.0 / d;
- final double _x = _qStorage[0];
- final double _y = _qStorage[1];
- final double _z = _qStorage[2];
- final double _w = _qStorage[3];
+ final _x = _qStorage[0];
+ final _y = _qStorage[1];
+ final _z = _qStorage[2];
+ final _w = _qStorage[3];
- final double xs = _x * s;
- final double ys = _y * s;
- final double zs = _z * s;
+ final xs = _x * s;
+ final ys = _y * s;
+ final zs = _z * s;
- final double wx = _w * xs;
- final double wy = _w * ys;
- final double wz = _w * zs;
+ final wx = _w * xs;
+ final wy = _w * ys;
+ final wz = _w * zs;
- final double xx = _x * xs;
- final double xy = _x * ys;
- final double xz = _x * zs;
+ final xx = _x * xs;
+ final xy = _x * ys;
+ final xz = _x * zs;
- final double yy = _y * ys;
- final double yz = _y * zs;
- final double zz = _z * zs;
+ final yy = _y * ys;
+ final yz = _y * zs;
+ final zz = _z * zs;
- final Float32List rotationMatrixStorage = rotationMatrix.storage;
+ final rotationMatrixStorage = rotationMatrix.storage;
rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0
rotationMatrixStorage[1] = xy + wz;
rotationMatrixStorage[2] = xz - wy;
@@ -460,17 +460,17 @@
/// Relative error between this and [correct].
double relativeError(Quaternion correct) {
- final Quaternion diff = correct - this;
- final double norm_diff = diff.length;
- final double correct_norm = correct.length;
+ final diff = correct - this;
+ final norm_diff = diff.length;
+ final correct_norm = correct.length;
return norm_diff / correct_norm;
}
/// Absolute error between this and [correct].
double absoluteError(Quaternion correct) {
- final double this_norm = length;
- final double correct_norm = correct.length;
- final double norm_diff = (this_norm - correct_norm).abs();
+ final this_norm = length;
+ final correct_norm = correct.length;
+ final norm_diff = (this_norm - correct_norm).abs();
return norm_diff;
}
}
diff --git a/lib/src/vector_math/ray.dart b/lib/src/vector_math/ray.dart
index b91394a..779fb96 100644
--- a/lib/src/vector_math/ray.dart
+++ b/lib/src/vector_math/ray.dart
@@ -50,20 +50,20 @@
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithSphere(Sphere other) {
- final double r = other.radius;
- final double r2 = r * r;
- final Vector3 l = other._center.clone()..sub(_origin);
- final double s = l.dot(_direction);
- final double l2 = l.dot(l);
+ double? intersectsWithSphere(Sphere other) {
+ final r = other.radius;
+ final r2 = r * r;
+ final l = other._center.clone()..sub(_origin);
+ final s = l.dot(_direction);
+ final l2 = l.dot(l);
if (s < 0 && l2 > r2) {
return null;
}
- final double m2 = l2 - s * s;
+ final m2 = l2 - s * s;
if (m2 > r2) {
return null;
}
- final double q = math.sqrt(r2 - m2);
+ final q = math.sqrt(r2 - m2);
return (l2 > r2) ? s - q : s + q;
}
@@ -71,20 +71,20 @@
// Some varaibles that are used for intersectsWithTriangle and
// intersectsWithQuad. The performance is better in Dart and JS if we avoid
// to create temporary instance over and over. Also reduce GC.
- static final Vector3 _e1 = Vector3.zero();
- static final Vector3 _e2 = Vector3.zero();
- static final Vector3 _q = Vector3.zero();
- static final Vector3 _s = Vector3.zero();
- static final Vector3 _r = Vector3.zero();
+ static final _e1 = Vector3.zero();
+ static final _e2 = Vector3.zero();
+ static final _q = Vector3.zero();
+ static final _s = Vector3.zero();
+ static final _r = Vector3.zero();
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithTriangle(Triangle other) {
- const double epsilon = 10e-6;
+ double? intersectsWithTriangle(Triangle other) {
+ const epsilon = 10e-6;
- final Vector3 point0 = other._point0;
- final Vector3 point1 = other._point1;
- final Vector3 point2 = other._point2;
+ final point0 = other._point0;
+ final point1 = other._point1;
+ final point2 = other._point2;
_e1
..setFrom(point1)
@@ -94,38 +94,38 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final double a = _e1.dot(_q);
+ final a = _e1.dot(_q);
if (a > -epsilon && a < epsilon) {
return null;
}
- final double f = 1 / a;
+ final f = 1 / a;
_s
..setFrom(_origin)
..sub(point0);
- final double u = f * (_s.dot(_q));
+ final u = f * (_s.dot(_q));
if (u < 0.0) {
return null;
}
_s.crossInto(_e1, _r);
- final double v = f * (_direction.dot(_r));
+ final v = f * (_direction.dot(_r));
if (v < -epsilon || u + v > 1.0 + epsilon) {
return null;
}
- final double t = f * (_e2.dot(_r));
+ final t = f * (_e2.dot(_r));
return t;
}
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithQuad(Quad other) {
- const double epsilon = 10e-6;
+ double? intersectsWithQuad(Quad other) {
+ const epsilon = 10e-6;
// First triangle
var point0 = other._point0;
@@ -140,21 +140,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final double a0 = _e1.dot(_q);
+ final a0 = _e1.dot(_q);
if (!(a0 > -epsilon && a0 < epsilon)) {
- final double f = 1 / a0;
+ final f = 1 / a0;
_s
..setFrom(_origin)
..sub(point0);
- final double u = f * (_s.dot(_q));
+ final u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final double v = f * (_direction.dot(_r));
+ final v = f * (_direction.dot(_r));
if (!(v < -epsilon || u + v > 1.0 + epsilon)) {
- final double t = f * (_e2.dot(_r));
+ final t = f * (_e2.dot(_r));
return t;
}
@@ -174,21 +174,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final double a1 = _e1.dot(_q);
+ final a1 = _e1.dot(_q);
if (!(a1 > -epsilon && a1 < epsilon)) {
- final double f = 1 / a1;
+ final f = 1 / a1;
_s
..setFrom(_origin)
..sub(point0);
- final double u = f * (_s.dot(_q));
+ final u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final double v = f * (_direction.dot(_r));
+ final v = f * (_direction.dot(_r));
if (!(v < -epsilon || u + v > 1.0 + epsilon)) {
- final double t = f * (_e2.dot(_r));
+ final t = f * (_e2.dot(_r));
return t;
}
@@ -200,9 +200,9 @@
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithAabb3(Aabb3 other) {
- final Vector3 otherMin = other.min;
- final Vector3 otherMax = other.max;
+ double? intersectsWithAabb3(Aabb3 other) {
+ final otherMin = other.min;
+ final otherMax = other.max;
var tNear = -double.maxFinite;
var tFar = double.maxFinite;
@@ -217,7 +217,7 @@
var t2 = (otherMax[i] - _origin[i]) / _direction[i];
if (t1 > t2) {
- final double temp = t1;
+ final temp = t1;
t1 = t2;
t2 = temp;
}
diff --git a/lib/src/vector_math/sphere.dart b/lib/src/vector_math/sphere.dart
index 77a8589..492f0f6 100644
--- a/lib/src/vector_math/sphere.dart
+++ b/lib/src/vector_math/sphere.dart
@@ -44,7 +44,7 @@
/// Return if this intersects with [other].
bool intersectsWithSphere(Sphere other) {
- final double radiusSum = radius + other.radius;
+ final radiusSum = radius + other.radius;
return other.center.distanceToSquared(center) <= (radiusSum * radiusSum);
}
diff --git a/lib/src/vector_math/third_party/noise.dart b/lib/src/vector_math/third_party/noise.dart
index 1931ae1..0e78bfb 100644
--- a/lib/src/vector_math/third_party/noise.dart
+++ b/lib/src/vector_math/third_party/noise.dart
@@ -78,16 +78,16 @@
];
// To remove the need for index wrapping, double the permutation table length
- List<int> _perm;
- List<int> _permMod12;
+ late final List<int> _perm;
+ late final List<int> _permMod12;
// Skewing and unskewing factors for 2, 3, and 4 dimensions
- static final double _F2 = 0.5 * (math.sqrt(3.0) - 1.0);
- static final double _G2 = (3.0 - math.sqrt(3.0)) / 6.0;
+ static final _F2 = 0.5 * (math.sqrt(3.0) - 1.0);
+ static final _G2 = (3.0 - math.sqrt(3.0)) / 6.0;
static const double _f3 = 1.0 / 3.0;
static const double _g3 = 1.0 / 6.0;
- static final double _F4 = (math.sqrt(5.0) - 1.0) / 4.0;
- static final double _G4 = (5.0 - math.sqrt(5.0)) / 20.0;
+ static final _F4 = (math.sqrt(5.0) - 1.0) / 4.0;
+ static final _G4 = (5.0 - math.sqrt(5.0)) / 20.0;
double _dot2(List<double> g, double x, double y) => g[0] * x + g[1] * y;
@@ -97,10 +97,9 @@
double _dot4(List<double> g, double x, double y, double z, double w) =>
g[0] * x + g[1] * y + g[2] * z + g[3] * w;
- SimplexNoise([math.Random r]) {
+ SimplexNoise([math.Random? r]) {
r ??= math.Random();
- final List<int> p =
- List<int>.generate(256, (_) => r.nextInt(256), growable: false);
+ final p = List<int>.generate(256, (_) => r!.nextInt(256), growable: false);
_perm = List<int>.generate(p.length * 2, (int i) => p[i % p.length],
growable: false);
_permMod12 = List<int>.generate(_perm.length, (int i) => _perm[i] % 12,
@@ -110,14 +109,14 @@
double noise2D(double xin, double yin) {
double n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
- final double s = (xin + yin) * _F2; // Hairy factor for 2D
- final int i = (xin + s).floor();
- final int j = (yin + s).floor();
- final double t = (i + j) * _G2;
- final double X0 = i - t; // Unskew the cell origin back to (x,y) space
- final double Y0 = j - t;
- final double x0 = xin - X0; // The x,y distances from the cell origin
- final double y0 = yin - Y0;
+ final s = (xin + yin) * _F2; // Hairy factor for 2D
+ final i = (xin + s).floor();
+ final j = (yin + s).floor();
+ final t = (i + j) * _G2;
+ final X0 = i - t; // Unskew the cell origin back to (x,y) space
+ final Y0 = j - t;
+ final x0 = xin - X0; // The x,y distances from the cell origin
+ final y0 = yin - Y0;
// For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
@@ -132,19 +131,19 @@
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
- final double x1 =
+ final x1 =
x0 - i1 + _G2; // Offsets for middle corner in (x,y) unskewed coords
- final double y1 = y0 - j1 + _G2;
- final double x2 = x0 -
+ final y1 = y0 - j1 + _G2;
+ final x2 = x0 -
1.0 +
2.0 * _G2; // Offsets for last corner in (x,y) unskewed coords
- final double y2 = y0 - 1.0 + 2.0 * _G2;
+ final y2 = y0 - 1.0 + 2.0 * _G2;
// Work out the hashed gradient indices of the three simplex corners
- final int ii = i & 255;
- final int jj = j & 255;
- final int gi0 = _permMod12[ii + _perm[jj]];
- final int gi1 = _permMod12[ii + i1 + _perm[jj + j1]];
- final int gi2 = _permMod12[ii + 1 + _perm[jj + 1]];
+ final ii = i & 255;
+ final jj = j & 255;
+ final gi0 = _permMod12[ii + _perm[jj]];
+ final gi1 = _permMod12[ii + i1 + _perm[jj + j1]];
+ final gi2 = _permMod12[ii + 1 + _perm[jj + 1]];
// Calculate the contribution from the three corners
var t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0) {
@@ -178,18 +177,18 @@
double noise3D(double xin, double yin, double zin) {
double n0, n1, n2, n3; // Noise contributions from the four corners
// Skew the input space to determine which simplex cell we're in
- final double s =
+ final s =
(xin + yin + zin) * _f3; // Very nice and simple skew factor for 3D
- final int i = (xin + s).floor();
- final int j = (yin + s).floor();
- final int k = (zin + s).floor();
- final double t = (i + j + k) * _g3;
- final double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
- final double Y0 = j - t;
- final double Z0 = k - t;
- final double x0 = xin - X0; // The x,y,z distances from the cell origin
- final double y0 = yin - Y0;
- final double z0 = zin - Z0;
+ final i = (xin + s).floor();
+ final j = (yin + s).floor();
+ final k = (zin + s).floor();
+ final t = (i + j + k) * _g3;
+ final X0 = i - t; // Unskew the cell origin back to (x,y,z) space
+ final Y0 = j - t;
+ final Z0 = k - t;
+ final x0 = xin - X0; // The x,y,z distances from the cell origin
+ final y0 = yin - Y0;
+ final z0 = zin - Z0;
// For the 3D case, the simplex shape is a slightly irregular tetrahedron.
// Determine which simplex we are in.
int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
@@ -250,26 +249,25 @@
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
- final double x1 =
- x0 - i1 + _g3; // Offsets for second corner in (x,y,z) coords
- final double y1 = y0 - j1 + _g3;
- final double z1 = z0 - k1 + _g3;
- final double x2 =
+ final x1 = x0 - i1 + _g3; // Offsets for second corner in (x,y,z) coords
+ final y1 = y0 - j1 + _g3;
+ final z1 = z0 - k1 + _g3;
+ final x2 =
x0 - i2 + 2.0 * _g3; // Offsets for third corner in (x,y,z) coords
- final double y2 = y0 - j2 + 2.0 * _g3;
- final double z2 = z0 - k2 + 2.0 * _g3;
- final double x3 =
+ final y2 = y0 - j2 + 2.0 * _g3;
+ final z2 = z0 - k2 + 2.0 * _g3;
+ final x3 =
x0 - 1.0 + 3.0 * _g3; // Offsets for last corner in (x,y,z) coords
- final double y3 = y0 - 1.0 + 3.0 * _g3;
- final double z3 = z0 - 1.0 + 3.0 * _g3;
+ final y3 = y0 - 1.0 + 3.0 * _g3;
+ final z3 = z0 - 1.0 + 3.0 * _g3;
// Work out the hashed gradient indices of the four simplex corners
- final int ii = i & 255;
- final int jj = j & 255;
- final int kk = k & 255;
- final int gi0 = _permMod12[ii + _perm[jj + _perm[kk]]];
- final int gi1 = _permMod12[ii + i1 + _perm[jj + j1 + _perm[kk + k1]]];
- final int gi2 = _permMod12[ii + i2 + _perm[jj + j2 + _perm[kk + k2]]];
- final int gi3 = _permMod12[ii + 1 + _perm[jj + 1 + _perm[kk + 1]]];
+ final ii = i & 255;
+ final jj = j & 255;
+ final kk = k & 255;
+ final gi0 = _permMod12[ii + _perm[jj + _perm[kk]]];
+ final gi1 = _permMod12[ii + i1 + _perm[jj + j1 + _perm[kk + k1]]];
+ final gi2 = _permMod12[ii + i2 + _perm[jj + j2 + _perm[kk + k2]]];
+ final gi3 = _permMod12[ii + 1 + _perm[jj + 1 + _perm[kk + 1]]];
// Calculate the contribution from the four corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0) {
@@ -308,20 +306,20 @@
double noise4D(double x, double y, double z, double w) {
double n0, n1, n2, n3, n4; // Noise contributions from the five corners
// Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
- final double s = (x + y + z + w) * _F4; // Factor for 4D skewing
- final int i = (x + s).floor();
- final int j = (y + s).floor();
- final int k = (z + s).floor();
- final int l = (w + s).floor();
- final double t = (i + j + k + l) * _G4; // Factor for 4D unskewing
- final double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
- final double Y0 = j - t;
- final double Z0 = k - t;
- final double W0 = l - t;
- final double x0 = x - X0; // The x,y,z,w distances from the cell origin
- final double y0 = y - Y0;
- final double z0 = z - Z0;
- final double w0 = w - W0;
+ final s = (x + y + z + w) * _F4; // Factor for 4D skewing
+ final i = (x + s).floor();
+ final j = (y + s).floor();
+ final k = (z + s).floor();
+ final l = (w + s).floor();
+ final t = (i + j + k + l) * _G4; // Factor for 4D unskewing
+ final X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
+ final Y0 = j - t;
+ final Z0 = k - t;
+ final W0 = l - t;
+ final x0 = x - X0; // The x,y,z,w distances from the cell origin
+ final y0 = y - Y0;
+ final z0 = z - Z0;
+ final w0 = w - W0;
// For the 4D case, the simplex is a 4D shape I won't even try to describe.
// To find out which of the 24 possible simplices we're in, we need to
// determine the magnitude ordering of x0, y0, z0 and w0.
@@ -384,39 +382,38 @@
k3 = rankz >= 1 ? 1 : 0;
l3 = rankw >= 1 ? 1 : 0;
// The fifth corner has all coordinate offsets = 1, so no need to compute that.
- final double x1 =
- x0 - i1 + _G4; // Offsets for second corner in (x,y,z,w) coords
- final double y1 = y0 - j1 + _G4;
- final double z1 = z0 - k1 + _G4;
- final double w1 = w0 - l1 + _G4;
- final double x2 =
+ final x1 = x0 - i1 + _G4; // Offsets for second corner in (x,y,z,w) coords
+ final y1 = y0 - j1 + _G4;
+ final z1 = z0 - k1 + _G4;
+ final w1 = w0 - l1 + _G4;
+ final x2 =
x0 - i2 + 2.0 * _G4; // Offsets for third corner in (x,y,z,w) coords
- final double y2 = y0 - j2 + 2.0 * _G4;
- final double z2 = z0 - k2 + 2.0 * _G4;
- final double w2 = w0 - l2 + 2.0 * _G4;
- final double x3 =
+ final y2 = y0 - j2 + 2.0 * _G4;
+ final z2 = z0 - k2 + 2.0 * _G4;
+ final w2 = w0 - l2 + 2.0 * _G4;
+ final x3 =
x0 - i3 + 3.0 * _G4; // Offsets for fourth corner in (x,y,z,w) coords
- final double y3 = y0 - j3 + 3.0 * _G4;
- final double z3 = z0 - k3 + 3.0 * _G4;
- final double w3 = w0 - l3 + 3.0 * _G4;
- final double x4 =
+ final y3 = y0 - j3 + 3.0 * _G4;
+ final z3 = z0 - k3 + 3.0 * _G4;
+ final w3 = w0 - l3 + 3.0 * _G4;
+ final x4 =
x0 - 1.0 + 4.0 * _G4; // Offsets for last corner in (x,y,z,w) coords
- final double y4 = y0 - 1.0 + 4.0 * _G4;
- final double z4 = z0 - 1.0 + 4.0 * _G4;
- final double w4 = w0 - 1.0 + 4.0 * _G4;
+ final y4 = y0 - 1.0 + 4.0 * _G4;
+ final z4 = z0 - 1.0 + 4.0 * _G4;
+ final w4 = w0 - 1.0 + 4.0 * _G4;
// Work out the hashed gradient indices of the five simplex corners
- final int ii = i & 255;
- final int jj = j & 255;
- final int kk = k & 255;
- final int ll = l & 255;
- final int gi0 = _perm[ii + _perm[jj + _perm[kk + _perm[ll]]]] % 32;
- final int gi1 =
+ final ii = i & 255;
+ final jj = j & 255;
+ final kk = k & 255;
+ final ll = l & 255;
+ final gi0 = _perm[ii + _perm[jj + _perm[kk + _perm[ll]]]] % 32;
+ final gi1 =
_perm[ii + i1 + _perm[jj + j1 + _perm[kk + k1 + _perm[ll + l1]]]] % 32;
- final int gi2 =
+ final gi2 =
_perm[ii + i2 + _perm[jj + j2 + _perm[kk + k2 + _perm[ll + l2]]]] % 32;
- final int gi3 =
+ final gi3 =
_perm[ii + i3 + _perm[jj + j3 + _perm[kk + k3 + _perm[ll + l3]]]] % 32;
- final int gi4 =
+ final gi4 =
_perm[ii + 1 + _perm[jj + 1 + _perm[kk + 1 + _perm[ll + 1]]]] % 32;
// Calculate the contribution from the five corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
diff --git a/lib/src/vector_math/triangle.dart b/lib/src/vector_math/triangle.dart
index 043328b..2c878ed 100644
--- a/lib/src/vector_math/triangle.dart
+++ b/lib/src/vector_math/triangle.dart
@@ -46,7 +46,7 @@
/// Copy the normal of this into [normal].
void copyNormalInto(Vector3 normal) {
- final Vector3 v0 = point0.clone()..sub(point1);
+ final v0 = point0.clone()..sub(point1);
normal
..setFrom(point2)
..sub(point1)
diff --git a/lib/src/vector_math/utilities.dart b/lib/src/vector_math/utilities.dart
index 29cc2a2..332cbfb 100644
--- a/lib/src/vector_math/utilities.dart
+++ b/lib/src/vector_math/utilities.dart
@@ -18,8 +18,7 @@
/// [edge1] by [amount]. The computation is equivalent to the GLSL function
/// smoothstep.
double smoothStep(double edge0, double edge1, double amount) {
- final double t =
- ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble();
+ final t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble();
return t * t * (3.0 - 2.0 * t);
}
diff --git a/lib/src/vector_math/vector.dart b/lib/src/vector_math/vector.dart
index ab634d2..c769450 100644
--- a/lib/src/vector_math/vector.dart
+++ b/lib/src/vector_math/vector.dart
@@ -20,7 +20,7 @@
/// 2D cross product. double x vec2.
void cross2A(double x, Vector2 y, Vector2 out) {
- final double tempy = x * y.x;
+ final tempy = x * y.x;
out
..x = -x * y.y
..y = tempy;
@@ -28,7 +28,7 @@
/// 2D cross product. vec2 x double.
void cross2B(Vector2 x, double y, Vector2 out) {
- final double tempy = -y * x.x;
+ final tempy = -y * x.x;
out
..x = y * x.y
..y = tempy;
@@ -39,9 +39,8 @@
void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) {
if (planeNormal.z.abs() > math.sqrt1_2) {
// choose u in y-z plane
- final double a =
- planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
- final double k = 1.0 / math.sqrt(a);
+ final a = planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
+ final k = 1.0 / math.sqrt(a);
u
..x = 0.0
..y = -planeNormal.z * k
@@ -53,9 +52,8 @@
..z = planeNormal[0] * (-planeNormal[2] * k);
} else {
// choose u in x-y plane
- final double a =
- planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
- final double k = 1.0 / math.sqrt(a);
+ final a = planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
+ final k = 1.0 / math.sqrt(a);
u
..x = -planeNormal[1] * k
..y = planeNormal[0] * k
diff --git a/lib/src/vector_math/vector2.dart b/lib/src/vector_math/vector2.dart
index a74d55c..eb2aa21 100644
--- a/lib/src/vector_math/vector2.dart
+++ b/lib/src/vector_math/vector2.dart
@@ -60,7 +60,7 @@
/// Generate random vector in the range (0, 0) to (1, 1). You can
/// optionally pass your own random number generator.
- factory Vector2.random([math.Random rng]) {
+ factory Vector2.random([math.Random? rng]) {
rng ??= math.Random();
return Vector2(rng.nextDouble(), rng.nextDouble());
}
@@ -79,7 +79,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector2 other) {
- final Float32List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
_v2storage[1] = otherStorage[1];
_v2storage[0] = otherStorage[0];
}
@@ -96,7 +96,7 @@
/// Check if two vectors are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Vector2) &&
(_v2storage[0] == other._v2storage[0]) &&
(_v2storage[1] == other._v2storage[1]);
@@ -156,11 +156,11 @@
/// Normalize this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_v2storage[0] *= d;
_v2storage[1] *= d;
return l;
@@ -187,40 +187,40 @@
/// Squared distance from this to [arg]
double distanceToSquared(Vector2 arg) {
- final double dx = x - arg.x;
- final double dy = y - arg.y;
+ final dx = x - arg.x;
+ final dy = y - arg.y;
return dx * dx + dy * dy;
}
/// Returns the angle between this vector and [other] in radians.
double angleTo(Vector2 other) {
- final Float32List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final double d = dot(other) / (length * other.length);
+ final d = dot(other) / (length * other.length);
return math.acos(d.clamp(-1.0, 1.0));
}
/// Returns the signed angle between this and [other] in radians.
double angleToSigned(Vector2 other) {
- final Float32List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final double s = cross(other);
- final double c = dot(other);
+ final s = cross(other);
+ final c = dot(other);
return math.atan2(s, c);
}
/// Inner product.
double dot(Vector2 other) {
- final Float32List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
double sum;
sum = _v2storage[0] * otherStorage[0];
sum += _v2storage[1] * otherStorage[1];
@@ -234,16 +234,16 @@
/// the inverse of the transformation.
///
void postmultiply(Matrix2 arg) {
- final Float32List argStorage = arg.storage;
- final double v0 = _v2storage[0];
- final double v1 = _v2storage[1];
+ final argStorage = arg.storage;
+ final v0 = _v2storage[0];
+ final v1 = _v2storage[1];
_v2storage[0] = v0 * argStorage[0] + v1 * argStorage[1];
_v2storage[1] = v0 * argStorage[2] + v1 * argStorage[3];
}
/// Cross product.
double cross(Vector2 other) {
- final Float32List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
return _v2storage[0] * otherStorage[1] - _v2storage[1] * otherStorage[0];
}
@@ -263,8 +263,8 @@
/// Relative error between this and [correct]
double relativeError(Vector2 correct) {
- final double correct_norm = correct.length;
- final double diff_norm = (this - correct).length;
+ final correct_norm = correct.length;
+ final diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
@@ -289,35 +289,35 @@
/// Add [arg] to this.
void add(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] + argStorage[0];
_v2storage[1] = _v2storage[1] + argStorage[1];
}
/// Add [arg] scaled by [factor] to this.
void addScaled(Vector2 arg, double factor) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] + argStorage[0] * factor;
_v2storage[1] = _v2storage[1] + argStorage[1] * factor;
}
/// Subtract [arg] from this.
void sub(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] - argStorage[0];
_v2storage[1] = _v2storage[1] - argStorage[1];
}
/// Multiply entries in this with entries in [arg].
void multiply(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] * argStorage[0];
_v2storage[1] = _v2storage[1] * argStorage[1];
}
/// Divide entries in this with entries in [arg].
void divide(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] / argStorage[0];
_v2storage[1] = _v2storage[1] / argStorage[1];
}
@@ -345,8 +345,8 @@
/// Clamp each entry n in this in the range [min[n]]-[max[n]].
void clamp(Vector2 min, Vector2 max) {
- final Float32List minStorage = min.storage;
- final Float32List maxStorage = max.storage;
+ final minStorage = min.storage;
+ final maxStorage = max.storage;
_v2storage[0] =
_v2storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
_v2storage[1] =
@@ -392,7 +392,7 @@
/// Copy this into [arg]. Returns [arg].
Vector2 copyInto(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
argStorage[1] = _v2storage[1];
argStorage[0] = _v2storage[0];
return arg;
@@ -411,13 +411,13 @@
}
set xy(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = argStorage[0];
_v2storage[1] = argStorage[1];
}
set yx(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[1] = argStorage[0];
_v2storage[0] = argStorage[1];
}
diff --git a/lib/src/vector_math/vector3.dart b/lib/src/vector_math/vector3.dart
index d9abe44..6ed3d08 100644
--- a/lib/src/vector_math/vector3.dart
+++ b/lib/src/vector_math/vector3.dart
@@ -64,7 +64,7 @@
/// Generate random vector in the range (0, 0, 0) to (1, 1, 1). You can
/// optionally pass your own random number generator.
- factory Vector3.random([math.Random rng]) {
+ factory Vector3.random([math.Random? rng]) {
rng ??= math.Random();
return Vector3(rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
}
@@ -85,7 +85,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector3 other) {
- final Float32List otherStorage = other._v3storage;
+ final otherStorage = other._v3storage;
_v3storage[0] = otherStorage[0];
_v3storage[1] = otherStorage[1];
_v3storage[2] = otherStorage[2];
@@ -104,7 +104,7 @@
/// Check if two vectors are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Vector3) &&
(_v3storage[0] == other._v3storage[0]) &&
(_v3storage[1] == other._v3storage[1]) &&
@@ -167,11 +167,11 @@
/// Normalizes this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_v3storage[0] *= d;
_v3storage[1] *= d;
_v3storage[2] *= d;
@@ -199,24 +199,24 @@
/// Squared distance from this to [arg]
double distanceToSquared(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
- final double dx = _v3storage[0] - argStorage[0];
- final double dy = _v3storage[1] - argStorage[1];
- final double dz = _v3storage[2] - argStorage[2];
+ final argStorage = arg._v3storage;
+ final dx = _v3storage[0] - argStorage[0];
+ final dy = _v3storage[1] - argStorage[1];
+ final dz = _v3storage[2] - argStorage[2];
return dx * dx + dy * dy + dz * dz;
}
/// Returns the angle between this vector and [other] in radians.
double angleTo(Vector3 other) {
- final Float32List otherStorage = other._v3storage;
+ final otherStorage = other._v3storage;
if (_v3storage[0] == otherStorage[0] &&
_v3storage[1] == otherStorage[1] &&
_v3storage[2] == otherStorage[2]) {
return 0.0;
}
- final double d = dot(other) / (length * other.length);
+ final d = dot(other) / (length * other.length);
return math.acos(d.clamp(-1.0, 1.0));
}
@@ -224,16 +224,16 @@
/// Returns the signed angle between this and [other] around [normal]
/// in radians.
double angleToSigned(Vector3 other, Vector3 normal) {
- final double angle = angleTo(other);
- final Vector3 c = cross(other);
- final double d = c.dot(normal);
+ final angle = angleTo(other);
+ final c = cross(other);
+ final d = c.dot(normal);
return d < 0.0 ? -angle : angle;
}
/// Inner product.
double dot(Vector3 other) {
- final Float32List otherStorage = other._v3storage;
+ final otherStorage = other._v3storage;
double sum;
sum = _v3storage[0] * otherStorage[0];
sum += _v3storage[1] * otherStorage[1];
@@ -246,10 +246,10 @@
/// If [arg] is a rotation matrix, this is a computational shortcut for applying,
/// the inverse of the transformation.
void postmultiply(Matrix3 arg) {
- final Float32List argStorage = arg.storage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
+ final argStorage = arg.storage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
_v3storage[0] =
v0 * argStorage[0] + v1 * argStorage[1] + v2 * argStorage[2];
@@ -261,26 +261,26 @@
/// Cross product.
Vector3 cross(Vector3 other) {
- final double _x = _v3storage[0];
- final double _y = _v3storage[1];
- final double _z = _v3storage[2];
- final Float32List otherStorage = other._v3storage;
- final double ox = otherStorage[0];
- final double oy = otherStorage[1];
- final double oz = otherStorage[2];
+ final _x = _v3storage[0];
+ final _y = _v3storage[1];
+ final _z = _v3storage[2];
+ final otherStorage = other._v3storage;
+ final ox = otherStorage[0];
+ final oy = otherStorage[1];
+ final oz = otherStorage[2];
return Vector3(_y * oz - _z * oy, _z * ox - _x * oz, _x * oy - _y * ox);
}
/// Cross product. Stores result in [out].
Vector3 crossInto(Vector3 other, Vector3 out) {
- final double x = _v3storage[0];
- final double y = _v3storage[1];
- final double z = _v3storage[2];
- final Float32List otherStorage = other._v3storage;
- final double ox = otherStorage[0];
- final double oy = otherStorage[1];
- final double oz = otherStorage[2];
- final Float32List outStorage = out._v3storage;
+ final x = _v3storage[0];
+ final y = _v3storage[1];
+ final z = _v3storage[2];
+ final otherStorage = other._v3storage;
+ final ox = otherStorage[0];
+ final oy = otherStorage[1];
+ final oz = otherStorage[2];
+ final outStorage = out._v3storage;
outStorage[0] = y * oz - z * oy;
outStorage[1] = z * ox - x * oz;
outStorage[2] = x * oy - y * ox;
@@ -297,11 +297,11 @@
/// Projects this using the projection matrix [arg]
void applyProjection(Matrix4 arg) {
- final Float32List argStorage = arg.storage;
- final double x = _v3storage[0];
- final double y = _v3storage[1];
- final double z = _v3storage[2];
- final double d = 1.0 /
+ final argStorage = arg.storage;
+ final x = _v3storage[0];
+ final y = _v3storage[1];
+ final z = _v3storage[2];
+ final d = 1.0 /
(argStorage[3] * x +
argStorage[7] * y +
argStorage[11] * z +
@@ -330,18 +330,18 @@
/// Applies a quaternion transform.
void applyQuaternion(Quaternion arg) {
- final Float32List argStorage = arg._qStorage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
- final double qx = argStorage[0];
- final double qy = argStorage[1];
- final double qz = argStorage[2];
- final double qw = argStorage[3];
- final double ix = qw * v0 + qy * v2 - qz * v1;
- final double iy = qw * v1 + qz * v0 - qx * v2;
- final double iz = qw * v2 + qx * v1 - qy * v0;
- final double iw = -qx * v0 - qy * v1 - qz * v2;
+ final argStorage = arg._qStorage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
+ final qx = argStorage[0];
+ final qy = argStorage[1];
+ final qz = argStorage[2];
+ final qw = argStorage[3];
+ final ix = qw * v0 + qy * v2 - qz * v1;
+ final iy = qw * v1 + qz * v0 - qx * v2;
+ final iz = qw * v2 + qx * v1 - qy * v0;
+ final iw = -qx * v0 - qy * v1 - qz * v2;
_v3storage[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
_v3storage[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
_v3storage[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
@@ -349,10 +349,10 @@
/// Multiplies this by [arg].
void applyMatrix3(Matrix3 arg) {
- final Float32List argStorage = arg.storage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
+ final argStorage = arg.storage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
_v3storage[0] =
argStorage[0] * v0 + argStorage[3] * v1 + argStorage[6] * v2;
_v3storage[1] =
@@ -364,10 +364,10 @@
/// Multiplies this by a 4x3 subset of [arg]. Expects [arg] to be an affine
/// transformation matrix.
void applyMatrix4(Matrix4 arg) {
- final Float32List argStorage = arg.storage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
+ final argStorage = arg.storage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
_v3storage[0] = argStorage[0] * v0 +
argStorage[4] * v1 +
argStorage[8] * v2 +
@@ -384,8 +384,8 @@
/// Relative error between this and [correct]
double relativeError(Vector3 correct) {
- final double correct_norm = correct.length;
- final double diff_norm = (this - correct).length;
+ final correct_norm = correct.length;
+ final diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
@@ -412,7 +412,7 @@
/// Add [arg] to this.
void add(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0];
_v3storage[1] = _v3storage[1] + argStorage[1];
_v3storage[2] = _v3storage[2] + argStorage[2];
@@ -420,7 +420,7 @@
/// Add [arg] scaled by [factor] to this.
void addScaled(Vector3 arg, double factor) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0] * factor;
_v3storage[1] = _v3storage[1] + argStorage[1] * factor;
_v3storage[2] = _v3storage[2] + argStorage[2] * factor;
@@ -428,7 +428,7 @@
/// Subtract [arg] from this.
void sub(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] - argStorage[0];
_v3storage[1] = _v3storage[1] - argStorage[1];
_v3storage[2] = _v3storage[2] - argStorage[2];
@@ -436,7 +436,7 @@
/// Multiply entries in this with entries in [arg].
void multiply(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] * argStorage[0];
_v3storage[1] = _v3storage[1] * argStorage[1];
_v3storage[2] = _v3storage[2] * argStorage[2];
@@ -444,7 +444,7 @@
/// Divide entries in this with entries in [arg].
void divide(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] / argStorage[0];
_v3storage[1] = _v3storage[1] / argStorage[1];
_v3storage[2] = _v3storage[2] / argStorage[2];
@@ -476,8 +476,8 @@
/// Clamp each entry n in this in the range [min[n]]-[max[n]].
void clamp(Vector3 min, Vector3 max) {
- final Float32List minStorage = min.storage;
- final Float32List maxStorage = max.storage;
+ final minStorage = min.storage;
+ final maxStorage = max.storage;
_v3storage[0] =
_v3storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
_v3storage[1] =
@@ -532,7 +532,7 @@
/// Copy this into [arg].
Vector3 copyInto(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
argStorage[0] = _v3storage[0];
argStorage[1] = _v3storage[1];
argStorage[2] = _v3storage[2];
@@ -554,78 +554,78 @@
}
set xy(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set yx(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set zx(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xyz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set xzy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set yxz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set yzx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[0] = argStorage[2];
}
set zxy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set zyx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[2] = argStorage[0];
_v3storage[1] = argStorage[1];
_v3storage[0] = argStorage[2];
diff --git a/lib/src/vector_math/vector4.dart b/lib/src/vector_math/vector4.dart
index 15a6cfc..e200d8d 100644
--- a/lib/src/vector_math/vector4.dart
+++ b/lib/src/vector_math/vector4.dart
@@ -70,7 +70,7 @@
/// Generate random vector in the range (0, 0, 0, 0) to (1, 1, 1, 1). You can
/// optionally pass your own random number generator.
- factory Vector4.random([math.Random rng]) {
+ factory Vector4.random([math.Random? rng]) {
rng ??= math.Random();
return Vector4(
rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
@@ -102,7 +102,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector4 other) {
- final Float32List otherStorage = other._v4storage;
+ final otherStorage = other._v4storage;
_v4storage[3] = otherStorage[3];
_v4storage[2] = otherStorage[2];
_v4storage[1] = otherStorage[1];
@@ -124,7 +124,7 @@
/// Check if two vectors are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Vector4) &&
(_v4storage[0] == other._v4storage[0]) &&
(_v4storage[1] == other._v4storage[1]) &&
@@ -190,11 +190,11 @@
/// Normalizes this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_v4storage[0] *= d;
_v4storage[1] *= d;
_v4storage[2] *= d;
@@ -223,18 +223,18 @@
/// Squared distance from this to [arg]
double distanceToSquared(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
- final double dx = _v4storage[0] - argStorage[0];
- final double dy = _v4storage[1] - argStorage[1];
- final double dz = _v4storage[2] - argStorage[2];
- final double dw = _v4storage[3] - argStorage[3];
+ final argStorage = arg._v4storage;
+ final dx = _v4storage[0] - argStorage[0];
+ final dy = _v4storage[1] - argStorage[1];
+ final dz = _v4storage[2] - argStorage[2];
+ final dw = _v4storage[3] - argStorage[3];
return dx * dx + dy * dy + dz * dz + dw * dw;
}
/// Inner product.
double dot(Vector4 other) {
- final Float32List otherStorage = other._v4storage;
+ final otherStorage = other._v4storage;
double sum;
sum = _v4storage[0] * otherStorage[0];
sum += _v4storage[1] * otherStorage[1];
@@ -245,11 +245,11 @@
/// Multiplies this by [arg].
void applyMatrix4(Matrix4 arg) {
- final double v1 = _v4storage[0];
- final double v2 = _v4storage[1];
- final double v3 = _v4storage[2];
- final double v4 = _v4storage[3];
- final Float32List argStorage = arg.storage;
+ final v1 = _v4storage[0];
+ final v2 = _v4storage[1];
+ final v3 = _v4storage[2];
+ final v4 = _v4storage[3];
+ final argStorage = arg.storage;
_v4storage[0] = argStorage[0] * v1 +
argStorage[4] * v2 +
argStorage[8] * v3 +
@@ -270,8 +270,8 @@
/// Relative error between this and [correct]
double relativeError(Vector4 correct) {
- final double correct_norm = correct.length;
- final double diff_norm = (this - correct).length;
+ final correct_norm = correct.length;
+ final diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
@@ -299,7 +299,7 @@
}
void add(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0];
_v4storage[1] = _v4storage[1] + argStorage[1];
_v4storage[2] = _v4storage[2] + argStorage[2];
@@ -308,7 +308,7 @@
/// Add [arg] scaled by [factor] to this.
void addScaled(Vector4 arg, double factor) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0] * factor;
_v4storage[1] = _v4storage[1] + argStorage[1] * factor;
_v4storage[2] = _v4storage[2] + argStorage[2] * factor;
@@ -317,7 +317,7 @@
/// Subtract [arg] from this.
void sub(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] - argStorage[0];
_v4storage[1] = _v4storage[1] - argStorage[1];
_v4storage[2] = _v4storage[2] - argStorage[2];
@@ -326,7 +326,7 @@
/// Multiply this by [arg].
void multiply(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] * argStorage[0];
_v4storage[1] = _v4storage[1] * argStorage[1];
_v4storage[2] = _v4storage[2] * argStorage[2];
@@ -335,7 +335,7 @@
/// Divide this by [arg].
void div(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] / argStorage[0];
_v4storage[1] = _v4storage[1] / argStorage[1];
_v4storage[2] = _v4storage[2] / argStorage[2];
@@ -371,8 +371,8 @@
/// Clamp each entry n in this in the range [min[n]]-[max[n]].
void clamp(Vector4 min, Vector4 max) {
- final Float32List minStorage = min.storage;
- final Float32List maxStorage = max.storage;
+ final minStorage = min.storage;
+ final maxStorage = max.storage;
_v4storage[0] =
_v4storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
_v4storage[1] =
@@ -436,7 +436,7 @@
/// Copy this
Vector4 copyInto(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
argStorage[0] = _v4storage[0];
argStorage[1] = _v4storage[1];
argStorage[2] = _v4storage[2];
@@ -461,247 +461,247 @@
}
set xy(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xw(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set yx(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set yw(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set zx(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set zw(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set wx(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set wy(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set wz(Vector2 arg) {
- final Float32List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xyz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set xyw(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xzy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xzw(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xwy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xwz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxw(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set yzx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set yzw(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set ywx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set ywz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set zxy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set zxw(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zyx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zyw(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zwx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zwy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wyx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wyz(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wzx(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wzy(Vector3 arg) {
- final Float32List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xyzw(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -709,7 +709,7 @@
}
set xywz(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -717,7 +717,7 @@
}
set xzyw(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -725,7 +725,7 @@
}
set xzwy(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -733,7 +733,7 @@
}
set xwyz(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -741,7 +741,7 @@
}
set xwzy(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -749,7 +749,7 @@
}
set yxzw(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -757,7 +757,7 @@
}
set yxwz(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -765,7 +765,7 @@
}
set yzxw(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -773,7 +773,7 @@
}
set yzwx(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -781,7 +781,7 @@
}
set ywxz(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -789,7 +789,7 @@
}
set ywzx(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -797,7 +797,7 @@
}
set zxyw(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -805,7 +805,7 @@
}
set zxwy(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -813,7 +813,7 @@
}
set zyxw(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -821,7 +821,7 @@
}
set zywx(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -829,7 +829,7 @@
}
set zwxy(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -837,7 +837,7 @@
}
set zwyx(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -845,7 +845,7 @@
}
set wxyz(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -853,7 +853,7 @@
}
set wxzy(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -861,7 +861,7 @@
}
set wyxz(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -869,7 +869,7 @@
}
set wyzx(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -877,7 +877,7 @@
}
set wzxy(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -885,7 +885,7 @@
}
set wzyx(Vector4 arg) {
- final Float32List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
diff --git a/lib/src/vector_math_64/aabb2.dart b/lib/src/vector_math_64/aabb2.dart
index 1f3e176..88aa1e6 100644
--- a/lib/src/vector_math_64/aabb2.dart
+++ b/lib/src/vector_math_64/aabb2.dart
@@ -76,12 +76,10 @@
_max.setFrom(other._max);
}
- static Vector2 _center;
- static Vector2 _halfExtents;
- void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(
- _center ??= Vector2.zero(),
- _halfExtents ??= Vector2.zero(),
- );
+ static late final _center = Vector2.zero();
+ static late final _halfExtents = Vector2.zero();
+ void _updateCenterAndHalfExtents() =>
+ copyCenterAndHalfExtents(_center, _halfExtents);
/// Transform this by the transform [t].
void transform(Matrix3 t) {
@@ -136,8 +134,8 @@
/// Return if this contains [other].
bool containsAabb2(Aabb2 other) {
- final Vector2 otherMax = other._max;
- final Vector2 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -154,8 +152,8 @@
/// Return if this intersects with [other].
bool intersectsWithAabb2(Aabb2 other) {
- final Vector2 otherMax = other._max;
- final Vector2 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
diff --git a/lib/src/vector_math_64/aabb3.dart b/lib/src/vector_math_64/aabb3.dart
index cc8b10d..96e8da2 100644
--- a/lib/src/vector_math_64/aabb3.dart
+++ b/lib/src/vector_math_64/aabb3.dart
@@ -125,7 +125,7 @@
/// Set the AABB to enclose a [obb].
void setObb3(Obb3 obb) {
- final Vector3 corner = Vector3.zero();
+ final corner = Vector3.zero();
obb.copyCorner(0, corner);
_min.setFrom(corner);
@@ -159,19 +159,19 @@
ray..copyAt(_min, limitMin)..copyAt(_max, limitMax);
if (_max.x < _min.x) {
- final double temp = _max.x;
+ final temp = _max.x;
_max.x = _min.x;
_min.x = temp;
}
if (_max.y < _min.y) {
- final double temp = _max.y;
+ final temp = _max.y;
_max.y = _min.y;
_min.y = temp;
}
if (_max.z < _min.z) {
- final double temp = _max.z;
+ final temp = _max.z;
_max.z = _min.z;
_min.z = temp;
}
@@ -203,12 +203,10 @@
_max.setFrom(other._max);
}
- static Vector3 _center;
- static Vector3 _halfExtents;
- void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(
- _center ??= Vector3.zero(),
- _halfExtents ??= Vector3.zero(),
- );
+ static late final _center = Vector3.zero();
+ static late final _halfExtents = Vector3.zero();
+ void _updateCenterAndHalfExtents() =>
+ copyCenterAndHalfExtents(_center, _halfExtents);
/// Transform this by the transform [t].
void transform(Matrix4 t) {
@@ -289,8 +287,8 @@
/// Return if this contains [other].
bool containsAabb3(Aabb3 other) {
- final Vector3 otherMax = other._max;
- final Vector3 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -302,9 +300,8 @@
/// Return if this contains [other].
bool containsSphere(Sphere other) {
- final Vector3 boxExtends = Vector3.all(other.radius);
- final Aabb3 sphereBox =
- Aabb3.centerAndHalfExtents(other._center, boxExtends);
+ final boxExtends = Vector3.all(other.radius);
+ final sphereBox = Aabb3.centerAndHalfExtents(other._center, boxExtends);
return containsAabb3(sphereBox);
}
@@ -326,8 +323,8 @@
/// Return if this intersects with [other].
bool intersectsWithAabb3(Aabb3 other) {
- final Vector3 otherMax = other._max;
- final Vector3 otherMin = other._min;
+ final otherMax = other._max;
+ final otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
@@ -339,8 +336,8 @@
/// Return if this intersects with [other].
bool intersectsWithSphere(Sphere other) {
- final Vector3 center = other._center;
- final double radius = other.radius;
+ final center = other._center;
+ final radius = other.radius;
var d = 0.0;
var e = 0.0;
@@ -375,19 +372,19 @@
(_max.z >= other.z);
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Vector3 _aabbCenter = Vector3.zero();
- static final Vector3 _aabbHalfExtents = Vector3.zero();
- static final Vector3 _v0 = Vector3.zero();
- static final Vector3 _v1 = Vector3.zero();
- static final Vector3 _v2 = Vector3.zero();
- static final Vector3 _f0 = Vector3.zero();
- static final Vector3 _f1 = Vector3.zero();
- static final Vector3 _f2 = Vector3.zero();
- static final Plane _trianglePlane = Plane();
+ static final _aabbCenter = Vector3.zero();
+ static final _aabbHalfExtents = Vector3.zero();
+ static final _v0 = Vector3.zero();
+ static final _v1 = Vector3.zero();
+ static final _v2 = Vector3.zero();
+ static final _f0 = Vector3.zero();
+ static final _f1 = Vector3.zero();
+ static final _f2 = Vector3.zero();
+ static final _trianglePlane = Plane();
- static final Vector3 _u0 = Vector3(1.0, 0.0, 0.0);
- static final Vector3 _u1 = Vector3(0.0, 1.0, 0.0);
- static final Vector3 _u2 = Vector3(0.0, 0.0, 1.0);
+ static final _u0 = Vector3(1.0, 0.0, 0.0);
+ static final _u1 = Vector3(0.0, 1.0, 0.0);
+ static final _u2 = Vector3(0.0, 0.0, 1.0);
/// Return if this intersects with [other].
/// [epsilon] allows the caller to specify a custum eplsilon value that should
@@ -395,7 +392,7 @@
/// found, result is modified to contain more details about the type of
/// intersection.
bool intersectsWithTriangle(Triangle other,
- {double epsilon = 1e-3, IntersectionResult result}) {
+ {double epsilon = 1e-3, IntersectionResult? result}) {
double p0, p1, p2, r, len;
double a;
@@ -438,7 +435,7 @@
}
a = math.min(p0, p2) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u0.crossInto(_f0, result.axis);
}
@@ -456,7 +453,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u0.crossInto(_f1, result.axis);
}
@@ -474,7 +471,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u0.crossInto(_f2, result.axis);
}
@@ -492,7 +489,7 @@
}
a = math.min(p0, p2) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u1.crossInto(_f0, result.axis);
}
@@ -510,7 +507,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u1.crossInto(_f1, result.axis);
}
@@ -528,7 +525,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u1.crossInto(_f2, result.axis);
}
@@ -546,7 +543,7 @@
}
a = math.min(p0, p2) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u2.crossInto(_f0, result.axis);
}
@@ -564,7 +561,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u2.crossInto(_f1, result.axis);
}
@@ -582,7 +579,7 @@
}
a = math.min(p0, p1) - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
_u2.crossInto(_f2, result.axis);
}
@@ -595,7 +592,7 @@
return false;
}
a = math.min(_v0.x, math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(_u0);
}
@@ -605,7 +602,7 @@
return false;
}
a = math.min(_v0.y, math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(_u1);
}
@@ -615,7 +612,7 @@
return false;
}
a = math.min(_v0.z, math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
- if (result != null && (result._depth == null || result._depth < a)) {
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(_u2);
}
@@ -631,20 +628,20 @@
}
/// Return if this intersects with [other]
- bool intersectsWithPlane(Plane other, {IntersectionResult result}) {
+ bool intersectsWithPlane(Plane other, {IntersectionResult? result}) {
// This line is not necessary with a (center, extents) AABB representation
copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents);
// Compute the projection interval radius of b onto L(t) = b.c + t * p.n
- final double r = _aabbHalfExtents[0] * other.normal[0].abs() +
+ final r = _aabbHalfExtents[0] * other.normal[0].abs() +
_aabbHalfExtents[1] * other.normal[1].abs() +
_aabbHalfExtents[2] * other.normal[2].abs();
// Compute distance of box center from plane
- final double s = other.normal.dot(_aabbCenter) - other.constant;
+ final s = other.normal.dot(_aabbCenter) - other.constant;
// Intersection occurs when distance s falls within [-r,+r] interval
if (s.abs() <= r) {
- final double a = s - r;
- if (result != null && (result._depth == null || result._depth < a)) {
+ final a = s - r;
+ if (result != null && (result._depth == null || (result._depth!) < a)) {
result._depth = a;
result.axis.setFrom(other.normal);
}
@@ -655,15 +652,15 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Triangle _quadTriangle0 = Triangle();
- static final Triangle _quadTriangle1 = Triangle();
+ static final _quadTriangle0 = Triangle();
+ static final _quadTriangle1 = Triangle();
/// Return `true` if this intersects with [other].
///
/// If [result] is specified and an intersection is
/// found, result is modified to contain more details about the type of
/// intersection.
- bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
+ bool intersectsWithQuad(Quad other, {IntersectionResult? result}) {
other.copyTriangles(_quadTriangle0, _quadTriangle1);
return intersectsWithTriangle(_quadTriangle0, result: result) ||
diff --git a/lib/src/vector_math_64/colors.dart b/lib/src/vector_math_64/colors.dart
index 38cfc12..49b30f7 100644
--- a/lib/src/vector_math_64/colors.dart
+++ b/lib/src/vector_math_64/colors.dart
@@ -8,10 +8,10 @@
/// manipulating colors. In addition to that, some known colors can be accessed
/// for fast prototyping.
class Colors {
- static final RegExp _hexStringFullRegex = RegExp(
+ static final _hexStringFullRegex = RegExp(
r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?',
caseSensitive: false);
- static final RegExp _hexStringSmallRegex = RegExp(
+ static final _hexStringSmallRegex = RegExp(
r'\#?([0-9a-f])([0-9a-f])([0-9a-f])(?:([0-9a-f]))?',
caseSensitive: false);
@@ -26,42 +26,42 @@
/// corresponding color value and store it in [result]. The first group is
/// treated as the alpha channel if a [value] with four groups is passed.
static void fromHexString(String value, Vector4 result) {
- final Match fullMatch = _hexStringFullRegex.matchAsPrefix(value);
+ final fullMatch = _hexStringFullRegex.matchAsPrefix(value);
if (fullMatch != null) {
if (fullMatch[4] == null) {
- final int r = int.parse(fullMatch[1], radix: 16);
- final int g = int.parse(fullMatch[2], radix: 16);
- final int b = int.parse(fullMatch[3], radix: 16);
+ final r = int.parse(fullMatch[1]!, radix: 16);
+ final g = int.parse(fullMatch[2]!, radix: 16);
+ final b = int.parse(fullMatch[3]!, radix: 16);
fromRgba(r, g, b, 255, result);
return;
} else {
- final int a = int.parse(fullMatch[1], radix: 16);
- final int r = int.parse(fullMatch[2], radix: 16);
- final int g = int.parse(fullMatch[3], radix: 16);
- final int b = int.parse(fullMatch[4], radix: 16);
+ final a = int.parse(fullMatch[1]!, radix: 16);
+ final r = int.parse(fullMatch[2]!, radix: 16);
+ final g = int.parse(fullMatch[3]!, radix: 16);
+ final b = int.parse(fullMatch[4]!, radix: 16);
fromRgba(r, g, b, a, result);
return;
}
}
- final Match smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
+ final smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
if (smallMatch != null) {
if (smallMatch[4] == null) {
- final int r = int.parse(smallMatch[1] + smallMatch[1], radix: 16);
- final int g = int.parse(smallMatch[2] + smallMatch[2], radix: 16);
- final int b = int.parse(smallMatch[3] + smallMatch[3], radix: 16);
+ final r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16);
+ final g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16);
+ final b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16);
fromRgba(r, g, b, 255, result);
return;
} else {
- final int a = int.parse(smallMatch[1] + smallMatch[1], radix: 16);
- final int r = int.parse(smallMatch[2] + smallMatch[2], radix: 16);
- final int g = int.parse(smallMatch[3] + smallMatch[3], radix: 16);
- final int b = int.parse(smallMatch[4] + smallMatch[4], radix: 16);
+ final a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16);
+ final r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16);
+ final g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16);
+ final b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16);
fromRgba(r, g, b, a, result);
return;
@@ -77,25 +77,25 @@
/// (default false).
static String toHexString(Vector4 input,
{bool alpha = false, bool short = false}) {
- final int r = (input.r * 0xFF).floor() & 0xFF;
- final int g = (input.g * 0xFF).floor() & 0xFF;
- final int b = (input.b * 0xFF).floor() & 0xFF;
- final int a = (input.a * 0xFF).floor() & 0xFF;
+ final r = (input.r * 0xFF).floor() & 0xFF;
+ final g = (input.g * 0xFF).floor() & 0xFF;
+ final b = (input.b * 0xFF).floor() & 0xFF;
+ final a = (input.a * 0xFF).floor() & 0xFF;
- final bool isShort = short &&
+ final isShort = short &&
((r >> 4) == (r & 0xF)) &&
((g >> 4) == (g & 0xF)) &&
((b >> 4) == (b & 0xF)) &&
(!alpha || (a >> 4) == (a & 0xF));
if (isShort) {
- final String rgb = (r & 0xF).toRadixString(16) +
+ final rgb = (r & 0xF).toRadixString(16) +
(g & 0xF).toRadixString(16) +
(b & 0xF).toRadixString(16);
return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb;
} else {
- final String rgb = r.toRadixString(16).padLeft(2, '0') +
+ final rgb = r.toRadixString(16).padLeft(2, '0') +
g.toRadixString(16).padLeft(2, '0') +
b.toRadixString(16).padLeft(2, '0');
@@ -107,16 +107,16 @@
/// in [result].
static void alphaBlend(
Vector4 foreground, Vector4 background, Vector4 result) {
- final double a = foreground.a + (1.0 - foreground.a) * background.a;
- final double factor = 1.0 / a;
+ final a = foreground.a + (1.0 - foreground.a) * background.a;
+ final factor = 1.0 / a;
- final double r = factor *
+ final r = factor *
(foreground.a * foreground.r +
(1.0 - foreground.a) * background.a * background.r);
- final double g = factor *
+ final g = factor *
(foreground.a * foreground.g +
(1.0 - foreground.a) * background.a * background.g);
- final double b = factor *
+ final b = factor *
(foreground.a * foreground.b +
(1.0 - foreground.a) * background.a * background.b);
@@ -125,7 +125,7 @@
/// Convert a [input] color to a gray scaled color and store it in [result].
static void toGrayscale(Vector4 input, Vector4 result) {
- final double value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
+ final value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
result
..r = value
@@ -139,7 +139,7 @@
/// the default value is 2.2.
static void linearToGamma(Vector4 linearColor, Vector4 gammaColor,
[double gamma = 2.2]) {
- final double exponent = 1.0 / gamma;
+ final exponent = 1.0 / gamma;
gammaColor
..r = math.pow(linearColor.r, exponent).toDouble()
@@ -163,11 +163,11 @@
/// Convert [rgbColor] from rgb color model to the hue, saturation, and value
/// (HSV) color model and store it in [hsvColor].
static void rgbToHsv(Vector4 rgbColor, Vector4 hsvColor) {
- final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
- final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
- final double d = max - min;
- final double v = max;
- final double s = max == 0.0 ? 0.0 : d / max;
+ final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
+ final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
+ final d = max - min;
+ final v = max;
+ final s = max == 0.0 ? 0.0 : d / max;
var h = 0.0;
if (max != min) {
@@ -189,11 +189,11 @@
/// Convert [hsvColor] from hue, saturation, and value (HSV) color model to
/// the RGB color model and store it in [rgbColor].
static void hsvToRgb(Vector4 hsvColor, Vector4 rgbColor) {
- final int i = (hsvColor.x * 6.0).floor();
- final double f = hsvColor.x * 6.0 - i.toDouble();
- final double p = hsvColor.z * (1.0 - hsvColor.y);
- final double q = hsvColor.z * (1.0 - f * hsvColor.y);
- final double t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y);
+ final i = (hsvColor.x * 6.0).floor();
+ final f = hsvColor.x * 6.0 - i.toDouble();
+ final p = hsvColor.z * (1.0 - hsvColor.y);
+ final q = hsvColor.z * (1.0 - f * hsvColor.y);
+ final t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y);
switch (i % 6) {
case 0:
@@ -220,14 +220,14 @@
/// Convert [rgbColor] from rgb color model to the hue, saturation, and
/// lightness (HSL) color model and store it in [hslColor].
static void rgbToHsl(Vector4 rgbColor, Vector4 hslColor) {
- final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
- final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
- final double l = (max + min) / 2.0;
+ final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b);
+ final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b);
+ final l = (max + min) / 2.0;
var h = 0.0;
var s = 0.0;
if (max != min) {
- final double d = max - min;
+ final d = max - min;
s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min);
@@ -252,14 +252,14 @@
if (hslColor.y == 0.0) {
rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a);
} else {
- final double q = hslColor.z < 0.5
+ final q = hslColor.z < 0.5
? hslColor.z * (1.0 + hslColor.y)
: hslColor.z + hslColor.y - hslColor.z * hslColor.y;
- final double p = 2.0 * hslColor.z - q;
+ final p = 2.0 * hslColor.z - q;
- final double r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0);
- final double g = _hueToRgb(p, q, hslColor.x);
- final double b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0);
+ final r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0);
+ final g = _hueToRgb(p, q, hslColor.x);
+ final b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0);
rgbColor.setValues(r, g, b, hslColor.a);
}
diff --git a/lib/src/vector_math_64/error_helpers.dart b/lib/src/vector_math_64/error_helpers.dart
index b1a43fa..6cc4293 100644
--- a/lib/src/vector_math_64/error_helpers.dart
+++ b/lib/src/vector_math_64/error_helpers.dart
@@ -9,7 +9,7 @@
/// be any vector, matrix, or quaternion.
double relativeError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- final double diff = (calculated - correct).abs().toDouble();
+ final diff = (calculated - correct).abs().toDouble();
return diff / correct;
}
// ignore: return_of_invalid_type
@@ -21,7 +21,7 @@
/// be any vector, matrix, or quaternion.
double absoluteError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- final double diff = (calculated - correct).abs().toDouble();
+ final diff = (calculated - correct).abs().toDouble();
return diff;
}
// ignore: return_of_invalid_type
diff --git a/lib/src/vector_math_64/frustum.dart b/lib/src/vector_math_64/frustum.dart
index 7f51467..3b8fac6 100644
--- a/lib/src/vector_math_64/frustum.dart
+++ b/lib/src/vector_math_64/frustum.dart
@@ -58,11 +58,11 @@
/// Set this from [matrix].
void setFromMatrix(Matrix4 matrix) {
- final Float64List me = matrix.storage;
- final double me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
- final double me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
- final double me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
- final double me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
+ final me = matrix.storage;
+ final me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
+ final me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
+ final me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
+ final me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
_plane0
..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12)
@@ -144,8 +144,8 @@
/// Check if this intersects with [sphere].
bool intersectsWithSphere(Sphere sphere) {
- final double negativeRadius = -sphere.radius;
- final Vector3 center = sphere.center;
+ final negativeRadius = -sphere.radius;
+ final center = sphere.center;
if (_plane0.distanceToVector3(center) < negativeRadius) {
return false;
@@ -222,11 +222,11 @@
outNz = aabb.min.z;
}
- final double d1 = plane._normal.x * outPx +
+ final d1 = plane._normal.x * outPx +
plane._normal.y * outPy +
plane._normal.z * outPz +
plane.constant;
- final double d2 = plane._normal.x * outNx +
+ final d2 = plane._normal.x * outNx +
plane._normal.y * outNy +
plane._normal.z * outNz +
plane.constant;
diff --git a/lib/src/vector_math_64/intersection_result.dart b/lib/src/vector_math_64/intersection_result.dart
index 081cbf2..ff5a583 100644
--- a/lib/src/vector_math_64/intersection_result.dart
+++ b/lib/src/vector_math_64/intersection_result.dart
@@ -5,13 +5,13 @@
/// Defines a result of an intersection test.
class IntersectionResult {
- double _depth;
+ double? _depth;
/// The penetration depth of the intersection.
- double get depth => _depth;
+ double? get depth => _depth;
/// The [axis] of the intersection.
- final Vector3 axis = Vector3.zero();
+ final axis = Vector3.zero();
IntersectionResult();
}
diff --git a/lib/src/vector_math_64/matrix2.dart b/lib/src/vector_math_64/matrix2.dart
index 9d8c785..c5e9074 100644
--- a/lib/src/vector_math_64/matrix2.dart
+++ b/lib/src/vector_math_64/matrix2.dart
@@ -14,12 +14,12 @@
/// Solve [A] * [x] = [b].
static void solve(Matrix2 A, Vector2 x, Vector2 b) {
- final double a11 = A.entry(0, 0);
- final double a12 = A.entry(0, 1);
- final double a21 = A.entry(1, 0);
- final double a22 = A.entry(1, 1);
- final double bx = b.x;
- final double by = b.y;
+ final a11 = A.entry(0, 0);
+ final a12 = A.entry(0, 1);
+ final a21 = A.entry(1, 0);
+ final a22 = A.entry(1, 1);
+ final bx = b.x;
+ final by = b.y;
var det = a11 * a22 - a12 * a21;
if (det != 0.0) {
@@ -88,8 +88,8 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector2 arg0, Vector2 arg1) {
- final Float64List arg0Storage = arg0._v2storage;
- final Float64List arg1Storage = arg1._v2storage;
+ final arg0Storage = arg0._v2storage;
+ final arg1Storage = arg1._v2storage;
_m2storage[0] = arg0Storage[0];
_m2storage[1] = arg0Storage[1];
_m2storage[2] = arg1Storage[0];
@@ -98,7 +98,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix2 arg) {
- final Float64List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
_m2storage[3] = argStorage[3];
_m2storage[2] = argStorage[2];
_m2storage[1] = argStorage[1];
@@ -107,8 +107,8 @@
/// Set this to the outer product of [u] and [v].
void setOuter(Vector2 u, Vector2 v) {
- final Float64List uStorage = u._v2storage;
- final Float64List vStorage = v._v2storage;
+ final uStorage = u._v2storage;
+ final vStorage = v._v2storage;
_m2storage[0] = uStorage[0] * vStorage[0];
_m2storage[1] = uStorage[0] * vStorage[1];
_m2storage[2] = uStorage[1] * vStorage[0];
@@ -123,7 +123,7 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_m2storage[0] = argStorage[0];
_m2storage[3] = argStorage[1];
}
@@ -145,7 +145,7 @@
/// Check if two matrices are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Matrix2) &&
(_m2storage[0] == other._m2storage[0]) &&
(_m2storage[1] == other._m2storage[1]) &&
@@ -169,15 +169,15 @@
/// Sets [row] of the matrix to values in [arg]
void setRow(int row, Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_m2storage[index(row, 0)] = argStorage[0];
_m2storage[index(row, 1)] = argStorage[1];
}
/// Gets the [row] of the matrix
Vector2 getRow(int row) {
- final Vector2 r = Vector2.zero();
- final Float64List rStorage = r._v2storage;
+ final r = Vector2.zero();
+ final rStorage = r._v2storage;
rStorage[0] = _m2storage[index(row, 0)];
rStorage[1] = _m2storage[index(row, 1)];
return r;
@@ -185,17 +185,17 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
- final int entry = column * 2;
+ final argStorage = arg._v2storage;
+ final entry = column * 2;
_m2storage[entry + 1] = argStorage[1];
_m2storage[entry + 0] = argStorage[0];
}
/// Gets the [column] of the matrix
Vector2 getColumn(int column) {
- final Vector2 r = Vector2.zero();
- final int entry = column * 2;
- final Float64List rStorage = r._v2storage;
+ final r = Vector2.zero();
+ final entry = column * 2;
+ final rStorage = r._v2storage;
rStorage[1] = _m2storage[entry + 1];
rStorage[0] = _m2storage[entry + 0];
return r;
@@ -206,7 +206,7 @@
/// Copy this into [arg].
Matrix2 copyInto(Matrix2 arg) {
- final Float64List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
argStorage[0] = _m2storage[0];
argStorage[1] = _m2storage[1];
argStorage[2] = _m2storage[2];
@@ -257,15 +257,15 @@
Matrix2 transposed() => clone()..transpose();
void transpose() {
- final double temp = _m2storage[2];
+ final temp = _m2storage[2];
_m2storage[2] = _m2storage[1];
_m2storage[1] = temp;
}
/// Returns the component wise absolute value of this.
Matrix2 absolute() {
- final Matrix2 r = Matrix2.zero();
- final Float64List rStorage = r._m2storage;
+ final r = Matrix2.zero();
+ final rStorage = r._m2storage;
rStorage[0] = _m2storage[0].abs();
rStorage[1] = _m2storage[1].abs();
rStorage[2] = _m2storage[2].abs();
@@ -279,13 +279,13 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector2 v) {
- final Float64List vStorage = v._v2storage;
+ final vStorage = v._v2storage;
return _m2storage[i] * vStorage[0] + _m2storage[2 + i] * vStorage[1];
}
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector2 v) {
- final Float64List vStorage = v._v2storage;
+ final vStorage = v._v2storage;
return _m2storage[j * 2] * vStorage[0] +
_m2storage[(j * 2) + 1] * vStorage[1];
}
@@ -318,28 +318,28 @@
/// Returns relative error between this and [correct]
double relativeError(Matrix2 correct) {
- final Matrix2 diff = correct - this;
- final double correctNorm = correct.infinityNorm();
- final double diff_norm = diff.infinityNorm();
+ final diff = correct - this;
+ final correctNorm = correct.infinityNorm();
+ final diff_norm = diff.infinityNorm();
return diff_norm / correctNorm;
}
/// Returns absolute error between this and [correct]
double absoluteError(Matrix2 correct) {
- final double this_norm = infinityNorm();
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = (this_norm - correct_norm).abs();
+ final this_norm = infinityNorm();
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Invert the matrix. Returns the determinant.
double invert() {
- final double det = determinant();
+ final det = determinant();
if (det == 0.0) {
return 0.0;
}
- final double invDet = 1.0 / det;
- final double temp = _m2storage[0];
+ final invDet = 1.0 / det;
+ final temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * invDet;
_m2storage[1] = -_m2storage[1] * invDet;
_m2storage[2] = -_m2storage[2] * invDet;
@@ -349,13 +349,13 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix2 arg) {
- final double det = arg.determinant();
+ final det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final double invDet = 1.0 / det;
- final Float64List argStorage = arg._m2storage;
+ final invDet = 1.0 / det;
+ final argStorage = arg._m2storage;
_m2storage[0] = argStorage[3] * invDet;
_m2storage[1] = -argStorage[1] * invDet;
_m2storage[2] = -argStorage[2] * invDet;
@@ -365,8 +365,8 @@
/// Turns the matrix into a rotation of [radians]
void setRotation(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m2storage[0] = c;
_m2storage[1] = s;
_m2storage[2] = -s;
@@ -375,7 +375,7 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- final double temp = _m2storage[0];
+ final temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * scale;
_m2storage[2] = -_m2storage[2] * scale;
_m2storage[1] = -_m2storage[1] * scale;
@@ -395,7 +395,7 @@
/// Add [o] to this.
void add(Matrix2 o) {
- final Float64List oStorage = o._m2storage;
+ final oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] + oStorage[0];
_m2storage[1] = _m2storage[1] + oStorage[1];
_m2storage[2] = _m2storage[2] + oStorage[2];
@@ -404,7 +404,7 @@
/// Subtract [o] from this.
void sub(Matrix2 o) {
- final Float64List oStorage = o._m2storage;
+ final oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] - oStorage[0];
_m2storage[1] = _m2storage[1] - oStorage[1];
_m2storage[2] = _m2storage[2] - oStorage[2];
@@ -421,15 +421,15 @@
/// Multiply this with [arg] and store it in this.
void multiply(Matrix2 arg) {
- final double m00 = _m2storage[0];
- final double m01 = _m2storage[2];
- final double m10 = _m2storage[1];
- final double m11 = _m2storage[3];
- final Float64List argStorage = arg._m2storage;
- final double n00 = argStorage[0];
- final double n01 = argStorage[2];
- final double n10 = argStorage[1];
- final double n11 = argStorage[3];
+ final m00 = _m2storage[0];
+ final m01 = _m2storage[2];
+ final m10 = _m2storage[1];
+ final m11 = _m2storage[3];
+ final argStorage = arg._m2storage;
+ final n00 = argStorage[0];
+ final n01 = argStorage[2];
+ final n10 = argStorage[1];
+ final n11 = argStorage[3];
_m2storage[0] = (m00 * n00) + (m01 * n10);
_m2storage[2] = (m00 * n01) + (m01 * n11);
_m2storage[1] = (m10 * n00) + (m11 * n10);
@@ -441,11 +441,11 @@
/// Multiply a transposed this with [arg].
void transposeMultiply(Matrix2 arg) {
- final double m00 = _m2storage[0];
- final double m01 = _m2storage[1];
- final double m10 = _m2storage[2];
- final double m11 = _m2storage[3];
- final Float64List argStorage = arg._m2storage;
+ final m00 = _m2storage[0];
+ final m01 = _m2storage[1];
+ final m10 = _m2storage[2];
+ final m11 = _m2storage[3];
+ final argStorage = arg._m2storage;
_m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]);
_m2storage[2] = (m00 * argStorage[2]) + (m01 * argStorage[3]);
_m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[1]);
@@ -454,11 +454,11 @@
/// Multiply this with a transposed [arg].
void multiplyTranspose(Matrix2 arg) {
- final double m00 = _m2storage[0];
- final double m01 = _m2storage[2];
- final double m10 = _m2storage[1];
- final double m11 = _m2storage[3];
- final Float64List argStorage = arg._m2storage;
+ final m00 = _m2storage[0];
+ final m01 = _m2storage[2];
+ final m10 = _m2storage[1];
+ final m11 = _m2storage[3];
+ final argStorage = arg._m2storage;
_m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[2]);
_m2storage[2] = (m00 * argStorage[1]) + (m01 * argStorage[3]);
_m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[2]);
@@ -468,11 +468,9 @@
/// Transform [arg] of type [Vector2] using the transformation defined by
/// this.
Vector2 transform(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
- final double x =
- (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]);
- final double y =
- (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]);
+ final argStorage = arg._v2storage;
+ final x = (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]);
+ final y = (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]);
argStorage[0] = x;
argStorage[1] = y;
return arg;
@@ -481,7 +479,7 @@
/// Transform a copy of [arg] of type [Vector2] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector2 transformed(Vector2 arg, [Vector2 out]) {
+ Vector2 transformed(Vector2 arg, [Vector2? out]) {
if (out == null) {
out = Vector2.copy(arg);
} else {
@@ -492,7 +490,7 @@
/// Copies this into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
array[i + 3] = _m2storage[3];
array[i + 2] = _m2storage[2];
array[i + 1] = _m2storage[1];
@@ -501,7 +499,7 @@
/// Copies elements from [array] into this starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
_m2storage[3] = array[i + 3];
_m2storage[2] = array[i + 2];
_m2storage[1] = array[i + 1];
diff --git a/lib/src/vector_math_64/matrix3.dart b/lib/src/vector_math_64/matrix3.dart
index 117dc8b..79c8e0e 100644
--- a/lib/src/vector_math_64/matrix3.dart
+++ b/lib/src/vector_math_64/matrix3.dart
@@ -14,12 +14,12 @@
/// Solve [A] * [x] = [b].
static void solve2(Matrix3 A, Vector2 x, Vector2 b) {
- final double a11 = A.entry(0, 0);
- final double a12 = A.entry(0, 1);
- final double a21 = A.entry(1, 0);
- final double a22 = A.entry(1, 1);
- final double bx = b.x - A.storage[6];
- final double by = b.y - A.storage[7];
+ final a11 = A.entry(0, 0);
+ final a12 = A.entry(0, 1);
+ final a21 = A.entry(1, 0);
+ final a22 = A.entry(1, 1);
+ final bx = b.x - A.storage[6];
+ final by = b.y - A.storage[7];
var det = a11 * a22 - a12 * a21;
if (det != 0.0) {
@@ -33,15 +33,15 @@
/// Solve [A] * [x] = [b].
static void solve(Matrix3 A, Vector3 x, Vector3 b) {
- final double A0x = A.entry(0, 0);
- final double A0y = A.entry(1, 0);
- final double A0z = A.entry(2, 0);
- final double A1x = A.entry(0, 1);
- final double A1y = A.entry(1, 1);
- final double A1z = A.entry(2, 1);
- final double A2x = A.entry(0, 2);
- final double A2y = A.entry(1, 2);
- final double A2z = A.entry(2, 2);
+ final A0x = A.entry(0, 0);
+ final A0y = A.entry(1, 0);
+ final A0z = A.entry(2, 0);
+ final A1x = A.entry(0, 1);
+ final A1y = A.entry(1, 1);
+ final A1z = A.entry(2, 1);
+ final A2x = A.entry(0, 2);
+ final A2y = A.entry(1, 2);
+ final A2z = A.entry(2, 2);
double rx, ry, rz;
double det;
@@ -57,21 +57,21 @@
}
// b dot [Column1 cross Column 2]
- final double x_ = det * (b.x * rx + b.y * ry + b.z * rz);
+ final x_ = det * (b.x * rx + b.y * ry + b.z * rz);
// Column2 cross b
rx = -(A2y * b.z - A2z * b.y);
ry = -(A2z * b.x - A2x * b.z);
rz = -(A2x * b.y - A2y * b.x);
// Column0 dot -[Column2 cross b (Column3)]
- final double y_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final y_ = det * (A0x * rx + A0y * ry + A0z * rz);
// b cross Column 1
rx = -(b.y * A1z - b.z * A1y);
ry = -(b.z * A1x - b.x * A1z);
rz = -(b.x * A1y - b.y * A1x);
// Column0 dot -[b cross Column 1]
- final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final z_ = det * (A0x * rx + A0y * ry + A0z * rz);
x
..x = x_
@@ -153,9 +153,9 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector3 arg0, Vector3 arg1, Vector3 arg2) {
- final Float64List arg0Storage = arg0._v3storage;
- final Float64List arg1Storage = arg1._v3storage;
- final Float64List arg2Storage = arg2._v3storage;
+ final arg0Storage = arg0._v3storage;
+ final arg1Storage = arg1._v3storage;
+ final arg2Storage = arg2._v3storage;
_m3storage[0] = arg0Storage[0];
_m3storage[1] = arg0Storage[1];
_m3storage[2] = arg0Storage[2];
@@ -169,7 +169,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix3 arg) {
- final Float64List argStorage = arg._m3storage;
+ final argStorage = arg._m3storage;
_m3storage[8] = argStorage[8];
_m3storage[7] = argStorage[7];
_m3storage[6] = argStorage[6];
@@ -183,8 +183,8 @@
/// Set this to the outer product of [u] and [v].
void setOuter(Vector3 u, Vector3 v) {
- final Float64List uStorage = u._v3storage;
- final Float64List vStorage = v._v3storage;
+ final uStorage = u._v3storage;
+ final vStorage = v._v3storage;
_m3storage[0] = uStorage[0] * vStorage[0];
_m3storage[1] = uStorage[0] * vStorage[1];
_m3storage[2] = uStorage[0] * vStorage[2];
@@ -212,7 +212,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final Float64List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
_m3storage[0] = argStorage[0];
_m3storage[1] = argStorage[1];
_m3storage[3] = argStorage[2];
@@ -236,7 +236,7 @@
/// Check if two matrices are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Matrix3) &&
(_m3storage[0] == other._m3storage[0]) &&
(_m3storage[1] == other._m3storage[1]) &&
@@ -271,7 +271,7 @@
/// Assigns the [row] of to [arg].
void setRow(int row, Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_m3storage[index(row, 0)] = argStorage[0];
_m3storage[index(row, 1)] = argStorage[1];
_m3storage[index(row, 2)] = argStorage[2];
@@ -279,8 +279,8 @@
/// Gets the [row] of the matrix
Vector3 getRow(int row) {
- final Vector3 r = Vector3.zero();
- final Float64List rStorage = r._v3storage;
+ final r = Vector3.zero();
+ final rStorage = r._v3storage;
rStorage[0] = _m3storage[index(row, 0)];
rStorage[1] = _m3storage[index(row, 1)];
rStorage[2] = _m3storage[index(row, 2)];
@@ -289,8 +289,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
- final int entry = column * 3;
+ final argStorage = arg._v3storage;
+ final entry = column * 3;
_m3storage[entry + 2] = argStorage[2];
_m3storage[entry + 1] = argStorage[1];
_m3storage[entry + 0] = argStorage[0];
@@ -298,9 +298,9 @@
/// Gets the [column] of the matrix
Vector3 getColumn(int column) {
- final Vector3 r = Vector3.zero();
- final Float64List rStorage = r._v3storage;
- final int entry = column * 3;
+ final r = Vector3.zero();
+ final rStorage = r._v3storage;
+ final entry = column * 3;
rStorage[2] = _m3storage[entry + 2];
rStorage[1] = _m3storage[entry + 1];
rStorage[0] = _m3storage[entry + 0];
@@ -312,7 +312,7 @@
/// Copy this into [arg].
Matrix3 copyInto(Matrix3 arg) {
- final Float64List argStorage = arg._m3storage;
+ final argStorage = arg._m3storage;
argStorage[0] = _m3storage[0];
argStorage[1] = _m3storage[1];
argStorage[2] = _m3storage[2];
@@ -393,8 +393,8 @@
/// Returns the component wise absolute value of this.
Matrix3 absolute() {
- final Matrix3 r = Matrix3.zero();
- final Float64List rStorage = r._m3storage;
+ final r = Matrix3.zero();
+ final rStorage = r._m3storage;
rStorage[0] = _m3storage[0].abs();
rStorage[1] = _m3storage[1].abs();
rStorage[2] = _m3storage[2].abs();
@@ -409,18 +409,18 @@
/// Returns the determinant of this matrix.
double determinant() {
- final double x = _m3storage[0] *
+ final x = _m3storage[0] *
((_m3storage[4] * _m3storage[8]) - (_m3storage[5] * _m3storage[7]));
- final double y = _m3storage[1] *
+ final y = _m3storage[1] *
((_m3storage[3] * _m3storage[8]) - (_m3storage[5] * _m3storage[6]));
- final double z = _m3storage[2] *
+ final z = _m3storage[2] *
((_m3storage[3] * _m3storage[7]) - (_m3storage[4] * _m3storage[6]));
return x - y + z;
}
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector3 v) {
- final Float64List vStorage = v._v3storage;
+ final vStorage = v._v3storage;
return _m3storage[i] * vStorage[0] +
_m3storage[3 + i] * vStorage[1] +
_m3storage[6 + i] * vStorage[2];
@@ -428,7 +428,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector3 v) {
- final Float64List vStorage = v._v3storage;
+ final vStorage = v._v3storage;
return _m3storage[j * 3] * vStorage[0] +
_m3storage[j * 3 + 1] * vStorage[1] +
_m3storage[j * 3 + 2] * vStorage[2];
@@ -473,17 +473,17 @@
/// Returns relative error between this and [correct]
double relativeError(Matrix3 correct) {
- final Matrix3 diff = correct - this;
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = diff.infinityNorm();
+ final diff = correct - this;
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between this and [correct]
double absoluteError(Matrix3 correct) {
- final double this_norm = infinityNorm();
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = (this_norm - correct_norm).abs();
+ final this_norm = infinityNorm();
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
@@ -492,30 +492,30 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix3 arg) {
- final double det = arg.determinant();
+ final det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final double invDet = 1.0 / det;
- final Float64List argStorage = arg._m3storage;
- final double ix = invDet *
+ final invDet = 1.0 / det;
+ final argStorage = arg._m3storage;
+ final ix = invDet *
(argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]);
- final double iy = invDet *
+ final iy = invDet *
(argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]);
- final double iz = invDet *
+ final iz = invDet *
(argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]);
- final double jx = invDet *
+ final jx = invDet *
(argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]);
- final double jy = invDet *
+ final jy = invDet *
(argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]);
- final double jz = invDet *
+ final jz = invDet *
(argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]);
- final double kx = invDet *
+ final kx = invDet *
(argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]);
- final double ky = invDet *
+ final ky = invDet *
(argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]);
- final double kz = invDet *
+ final kz = invDet *
(argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]);
_m3storage[0] = ix;
_m3storage[1] = iy;
@@ -537,8 +537,8 @@
/// Turns the matrix into a rotation of [radians] around X
void setRotationX(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m3storage[0] = 1.0;
_m3storage[1] = 0.0;
_m3storage[2] = 0.0;
@@ -552,8 +552,8 @@
/// Turns the matrix into a rotation of [radians] around Y
void setRotationY(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = 0.0;
_m3storage[2] = s;
@@ -567,8 +567,8 @@
/// Turns the matrix into a rotation of [radians] around Z
void setRotationZ(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = s;
_m3storage[2] = 0.0;
@@ -582,15 +582,15 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[3];
- final double m02 = _m3storage[6];
- final double m10 = _m3storage[1];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[7];
- final double m20 = _m3storage[2];
- final double m21 = _m3storage[5];
- final double m22 = _m3storage[8];
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[3];
+ final m02 = _m3storage[6];
+ final m10 = _m3storage[1];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[7];
+ final m20 = _m3storage[2];
+ final m21 = _m3storage[5];
+ final m22 = _m3storage[8];
_m3storage[0] = (m11 * m22 - m12 * m21) * scale;
_m3storage[1] = (m12 * m20 - m10 * m22) * scale;
_m3storage[2] = (m10 * m21 - m11 * m20) * scale;
@@ -606,19 +606,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- final double m00 = _m3storage[0].abs();
- final double m01 = _m3storage[3].abs();
- final double m02 = _m3storage[6].abs();
- final double m10 = _m3storage[1].abs();
- final double m11 = _m3storage[4].abs();
- final double m12 = _m3storage[7].abs();
- final double m20 = _m3storage[2].abs();
- final double m21 = _m3storage[5].abs();
- final double m22 = _m3storage[8].abs();
- final Float64List argStorage = arg._v3storage;
- final double x = argStorage[0];
- final double y = argStorage[1];
- final double z = argStorage[2];
+ final m00 = _m3storage[0].abs();
+ final m01 = _m3storage[3].abs();
+ final m02 = _m3storage[6].abs();
+ final m10 = _m3storage[1].abs();
+ final m11 = _m3storage[4].abs();
+ final m12 = _m3storage[7].abs();
+ final m20 = _m3storage[2].abs();
+ final m21 = _m3storage[5].abs();
+ final m22 = _m3storage[8].abs();
+ final argStorage = arg._v3storage;
+ final x = argStorage[0];
+ final y = argStorage[1];
+ final z = argStorage[2];
argStorage[0] = x * m00 + y * m01 + z * m02;
argStorage[1] = x * m10 + y * m11 + z * m12;
argStorage[2] = x * m20 + y * m21 + z * m22;
@@ -629,13 +629,13 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector2 absoluteRotate2(Vector2 arg) {
- final double m00 = _m3storage[0].abs();
- final double m01 = _m3storage[3].abs();
- final double m10 = _m3storage[1].abs();
- final double m11 = _m3storage[4].abs();
- final Float64List argStorage = arg._v2storage;
- final double x = argStorage[0];
- final double y = argStorage[1];
+ final m00 = _m3storage[0].abs();
+ final m01 = _m3storage[3].abs();
+ final m10 = _m3storage[1].abs();
+ final m11 = _m3storage[4].abs();
+ final argStorage = arg._v2storage;
+ final x = argStorage[0];
+ final y = argStorage[1];
argStorage[0] = x * m00 + y * m01;
argStorage[1] = x * m10 + y * m11;
return arg;
@@ -643,11 +643,11 @@
/// Transforms [arg] with this.
Vector2 transform2(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
- final double x_ = (_m3storage[0] * argStorage[0]) +
+ final argStorage = arg._v2storage;
+ final x_ = (_m3storage[0] * argStorage[0]) +
(_m3storage[3] * argStorage[1]) +
_m3storage[6];
- final double y_ = (_m3storage[1] * argStorage[0]) +
+ final y_ = (_m3storage[1] * argStorage[0]) +
(_m3storage[4] * argStorage[1]) +
_m3storage[7];
argStorage[0] = x_;
@@ -673,7 +673,7 @@
/// Add [o] to this.
void add(Matrix3 o) {
- final Float64List oStorage = o._m3storage;
+ final oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] + oStorage[0];
_m3storage[1] = _m3storage[1] + oStorage[1];
_m3storage[2] = _m3storage[2] + oStorage[2];
@@ -687,7 +687,7 @@
/// Subtract [o] from this.
void sub(Matrix3 o) {
- final Float64List oStorage = o._m3storage;
+ final oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] - oStorage[0];
_m3storage[1] = _m3storage[1] - oStorage[1];
_m3storage[2] = _m3storage[2] - oStorage[2];
@@ -714,25 +714,25 @@
/// Multiply this by [arg].
void multiply(Matrix3 arg) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[3];
- final double m02 = _m3storage[6];
- final double m10 = _m3storage[1];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[7];
- final double m20 = _m3storage[2];
- final double m21 = _m3storage[5];
- final double m22 = _m3storage[8];
- final Float64List argStorage = arg._m3storage;
- final double n00 = argStorage[0];
- final double n01 = argStorage[3];
- final double n02 = argStorage[6];
- final double n10 = argStorage[1];
- final double n11 = argStorage[4];
- final double n12 = argStorage[7];
- final double n20 = argStorage[2];
- final double n21 = argStorage[5];
- final double n22 = argStorage[8];
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[3];
+ final m02 = _m3storage[6];
+ final m10 = _m3storage[1];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[7];
+ final m20 = _m3storage[2];
+ final m21 = _m3storage[5];
+ final m22 = _m3storage[8];
+ final argStorage = arg._m3storage;
+ final n00 = argStorage[0];
+ final n01 = argStorage[3];
+ final n02 = argStorage[6];
+ final n10 = argStorage[1];
+ final n11 = argStorage[4];
+ final n12 = argStorage[7];
+ final n20 = argStorage[2];
+ final n21 = argStorage[5];
+ final n22 = argStorage[8];
_m3storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20);
_m3storage[3] = (m00 * n01) + (m01 * n11) + (m02 * n21);
_m3storage[6] = (m00 * n02) + (m01 * n12) + (m02 * n22);
@@ -748,16 +748,16 @@
Matrix3 multiplied(Matrix3 arg) => clone()..multiply(arg);
void transposeMultiply(Matrix3 arg) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[1];
- final double m02 = _m3storage[2];
- final double m10 = _m3storage[3];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[5];
- final double m20 = _m3storage[6];
- final double m21 = _m3storage[7];
- final double m22 = _m3storage[8];
- final Float64List argStorage = arg._m3storage;
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[1];
+ final m02 = _m3storage[2];
+ final m10 = _m3storage[3];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[5];
+ final m20 = _m3storage[6];
+ final m21 = _m3storage[7];
+ final m22 = _m3storage[8];
+ final argStorage = arg._m3storage;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * argStorage[1]) + (m02 * argStorage[2]);
_m3storage[3] =
@@ -779,16 +779,16 @@
}
void multiplyTranspose(Matrix3 arg) {
- final double m00 = _m3storage[0];
- final double m01 = _m3storage[3];
- final double m02 = _m3storage[6];
- final double m10 = _m3storage[1];
- final double m11 = _m3storage[4];
- final double m12 = _m3storage[7];
- final double m20 = _m3storage[2];
- final double m21 = _m3storage[5];
- final double m22 = _m3storage[8];
- final Float64List argStorage = arg._m3storage;
+ final m00 = _m3storage[0];
+ final m01 = _m3storage[3];
+ final m02 = _m3storage[6];
+ final m10 = _m3storage[1];
+ final m11 = _m3storage[4];
+ final m12 = _m3storage[7];
+ final m20 = _m3storage[2];
+ final m21 = _m3storage[5];
+ final m22 = _m3storage[8];
+ final argStorage = arg._m3storage;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * argStorage[3]) + (m02 * argStorage[6]);
_m3storage[3] =
@@ -812,14 +812,14 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// this.
Vector3 transform(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
- final double x_ = (_m3storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m3storage[0] * argStorage[0]) +
(_m3storage[3] * argStorage[1]) +
(_m3storage[6] * argStorage[2]);
- final double y_ = (_m3storage[1] * argStorage[0]) +
+ final y_ = (_m3storage[1] * argStorage[0]) +
(_m3storage[4] * argStorage[1]) +
(_m3storage[7] * argStorage[2]);
- final double z_ = (_m3storage[2] * argStorage[0]) +
+ final z_ = (_m3storage[2] * argStorage[0]) +
(_m3storage[5] * argStorage[1]) +
(_m3storage[8] * argStorage[2]);
arg
@@ -832,7 +832,7 @@
/// Transform a copy of [arg] of type [Vector3] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector3 transformed(Vector3 arg, [Vector3 out]) {
+ Vector3 transformed(Vector3 arg, [Vector3? out]) {
if (out == null) {
out = Vector3.copy(arg);
} else {
@@ -843,7 +843,7 @@
/// Copies this into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
array[i + 8] = _m3storage[8];
array[i + 7] = _m3storage[7];
array[i + 6] = _m3storage[6];
@@ -857,7 +857,7 @@
/// Copies elements from [array] into this starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
_m3storage[8] = array[i + 8];
_m3storage[7] = array[i + 7];
_m3storage[6] = array[i + 6];
@@ -871,8 +871,8 @@
/// Multiply this to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final Vector3 v = Vector3.array(array, j)..applyMatrix3(this);
+ for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final v = Vector3.array(array, j)..applyMatrix3(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -882,23 +882,23 @@
}
Vector3 get right {
- final double x = _m3storage[0];
- final double y = _m3storage[1];
- final double z = _m3storage[2];
+ final x = _m3storage[0];
+ final y = _m3storage[1];
+ final z = _m3storage[2];
return Vector3(x, y, z);
}
Vector3 get up {
- final double x = _m3storage[3];
- final double y = _m3storage[4];
- final double z = _m3storage[5];
+ final x = _m3storage[3];
+ final y = _m3storage[4];
+ final z = _m3storage[5];
return Vector3(x, y, z);
}
Vector3 get forward {
- final double x = _m3storage[6];
- final double y = _m3storage[7];
- final double z = _m3storage[8];
+ final x = _m3storage[6];
+ final y = _m3storage[7];
+ final z = _m3storage[8];
return Vector3(x, y, z);
}
diff --git a/lib/src/vector_math_64/matrix4.dart b/lib/src/vector_math_64/matrix4.dart
index 838d6d9..77f227a 100644
--- a/lib/src/vector_math_64/matrix4.dart
+++ b/lib/src/vector_math_64/matrix4.dart
@@ -14,12 +14,12 @@
/// Solve [A] * [x] = [b].
static void solve2(Matrix4 A, Vector2 x, Vector2 b) {
- final double a11 = A.entry(0, 0);
- final double a12 = A.entry(0, 1);
- final double a21 = A.entry(1, 0);
- final double a22 = A.entry(1, 1);
- final double bx = b.x - A._m4storage[8];
- final double by = b.y - A._m4storage[9];
+ final a11 = A.entry(0, 0);
+ final a12 = A.entry(0, 1);
+ final a21 = A.entry(1, 0);
+ final a22 = A.entry(1, 1);
+ final bx = b.x - A._m4storage[8];
+ final by = b.y - A._m4storage[9];
var det = a11 * a22 - a12 * a21;
if (det != 0.0) {
@@ -33,18 +33,18 @@
/// Solve [A] * [x] = [b].
static void solve3(Matrix4 A, Vector3 x, Vector3 b) {
- final double A0x = A.entry(0, 0);
- final double A0y = A.entry(1, 0);
- final double A0z = A.entry(2, 0);
- final double A1x = A.entry(0, 1);
- final double A1y = A.entry(1, 1);
- final double A1z = A.entry(2, 1);
- final double A2x = A.entry(0, 2);
- final double A2y = A.entry(1, 2);
- final double A2z = A.entry(2, 2);
- final double bx = b.x - A._m4storage[12];
- final double by = b.y - A._m4storage[13];
- final double bz = b.z - A._m4storage[14];
+ final A0x = A.entry(0, 0);
+ final A0y = A.entry(1, 0);
+ final A0z = A.entry(2, 0);
+ final A1x = A.entry(0, 1);
+ final A1y = A.entry(1, 1);
+ final A1z = A.entry(2, 1);
+ final A2x = A.entry(0, 2);
+ final A2y = A.entry(1, 2);
+ final A2z = A.entry(2, 2);
+ final bx = b.x - A._m4storage[12];
+ final by = b.y - A._m4storage[13];
+ final bz = b.z - A._m4storage[14];
double rx, ry, rz;
double det;
@@ -60,21 +60,21 @@
}
// b dot [Column1 cross Column 2]
- final double x_ = det * (bx * rx + by * ry + bz * rz);
+ final x_ = det * (bx * rx + by * ry + bz * rz);
// Column2 cross b
rx = -(A2y * bz - A2z * by);
ry = -(A2z * bx - A2x * bz);
rz = -(A2x * by - A2y * bx);
// Column0 dot -[Column2 cross b (Column3)]
- final double y_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final y_ = det * (A0x * rx + A0y * ry + A0z * rz);
// b cross Column 1
rx = -(by * A1z - bz * A1y);
ry = -(bz * A1x - bx * A1z);
rz = -(bx * A1y - by * A1x);
// Column0 dot -[b cross Column 1]
- final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
+ final z_ = det * (A0x * rx + A0y * ry + A0z * rz);
x
..x = x_
@@ -84,39 +84,39 @@
/// Solve [A] * [x] = [b].
static void solve(Matrix4 A, Vector4 x, Vector4 b) {
- final double a00 = A._m4storage[0];
- final double a01 = A._m4storage[1];
- final double a02 = A._m4storage[2];
- final double a03 = A._m4storage[3];
- final double a10 = A._m4storage[4];
- final double a11 = A._m4storage[5];
- final double a12 = A._m4storage[6];
- final double a13 = A._m4storage[7];
- final double a20 = A._m4storage[8];
- final double a21 = A._m4storage[9];
- final double a22 = A._m4storage[10];
- final double a23 = A._m4storage[11];
- final double a30 = A._m4storage[12];
- final double a31 = A._m4storage[13];
- final double a32 = A._m4storage[14];
- final double a33 = A._m4storage[15];
- final double b00 = a00 * a11 - a01 * a10;
- final double b01 = a00 * a12 - a02 * a10;
- final double b02 = a00 * a13 - a03 * a10;
- final double b03 = a01 * a12 - a02 * a11;
- final double b04 = a01 * a13 - a03 * a11;
- final double b05 = a02 * a13 - a03 * a12;
- final double b06 = a20 * a31 - a21 * a30;
- final double b07 = a20 * a32 - a22 * a30;
- final double b08 = a20 * a33 - a23 * a30;
- final double b09 = a21 * a32 - a22 * a31;
- final double b10 = a21 * a33 - a23 * a31;
- final double b11 = a22 * a33 - a23 * a32;
+ final a00 = A._m4storage[0];
+ final a01 = A._m4storage[1];
+ final a02 = A._m4storage[2];
+ final a03 = A._m4storage[3];
+ final a10 = A._m4storage[4];
+ final a11 = A._m4storage[5];
+ final a12 = A._m4storage[6];
+ final a13 = A._m4storage[7];
+ final a20 = A._m4storage[8];
+ final a21 = A._m4storage[9];
+ final a22 = A._m4storage[10];
+ final a23 = A._m4storage[11];
+ final a30 = A._m4storage[12];
+ final a31 = A._m4storage[13];
+ final a32 = A._m4storage[14];
+ final a33 = A._m4storage[15];
+ final b00 = a00 * a11 - a01 * a10;
+ final b01 = a00 * a12 - a02 * a10;
+ final b02 = a00 * a13 - a03 * a10;
+ final b03 = a01 * a12 - a02 * a11;
+ final b04 = a01 * a13 - a03 * a11;
+ final b05 = a02 * a13 - a03 * a12;
+ final b06 = a20 * a31 - a21 * a30;
+ final b07 = a20 * a32 - a22 * a30;
+ final b08 = a20 * a33 - a23 * a30;
+ final b09 = a21 * a32 - a22 * a31;
+ final b10 = a21 * a33 - a23 * a31;
+ final b11 = a22 * a33 - a23 * a32;
- final double bX = b.storage[0];
- final double bY = b.storage[1];
- final double bZ = b.storage[2];
- final double bW = b.storage[3];
+ final bX = b.storage[0];
+ final bY = b.storage[1];
+ final bZ = b.storage[2];
+ final bW = b.storage[3];
var det =
b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
@@ -150,9 +150,9 @@
/// Returns a matrix that is the inverse of [other] if [other] is invertible,
/// otherwise `null`.
- static Matrix4 tryInvert(Matrix4 other) {
- final Matrix4 r = Matrix4.zero();
- final double determinant = r.copyInverse(other);
+ static Matrix4? tryInvert(Matrix4 other) {
+ final r = Matrix4.zero();
+ final determinant = r.copyInverse(other);
if (determinant == 0.0) {
return null;
}
@@ -231,8 +231,8 @@
/// Constructs a matrix that is the inverse of [other].
factory Matrix4.inverted(Matrix4 other) {
- final Matrix4 r = Matrix4.zero();
- final double determinant = r.copyInverse(other);
+ final r = Matrix4.zero();
+ final determinant = r.copyInverse(other);
if (determinant == 0.0) {
throw ArgumentError.value(other, 'other', 'Matrix cannot be inverted');
}
@@ -275,9 +275,9 @@
/// Scale matrix.
factory Matrix4.diagonal3(Vector3 scale) {
- final Matrix4 m = Matrix4.zero();
- final Float64List mStorage = m._m4storage;
- final Float64List scaleStorage = scale._v3storage;
+ final m = Matrix4.zero();
+ final mStorage = m._m4storage;
+ final scaleStorage = scale._v3storage;
mStorage[15] = 1.0;
mStorage[10] = scaleStorage[2];
mStorage[5] = scaleStorage[1];
@@ -295,21 +295,21 @@
/// Skew matrix around X axis
factory Matrix4.skewX(double alpha) {
- final Matrix4 m = Matrix4.identity();
+ final m = Matrix4.identity();
m._m4storage[4] = math.tan(alpha);
return m;
}
/// Skew matrix around Y axis.
factory Matrix4.skewY(double beta) {
- final Matrix4 m = Matrix4.identity();
+ final m = Matrix4.identity();
m._m4storage[1] = math.tan(beta);
return m;
}
/// Skew matrix around X axis (alpha) and Y axis (beta).
factory Matrix4.skew(double alpha, double beta) {
- final Matrix4 m = Matrix4.identity();
+ final m = Matrix4.identity();
m._m4storage[1] = math.tan(beta);
m._m4storage[4] = math.tan(alpha);
return m;
@@ -375,10 +375,10 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) {
- final Float64List arg0Storage = arg0._v4storage;
- final Float64List arg1Storage = arg1._v4storage;
- final Float64List arg2Storage = arg2._v4storage;
- final Float64List arg3Storage = arg3._v4storage;
+ final arg0Storage = arg0._v4storage;
+ final arg1Storage = arg1._v4storage;
+ final arg2Storage = arg2._v4storage;
+ final arg3Storage = arg3._v4storage;
_m4storage[0] = arg0Storage[0];
_m4storage[1] = arg0Storage[1];
_m4storage[2] = arg0Storage[2];
@@ -399,7 +399,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix4 arg) {
- final Float64List argStorage = arg._m4storage;
+ final argStorage = arg._m4storage;
_m4storage[15] = argStorage[15];
_m4storage[14] = argStorage[14];
_m4storage[13] = argStorage[13];
@@ -420,25 +420,25 @@
/// Sets the matrix from translation [arg0] and rotation [arg1].
void setFromTranslationRotation(Vector3 arg0, Quaternion arg1) {
- final Float64List arg1Storage = arg1._qStorage;
- final double x = arg1Storage[0];
- final double y = arg1Storage[1];
- final double z = arg1Storage[2];
- final double w = arg1Storage[3];
- final double x2 = x + x;
- final double y2 = y + y;
- final double z2 = z + z;
- final double xx = x * x2;
- final double xy = x * y2;
- final double xz = x * z2;
- final double yy = y * y2;
- final double yz = y * z2;
- final double zz = z * z2;
- final double wx = w * x2;
- final double wy = w * y2;
- final double wz = w * z2;
+ final arg1Storage = arg1._qStorage;
+ final x = arg1Storage[0];
+ final y = arg1Storage[1];
+ final z = arg1Storage[2];
+ final w = arg1Storage[3];
+ final x2 = x + x;
+ final y2 = y + y;
+ final z2 = z + z;
+ final xx = x * x2;
+ final xy = x * y2;
+ final xz = x * z2;
+ final yy = y * y2;
+ final yz = y * z2;
+ final zz = z * z2;
+ final wx = w * x2;
+ final wy = w * y2;
+ final wz = w * z2;
- final Float64List arg0Storage = arg0._v3storage;
+ final arg0Storage = arg0._v3storage;
_m4storage[0] = 1.0 - (yy + zz);
_m4storage[1] = xy + wz;
_m4storage[2] = xz - wy;
@@ -466,7 +466,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final Float64List argStorage = arg._m2storage;
+ final argStorage = arg._m2storage;
_m4storage[0] = argStorage[0];
_m4storage[1] = argStorage[1];
_m4storage[4] = argStorage[2];
@@ -475,7 +475,7 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_m4storage[0] = argStorage[0];
_m4storage[5] = argStorage[1];
_m4storage[10] = argStorage[2];
@@ -483,8 +483,8 @@
}
void setOuter(Vector4 u, Vector4 v) {
- final Float64List uStorage = u._v4storage;
- final Float64List vStorage = v._v4storage;
+ final uStorage = u._v4storage;
+ final vStorage = v._v4storage;
_m4storage[0] = uStorage[0] * vStorage[0];
_m4storage[1] = uStorage[0] * vStorage[1];
_m4storage[2] = uStorage[0] * vStorage[2];
@@ -521,7 +521,7 @@
/// Check if two matrices are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Matrix4) &&
(_m4storage[0] == other._m4storage[0]) &&
(_m4storage[1] == other._m4storage[1]) &&
@@ -569,7 +569,7 @@
/// Assigns the [row] of the matrix [arg]
void setRow(int row, Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_m4storage[index(row, 0)] = argStorage[0];
_m4storage[index(row, 1)] = argStorage[1];
_m4storage[index(row, 2)] = argStorage[2];
@@ -578,8 +578,8 @@
/// Gets the [row] of the matrix
Vector4 getRow(int row) {
- final Vector4 r = Vector4.zero();
- final Float64List rStorage = r._v4storage;
+ final r = Vector4.zero();
+ final rStorage = r._v4storage;
rStorage[0] = _m4storage[index(row, 0)];
rStorage[1] = _m4storage[index(row, 1)];
rStorage[2] = _m4storage[index(row, 2)];
@@ -589,8 +589,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector4 arg) {
- final int entry = column * 4;
- final Float64List argStorage = arg._v4storage;
+ final entry = column * 4;
+ final argStorage = arg._v4storage;
_m4storage[entry + 3] = argStorage[3];
_m4storage[entry + 2] = argStorage[2];
_m4storage[entry + 1] = argStorage[1];
@@ -599,9 +599,9 @@
/// Gets the [column] of the matrix
Vector4 getColumn(int column) {
- final Vector4 r = Vector4.zero();
- final Float64List rStorage = r._v4storage;
- final int entry = column * 4;
+ final r = Vector4.zero();
+ final rStorage = r._v4storage;
+ final entry = column * 4;
rStorage[3] = _m4storage[entry + 3];
rStorage[2] = _m4storage[entry + 2];
rStorage[1] = _m4storage[entry + 1];
@@ -614,7 +614,7 @@
/// Copy into [arg].
Matrix4 copyInto(Matrix4 arg) {
- final Float64List argStorage = arg._m4storage;
+ final argStorage = arg._m4storage;
argStorage[0] = _m4storage[0];
argStorage[1] = _m4storage[1];
argStorage[2] = _m4storage[2];
@@ -665,7 +665,7 @@
double tx;
double ty;
double tz;
- final double tw = x is Vector4 ? x.w : 1.0;
+ final tw = x is Vector4 ? x.w : 1.0;
if (x is Vector3) {
tx = x.x;
ty = x.y;
@@ -678,20 +678,22 @@
tx = x;
ty = y;
tz = z;
+ } else {
+ throw UnimplementedError();
}
- final double t1 = _m4storage[0] * tx +
+ final t1 = _m4storage[0] * tx +
_m4storage[4] * ty +
_m4storage[8] * tz +
_m4storage[12] * tw;
- final double t2 = _m4storage[1] * tx +
+ final t2 = _m4storage[1] * tx +
_m4storage[5] * ty +
_m4storage[9] * tz +
_m4storage[13] * tw;
- final double t3 = _m4storage[2] * tx +
+ final t3 = _m4storage[2] * tx +
_m4storage[6] * ty +
_m4storage[10] * tz +
_m4storage[14] * tw;
- final double t4 = _m4storage[3] * tx +
+ final t4 = _m4storage[3] * tx +
_m4storage[7] * ty +
_m4storage[11] * tz +
_m4storage[15] * tw;
@@ -707,7 +709,7 @@
double tx;
double ty;
double tz;
- final double tw = x is Vector4 ? x.w : 1.0;
+ final tw = x is Vector4 ? x.w : 1.0;
if (x is Vector3) {
tx = x.x;
ty = x.y;
@@ -720,6 +722,8 @@
tx = x;
ty = y;
tz = z;
+ } else {
+ throw UnimplementedError();
}
// Column 1
@@ -749,46 +753,36 @@
/// Rotate this [angle] radians around [axis]
void rotate(Vector3 axis, double angle) {
- final double len = axis.length;
- final Float64List axisStorage = axis._v3storage;
- final double x = axisStorage[0] / len;
- final double y = axisStorage[1] / len;
- final double z = axisStorage[2] / len;
- final double c = math.cos(angle);
- final double s = math.sin(angle);
- final double C = 1.0 - c;
- final double m11 = x * x * C + c;
- final double m12 = x * y * C - z * s;
- final double m13 = x * z * C + y * s;
- final double m21 = y * x * C + z * s;
- final double m22 = y * y * C + c;
- final double m23 = y * z * C - x * s;
- final double m31 = z * x * C - y * s;
- final double m32 = z * y * C + x * s;
- final double m33 = z * z * C + c;
- final double t1 =
- _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31;
- final double t2 =
- _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31;
- final double t3 =
- _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31;
- final double t4 =
- _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31;
- final double t5 =
- _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32;
- final double t6 =
- _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32;
- final double t7 =
- _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32;
- final double t8 =
- _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32;
- final double t9 =
- _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33;
- final double t10 =
- _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33;
- final double t11 =
+ final len = axis.length;
+ final axisStorage = axis._v3storage;
+ final x = axisStorage[0] / len;
+ final y = axisStorage[1] / len;
+ final z = axisStorage[2] / len;
+ final c = math.cos(angle);
+ final s = math.sin(angle);
+ final C = 1.0 - c;
+ final m11 = x * x * C + c;
+ final m12 = x * y * C - z * s;
+ final m13 = x * z * C + y * s;
+ final m21 = y * x * C + z * s;
+ final m22 = y * y * C + c;
+ final m23 = y * z * C - x * s;
+ final m31 = z * x * C - y * s;
+ final m32 = z * y * C + x * s;
+ final m33 = z * z * C + c;
+ final t1 = _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31;
+ final t2 = _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31;
+ final t3 = _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31;
+ final t4 = _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31;
+ final t5 = _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32;
+ final t6 = _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32;
+ final t7 = _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32;
+ final t8 = _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32;
+ final t9 = _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33;
+ final t10 = _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33;
+ final t11 =
_m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33;
- final double t12 =
+ final t12 =
_m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33;
_m4storage[0] = t1;
_m4storage[1] = t2;
@@ -806,16 +800,16 @@
/// Rotate this [angle] radians around X
void rotateX(double angle) {
- final double cosAngle = math.cos(angle);
- final double sinAngle = math.sin(angle);
- final double t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle;
- final double t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle;
- final double t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle;
- final double t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle;
- final double t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle;
- final double t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle;
- final double t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle;
- final double t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle;
+ final cosAngle = math.cos(angle);
+ final sinAngle = math.sin(angle);
+ final t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle;
+ final t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle;
+ final t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle;
+ final t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle;
+ final t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle;
+ final t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle;
+ final t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle;
+ final t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle;
_m4storage[4] = t1;
_m4storage[5] = t2;
_m4storage[6] = t3;
@@ -828,16 +822,16 @@
/// Rotate this matrix [angle] radians around Y
void rotateY(double angle) {
- final double cosAngle = math.cos(angle);
- final double sinAngle = math.sin(angle);
- final double t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle;
- final double t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle;
- final double t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle;
- final double t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle;
- final double t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle;
- final double t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle;
- final double t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle;
- final double t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle;
+ final cosAngle = math.cos(angle);
+ final sinAngle = math.sin(angle);
+ final t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle;
+ final t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle;
+ final t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle;
+ final t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle;
+ final t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle;
+ final t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle;
+ final t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle;
+ final t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -850,16 +844,16 @@
/// Rotate this matrix [angle] radians around Z
void rotateZ(double angle) {
- final double cosAngle = math.cos(angle);
- final double sinAngle = math.sin(angle);
- final double t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle;
- final double t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle;
- final double t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle;
- final double t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle;
- final double t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle;
- final double t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle;
- final double t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle;
- final double t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle;
+ final cosAngle = math.cos(angle);
+ final sinAngle = math.sin(angle);
+ final t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle;
+ final t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle;
+ final t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle;
+ final t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle;
+ final t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle;
+ final t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle;
+ final t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle;
+ final t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -871,11 +865,11 @@
}
/// Scale this matrix by a [Vector3], [Vector4], or x,y,z
- void scale(dynamic x, [double y, double z]) {
+ void scale(dynamic x, [double? y, double? z]) {
double sx;
double sy;
double sz;
- final double sw = x is Vector4 ? x.w : 1.0;
+ final sw = x is Vector4 ? x.w : 1.0;
if (x is Vector3) {
sx = x.x;
sy = x.y;
@@ -888,6 +882,8 @@
sx = x;
sy = y ?? x;
sz = z ?? x;
+ } else {
+ throw UnimplementedError();
}
_m4storage[0] *= sx;
_m4storage[1] *= sx;
@@ -909,7 +905,7 @@
/// Create a copy of this scaled by a [Vector3], [Vector4] or [x],[y], and
/// [z].
- Matrix4 scaled(dynamic x, [double y, double z]) => clone()..scale(x, y, z);
+ Matrix4 scaled(dynamic x, [double? y, double? z]) => clone()..scale(x, y, z);
/// Zeros this.
void setZero() {
@@ -978,8 +974,8 @@
/// Returns the component wise absolute value of this.
Matrix4 absolute() {
- final Matrix4 r = Matrix4.zero();
- final Float64List rStorage = r._m4storage;
+ final r = Matrix4.zero();
+ final rStorage = r._m4storage;
rStorage[0] = _m4storage[0].abs();
rStorage[1] = _m4storage[1].abs();
rStorage[2] = _m4storage[2].abs();
@@ -1001,28 +997,28 @@
/// Returns the determinant of this matrix.
double determinant() {
- final double det2_01_01 =
+ final det2_01_01 =
_m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4];
- final double det2_01_02 =
+ final det2_01_02 =
_m4storage[0] * _m4storage[6] - _m4storage[2] * _m4storage[4];
- final double det2_01_03 =
+ final det2_01_03 =
_m4storage[0] * _m4storage[7] - _m4storage[3] * _m4storage[4];
- final double det2_01_12 =
+ final det2_01_12 =
_m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5];
- final double det2_01_13 =
+ final det2_01_13 =
_m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5];
- final double det2_01_23 =
+ final det2_01_23 =
_m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6];
- final double det3_201_012 = _m4storage[8] * det2_01_12 -
+ final det3_201_012 = _m4storage[8] * det2_01_12 -
_m4storage[9] * det2_01_02 +
_m4storage[10] * det2_01_01;
- final double det3_201_013 = _m4storage[8] * det2_01_13 -
+ final det3_201_013 = _m4storage[8] * det2_01_13 -
_m4storage[9] * det2_01_03 +
_m4storage[11] * det2_01_01;
- final double det3_201_023 = _m4storage[8] * det2_01_23 -
+ final det3_201_023 = _m4storage[8] * det2_01_23 -
_m4storage[10] * det2_01_03 +
_m4storage[11] * det2_01_02;
- final double det3_201_123 = _m4storage[9] * det2_01_23 -
+ final det3_201_123 = _m4storage[9] * det2_01_23 -
_m4storage[10] * det2_01_13 +
_m4storage[11] * det2_01_12;
return -det3_201_123 * _m4storage[12] +
@@ -1033,7 +1029,7 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector4 v) {
- final Float64List vStorage = v._v4storage;
+ final vStorage = v._v4storage;
return _m4storage[i] * vStorage[0] +
_m4storage[4 + i] * vStorage[1] +
_m4storage[8 + i] * vStorage[2] +
@@ -1042,7 +1038,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector4 v) {
- final Float64List vStorage = v._v4storage;
+ final vStorage = v._v4storage;
return _m4storage[j * 4] * vStorage[0] +
_m4storage[j * 4 + 1] * vStorage[1] +
_m4storage[j * 4 + 2] * vStorage[2] +
@@ -1100,34 +1096,34 @@
/// Returns relative error between this and [correct]
double relativeError(Matrix4 correct) {
- final Matrix4 diff = correct - this;
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = diff.infinityNorm();
+ final diff = correct - this;
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between this and [correct]
double absoluteError(Matrix4 correct) {
- final double this_norm = infinityNorm();
- final double correct_norm = correct.infinityNorm();
- final double diff_norm = (this_norm - correct_norm).abs();
+ final this_norm = infinityNorm();
+ final correct_norm = correct.infinityNorm();
+ final diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Returns the translation vector from this homogeneous transformation matrix.
Vector3 getTranslation() {
- final double z = _m4storage[14];
- final double y = _m4storage[13];
- final double x = _m4storage[12];
+ final z = _m4storage[14];
+ final y = _m4storage[13];
+ final x = _m4storage[12];
return Vector3(x, y, z);
}
/// Sets the translation vector in this homogeneous transformation matrix.
void setTranslation(Vector3 t) {
- final Float64List tStorage = t._v3storage;
- final double z = tStorage[2];
- final double y = tStorage[1];
- final double x = tStorage[0];
+ final tStorage = t._v3storage;
+ final z = tStorage[2];
+ final y = tStorage[1];
+ final x = tStorage[0];
_m4storage[14] = z;
_m4storage[13] = y;
_m4storage[12] = x;
@@ -1142,7 +1138,7 @@
/// Returns the rotation matrix from this homogeneous transformation matrix.
Matrix3 getRotation() {
- final Matrix3 r = Matrix3.zero();
+ final r = Matrix3.zero();
copyRotation(r);
return r;
}
@@ -1150,7 +1146,7 @@
/// Copies the rotation matrix from this homogeneous transformation matrix
/// into [rotation].
void copyRotation(Matrix3 rotation) {
- final Float64List rStorage = rotation._m3storage;
+ final rStorage = rotation._m3storage;
rStorage[0] = _m4storage[0];
rStorage[1] = _m4storage[1];
rStorage[2] = _m4storage[2];
@@ -1164,7 +1160,7 @@
/// Sets the rotation matrix in this homogeneous transformation matrix.
void setRotation(Matrix3 r) {
- final Float64List rStorage = r._m3storage;
+ final rStorage = r._m3storage;
_m4storage[0] = rStorage[0];
_m4storage[1] = rStorage[1];
_m4storage[2] = rStorage[2];
@@ -1182,13 +1178,13 @@
/// Returns the max scale value of the 3 axes.
double getMaxScaleOnAxis() {
- final double scaleXSq = _m4storage[0] * _m4storage[0] +
+ final scaleXSq = _m4storage[0] * _m4storage[0] +
_m4storage[1] * _m4storage[1] +
_m4storage[2] * _m4storage[2];
- final double scaleYSq = _m4storage[4] * _m4storage[4] +
+ final scaleYSq = _m4storage[4] * _m4storage[4] +
_m4storage[5] * _m4storage[5] +
_m4storage[6] * _m4storage[6];
- final double scaleZSq = _m4storage[8] * _m4storage[8] +
+ final scaleZSq = _m4storage[8] * _m4storage[8] +
_m4storage[9] * _m4storage[9] +
_m4storage[10] * _m4storage[10];
return math.sqrt(math.max(scaleXSq, math.max(scaleYSq, scaleZSq)));
@@ -1222,42 +1218,42 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix4 arg) {
- final Float64List argStorage = arg._m4storage;
- final double a00 = argStorage[0];
- final double a01 = argStorage[1];
- final double a02 = argStorage[2];
- final double a03 = argStorage[3];
- final double a10 = argStorage[4];
- final double a11 = argStorage[5];
- final double a12 = argStorage[6];
- final double a13 = argStorage[7];
- final double a20 = argStorage[8];
- final double a21 = argStorage[9];
- final double a22 = argStorage[10];
- final double a23 = argStorage[11];
- final double a30 = argStorage[12];
- final double a31 = argStorage[13];
- final double a32 = argStorage[14];
- final double a33 = argStorage[15];
- final double b00 = a00 * a11 - a01 * a10;
- final double b01 = a00 * a12 - a02 * a10;
- final double b02 = a00 * a13 - a03 * a10;
- final double b03 = a01 * a12 - a02 * a11;
- final double b04 = a01 * a13 - a03 * a11;
- final double b05 = a02 * a13 - a03 * a12;
- final double b06 = a20 * a31 - a21 * a30;
- final double b07 = a20 * a32 - a22 * a30;
- final double b08 = a20 * a33 - a23 * a30;
- final double b09 = a21 * a32 - a22 * a31;
- final double b10 = a21 * a33 - a23 * a31;
- final double b11 = a22 * a33 - a23 * a32;
- final double det =
+ final argStorage = arg._m4storage;
+ final a00 = argStorage[0];
+ final a01 = argStorage[1];
+ final a02 = argStorage[2];
+ final a03 = argStorage[3];
+ final a10 = argStorage[4];
+ final a11 = argStorage[5];
+ final a12 = argStorage[6];
+ final a13 = argStorage[7];
+ final a20 = argStorage[8];
+ final a21 = argStorage[9];
+ final a22 = argStorage[10];
+ final a23 = argStorage[11];
+ final a30 = argStorage[12];
+ final a31 = argStorage[13];
+ final a32 = argStorage[14];
+ final a33 = argStorage[15];
+ final b00 = a00 * a11 - a01 * a10;
+ final b01 = a00 * a12 - a02 * a10;
+ final b02 = a00 * a13 - a03 * a10;
+ final b03 = a01 * a12 - a02 * a11;
+ final b04 = a01 * a13 - a03 * a11;
+ final b05 = a02 * a13 - a03 * a12;
+ final b06 = a20 * a31 - a21 * a30;
+ final b07 = a20 * a32 - a22 * a30;
+ final b08 = a20 * a33 - a23 * a30;
+ final b09 = a21 * a32 - a22 * a31;
+ final b10 = a21 * a33 - a23 * a31;
+ final b11 = a22 * a33 - a23 * a32;
+ final det =
b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final double invDet = 1.0 / det;
+ final invDet = 1.0 / det;
_m4storage[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
_m4storage[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
_m4storage[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet;
@@ -1278,11 +1274,11 @@
}
double invertRotation() {
- final double det = determinant();
+ final det = determinant();
if (det == 0.0) {
return 0.0;
}
- final double invDet = 1.0 / det;
+ final invDet = 1.0 / det;
double ix;
double iy;
double iz;
@@ -1324,8 +1320,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around X
void setRotationX(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m4storage[0] = 1.0;
_m4storage[1] = 0.0;
_m4storage[2] = 0.0;
@@ -1342,8 +1338,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Y
void setRotationY(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = 0.0;
_m4storage[2] = -s;
@@ -1360,8 +1356,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Z
void setRotationZ(double radians) {
- final double c = math.cos(radians);
- final double s = math.sin(radians);
+ final c = math.cos(radians);
+ final s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = s;
_m4storage[2] = 0.0;
@@ -1379,22 +1375,22 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
// Adapted from code by Richard Carling.
- final double a1 = _m4storage[0];
- final double b1 = _m4storage[4];
- final double c1 = _m4storage[8];
- final double d1 = _m4storage[12];
- final double a2 = _m4storage[1];
- final double b2 = _m4storage[5];
- final double c2 = _m4storage[9];
- final double d2 = _m4storage[13];
- final double a3 = _m4storage[2];
- final double b3 = _m4storage[6];
- final double c3 = _m4storage[10];
- final double d3 = _m4storage[14];
- final double a4 = _m4storage[3];
- final double b4 = _m4storage[7];
- final double c4 = _m4storage[11];
- final double d4 = _m4storage[15];
+ final a1 = _m4storage[0];
+ final b1 = _m4storage[4];
+ final c1 = _m4storage[8];
+ final d1 = _m4storage[12];
+ final a2 = _m4storage[1];
+ final b2 = _m4storage[5];
+ final c2 = _m4storage[9];
+ final d2 = _m4storage[13];
+ final a3 = _m4storage[2];
+ final b3 = _m4storage[6];
+ final c3 = _m4storage[10];
+ final d3 = _m4storage[14];
+ final a4 = _m4storage[3];
+ final b4 = _m4storage[7];
+ final c4 = _m4storage[11];
+ final d4 = _m4storage[15];
_m4storage[0] = (b2 * (c3 * d4 - c4 * d3) -
c2 * (b3 * d4 - b4 * d3) +
d2 * (b3 * c4 - b4 * c3)) *
@@ -1465,19 +1461,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- final double m00 = _m4storage[0].abs();
- final double m01 = _m4storage[4].abs();
- final double m02 = _m4storage[8].abs();
- final double m10 = _m4storage[1].abs();
- final double m11 = _m4storage[5].abs();
- final double m12 = _m4storage[9].abs();
- final double m20 = _m4storage[2].abs();
- final double m21 = _m4storage[6].abs();
- final double m22 = _m4storage[10].abs();
- final Float64List argStorage = arg._v3storage;
- final double x = argStorage[0];
- final double y = argStorage[1];
- final double z = argStorage[2];
+ final m00 = _m4storage[0].abs();
+ final m01 = _m4storage[4].abs();
+ final m02 = _m4storage[8].abs();
+ final m10 = _m4storage[1].abs();
+ final m11 = _m4storage[5].abs();
+ final m12 = _m4storage[9].abs();
+ final m20 = _m4storage[2].abs();
+ final m21 = _m4storage[6].abs();
+ final m22 = _m4storage[10].abs();
+ final argStorage = arg._v3storage;
+ final x = argStorage[0];
+ final y = argStorage[1];
+ final z = argStorage[2];
argStorage[0] = x * m00 + y * m01 + z * m02 + 0.0 * 0.0;
argStorage[1] = x * m10 + y * m11 + z * m12 + 0.0 * 0.0;
argStorage[2] = x * m20 + y * m21 + z * m22 + 0.0 * 0.0;
@@ -1486,7 +1482,7 @@
/// Adds [o] to this.
void add(Matrix4 o) {
- final Float64List oStorage = o._m4storage;
+ final oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] + oStorage[0];
_m4storage[1] = _m4storage[1] + oStorage[1];
_m4storage[2] = _m4storage[2] + oStorage[2];
@@ -1507,7 +1503,7 @@
/// Subtracts [o] from this.
void sub(Matrix4 o) {
- final Float64List oStorage = o._m4storage;
+ final oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] - oStorage[0];
_m4storage[1] = _m4storage[1] - oStorage[1];
_m4storage[2] = _m4storage[2] - oStorage[2];
@@ -1548,39 +1544,39 @@
/// Multiply this by [arg].
void multiply(Matrix4 arg) {
- final double m00 = _m4storage[0];
- final double m01 = _m4storage[4];
- final double m02 = _m4storage[8];
- final double m03 = _m4storage[12];
- final double m10 = _m4storage[1];
- final double m11 = _m4storage[5];
- final double m12 = _m4storage[9];
- final double m13 = _m4storage[13];
- final double m20 = _m4storage[2];
- final double m21 = _m4storage[6];
- final double m22 = _m4storage[10];
- final double m23 = _m4storage[14];
- final double m30 = _m4storage[3];
- final double m31 = _m4storage[7];
- final double m32 = _m4storage[11];
- final double m33 = _m4storage[15];
- final Float64List argStorage = arg._m4storage;
- final double n00 = argStorage[0];
- final double n01 = argStorage[4];
- final double n02 = argStorage[8];
- final double n03 = argStorage[12];
- final double n10 = argStorage[1];
- final double n11 = argStorage[5];
- final double n12 = argStorage[9];
- final double n13 = argStorage[13];
- final double n20 = argStorage[2];
- final double n21 = argStorage[6];
- final double n22 = argStorage[10];
- final double n23 = argStorage[14];
- final double n30 = argStorage[3];
- final double n31 = argStorage[7];
- final double n32 = argStorage[11];
- final double n33 = argStorage[15];
+ final m00 = _m4storage[0];
+ final m01 = _m4storage[4];
+ final m02 = _m4storage[8];
+ final m03 = _m4storage[12];
+ final m10 = _m4storage[1];
+ final m11 = _m4storage[5];
+ final m12 = _m4storage[9];
+ final m13 = _m4storage[13];
+ final m20 = _m4storage[2];
+ final m21 = _m4storage[6];
+ final m22 = _m4storage[10];
+ final m23 = _m4storage[14];
+ final m30 = _m4storage[3];
+ final m31 = _m4storage[7];
+ final m32 = _m4storage[11];
+ final m33 = _m4storage[15];
+ final argStorage = arg._m4storage;
+ final n00 = argStorage[0];
+ final n01 = argStorage[4];
+ final n02 = argStorage[8];
+ final n03 = argStorage[12];
+ final n10 = argStorage[1];
+ final n11 = argStorage[5];
+ final n12 = argStorage[9];
+ final n13 = argStorage[13];
+ final n20 = argStorage[2];
+ final n21 = argStorage[6];
+ final n22 = argStorage[10];
+ final n23 = argStorage[14];
+ final n30 = argStorage[3];
+ final n31 = argStorage[7];
+ final n32 = argStorage[11];
+ final n33 = argStorage[15];
_m4storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30);
_m4storage[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31);
_m4storage[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32);
@@ -1604,23 +1600,23 @@
/// Multiply a transposed this with [arg].
void transposeMultiply(Matrix4 arg) {
- final double m00 = _m4storage[0];
- final double m01 = _m4storage[1];
- final double m02 = _m4storage[2];
- final double m03 = _m4storage[3];
- final double m10 = _m4storage[4];
- final double m11 = _m4storage[5];
- final double m12 = _m4storage[6];
- final double m13 = _m4storage[7];
- final double m20 = _m4storage[8];
- final double m21 = _m4storage[9];
- final double m22 = _m4storage[10];
- final double m23 = _m4storage[11];
- final double m30 = _m4storage[12];
- final double m31 = _m4storage[13];
- final double m32 = _m4storage[14];
- final double m33 = _m4storage[15];
- final Float64List argStorage = arg._m4storage;
+ final m00 = _m4storage[0];
+ final m01 = _m4storage[1];
+ final m02 = _m4storage[2];
+ final m03 = _m4storage[3];
+ final m10 = _m4storage[4];
+ final m11 = _m4storage[5];
+ final m12 = _m4storage[6];
+ final m13 = _m4storage[7];
+ final m20 = _m4storage[8];
+ final m21 = _m4storage[9];
+ final m22 = _m4storage[10];
+ final m23 = _m4storage[11];
+ final m30 = _m4storage[12];
+ final m31 = _m4storage[13];
+ final m32 = _m4storage[14];
+ final m33 = _m4storage[15];
+ final argStorage = arg._m4storage;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[1]) +
(m02 * argStorage[2]) +
@@ -1689,23 +1685,23 @@
/// Multiply this with a transposed [arg].
void multiplyTranspose(Matrix4 arg) {
- final double m00 = _m4storage[0];
- final double m01 = _m4storage[4];
- final double m02 = _m4storage[8];
- final double m03 = _m4storage[12];
- final double m10 = _m4storage[1];
- final double m11 = _m4storage[5];
- final double m12 = _m4storage[9];
- final double m13 = _m4storage[13];
- final double m20 = _m4storage[2];
- final double m21 = _m4storage[6];
- final double m22 = _m4storage[10];
- final double m23 = _m4storage[14];
- final double m30 = _m4storage[3];
- final double m31 = _m4storage[7];
- final double m32 = _m4storage[11];
- final double m33 = _m4storage[15];
- final Float64List argStorage = arg._m4storage;
+ final m00 = _m4storage[0];
+ final m01 = _m4storage[4];
+ final m02 = _m4storage[8];
+ final m03 = _m4storage[12];
+ final m10 = _m4storage[1];
+ final m11 = _m4storage[5];
+ final m12 = _m4storage[9];
+ final m13 = _m4storage[13];
+ final m20 = _m4storage[2];
+ final m21 = _m4storage[6];
+ final m22 = _m4storage[10];
+ final m23 = _m4storage[14];
+ final m30 = _m4storage[3];
+ final m31 = _m4storage[7];
+ final m32 = _m4storage[11];
+ final m33 = _m4storage[15];
+ final argStorage = arg._m4storage;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[4]) +
(m02 * argStorage[8]) +
@@ -1774,11 +1770,11 @@
/// Decomposes this into [translation], [rotation] and [scale] components.
void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) {
- final Vector3 v = _decomposeV ??= Vector3.zero();
+ final v = _decomposeV ??= Vector3.zero();
var sx = (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
- final double sy =
+ final sy =
(v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
- final double sz =
+ final sz =
(v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length;
if (determinant() < 0) {
@@ -1789,11 +1785,11 @@
translation._v3storage[1] = _m4storage[13];
translation._v3storage[2] = _m4storage[14];
- final double invSX = 1.0 / sx;
- final double invSY = 1.0 / sy;
- final double invSZ = 1.0 / sz;
+ final invSX = 1.0 / sx;
+ final invSY = 1.0 / sy;
+ final invSZ = 1.0 / sz;
- final Matrix4 m = _decomposeM ??= Matrix4.zero();
+ final m = _decomposeM ??= Matrix4.zero();
m.setFrom(this);
m._m4storage[0] *= invSX;
m._m4storage[1] *= invSX;
@@ -1805,7 +1801,7 @@
m._m4storage[9] *= invSZ;
m._m4storage[10] *= invSZ;
- final Matrix3 r = _decomposeR ??= Matrix3.zero();
+ final r = _decomposeR ??= Matrix3.zero();
m.copyRotation(r);
rotation.setFromRotation(r);
@@ -1814,20 +1810,20 @@
scale._v3storage[2] = sz;
}
- static Vector3 _decomposeV;
- static Matrix4 _decomposeM;
- static Matrix3 _decomposeR;
+ static Vector3? _decomposeV;
+ static Matrix4? _decomposeM;
+ static Matrix3? _decomposeR;
/// Rotate [arg] of type [Vector3] using the rotation defined by this.
Vector3 rotate3(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]);
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]);
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]);
argStorage[0] = x_;
@@ -1838,7 +1834,7 @@
/// Rotate a copy of [arg] of type [Vector3] using the rotation defined by
/// this. If a [out] parameter is supplied, the copy is stored in [out].
- Vector3 rotated3(Vector3 arg, [Vector3 out]) {
+ Vector3 rotated3(Vector3 arg, [Vector3? out]) {
if (out == null) {
out = Vector3.copy(arg);
} else {
@@ -1850,16 +1846,16 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// this.
Vector3 transform3(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
@@ -1872,7 +1868,7 @@
/// Transform a copy of [arg] of type [Vector3] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector3 transformed3(Vector3 arg, [Vector3 out]) {
+ Vector3 transformed3(Vector3 arg, [Vector3? out]) {
if (out == null) {
out = Vector3.copy(arg);
} else {
@@ -1884,20 +1880,20 @@
/// Transform [arg] of type [Vector4] using the transformation defined by
/// this.
Vector4 transform(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v4storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
(_m4storage[12] * argStorage[3]);
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
(_m4storage[13] * argStorage[3]);
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
(_m4storage[14] * argStorage[3]);
- final double w_ = (_m4storage[3] * argStorage[0]) +
+ final w_ = (_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
(_m4storage[15] * argStorage[3]);
@@ -1911,20 +1907,20 @@
/// Transform [arg] of type [Vector3] using the perspective transformation
/// defined by this.
Vector3 perspectiveTransform(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
- final double x_ = (_m4storage[0] * argStorage[0]) +
+ final argStorage = arg._v3storage;
+ final x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final double y_ = (_m4storage[1] * argStorage[0]) +
+ final y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final double z_ = (_m4storage[2] * argStorage[0]) +
+ final z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
- final double w_ = 1.0 /
+ final w_ = 1.0 /
((_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
@@ -1938,7 +1934,7 @@
/// Transform a copy of [arg] of type [Vector4] using the transformation
/// defined by this. If a [out] parameter is supplied, the copy is stored in
/// [out].
- Vector4 transformed(Vector4 arg, [Vector4 out]) {
+ Vector4 transformed(Vector4 arg, [Vector4? out]) {
if (out == null) {
out = Vector4.copy(arg);
} else {
@@ -1949,7 +1945,7 @@
/// Copies this into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
array[i + 15] = _m4storage[15];
array[i + 14] = _m4storage[14];
array[i + 13] = _m4storage[13];
@@ -1970,7 +1966,7 @@
/// Copies elements from [array] into this starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- final int i = offset;
+ final i = offset;
_m4storage[15] = array[i + 15];
_m4storage[14] = array[i + 14];
_m4storage[13] = array[i + 13];
@@ -1991,8 +1987,8 @@
/// Multiply this to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final Vector3 v = Vector3.array(array, j)..applyMatrix4(this);
+ for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final v = Vector3.array(array, j)..applyMatrix4(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -2002,23 +1998,23 @@
}
Vector3 get right {
- final double x = _m4storage[0];
- final double y = _m4storage[1];
- final double z = _m4storage[2];
+ final x = _m4storage[0];
+ final y = _m4storage[1];
+ final z = _m4storage[2];
return Vector3(x, y, z);
}
Vector3 get up {
- final double x = _m4storage[4];
- final double y = _m4storage[5];
- final double z = _m4storage[6];
+ final x = _m4storage[4];
+ final y = _m4storage[5];
+ final z = _m4storage[6];
return Vector3(x, y, z);
}
Vector3 get forward {
- final double x = _m4storage[8];
- final double y = _m4storage[9];
- final double z = _m4storage[10];
+ final x = _m4storage[8];
+ final y = _m4storage[9];
+ final z = _m4storage[10];
return Vector3(x, y, z);
}
diff --git a/lib/src/vector_math_64/obb3.dart b/lib/src/vector_math_64/obb3.dart
index 3cb5eca..62f15ea 100644
--- a/lib/src/vector_math_64/obb3.dart
+++ b/lib/src/vector_math_64/obb3.dart
@@ -169,7 +169,7 @@
/// Find the closest point [q] on the OBB to the point [p] and store it in [q].
void closestPointTo(Vector3 p, Vector3 q) {
- final Vector3 d = p - _center;
+ final d = p - _center;
q.setFrom(_center);
@@ -187,9 +187,9 @@
}
// Avoid allocating these instance on every call to intersectsWithObb3
- static final Matrix3 _r = Matrix3.zero();
- static final Matrix3 _absR = Matrix3.zero();
- static final Vector3 _t = Vector3.zero();
+ static final _r = Matrix3.zero();
+ static final _absR = Matrix3.zero();
+ static final _t = Vector3.zero();
/// Check for intersection between this and [other].
bool intersectsWithObb3(Obb3 other, [double epsilon = 1e-3]) {
@@ -339,12 +339,12 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Triangle _triangle = Triangle();
- static final Aabb3 _aabb3 = Aabb3();
- static final Vector3 _zeroVector = Vector3.zero();
+ static final _triangle = Triangle();
+ static final _aabb3 = Aabb3();
+ static final _zeroVector = Vector3.zero();
/// Return if this intersects with [other]
- bool intersectsWithTriangle(Triangle other, {IntersectionResult result}) {
+ bool intersectsWithTriangle(Triangle other, {IntersectionResult? result}) {
_triangle.copyFrom(other);
_triangle.point0
@@ -366,7 +366,7 @@
}
// Avoid allocating these instance on every call to intersectsWithVector3
- static final Vector3 _vector = Vector3.zero();
+ static final _vector = Vector3.zero();
/// Return if this intersects with [other]
bool intersectsWithVector3(Vector3 other) {
@@ -381,11 +381,11 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final Triangle _quadTriangle0 = Triangle();
- static final Triangle _quadTriangle1 = Triangle();
+ static final _quadTriangle0 = Triangle();
+ static final _quadTriangle1 = Triangle();
/// Return if this intersects with [other]
- bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
+ bool intersectsWithQuad(Quad other, {IntersectionResult? result}) {
other.copyTriangles(_quadTriangle0, _quadTriangle1);
return intersectsWithTriangle(_quadTriangle0, result: result) ||
diff --git a/lib/src/vector_math_64/opengl.dart b/lib/src/vector_math_64/opengl.dart
index b9160a0..66bccd5 100644
--- a/lib/src/vector_math_64/opengl.dart
+++ b/lib/src/vector_math_64/opengl.dart
@@ -56,10 +56,10 @@
/// [tx],[ty],[tz] specifies the position of the object.
void setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection,
Vector3 upDirection, double tx, double ty, double tz) {
- final Vector3 right = forwardDirection.cross(upDirection)..normalize();
- final Vector3 c1 = right;
- final Vector3 c2 = upDirection;
- final Vector3 c3 = -forwardDirection;
+ final right = forwardDirection.cross(upDirection)..normalize();
+ final c1 = right;
+ final c2 = upDirection;
+ final c3 = -forwardDirection;
modelMatrix.setValues(c1[0], c1[1], c1[2], 0.0, c2[0], c2[1], c2[2], 0.0,
c3[0], c3[1], c3[2], 0.0, tx, ty, tz, 1.0);
}
@@ -74,13 +74,13 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition,
Vector3 cameraFocusPosition, Vector3 upDirection) {
- final Vector3 z = (cameraPosition - cameraFocusPosition)..normalize();
- final Vector3 x = upDirection.cross(z)..normalize();
- final Vector3 y = z.cross(x)..normalize();
+ final z = (cameraPosition - cameraFocusPosition)..normalize();
+ final x = upDirection.cross(z)..normalize();
+ final y = z.cross(x)..normalize();
- final double rotatedEyeX = -x.dot(cameraPosition);
- final double rotatedEyeY = -y.dot(cameraPosition);
- final double rotatedEyeZ = -z.dot(cameraPosition);
+ final rotatedEyeX = -x.dot(cameraPosition);
+ final rotatedEyeY = -y.dot(cameraPosition);
+ final rotatedEyeZ = -z.dot(cameraPosition);
viewMatrix.setValues(x[0], y[0], z[0], 0.0, x[1], y[1], z[1], 0.0, x[2], y[2],
z[2], 0.0, rotatedEyeX, rotatedEyeY, rotatedEyeZ, 1.0);
@@ -93,7 +93,7 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
Matrix4 makeViewMatrix(
Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setViewMatrix(r, cameraPosition, cameraFocusPosition, upDirection);
return r;
}
@@ -110,9 +110,9 @@
/// (always positive).
void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians,
double aspectRatio, double zNear, double zFar) {
- final double height = math.tan(fovYRadians * 0.5);
- final double width = height * aspectRatio;
- final double near_minus_far = zNear - zFar;
+ final height = math.tan(fovYRadians * 0.5);
+ final width = height * aspectRatio;
+ final near_minus_far = zNear - zFar;
perspectiveMatrix
..setZero()
@@ -135,7 +135,7 @@
/// (always positive).
Matrix4 makePerspectiveMatrix(
double fovYRadians, double aspectRatio, double zNear, double zFar) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setPerspectiveMatrix(r, fovYRadians, aspectRatio, zNear, zFar);
return r;
}
@@ -149,8 +149,8 @@
/// (always positive).
void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians,
double aspectRatio, double zNear) {
- final double height = math.tan(fovYRadians * 0.5);
- final double width = height * aspectRatio;
+ final height = math.tan(fovYRadians * 0.5);
+ final width = height * aspectRatio;
infiniteMatrix
..setZero()
@@ -171,7 +171,7 @@
/// (always positive).
Matrix4 makeInfiniteMatrix(
double fovYRadians, double aspectRatio, double zNear) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setInfiniteMatrix(r, fovYRadians, aspectRatio, zNear);
return r;
}
@@ -186,10 +186,10 @@
/// planes.
void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right,
double bottom, double top, double near, double far) {
- final double two_near = 2.0 * near;
- final double right_minus_left = right - left;
- final double top_minus_bottom = top - bottom;
- final double far_minus_near = far - near;
+ final two_near = 2.0 * near;
+ final right_minus_left = right - left;
+ final top_minus_bottom = top - bottom;
+ final far_minus_near = far - near;
perspectiveMatrix
..setZero()
..setEntry(0, 0, two_near / right_minus_left)
@@ -211,7 +211,7 @@
/// planes.
Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top,
double near, double far) {
- final Matrix4 view = Matrix4.zero();
+ final view = Matrix4.zero();
setFrustumMatrix(view, left, right, bottom, top, near, far);
return view;
}
@@ -226,12 +226,12 @@
/// planes.
void setOrthographicMatrix(Matrix4 orthographicMatrix, double left,
double right, double bottom, double top, double near, double far) {
- final double rml = right - left;
- final double rpl = right + left;
- final double tmb = top - bottom;
- final double tpb = top + bottom;
- final double fmn = far - near;
- final double fpn = far + near;
+ final rml = right - left;
+ final rpl = right + left;
+ final tmb = top - bottom;
+ final tpb = top + bottom;
+ final fmn = far - near;
+ final fpn = far + near;
orthographicMatrix
..setZero()
..setEntry(0, 0, 2.0 / rml)
@@ -253,7 +253,7 @@
/// planes.
Matrix4 makeOrthographicMatrix(double left, double right, double bottom,
double top, double near, double far) {
- final Matrix4 r = Matrix4.zero();
+ final r = Matrix4.zero();
setOrthographicMatrix(r, left, right, bottom, top, near, far);
return r;
}
@@ -261,14 +261,13 @@
/// Returns a transformation matrix that transforms points onto
/// the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) {
- final Vector4 v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- final Matrix4 outer = Matrix4.outer(v, v);
+ final outer = Matrix4.outer(v, v);
var r = Matrix4.zero();
r = r - outer;
- final Vector3 scaledNormal =
- planeNormal.scaled(dot3(planePoint, planeNormal));
- final Vector4 T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
+ final scaledNormal = planeNormal.scaled(dot3(planePoint, planeNormal));
+ final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
@@ -277,14 +276,14 @@
/// Returns a transformation matrix that transforms points by reflecting
/// them through the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
- final Vector4 v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- final Matrix4 outer = Matrix4.outer(v, v)..scale(2.0);
+ final outer = Matrix4.outer(v, v)..scale(2.0);
var r = Matrix4.zero();
r = r - outer;
- final double scale = 2.0 * planePoint.dot(planeNormal);
- final Vector3 scaledNormal = planeNormal.scaled(scale);
- final Vector4 T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
+ final scale = 2.0 * planePoint.dot(planeNormal);
+ final scaledNormal = planeNormal.scaled(scale);
+ final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
@@ -334,17 +333,16 @@
}
// Copy camera matrix.
- final Matrix4 invertedCameraMatrix = Matrix4.copy(cameraMatrix);
+ final invertedCameraMatrix = Matrix4.copy(cameraMatrix);
// Invert the camera matrix.
invertedCameraMatrix.invert();
// Determine intersection point.
- final Vector4 v =
- Vector4(pickX.toDouble(), pickY.toDouble(), pickZ.toDouble(), 1.0);
+ final v = Vector4(pickX.toDouble(), pickY.toDouble(), pickZ.toDouble(), 1.0);
invertedCameraMatrix.transform(v);
if (v.w == 0.0) {
return false;
}
- final double invW = 1.0 / v.w;
+ final invW = 1.0 / v.w;
pickWorld
..x = v.x * invW
..y = v.y * invW
diff --git a/lib/src/vector_math_64/plane.dart b/lib/src/vector_math_64/plane.dart
index 82bdaab..f9295dc 100644
--- a/lib/src/vector_math_64/plane.dart
+++ b/lib/src/vector_math_64/plane.dart
@@ -11,21 +11,21 @@
/// Find the intersection point between the three planes [a], [b] and [c] and
/// copy it into [result].
static void intersection(Plane a, Plane b, Plane c, Vector3 result) {
- final Vector3 cross = Vector3.zero();
+ final cross = Vector3.zero();
b.normal.crossInto(c.normal, cross);
- final double f = -a.normal.dot(cross);
+ final f = -a.normal.dot(cross);
- final Vector3 v1 = cross.scaled(a.constant);
+ final v1 = cross.scaled(a.constant);
c.normal.crossInto(a.normal, cross);
- final Vector3 v2 = cross.scaled(b.constant);
+ final v2 = cross.scaled(b.constant);
a.normal.crossInto(b.normal, cross);
- final Vector3 v3 = cross.scaled(c.constant);
+ final v3 = cross.scaled(c.constant);
result
..x = (v1.x + v2.x + v3.x) / f
@@ -60,7 +60,7 @@
}
void normalize() {
- final double inverseLength = 1.0 / normal.length;
+ final inverseLength = 1.0 / normal.length;
_normal.scale(inverseLength);
constant *= inverseLength;
}
diff --git a/lib/src/vector_math_64/quad.dart b/lib/src/vector_math_64/quad.dart
index 0dc9d33..df160c4 100644
--- a/lib/src/vector_math_64/quad.dart
+++ b/lib/src/vector_math_64/quad.dart
@@ -54,7 +54,7 @@
/// Copy the normal of this into [normal].
void copyNormalInto(Vector3 normal) {
- final Vector3 v0 = _point0.clone()..sub(_point1);
+ final v0 = _point0.clone()..sub(_point1);
normal
..setFrom(_point2)
..sub(_point1)
diff --git a/lib/src/vector_math_64/quaternion.dart b/lib/src/vector_math_64/quaternion.dart
index d6508e6..8c8009c 100644
--- a/lib/src/vector_math_64/quaternion.dart
+++ b/lib/src/vector_math_64/quaternion.dart
@@ -92,7 +92,7 @@
/// Copy [source] into this.
void setFrom(Quaternion source) {
- final Float64List sourceStorage = source._qStorage;
+ final sourceStorage = source._qStorage;
_qStorage[0] = sourceStorage[0];
_qStorage[1] = sourceStorage[1];
_qStorage[2] = sourceStorage[2];
@@ -109,12 +109,12 @@
/// Set the quaternion with rotation of [radians] around [axis].
void setAxisAngle(Vector3 axis, double radians) {
- final double len = axis.length;
+ final len = axis.length;
if (len == 0.0) {
return;
}
- final double halfSin = math.sin(radians * 0.5) / len;
- final Float64List axisStorage = axis.storage;
+ final halfSin = math.sin(radians * 0.5) / len;
+ final axisStorage = axis.storage;
_qStorage[0] = axisStorage[0] * halfSin;
_qStorage[1] = axisStorage[1] * halfSin;
_qStorage[2] = axisStorage[2] * halfSin;
@@ -123,8 +123,8 @@
/// Set the quaternion with rotation from a rotation matrix [rotationMatrix].
void setFromRotation(Matrix3 rotationMatrix) {
- final Float64List rotationMatrixStorage = rotationMatrix.storage;
- final double trace = rotationMatrix.trace();
+ final rotationMatrixStorage = rotationMatrix.storage;
+ final trace = rotationMatrix.trace();
if (trace > 0.0) {
var s = math.sqrt(trace + 1.0);
_qStorage[3] = s * 0.5;
@@ -133,11 +133,11 @@
_qStorage[1] = (rotationMatrixStorage[6] - rotationMatrixStorage[2]) * s;
_qStorage[2] = (rotationMatrixStorage[1] - rotationMatrixStorage[3]) * s;
} else {
- final int i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
+ final i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1)
: (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0);
- final int j = (i + 1) % 3;
- final int k = (i + 2) % 3;
+ final j = (i + 1) % 3;
+ final k = (i + 2) % 3;
var s = math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] -
rotationMatrixStorage[rotationMatrix.index(j, j)] -
rotationMatrixStorage[rotationMatrix.index(k, k)] +
@@ -157,10 +157,10 @@
}
void setFromTwoVectors(Vector3 a, Vector3 b) {
- final Vector3 v1 = a.normalized();
- final Vector3 v2 = b.normalized();
+ final v1 = a.normalized();
+ final v2 = b.normalized();
- final double c = v1.dot(v2);
+ final c = v1.dot(v2);
var angle = math.acos(c);
var axis = v1.cross(v2);
@@ -192,15 +192,15 @@
void setRandom(math.Random rn) {
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// pg. 124-132.
- final double x0 = rn.nextDouble();
- final double r1 = math.sqrt(1.0 - x0);
- final double r2 = math.sqrt(x0);
- final double t1 = math.pi * 2.0 * rn.nextDouble();
- final double t2 = math.pi * 2.0 * rn.nextDouble();
- final double c1 = math.cos(t1);
- final double s1 = math.sin(t1);
- final double c2 = math.cos(t2);
- final double s2 = math.sin(t2);
+ final x0 = rn.nextDouble();
+ final r1 = math.sqrt(1.0 - x0);
+ final r2 = math.sqrt(x0);
+ final t1 = math.pi * 2.0 * rn.nextDouble();
+ final t2 = math.pi * 2.0 * rn.nextDouble();
+ final c1 = math.cos(t1);
+ final s1 = math.sin(t1);
+ final c2 = math.cos(t2);
+ final s2 = math.sin(t2);
_qStorage[0] = s1 * r1;
_qStorage[1] = c1 * r1;
_qStorage[2] = s2 * r2;
@@ -210,19 +210,19 @@
/// Set the quaternion to the time derivative of [q] with angular velocity
/// [omega].
void setDQ(Quaternion q, Vector3 omega) {
- final Float64List qStorage = q._qStorage;
- final Float64List omegaStorage = omega.storage;
- final double qx = qStorage[0];
- final double qy = qStorage[1];
- final double qz = qStorage[2];
- final double qw = qStorage[3];
- final double ox = omegaStorage[0];
- final double oy = omegaStorage[1];
- final double oz = omegaStorage[2];
- final double _x = ox * qw + oy * qz - oz * qy;
- final double _y = oy * qw + oz * qx - ox * qz;
- final double _z = oz * qw + ox * qy - oy * qx;
- final double _w = -ox * qx - oy * qy - oz * qz;
+ final qStorage = q._qStorage;
+ final omegaStorage = omega.storage;
+ final qx = qStorage[0];
+ final qy = qStorage[1];
+ final qz = qStorage[2];
+ final qw = qStorage[3];
+ final ox = omegaStorage[0];
+ final oy = omegaStorage[1];
+ final oz = omegaStorage[2];
+ final _x = ox * qw + oy * qz - oz * qy;
+ final _y = oy * qw + oz * qx - ox * qz;
+ final _z = oz * qw + ox * qy - oy * qx;
+ final _w = -ox * qx - oy * qy - oz * qz;
_qStorage[0] = _x * 0.5;
_qStorage[1] = _y * 0.5;
_qStorage[2] = _z * 0.5;
@@ -231,15 +231,15 @@
/// Set quaternion with rotation of [yaw], [pitch] and [roll].
void setEuler(double yaw, double pitch, double roll) {
- final double halfYaw = yaw * 0.5;
- final double halfPitch = pitch * 0.5;
- final double halfRoll = roll * 0.5;
- final double cosYaw = math.cos(halfYaw);
- final double sinYaw = math.sin(halfYaw);
- final double cosPitch = math.cos(halfPitch);
- final double sinPitch = math.sin(halfPitch);
- final double cosRoll = math.cos(halfRoll);
- final double sinRoll = math.sin(halfRoll);
+ final halfYaw = yaw * 0.5;
+ final halfPitch = pitch * 0.5;
+ final halfRoll = roll * 0.5;
+ final cosYaw = math.cos(halfYaw);
+ final sinYaw = math.sin(halfYaw);
+ final cosPitch = math.cos(halfPitch);
+ final sinPitch = math.sin(halfPitch);
+ final cosRoll = math.cos(halfRoll);
+ final sinRoll = math.sin(halfRoll);
_qStorage[0] = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw;
_qStorage[1] = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw;
_qStorage[2] = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw;
@@ -248,11 +248,11 @@
/// Normalize this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_qStorage[0] *= d;
_qStorage[1] *= d;
_qStorage[2] *= d;
@@ -269,7 +269,7 @@
/// Invert this.
void inverse() {
- final double l = 1.0 / length2;
+ final l = 1.0 / length2;
_qStorage[3] = _qStorage[3] * l;
_qStorage[2] = -_qStorage[2] * l;
_qStorage[1] = -_qStorage[1] * l;
@@ -290,23 +290,23 @@
/// [axis] of rotation.
Vector3 get axis {
- final double den = 1.0 - (_qStorage[3] * _qStorage[3]);
+ final den = 1.0 - (_qStorage[3] * _qStorage[3]);
if (den < 0.0005) {
// 0-angle rotation, so axis does not matter
return Vector3.zero();
}
- final double scale = 1.0 / math.sqrt(den);
+ final scale = 1.0 / math.sqrt(den);
return Vector3(
_qStorage[0] * scale, _qStorage[1] * scale, _qStorage[2] * scale);
}
/// Length squared.
double get length2 {
- final double x = _qStorage[0];
- final double y = _qStorage[1];
- final double z = _qStorage[2];
- final double w = _qStorage[3];
+ final x = _qStorage[0];
+ final y = _qStorage[1];
+ final z = _qStorage[2];
+ final w = _qStorage[3];
return (x * x) + (y * y) + (z * z) + (w * w);
}
@@ -315,7 +315,7 @@
/// Returns a copy of [v] rotated by quaternion.
Vector3 rotated(Vector3 v) {
- final Vector3 out = v.clone();
+ final out = v.clone();
rotate(out);
return out;
}
@@ -323,22 +323,22 @@
/// Rotates [v] by this.
Vector3 rotate(Vector3 v) {
// conjugate(this) * [v,0] * this
- final double _w = _qStorage[3];
- final double _z = _qStorage[2];
- final double _y = _qStorage[1];
- final double _x = _qStorage[0];
- final double tiw = _w;
- final double tiz = -_z;
- final double tiy = -_y;
- final double tix = -_x;
- final double tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y;
- final double ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z;
- final double tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x;
- final double tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z;
- final double result_x = tw * _x + tx * _w + ty * _z - tz * _y;
- final double result_y = tw * _y + ty * _w + tz * _x - tx * _z;
- final double result_z = tw * _z + tz * _w + tx * _y - ty * _x;
- final Float64List vStorage = v.storage;
+ final _w = _qStorage[3];
+ final _z = _qStorage[2];
+ final _y = _qStorage[1];
+ final _x = _qStorage[0];
+ final tiw = _w;
+ final tiz = -_z;
+ final tiy = -_y;
+ final tix = -_x;
+ final tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y;
+ final ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z;
+ final tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x;
+ final tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z;
+ final result_x = tw * _x + tx * _w + ty * _z - tz * _y;
+ final result_y = tw * _y + ty * _w + tz * _x - tx * _z;
+ final result_z = tw * _z + tz * _w + tx * _y - ty * _x;
+ final vStorage = v.storage;
vStorage[2] = result_z;
vStorage[1] = result_y;
vStorage[0] = result_x;
@@ -347,7 +347,7 @@
/// Add [arg] to this.
void add(Quaternion arg) {
- final Float64List argStorage = arg._qStorage;
+ final argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] + argStorage[0];
_qStorage[1] = _qStorage[1] + argStorage[1];
_qStorage[2] = _qStorage[2] + argStorage[2];
@@ -356,7 +356,7 @@
/// Subtracts [arg] from this.
void sub(Quaternion arg) {
- final Float64List argStorage = arg._qStorage;
+ final argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] - argStorage[0];
_qStorage[1] = _qStorage[1] - argStorage[1];
_qStorage[2] = _qStorage[2] - argStorage[2];
@@ -376,15 +376,15 @@
/// this rotated by [other].
Quaternion operator *(Quaternion other) {
- final double _w = _qStorage[3];
- final double _z = _qStorage[2];
- final double _y = _qStorage[1];
- final double _x = _qStorage[0];
- final Float64List otherStorage = other._qStorage;
- final double ow = otherStorage[3];
- final double oz = otherStorage[2];
- final double oy = otherStorage[1];
- final double ox = otherStorage[0];
+ final _w = _qStorage[3];
+ final _z = _qStorage[2];
+ final _y = _qStorage[1];
+ final _x = _qStorage[0];
+ final otherStorage = other._qStorage;
+ final ow = otherStorage[3];
+ final oz = otherStorage[2];
+ final oy = otherStorage[1];
+ final ox = otherStorage[0];
return Quaternion(
_w * ox + _x * ow + _y * oz - _z * oy,
_w * oy + _y * ow + _z * ox - _x * oz,
@@ -415,32 +415,32 @@
/// Set [rotationMatrix] to a rotation matrix containing the same rotation as
/// this.
Matrix3 copyRotationInto(Matrix3 rotationMatrix) {
- final double d = length2;
+ final d = length2;
assert(d != 0.0);
- final double s = 2.0 / d;
+ final s = 2.0 / d;
- final double _x = _qStorage[0];
- final double _y = _qStorage[1];
- final double _z = _qStorage[2];
- final double _w = _qStorage[3];
+ final _x = _qStorage[0];
+ final _y = _qStorage[1];
+ final _z = _qStorage[2];
+ final _w = _qStorage[3];
- final double xs = _x * s;
- final double ys = _y * s;
- final double zs = _z * s;
+ final xs = _x * s;
+ final ys = _y * s;
+ final zs = _z * s;
- final double wx = _w * xs;
- final double wy = _w * ys;
- final double wz = _w * zs;
+ final wx = _w * xs;
+ final wy = _w * ys;
+ final wz = _w * zs;
- final double xx = _x * xs;
- final double xy = _x * ys;
- final double xz = _x * zs;
+ final xx = _x * xs;
+ final xy = _x * ys;
+ final xz = _x * zs;
- final double yy = _y * ys;
- final double yz = _y * zs;
- final double zz = _z * zs;
+ final yy = _y * ys;
+ final yz = _y * zs;
+ final zz = _z * zs;
- final Float64List rotationMatrixStorage = rotationMatrix.storage;
+ final rotationMatrixStorage = rotationMatrix.storage;
rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0
rotationMatrixStorage[1] = xy + wz;
rotationMatrixStorage[2] = xz - wy;
@@ -460,17 +460,17 @@
/// Relative error between this and [correct].
double relativeError(Quaternion correct) {
- final Quaternion diff = correct - this;
- final double norm_diff = diff.length;
- final double correct_norm = correct.length;
+ final diff = correct - this;
+ final norm_diff = diff.length;
+ final correct_norm = correct.length;
return norm_diff / correct_norm;
}
/// Absolute error between this and [correct].
double absoluteError(Quaternion correct) {
- final double this_norm = length;
- final double correct_norm = correct.length;
- final double norm_diff = (this_norm - correct_norm).abs();
+ final this_norm = length;
+ final correct_norm = correct.length;
+ final norm_diff = (this_norm - correct_norm).abs();
return norm_diff;
}
}
diff --git a/lib/src/vector_math_64/ray.dart b/lib/src/vector_math_64/ray.dart
index 26fd754..2377c28 100644
--- a/lib/src/vector_math_64/ray.dart
+++ b/lib/src/vector_math_64/ray.dart
@@ -50,20 +50,20 @@
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithSphere(Sphere other) {
- final double r = other.radius;
- final double r2 = r * r;
- final Vector3 l = other._center.clone()..sub(_origin);
- final double s = l.dot(_direction);
- final double l2 = l.dot(l);
+ double? intersectsWithSphere(Sphere other) {
+ final r = other.radius;
+ final r2 = r * r;
+ final l = other._center.clone()..sub(_origin);
+ final s = l.dot(_direction);
+ final l2 = l.dot(l);
if (s < 0 && l2 > r2) {
return null;
}
- final double m2 = l2 - s * s;
+ final m2 = l2 - s * s;
if (m2 > r2) {
return null;
}
- final double q = math.sqrt(r2 - m2);
+ final q = math.sqrt(r2 - m2);
return (l2 > r2) ? s - q : s + q;
}
@@ -71,20 +71,20 @@
// Some varaibles that are used for intersectsWithTriangle and
// intersectsWithQuad. The performance is better in Dart and JS if we avoid
// to create temporary instance over and over. Also reduce GC.
- static final Vector3 _e1 = Vector3.zero();
- static final Vector3 _e2 = Vector3.zero();
- static final Vector3 _q = Vector3.zero();
- static final Vector3 _s = Vector3.zero();
- static final Vector3 _r = Vector3.zero();
+ static final _e1 = Vector3.zero();
+ static final _e2 = Vector3.zero();
+ static final _q = Vector3.zero();
+ static final _s = Vector3.zero();
+ static final _r = Vector3.zero();
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithTriangle(Triangle other) {
- const double epsilon = 10e-6;
+ double? intersectsWithTriangle(Triangle other) {
+ const epsilon = 10e-6;
- final Vector3 point0 = other._point0;
- final Vector3 point1 = other._point1;
- final Vector3 point2 = other._point2;
+ final point0 = other._point0;
+ final point1 = other._point1;
+ final point2 = other._point2;
_e1
..setFrom(point1)
@@ -94,38 +94,38 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final double a = _e1.dot(_q);
+ final a = _e1.dot(_q);
if (a > -epsilon && a < epsilon) {
return null;
}
- final double f = 1 / a;
+ final f = 1 / a;
_s
..setFrom(_origin)
..sub(point0);
- final double u = f * (_s.dot(_q));
+ final u = f * (_s.dot(_q));
if (u < 0.0) {
return null;
}
_s.crossInto(_e1, _r);
- final double v = f * (_direction.dot(_r));
+ final v = f * (_direction.dot(_r));
if (v < -epsilon || u + v > 1.0 + epsilon) {
return null;
}
- final double t = f * (_e2.dot(_r));
+ final t = f * (_e2.dot(_r));
return t;
}
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithQuad(Quad other) {
- const double epsilon = 10e-6;
+ double? intersectsWithQuad(Quad other) {
+ const epsilon = 10e-6;
// First triangle
var point0 = other._point0;
@@ -140,21 +140,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final double a0 = _e1.dot(_q);
+ final a0 = _e1.dot(_q);
if (!(a0 > -epsilon && a0 < epsilon)) {
- final double f = 1 / a0;
+ final f = 1 / a0;
_s
..setFrom(_origin)
..sub(point0);
- final double u = f * (_s.dot(_q));
+ final u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final double v = f * (_direction.dot(_r));
+ final v = f * (_direction.dot(_r));
if (!(v < -epsilon || u + v > 1.0 + epsilon)) {
- final double t = f * (_e2.dot(_r));
+ final t = f * (_e2.dot(_r));
return t;
}
@@ -174,21 +174,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final double a1 = _e1.dot(_q);
+ final a1 = _e1.dot(_q);
if (!(a1 > -epsilon && a1 < epsilon)) {
- final double f = 1 / a1;
+ final f = 1 / a1;
_s
..setFrom(_origin)
..sub(point0);
- final double u = f * (_s.dot(_q));
+ final u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final double v = f * (_direction.dot(_r));
+ final v = f * (_direction.dot(_r));
if (!(v < -epsilon || u + v > 1.0 + epsilon)) {
- final double t = f * (_e2.dot(_r));
+ final t = f * (_e2.dot(_r));
return t;
}
@@ -200,9 +200,9 @@
/// Return the distance from the origin of this to the intersection with
/// [other] if this intersects with [other], or null if the don't intersect.
- double intersectsWithAabb3(Aabb3 other) {
- final Vector3 otherMin = other.min;
- final Vector3 otherMax = other.max;
+ double? intersectsWithAabb3(Aabb3 other) {
+ final otherMin = other.min;
+ final otherMax = other.max;
var tNear = -double.maxFinite;
var tFar = double.maxFinite;
@@ -217,7 +217,7 @@
var t2 = (otherMax[i] - _origin[i]) / _direction[i];
if (t1 > t2) {
- final double temp = t1;
+ final temp = t1;
t1 = t2;
t2 = temp;
}
diff --git a/lib/src/vector_math_64/sphere.dart b/lib/src/vector_math_64/sphere.dart
index 9a61c31..5d61fb9 100644
--- a/lib/src/vector_math_64/sphere.dart
+++ b/lib/src/vector_math_64/sphere.dart
@@ -44,7 +44,7 @@
/// Return if this intersects with [other].
bool intersectsWithSphere(Sphere other) {
- final double radiusSum = radius + other.radius;
+ final radiusSum = radius + other.radius;
return other.center.distanceToSquared(center) <= (radiusSum * radiusSum);
}
diff --git a/lib/src/vector_math_64/third_party/noise.dart b/lib/src/vector_math_64/third_party/noise.dart
index 53bd877..dbbd5b5 100644
--- a/lib/src/vector_math_64/third_party/noise.dart
+++ b/lib/src/vector_math_64/third_party/noise.dart
@@ -78,16 +78,16 @@
];
// To remove the need for index wrapping, double the permutation table length
- List<int> _perm;
- List<int> _permMod12;
+ late final List<int> _perm;
+ late final List<int> _permMod12;
// Skewing and unskewing factors for 2, 3, and 4 dimensions
- static final double _F2 = 0.5 * (math.sqrt(3.0) - 1.0);
- static final double _G2 = (3.0 - math.sqrt(3.0)) / 6.0;
+ static final _F2 = 0.5 * (math.sqrt(3.0) - 1.0);
+ static final _G2 = (3.0 - math.sqrt(3.0)) / 6.0;
static const double _f3 = 1.0 / 3.0;
static const double _g3 = 1.0 / 6.0;
- static final double _F4 = (math.sqrt(5.0) - 1.0) / 4.0;
- static final double _G4 = (5.0 - math.sqrt(5.0)) / 20.0;
+ static final _F4 = (math.sqrt(5.0) - 1.0) / 4.0;
+ static final _G4 = (5.0 - math.sqrt(5.0)) / 20.0;
double _dot2(List<double> g, double x, double y) => g[0] * x + g[1] * y;
@@ -97,10 +97,9 @@
double _dot4(List<double> g, double x, double y, double z, double w) =>
g[0] * x + g[1] * y + g[2] * z + g[3] * w;
- SimplexNoise([math.Random r]) {
+ SimplexNoise([math.Random? r]) {
r ??= math.Random();
- final List<int> p =
- List<int>.generate(256, (_) => r.nextInt(256), growable: false);
+ final p = List<int>.generate(256, (_) => r!.nextInt(256), growable: false);
_perm = List<int>.generate(p.length * 2, (int i) => p[i % p.length],
growable: false);
_permMod12 = List<int>.generate(_perm.length, (int i) => _perm[i] % 12,
@@ -110,14 +109,14 @@
double noise2D(double xin, double yin) {
double n0, n1, n2; // Noise contributions from the three corners
// Skew the input space to determine which simplex cell we're in
- final double s = (xin + yin) * _F2; // Hairy factor for 2D
- final int i = (xin + s).floor();
- final int j = (yin + s).floor();
- final double t = (i + j) * _G2;
- final double X0 = i - t; // Unskew the cell origin back to (x,y) space
- final double Y0 = j - t;
- final double x0 = xin - X0; // The x,y distances from the cell origin
- final double y0 = yin - Y0;
+ final s = (xin + yin) * _F2; // Hairy factor for 2D
+ final i = (xin + s).floor();
+ final j = (yin + s).floor();
+ final t = (i + j) * _G2;
+ final X0 = i - t; // Unskew the cell origin back to (x,y) space
+ final Y0 = j - t;
+ final x0 = xin - X0; // The x,y distances from the cell origin
+ final y0 = yin - Y0;
// For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
@@ -132,19 +131,19 @@
// A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
// a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
// c = (3-sqrt(3))/6
- final double x1 =
+ final x1 =
x0 - i1 + _G2; // Offsets for middle corner in (x,y) unskewed coords
- final double y1 = y0 - j1 + _G2;
- final double x2 = x0 -
+ final y1 = y0 - j1 + _G2;
+ final x2 = x0 -
1.0 +
2.0 * _G2; // Offsets for last corner in (x,y) unskewed coords
- final double y2 = y0 - 1.0 + 2.0 * _G2;
+ final y2 = y0 - 1.0 + 2.0 * _G2;
// Work out the hashed gradient indices of the three simplex corners
- final int ii = i & 255;
- final int jj = j & 255;
- final int gi0 = _permMod12[ii + _perm[jj]];
- final int gi1 = _permMod12[ii + i1 + _perm[jj + j1]];
- final int gi2 = _permMod12[ii + 1 + _perm[jj + 1]];
+ final ii = i & 255;
+ final jj = j & 255;
+ final gi0 = _permMod12[ii + _perm[jj]];
+ final gi1 = _permMod12[ii + i1 + _perm[jj + j1]];
+ final gi2 = _permMod12[ii + 1 + _perm[jj + 1]];
// Calculate the contribution from the three corners
var t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0) {
@@ -178,18 +177,18 @@
double noise3D(double xin, double yin, double zin) {
double n0, n1, n2, n3; // Noise contributions from the four corners
// Skew the input space to determine which simplex cell we're in
- final double s =
+ final s =
(xin + yin + zin) * _f3; // Very nice and simple skew factor for 3D
- final int i = (xin + s).floor();
- final int j = (yin + s).floor();
- final int k = (zin + s).floor();
- final double t = (i + j + k) * _g3;
- final double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
- final double Y0 = j - t;
- final double Z0 = k - t;
- final double x0 = xin - X0; // The x,y,z distances from the cell origin
- final double y0 = yin - Y0;
- final double z0 = zin - Z0;
+ final i = (xin + s).floor();
+ final j = (yin + s).floor();
+ final k = (zin + s).floor();
+ final t = (i + j + k) * _g3;
+ final X0 = i - t; // Unskew the cell origin back to (x,y,z) space
+ final Y0 = j - t;
+ final Z0 = k - t;
+ final x0 = xin - X0; // The x,y,z distances from the cell origin
+ final y0 = yin - Y0;
+ final z0 = zin - Z0;
// For the 3D case, the simplex shape is a slightly irregular tetrahedron.
// Determine which simplex we are in.
int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
@@ -250,26 +249,25 @@
// a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
// a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
// c = 1/6.
- final double x1 =
- x0 - i1 + _g3; // Offsets for second corner in (x,y,z) coords
- final double y1 = y0 - j1 + _g3;
- final double z1 = z0 - k1 + _g3;
- final double x2 =
+ final x1 = x0 - i1 + _g3; // Offsets for second corner in (x,y,z) coords
+ final y1 = y0 - j1 + _g3;
+ final z1 = z0 - k1 + _g3;
+ final x2 =
x0 - i2 + 2.0 * _g3; // Offsets for third corner in (x,y,z) coords
- final double y2 = y0 - j2 + 2.0 * _g3;
- final double z2 = z0 - k2 + 2.0 * _g3;
- final double x3 =
+ final y2 = y0 - j2 + 2.0 * _g3;
+ final z2 = z0 - k2 + 2.0 * _g3;
+ final x3 =
x0 - 1.0 + 3.0 * _g3; // Offsets for last corner in (x,y,z) coords
- final double y3 = y0 - 1.0 + 3.0 * _g3;
- final double z3 = z0 - 1.0 + 3.0 * _g3;
+ final y3 = y0 - 1.0 + 3.0 * _g3;
+ final z3 = z0 - 1.0 + 3.0 * _g3;
// Work out the hashed gradient indices of the four simplex corners
- final int ii = i & 255;
- final int jj = j & 255;
- final int kk = k & 255;
- final int gi0 = _permMod12[ii + _perm[jj + _perm[kk]]];
- final int gi1 = _permMod12[ii + i1 + _perm[jj + j1 + _perm[kk + k1]]];
- final int gi2 = _permMod12[ii + i2 + _perm[jj + j2 + _perm[kk + k2]]];
- final int gi3 = _permMod12[ii + 1 + _perm[jj + 1 + _perm[kk + 1]]];
+ final ii = i & 255;
+ final jj = j & 255;
+ final kk = k & 255;
+ final gi0 = _permMod12[ii + _perm[jj + _perm[kk]]];
+ final gi1 = _permMod12[ii + i1 + _perm[jj + j1 + _perm[kk + k1]]];
+ final gi2 = _permMod12[ii + i2 + _perm[jj + j2 + _perm[kk + k2]]];
+ final gi3 = _permMod12[ii + 1 + _perm[jj + 1 + _perm[kk + 1]]];
// Calculate the contribution from the four corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0) {
@@ -308,20 +306,20 @@
double noise4D(double x, double y, double z, double w) {
double n0, n1, n2, n3, n4; // Noise contributions from the five corners
// Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
- final double s = (x + y + z + w) * _F4; // Factor for 4D skewing
- final int i = (x + s).floor();
- final int j = (y + s).floor();
- final int k = (z + s).floor();
- final int l = (w + s).floor();
- final double t = (i + j + k + l) * _G4; // Factor for 4D unskewing
- final double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
- final double Y0 = j - t;
- final double Z0 = k - t;
- final double W0 = l - t;
- final double x0 = x - X0; // The x,y,z,w distances from the cell origin
- final double y0 = y - Y0;
- final double z0 = z - Z0;
- final double w0 = w - W0;
+ final s = (x + y + z + w) * _F4; // Factor for 4D skewing
+ final i = (x + s).floor();
+ final j = (y + s).floor();
+ final k = (z + s).floor();
+ final l = (w + s).floor();
+ final t = (i + j + k + l) * _G4; // Factor for 4D unskewing
+ final X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
+ final Y0 = j - t;
+ final Z0 = k - t;
+ final W0 = l - t;
+ final x0 = x - X0; // The x,y,z,w distances from the cell origin
+ final y0 = y - Y0;
+ final z0 = z - Z0;
+ final w0 = w - W0;
// For the 4D case, the simplex is a 4D shape I won't even try to describe.
// To find out which of the 24 possible simplices we're in, we need to
// determine the magnitude ordering of x0, y0, z0 and w0.
@@ -384,39 +382,38 @@
k3 = rankz >= 1 ? 1 : 0;
l3 = rankw >= 1 ? 1 : 0;
// The fifth corner has all coordinate offsets = 1, so no need to compute that.
- final double x1 =
- x0 - i1 + _G4; // Offsets for second corner in (x,y,z,w) coords
- final double y1 = y0 - j1 + _G4;
- final double z1 = z0 - k1 + _G4;
- final double w1 = w0 - l1 + _G4;
- final double x2 =
+ final x1 = x0 - i1 + _G4; // Offsets for second corner in (x,y,z,w) coords
+ final y1 = y0 - j1 + _G4;
+ final z1 = z0 - k1 + _G4;
+ final w1 = w0 - l1 + _G4;
+ final x2 =
x0 - i2 + 2.0 * _G4; // Offsets for third corner in (x,y,z,w) coords
- final double y2 = y0 - j2 + 2.0 * _G4;
- final double z2 = z0 - k2 + 2.0 * _G4;
- final double w2 = w0 - l2 + 2.0 * _G4;
- final double x3 =
+ final y2 = y0 - j2 + 2.0 * _G4;
+ final z2 = z0 - k2 + 2.0 * _G4;
+ final w2 = w0 - l2 + 2.0 * _G4;
+ final x3 =
x0 - i3 + 3.0 * _G4; // Offsets for fourth corner in (x,y,z,w) coords
- final double y3 = y0 - j3 + 3.0 * _G4;
- final double z3 = z0 - k3 + 3.0 * _G4;
- final double w3 = w0 - l3 + 3.0 * _G4;
- final double x4 =
+ final y3 = y0 - j3 + 3.0 * _G4;
+ final z3 = z0 - k3 + 3.0 * _G4;
+ final w3 = w0 - l3 + 3.0 * _G4;
+ final x4 =
x0 - 1.0 + 4.0 * _G4; // Offsets for last corner in (x,y,z,w) coords
- final double y4 = y0 - 1.0 + 4.0 * _G4;
- final double z4 = z0 - 1.0 + 4.0 * _G4;
- final double w4 = w0 - 1.0 + 4.0 * _G4;
+ final y4 = y0 - 1.0 + 4.0 * _G4;
+ final z4 = z0 - 1.0 + 4.0 * _G4;
+ final w4 = w0 - 1.0 + 4.0 * _G4;
// Work out the hashed gradient indices of the five simplex corners
- final int ii = i & 255;
- final int jj = j & 255;
- final int kk = k & 255;
- final int ll = l & 255;
- final int gi0 = _perm[ii + _perm[jj + _perm[kk + _perm[ll]]]] % 32;
- final int gi1 =
+ final ii = i & 255;
+ final jj = j & 255;
+ final kk = k & 255;
+ final ll = l & 255;
+ final gi0 = _perm[ii + _perm[jj + _perm[kk + _perm[ll]]]] % 32;
+ final gi1 =
_perm[ii + i1 + _perm[jj + j1 + _perm[kk + k1 + _perm[ll + l1]]]] % 32;
- final int gi2 =
+ final gi2 =
_perm[ii + i2 + _perm[jj + j2 + _perm[kk + k2 + _perm[ll + l2]]]] % 32;
- final int gi3 =
+ final gi3 =
_perm[ii + i3 + _perm[jj + j3 + _perm[kk + k3 + _perm[ll + l3]]]] % 32;
- final int gi4 =
+ final gi4 =
_perm[ii + 1 + _perm[jj + 1 + _perm[kk + 1 + _perm[ll + 1]]]] % 32;
// Calculate the contribution from the five corners
var t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
diff --git a/lib/src/vector_math_64/triangle.dart b/lib/src/vector_math_64/triangle.dart
index 21b33c3..1aea2d3 100644
--- a/lib/src/vector_math_64/triangle.dart
+++ b/lib/src/vector_math_64/triangle.dart
@@ -46,7 +46,7 @@
/// Copy the normal of this into [normal].
void copyNormalInto(Vector3 normal) {
- final Vector3 v0 = point0.clone()..sub(point1);
+ final v0 = point0.clone()..sub(point1);
normal
..setFrom(point2)
..sub(point1)
diff --git a/lib/src/vector_math_64/utilities.dart b/lib/src/vector_math_64/utilities.dart
index ca46e00..d5d8a3e 100644
--- a/lib/src/vector_math_64/utilities.dart
+++ b/lib/src/vector_math_64/utilities.dart
@@ -18,8 +18,7 @@
/// [edge1] by [amount]. The computation is equivalent to the GLSL function
/// smoothstep.
double smoothStep(double edge0, double edge1, double amount) {
- final double t =
- ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble();
+ final t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble();
return t * t * (3.0 - 2.0 * t);
}
diff --git a/lib/src/vector_math_64/vector.dart b/lib/src/vector_math_64/vector.dart
index e1bc2ed..2d97566 100644
--- a/lib/src/vector_math_64/vector.dart
+++ b/lib/src/vector_math_64/vector.dart
@@ -20,7 +20,7 @@
/// 2D cross product. double x vec2.
void cross2A(double x, Vector2 y, Vector2 out) {
- final double tempy = x * y.x;
+ final tempy = x * y.x;
out
..x = -x * y.y
..y = tempy;
@@ -28,7 +28,7 @@
/// 2D cross product. vec2 x double.
void cross2B(Vector2 x, double y, Vector2 out) {
- final double tempy = -y * x.x;
+ final tempy = -y * x.x;
out
..x = y * x.y
..y = tempy;
@@ -39,9 +39,8 @@
void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) {
if (planeNormal.z.abs() > math.sqrt1_2) {
// choose u in y-z plane
- final double a =
- planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
- final double k = 1.0 / math.sqrt(a);
+ final a = planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
+ final k = 1.0 / math.sqrt(a);
u
..x = 0.0
..y = -planeNormal.z * k
@@ -53,9 +52,8 @@
..z = planeNormal[0] * (-planeNormal[2] * k);
} else {
// choose u in x-y plane
- final double a =
- planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
- final double k = 1.0 / math.sqrt(a);
+ final a = planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
+ final k = 1.0 / math.sqrt(a);
u
..x = -planeNormal[1] * k
..y = planeNormal[0] * k
diff --git a/lib/src/vector_math_64/vector2.dart b/lib/src/vector_math_64/vector2.dart
index a3a4229..0a6aebf 100644
--- a/lib/src/vector_math_64/vector2.dart
+++ b/lib/src/vector_math_64/vector2.dart
@@ -60,7 +60,7 @@
/// Generate random vector in the range (0, 0) to (1, 1). You can
/// optionally pass your own random number generator.
- factory Vector2.random([math.Random rng]) {
+ factory Vector2.random([math.Random? rng]) {
rng ??= math.Random();
return Vector2(rng.nextDouble(), rng.nextDouble());
}
@@ -79,7 +79,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector2 other) {
- final Float64List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
_v2storage[1] = otherStorage[1];
_v2storage[0] = otherStorage[0];
}
@@ -96,7 +96,7 @@
/// Check if two vectors are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Vector2) &&
(_v2storage[0] == other._v2storage[0]) &&
(_v2storage[1] == other._v2storage[1]);
@@ -156,11 +156,11 @@
/// Normalize this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_v2storage[0] *= d;
_v2storage[1] *= d;
return l;
@@ -187,40 +187,40 @@
/// Squared distance from this to [arg]
double distanceToSquared(Vector2 arg) {
- final double dx = x - arg.x;
- final double dy = y - arg.y;
+ final dx = x - arg.x;
+ final dy = y - arg.y;
return dx * dx + dy * dy;
}
/// Returns the angle between this vector and [other] in radians.
double angleTo(Vector2 other) {
- final Float64List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final double d = dot(other) / (length * other.length);
+ final d = dot(other) / (length * other.length);
return math.acos(d.clamp(-1.0, 1.0));
}
/// Returns the signed angle between this and [other] in radians.
double angleToSigned(Vector2 other) {
- final Float64List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final double s = cross(other);
- final double c = dot(other);
+ final s = cross(other);
+ final c = dot(other);
return math.atan2(s, c);
}
/// Inner product.
double dot(Vector2 other) {
- final Float64List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
double sum;
sum = _v2storage[0] * otherStorage[0];
sum += _v2storage[1] * otherStorage[1];
@@ -234,16 +234,16 @@
/// the inverse of the transformation.
///
void postmultiply(Matrix2 arg) {
- final Float64List argStorage = arg.storage;
- final double v0 = _v2storage[0];
- final double v1 = _v2storage[1];
+ final argStorage = arg.storage;
+ final v0 = _v2storage[0];
+ final v1 = _v2storage[1];
_v2storage[0] = v0 * argStorage[0] + v1 * argStorage[1];
_v2storage[1] = v0 * argStorage[2] + v1 * argStorage[3];
}
/// Cross product.
double cross(Vector2 other) {
- final Float64List otherStorage = other._v2storage;
+ final otherStorage = other._v2storage;
return _v2storage[0] * otherStorage[1] - _v2storage[1] * otherStorage[0];
}
@@ -263,8 +263,8 @@
/// Relative error between this and [correct]
double relativeError(Vector2 correct) {
- final double correct_norm = correct.length;
- final double diff_norm = (this - correct).length;
+ final correct_norm = correct.length;
+ final diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
@@ -289,35 +289,35 @@
/// Add [arg] to this.
void add(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] + argStorage[0];
_v2storage[1] = _v2storage[1] + argStorage[1];
}
/// Add [arg] scaled by [factor] to this.
void addScaled(Vector2 arg, double factor) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] + argStorage[0] * factor;
_v2storage[1] = _v2storage[1] + argStorage[1] * factor;
}
/// Subtract [arg] from this.
void sub(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] - argStorage[0];
_v2storage[1] = _v2storage[1] - argStorage[1];
}
/// Multiply entries in this with entries in [arg].
void multiply(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] * argStorage[0];
_v2storage[1] = _v2storage[1] * argStorage[1];
}
/// Divide entries in this with entries in [arg].
void divide(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] / argStorage[0];
_v2storage[1] = _v2storage[1] / argStorage[1];
}
@@ -345,8 +345,8 @@
/// Clamp each entry n in this in the range [min[n]]-[max[n]].
void clamp(Vector2 min, Vector2 max) {
- final Float64List minStorage = min.storage;
- final Float64List maxStorage = max.storage;
+ final minStorage = min.storage;
+ final maxStorage = max.storage;
_v2storage[0] =
_v2storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
_v2storage[1] =
@@ -392,7 +392,7 @@
/// Copy this into [arg]. Returns [arg].
Vector2 copyInto(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
argStorage[1] = _v2storage[1];
argStorage[0] = _v2storage[0];
return arg;
@@ -411,13 +411,13 @@
}
set xy(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[0] = argStorage[0];
_v2storage[1] = argStorage[1];
}
set yx(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v2storage[1] = argStorage[0];
_v2storage[0] = argStorage[1];
}
diff --git a/lib/src/vector_math_64/vector3.dart b/lib/src/vector_math_64/vector3.dart
index e2e0ff5..127488f 100644
--- a/lib/src/vector_math_64/vector3.dart
+++ b/lib/src/vector_math_64/vector3.dart
@@ -64,7 +64,7 @@
/// Generate random vector in the range (0, 0, 0) to (1, 1, 1). You can
/// optionally pass your own random number generator.
- factory Vector3.random([math.Random rng]) {
+ factory Vector3.random([math.Random? rng]) {
rng ??= math.Random();
return Vector3(rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
}
@@ -85,7 +85,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector3 other) {
- final Float64List otherStorage = other._v3storage;
+ final otherStorage = other._v3storage;
_v3storage[0] = otherStorage[0];
_v3storage[1] = otherStorage[1];
_v3storage[2] = otherStorage[2];
@@ -104,7 +104,7 @@
/// Check if two vectors are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Vector3) &&
(_v3storage[0] == other._v3storage[0]) &&
(_v3storage[1] == other._v3storage[1]) &&
@@ -167,11 +167,11 @@
/// Normalizes this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_v3storage[0] *= d;
_v3storage[1] *= d;
_v3storage[2] *= d;
@@ -199,24 +199,24 @@
/// Squared distance from this to [arg]
double distanceToSquared(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
- final double dx = _v3storage[0] - argStorage[0];
- final double dy = _v3storage[1] - argStorage[1];
- final double dz = _v3storage[2] - argStorage[2];
+ final argStorage = arg._v3storage;
+ final dx = _v3storage[0] - argStorage[0];
+ final dy = _v3storage[1] - argStorage[1];
+ final dz = _v3storage[2] - argStorage[2];
return dx * dx + dy * dy + dz * dz;
}
/// Returns the angle between this vector and [other] in radians.
double angleTo(Vector3 other) {
- final Float64List otherStorage = other._v3storage;
+ final otherStorage = other._v3storage;
if (_v3storage[0] == otherStorage[0] &&
_v3storage[1] == otherStorage[1] &&
_v3storage[2] == otherStorage[2]) {
return 0.0;
}
- final double d = dot(other) / (length * other.length);
+ final d = dot(other) / (length * other.length);
return math.acos(d.clamp(-1.0, 1.0));
}
@@ -224,16 +224,16 @@
/// Returns the signed angle between this and [other] around [normal]
/// in radians.
double angleToSigned(Vector3 other, Vector3 normal) {
- final double angle = angleTo(other);
- final Vector3 c = cross(other);
- final double d = c.dot(normal);
+ final angle = angleTo(other);
+ final c = cross(other);
+ final d = c.dot(normal);
return d < 0.0 ? -angle : angle;
}
/// Inner product.
double dot(Vector3 other) {
- final Float64List otherStorage = other._v3storage;
+ final otherStorage = other._v3storage;
double sum;
sum = _v3storage[0] * otherStorage[0];
sum += _v3storage[1] * otherStorage[1];
@@ -246,10 +246,10 @@
/// If [arg] is a rotation matrix, this is a computational shortcut for applying,
/// the inverse of the transformation.
void postmultiply(Matrix3 arg) {
- final Float64List argStorage = arg.storage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
+ final argStorage = arg.storage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
_v3storage[0] =
v0 * argStorage[0] + v1 * argStorage[1] + v2 * argStorage[2];
@@ -261,26 +261,26 @@
/// Cross product.
Vector3 cross(Vector3 other) {
- final double _x = _v3storage[0];
- final double _y = _v3storage[1];
- final double _z = _v3storage[2];
- final Float64List otherStorage = other._v3storage;
- final double ox = otherStorage[0];
- final double oy = otherStorage[1];
- final double oz = otherStorage[2];
+ final _x = _v3storage[0];
+ final _y = _v3storage[1];
+ final _z = _v3storage[2];
+ final otherStorage = other._v3storage;
+ final ox = otherStorage[0];
+ final oy = otherStorage[1];
+ final oz = otherStorage[2];
return Vector3(_y * oz - _z * oy, _z * ox - _x * oz, _x * oy - _y * ox);
}
/// Cross product. Stores result in [out].
Vector3 crossInto(Vector3 other, Vector3 out) {
- final double x = _v3storage[0];
- final double y = _v3storage[1];
- final double z = _v3storage[2];
- final Float64List otherStorage = other._v3storage;
- final double ox = otherStorage[0];
- final double oy = otherStorage[1];
- final double oz = otherStorage[2];
- final Float64List outStorage = out._v3storage;
+ final x = _v3storage[0];
+ final y = _v3storage[1];
+ final z = _v3storage[2];
+ final otherStorage = other._v3storage;
+ final ox = otherStorage[0];
+ final oy = otherStorage[1];
+ final oz = otherStorage[2];
+ final outStorage = out._v3storage;
outStorage[0] = y * oz - z * oy;
outStorage[1] = z * ox - x * oz;
outStorage[2] = x * oy - y * ox;
@@ -297,11 +297,11 @@
/// Projects this using the projection matrix [arg]
void applyProjection(Matrix4 arg) {
- final Float64List argStorage = arg.storage;
- final double x = _v3storage[0];
- final double y = _v3storage[1];
- final double z = _v3storage[2];
- final double d = 1.0 /
+ final argStorage = arg.storage;
+ final x = _v3storage[0];
+ final y = _v3storage[1];
+ final z = _v3storage[2];
+ final d = 1.0 /
(argStorage[3] * x +
argStorage[7] * y +
argStorage[11] * z +
@@ -330,18 +330,18 @@
/// Applies a quaternion transform.
void applyQuaternion(Quaternion arg) {
- final Float64List argStorage = arg._qStorage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
- final double qx = argStorage[0];
- final double qy = argStorage[1];
- final double qz = argStorage[2];
- final double qw = argStorage[3];
- final double ix = qw * v0 + qy * v2 - qz * v1;
- final double iy = qw * v1 + qz * v0 - qx * v2;
- final double iz = qw * v2 + qx * v1 - qy * v0;
- final double iw = -qx * v0 - qy * v1 - qz * v2;
+ final argStorage = arg._qStorage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
+ final qx = argStorage[0];
+ final qy = argStorage[1];
+ final qz = argStorage[2];
+ final qw = argStorage[3];
+ final ix = qw * v0 + qy * v2 - qz * v1;
+ final iy = qw * v1 + qz * v0 - qx * v2;
+ final iz = qw * v2 + qx * v1 - qy * v0;
+ final iw = -qx * v0 - qy * v1 - qz * v2;
_v3storage[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
_v3storage[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
_v3storage[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
@@ -349,10 +349,10 @@
/// Multiplies this by [arg].
void applyMatrix3(Matrix3 arg) {
- final Float64List argStorage = arg.storage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
+ final argStorage = arg.storage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
_v3storage[0] =
argStorage[0] * v0 + argStorage[3] * v1 + argStorage[6] * v2;
_v3storage[1] =
@@ -364,10 +364,10 @@
/// Multiplies this by a 4x3 subset of [arg]. Expects [arg] to be an affine
/// transformation matrix.
void applyMatrix4(Matrix4 arg) {
- final Float64List argStorage = arg.storage;
- final double v0 = _v3storage[0];
- final double v1 = _v3storage[1];
- final double v2 = _v3storage[2];
+ final argStorage = arg.storage;
+ final v0 = _v3storage[0];
+ final v1 = _v3storage[1];
+ final v2 = _v3storage[2];
_v3storage[0] = argStorage[0] * v0 +
argStorage[4] * v1 +
argStorage[8] * v2 +
@@ -384,8 +384,8 @@
/// Relative error between this and [correct]
double relativeError(Vector3 correct) {
- final double correct_norm = correct.length;
- final double diff_norm = (this - correct).length;
+ final correct_norm = correct.length;
+ final diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
@@ -412,7 +412,7 @@
/// Add [arg] to this.
void add(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0];
_v3storage[1] = _v3storage[1] + argStorage[1];
_v3storage[2] = _v3storage[2] + argStorage[2];
@@ -420,7 +420,7 @@
/// Add [arg] scaled by [factor] to this.
void addScaled(Vector3 arg, double factor) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0] * factor;
_v3storage[1] = _v3storage[1] + argStorage[1] * factor;
_v3storage[2] = _v3storage[2] + argStorage[2] * factor;
@@ -428,7 +428,7 @@
/// Subtract [arg] from this.
void sub(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] - argStorage[0];
_v3storage[1] = _v3storage[1] - argStorage[1];
_v3storage[2] = _v3storage[2] - argStorage[2];
@@ -436,7 +436,7 @@
/// Multiply entries in this with entries in [arg].
void multiply(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] * argStorage[0];
_v3storage[1] = _v3storage[1] * argStorage[1];
_v3storage[2] = _v3storage[2] * argStorage[2];
@@ -444,7 +444,7 @@
/// Divide entries in this with entries in [arg].
void divide(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] / argStorage[0];
_v3storage[1] = _v3storage[1] / argStorage[1];
_v3storage[2] = _v3storage[2] / argStorage[2];
@@ -476,8 +476,8 @@
/// Clamp each entry n in this in the range [min[n]]-[max[n]].
void clamp(Vector3 min, Vector3 max) {
- final Float64List minStorage = min.storage;
- final Float64List maxStorage = max.storage;
+ final minStorage = min.storage;
+ final maxStorage = max.storage;
_v3storage[0] =
_v3storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
_v3storage[1] =
@@ -532,7 +532,7 @@
/// Copy this into [arg].
Vector3 copyInto(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
argStorage[0] = _v3storage[0];
argStorage[1] = _v3storage[1];
argStorage[2] = _v3storage[2];
@@ -554,78 +554,78 @@
}
set xy(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set yx(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set zx(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xyz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set xzy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set yxz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set yzx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[0] = argStorage[2];
}
set zxy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set zyx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v3storage[2] = argStorage[0];
_v3storage[1] = argStorage[1];
_v3storage[0] = argStorage[2];
diff --git a/lib/src/vector_math_64/vector4.dart b/lib/src/vector_math_64/vector4.dart
index 50976a9..cff83f8 100644
--- a/lib/src/vector_math_64/vector4.dart
+++ b/lib/src/vector_math_64/vector4.dart
@@ -70,7 +70,7 @@
/// Generate random vector in the range (0, 0, 0, 0) to (1, 1, 1, 1). You can
/// optionally pass your own random number generator.
- factory Vector4.random([math.Random rng]) {
+ factory Vector4.random([math.Random? rng]) {
rng ??= math.Random();
return Vector4(
rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
@@ -102,7 +102,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector4 other) {
- final Float64List otherStorage = other._v4storage;
+ final otherStorage = other._v4storage;
_v4storage[3] = otherStorage[3];
_v4storage[2] = otherStorage[2];
_v4storage[1] = otherStorage[1];
@@ -124,7 +124,7 @@
/// Check if two vectors are the same.
@override
- bool operator ==(Object other) =>
+ bool operator ==(Object? other) =>
(other is Vector4) &&
(_v4storage[0] == other._v4storage[0]) &&
(_v4storage[1] == other._v4storage[1]) &&
@@ -190,11 +190,11 @@
/// Normalizes this.
double normalize() {
- final double l = length;
+ final l = length;
if (l == 0.0) {
return 0.0;
}
- final double d = 1.0 / l;
+ final d = 1.0 / l;
_v4storage[0] *= d;
_v4storage[1] *= d;
_v4storage[2] *= d;
@@ -223,18 +223,18 @@
/// Squared distance from this to [arg]
double distanceToSquared(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
- final double dx = _v4storage[0] - argStorage[0];
- final double dy = _v4storage[1] - argStorage[1];
- final double dz = _v4storage[2] - argStorage[2];
- final double dw = _v4storage[3] - argStorage[3];
+ final argStorage = arg._v4storage;
+ final dx = _v4storage[0] - argStorage[0];
+ final dy = _v4storage[1] - argStorage[1];
+ final dz = _v4storage[2] - argStorage[2];
+ final dw = _v4storage[3] - argStorage[3];
return dx * dx + dy * dy + dz * dz + dw * dw;
}
/// Inner product.
double dot(Vector4 other) {
- final Float64List otherStorage = other._v4storage;
+ final otherStorage = other._v4storage;
double sum;
sum = _v4storage[0] * otherStorage[0];
sum += _v4storage[1] * otherStorage[1];
@@ -245,11 +245,11 @@
/// Multiplies this by [arg].
void applyMatrix4(Matrix4 arg) {
- final double v1 = _v4storage[0];
- final double v2 = _v4storage[1];
- final double v3 = _v4storage[2];
- final double v4 = _v4storage[3];
- final Float64List argStorage = arg.storage;
+ final v1 = _v4storage[0];
+ final v2 = _v4storage[1];
+ final v3 = _v4storage[2];
+ final v4 = _v4storage[3];
+ final argStorage = arg.storage;
_v4storage[0] = argStorage[0] * v1 +
argStorage[4] * v2 +
argStorage[8] * v3 +
@@ -270,8 +270,8 @@
/// Relative error between this and [correct]
double relativeError(Vector4 correct) {
- final double correct_norm = correct.length;
- final double diff_norm = (this - correct).length;
+ final correct_norm = correct.length;
+ final diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
@@ -299,7 +299,7 @@
}
void add(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0];
_v4storage[1] = _v4storage[1] + argStorage[1];
_v4storage[2] = _v4storage[2] + argStorage[2];
@@ -308,7 +308,7 @@
/// Add [arg] scaled by [factor] to this.
void addScaled(Vector4 arg, double factor) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0] * factor;
_v4storage[1] = _v4storage[1] + argStorage[1] * factor;
_v4storage[2] = _v4storage[2] + argStorage[2] * factor;
@@ -317,7 +317,7 @@
/// Subtract [arg] from this.
void sub(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] - argStorage[0];
_v4storage[1] = _v4storage[1] - argStorage[1];
_v4storage[2] = _v4storage[2] - argStorage[2];
@@ -326,7 +326,7 @@
/// Multiply this by [arg].
void multiply(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] * argStorage[0];
_v4storage[1] = _v4storage[1] * argStorage[1];
_v4storage[2] = _v4storage[2] * argStorage[2];
@@ -335,7 +335,7 @@
/// Divide this by [arg].
void div(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] / argStorage[0];
_v4storage[1] = _v4storage[1] / argStorage[1];
_v4storage[2] = _v4storage[2] / argStorage[2];
@@ -371,8 +371,8 @@
/// Clamp each entry n in this in the range [min[n]]-[max[n]].
void clamp(Vector4 min, Vector4 max) {
- final Float64List minStorage = min.storage;
- final Float64List maxStorage = max.storage;
+ final minStorage = min.storage;
+ final maxStorage = max.storage;
_v4storage[0] =
_v4storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
_v4storage[1] =
@@ -436,7 +436,7 @@
/// Copy this
Vector4 copyInto(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
argStorage[0] = _v4storage[0];
argStorage[1] = _v4storage[1];
argStorage[2] = _v4storage[2];
@@ -461,247 +461,247 @@
}
set xy(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xw(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set yx(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set yw(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set zx(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set zw(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set wx(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set wy(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set wz(Vector2 arg) {
- final Float64List argStorage = arg._v2storage;
+ final argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xyz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set xyw(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xzy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xzw(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xwy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xwz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxw(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set yzx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set yzw(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set ywx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set ywz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set zxy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set zxw(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zyx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zyw(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zwx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zwy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wyx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wyz(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wzx(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wzy(Vector3 arg) {
- final Float64List argStorage = arg._v3storage;
+ final argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xyzw(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -709,7 +709,7 @@
}
set xywz(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -717,7 +717,7 @@
}
set xzyw(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -725,7 +725,7 @@
}
set xzwy(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -733,7 +733,7 @@
}
set xwyz(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -741,7 +741,7 @@
}
set xwzy(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -749,7 +749,7 @@
}
set yxzw(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -757,7 +757,7 @@
}
set yxwz(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -765,7 +765,7 @@
}
set yzxw(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -773,7 +773,7 @@
}
set yzwx(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -781,7 +781,7 @@
}
set ywxz(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -789,7 +789,7 @@
}
set ywzx(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -797,7 +797,7 @@
}
set zxyw(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -805,7 +805,7 @@
}
set zxwy(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -813,7 +813,7 @@
}
set zyxw(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -821,7 +821,7 @@
}
set zywx(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -829,7 +829,7 @@
}
set zwxy(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -837,7 +837,7 @@
}
set zwyx(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -845,7 +845,7 @@
}
set wxyz(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -853,7 +853,7 @@
}
set wxzy(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -861,7 +861,7 @@
}
set wyxz(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -869,7 +869,7 @@
}
set wyzx(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -877,7 +877,7 @@
}
set wzxy(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -885,7 +885,7 @@
}
set wzyx(Vector4 arg) {
- final Float64List argStorage = arg._v4storage;
+ final argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
diff --git a/lib/src/vector_math_geometry/filters/barycentric_filter.dart b/lib/src/vector_math_geometry/filters/barycentric_filter.dart
index 689becd..3fd3847 100644
--- a/lib/src/vector_math_geometry/filters/barycentric_filter.dart
+++ b/lib/src/vector_math_geometry/filters/barycentric_filter.dart
@@ -11,46 +11,44 @@
@override
MeshGeometry filter(MeshGeometry mesh) {
- final List<VertexAttrib> newAttribs =
- List<VertexAttrib>.from(mesh.attribs, growable: true);
+ final newAttribs = List<VertexAttrib>.from(mesh.attribs, growable: true);
if (mesh.getAttrib('BARYCENTRIC') == null) {
newAttribs.add(VertexAttrib('BARYCENTRIC', 3, 'float'));
}
- final MeshGeometry output =
- MeshGeometry(mesh.triangleVertexCount, newAttribs);
+ final output = MeshGeometry(mesh.triangleVertexCount, newAttribs);
Vector3List barycentricCoords;
- final VectorList<Vector> view = output.getViewForAttrib('BARYCENTRIC');
+ final view = output.getViewForAttrib('BARYCENTRIC');
if (view is Vector3List) {
barycentricCoords = view;
} else {
- return null;
+ throw UnimplementedError();
}
- final List<VectorList<Vector>> srcAttribs = <VectorList<Vector>>[];
- final List<VectorList<Vector>> destAttribs = <VectorList<Vector>>[];
+ final srcAttribs = <VectorList<Vector>>[];
+ final destAttribs = <VectorList<Vector>>[];
for (var attrib in mesh.attribs) {
if (attrib.name == 'BARYCENTRIC') {
continue;
}
- srcAttribs.add(mesh.getViewForAttrib(attrib.name));
- destAttribs.add(output.getViewForAttrib(attrib.name));
+ srcAttribs.add(mesh.getViewForAttrib(attrib.name)!);
+ destAttribs.add(output.getViewForAttrib(attrib.name)!);
}
- final Vector3 b0 = Vector3(1.0, 0.0, 0.0);
- final Vector3 b1 = Vector3(0.0, 1.0, 0.0);
- final Vector3 b2 = Vector3(0.0, 0.0, 1.0);
+ final b0 = Vector3(1.0, 0.0, 0.0);
+ final b1 = Vector3(0.0, 1.0, 0.0);
+ final b2 = Vector3(0.0, 0.0, 1.0);
int i0, i1, i2;
for (var i = 0; i < output.length; i += 3) {
if (mesh.indices != null) {
- i0 = mesh.indices[i];
- i1 = mesh.indices[i + 1];
- i2 = mesh.indices[i + 2];
+ i0 = mesh.indices![i];
+ i1 = mesh.indices![i + 1];
+ i2 = mesh.indices![i + 2];
} else {
i0 = i;
i1 = i + 1;
diff --git a/lib/src/vector_math_geometry/filters/color_filter.dart b/lib/src/vector_math_geometry/filters/color_filter.dart
index c25f586..60e81c2 100644
--- a/lib/src/vector_math_geometry/filters/color_filter.dart
+++ b/lib/src/vector_math_geometry/filters/color_filter.dart
@@ -26,14 +26,14 @@
output = MeshGeometry.copy(mesh);
}
- final VectorList<Vector> colors = output.getViewForAttrib('COLOR');
+ final colors = output.getViewForAttrib('COLOR');
if (colors is Vector4List) {
for (var i = 0; i < colors.length; ++i) {
colors[i] = color;
}
return output;
} else {
- return null;
+ throw UnimplementedError();
}
}
}
diff --git a/lib/src/vector_math_geometry/filters/flat_shade_filter.dart b/lib/src/vector_math_geometry/filters/flat_shade_filter.dart
index 2dabe78..6b41e9e 100644
--- a/lib/src/vector_math_geometry/filters/flat_shade_filter.dart
+++ b/lib/src/vector_math_geometry/filters/flat_shade_filter.dart
@@ -15,43 +15,41 @@
@override
MeshGeometry filter(MeshGeometry mesh) {
- final List<VertexAttrib> newAttribs =
- List<VertexAttrib>.from(mesh.attribs, growable: true);
+ final newAttribs = List<VertexAttrib>.from(mesh.attribs, growable: true);
if (mesh.getAttrib('NORMAL') == null) {
newAttribs.add(VertexAttrib('NORMAL', 3, 'float'));
}
- final MeshGeometry output =
- MeshGeometry(mesh.triangleVertexCount, newAttribs);
+ final output = MeshGeometry(mesh.triangleVertexCount, newAttribs);
- final Vector3 p0 = Vector3.zero(), p1 = Vector3.zero(), p2 = Vector3.zero();
+ final p0 = Vector3.zero(), p1 = Vector3.zero(), p2 = Vector3.zero();
- final VectorList<Vector> srcPosition = mesh.getViewForAttrib('POSITION');
- final VectorList<Vector> destPosition = output.getViewForAttrib('POSITION');
- final VectorList<Vector> normals = output.getViewForAttrib('NORMAL');
+ final srcPosition = mesh.getViewForAttrib('POSITION');
+ final destPosition = output.getViewForAttrib('POSITION');
+ final normals = output.getViewForAttrib('NORMAL');
if (srcPosition is! Vector3List ||
destPosition is! Vector3List ||
normals is! Vector3List) {
- return null;
+ throw UnimplementedError();
}
- final List<VectorList<Vector>> srcAttribs = <VectorList<Vector>>[];
- final List<VectorList<Vector>> destAttribs = <VectorList<Vector>>[];
+ final srcAttribs = <VectorList<Vector>>[];
+ final destAttribs = <VectorList<Vector>>[];
for (var attrib in mesh.attribs) {
if (attrib.name == 'POSITION' || attrib.name == 'NORMAL') {
continue;
}
- srcAttribs.add(mesh.getViewForAttrib(attrib.name));
- destAttribs.add(output.getViewForAttrib(attrib.name));
+ srcAttribs.add(mesh.getViewForAttrib(attrib.name)!);
+ destAttribs.add(output.getViewForAttrib(attrib.name)!);
}
for (var i = 0; i < output.length; i += 3) {
- final int i0 = mesh.indices[i];
- final int i1 = mesh.indices[i + 1];
- final int i2 = mesh.indices[i + 2];
+ final i0 = mesh.indices![i];
+ final i1 = mesh.indices![i + 1];
+ final i2 = mesh.indices![i + 2];
srcPosition..load(i0, p0)..load(i1, p1)..load(i2, p2);
diff --git a/lib/src/vector_math_geometry/filters/geometry_filter.dart b/lib/src/vector_math_geometry/filters/geometry_filter.dart
index a71befe..c915d74 100644
--- a/lib/src/vector_math_geometry/filters/geometry_filter.dart
+++ b/lib/src/vector_math_geometry/filters/geometry_filter.dart
@@ -19,7 +19,7 @@
@override
MeshGeometry filter(MeshGeometry mesh) {
- final MeshGeometry output = MeshGeometry.copy(mesh);
+ final output = MeshGeometry.copy(mesh);
filterInplace(output);
return output;
}
diff --git a/lib/src/vector_math_geometry/filters/invert_filter.dart b/lib/src/vector_math_geometry/filters/invert_filter.dart
index 1e63f6c..fc46c9a 100644
--- a/lib/src/vector_math_geometry/filters/invert_filter.dart
+++ b/lib/src/vector_math_geometry/filters/invert_filter.dart
@@ -12,13 +12,15 @@
// to return a new geometry?
// Swap all the triangle indices
- for (var i = 0; i < mesh.indices.length; i += 3) {
- final int tmp = mesh.indices[i];
- mesh.indices[i] = mesh.indices[i + 2];
- mesh.indices[i + 2] = tmp;
+ final indicies = mesh.indices!;
+
+ for (var i = 0; i < indicies.length; i += 3) {
+ final tmp = indicies[i];
+ indicies[i] = indicies[i + 2];
+ indicies[i + 2] = tmp;
}
- final VectorList<Vector> normals = mesh.getViewForAttrib('NORMAL');
+ final normals = mesh.getViewForAttrib('NORMAL');
if (normals is Vector3List) {
for (var i = 0; i < normals.length; ++i) {
normals[i] = -normals[i];
diff --git a/lib/src/vector_math_geometry/filters/transform_filter.dart b/lib/src/vector_math_geometry/filters/transform_filter.dart
index 669cbec..d677859 100644
--- a/lib/src/vector_math_geometry/filters/transform_filter.dart
+++ b/lib/src/vector_math_geometry/filters/transform_filter.dart
@@ -15,7 +15,7 @@
@override
void filterInplace(MeshGeometry mesh) {
- final VectorList<Vector> position = mesh.getViewForAttrib('POSITION');
+ final position = mesh.getViewForAttrib('POSITION');
if (position is Vector3List) {
for (var i = 0; i < position.length; ++i) {
// multiplication always returns Vector3 here
diff --git a/lib/src/vector_math_geometry/generators/attribute_generators.dart b/lib/src/vector_math_geometry/generators/attribute_generators.dart
index 436b4b0..888a354 100644
--- a/lib/src/vector_math_geometry/generators/attribute_generators.dart
+++ b/lib/src/vector_math_geometry/generators/attribute_generators.dart
@@ -9,7 +9,7 @@
/// [indices] is assumed to represent a triangle list.
void generateNormals(
Vector3List normals, Vector3List positions, Uint16List indices) {
- final Vector3 p0 = Vector3.zero(),
+ final p0 = Vector3.zero(),
p1 = Vector3.zero(),
p2 = Vector3.zero(),
norm = Vector3.zero();
@@ -17,7 +17,7 @@
// Loop through every polygon, find it's normal, and add that to the vertex
// normals.
for (var i = 0; i < indices.length; i += 3) {
- final int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
+ final i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
positions..load(i0, p0)..load(i1, p1)..load(i2, p2);
p1.sub(p0);
@@ -57,7 +57,7 @@
/// http://www.terathon.com/code/tangent.html
void generateTangents(Vector4List tangents, Vector3List positions,
Vector3List normals, Vector2List texCoords, Uint16List indices) {
- final Vector3 p0 = Vector3.zero(),
+ final p0 = Vector3.zero(),
p1 = Vector3.zero(),
p2 = Vector3.zero(),
n = Vector3.zero(),
@@ -65,17 +65,15 @@
udir = Vector3.zero(),
vdir = Vector3.zero();
- final Vector2 uv0 = Vector2.zero(),
- uv1 = Vector2.zero(),
- uv2 = Vector2.zero();
+ final uv0 = Vector2.zero(), uv1 = Vector2.zero(), uv2 = Vector2.zero();
- final Vector4 tan = Vector4.zero();
+ final tan = Vector4.zero();
- final Vector3List tan0 = Vector3List(positions.length),
+ final tan0 = Vector3List(positions.length),
tan1 = Vector3List(positions.length);
for (var i = 0; i < indices.length; i += 3) {
- final int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
+ final i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
positions..load(i0, p0)..load(i1, p1)..load(i2, p2);
texCoords..load(i0, uv0)..load(i1, uv1)..load(i2, uv2);
@@ -86,7 +84,7 @@
uv1.sub(uv0);
uv2.sub(uv0);
- final double r = 1.0 / (uv1.x * uv2.y - uv2.x * uv1.y);
+ final r = 1.0 / (uv1.x * uv2.y - uv2.x * uv1.y);
udir.setValues((uv2.y * p1.x - uv1.y * p2.x) * r,
(uv2.y * p1.y - uv1.y * p2.y) * r, (uv2.y * p1.z - uv1.y * p2.z) * r);
@@ -122,7 +120,7 @@
tan1.load(i, p1);
n.crossInto(t, p2);
- final double sign = (p2.dot(p1) < 0.0) ? -1.0 : 1.0;
+ final sign = (p2.dot(p1) < 0.0) ? -1.0 : 1.0;
tangents.load(i, tan);
tangents[i] = tan..setValues(p0.x, p0.y, p0.z, sign);
diff --git a/lib/src/vector_math_geometry/generators/circle_generator.dart b/lib/src/vector_math_geometry/generators/circle_generator.dart
index 1aeb9bc..582d123 100644
--- a/lib/src/vector_math_geometry/generators/circle_generator.dart
+++ b/lib/src/vector_math_geometry/generators/circle_generator.dart
@@ -5,10 +5,10 @@
part of vector_math_geometry;
class CircleGenerator extends GeometryGenerator {
- double _radius;
- int _segments;
- double _thetaStart;
- double _thetaLength;
+ late final double _radius;
+ late final int _segments;
+ late final double _thetaStart;
+ late final double _thetaLength;
@override
int get vertexCount => _segments + 2;
@@ -17,8 +17,8 @@
int get indexCount => _segments * 3;
MeshGeometry createCircle(double radius,
- {GeometryGeneratorFlags flags,
- List<GeometryFilter> filters,
+ {GeometryGeneratorFlags? flags,
+ List<GeometryFilter>? filters,
int segments = 64,
double thetaStart = 0.0,
double thetaLength = math.pi * 2.0}) {
@@ -31,11 +31,11 @@
@override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
- final Vector3 v = Vector3.zero();
+ final v = Vector3.zero();
positions[0] = v;
var index = 1;
for (var i = 0; i <= _segments; i++) {
- final double percent = i / _segments;
+ final percent = i / _segments;
v
..x = _radius * math.cos(_thetaStart + percent * _thetaLength)
..z = _radius * math.sin(_thetaStart + percent * _thetaLength);
@@ -48,13 +48,13 @@
@override
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
- final Vector2 v = Vector2(0.5, 0.5);
+ final v = Vector2(0.5, 0.5);
texCoords[0] = v;
var index = 1;
for (var i = 0; i <= _segments; i++) {
- final Vector3 position = positions[index];
- final double x = (position.x / (_radius + 1.0)) * 0.5;
- final double y = (position.z / (_radius + 1.0)) * 0.5;
+ final position = positions[index];
+ final x = (position.x / (_radius + 1.0)) * 0.5;
+ final y = (position.z / (_radius + 1.0)) * 0.5;
v
..x = x + 0.5
..y = y + 0.5;
diff --git a/lib/src/vector_math_geometry/generators/cube_generator.dart b/lib/src/vector_math_geometry/generators/cube_generator.dart
index dc5665c..a653ee4 100644
--- a/lib/src/vector_math_geometry/generators/cube_generator.dart
+++ b/lib/src/vector_math_geometry/generators/cube_generator.dart
@@ -5,9 +5,9 @@
part of vector_math_geometry;
class CubeGenerator extends GeometryGenerator {
- double _width;
- double _height;
- double _depth;
+ late final double _width;
+ late final double _height;
+ late final double _depth;
@override
int get vertexCount => 24;
@@ -16,7 +16,7 @@
int get indexCount => 36;
MeshGeometry createCube(num width, num height, num depth,
- {GeometryGeneratorFlags flags, List<GeometryFilter> filters}) {
+ {GeometryGeneratorFlags? flags, List<GeometryFilter>? filters}) {
_width = width.toDouble();
_height = height.toDouble();
_depth = depth.toDouble();
diff --git a/lib/src/vector_math_geometry/generators/cylinder_generator.dart b/lib/src/vector_math_geometry/generators/cylinder_generator.dart
index b840f30..362754b 100644
--- a/lib/src/vector_math_geometry/generators/cylinder_generator.dart
+++ b/lib/src/vector_math_geometry/generators/cylinder_generator.dart
@@ -5,10 +5,10 @@
part of vector_math_geometry;
class CylinderGenerator extends GeometryGenerator {
- double _topRadius;
- double _bottomRadius;
- double _height;
- int _segments;
+ late final double _topRadius;
+ late final double _bottomRadius;
+ late final double _height;
+ late final int _segments;
@override
int get vertexCount => ((_segments + 1) * 2) + (_segments * 2);
@@ -18,8 +18,8 @@
MeshGeometry createCylinder(num topRadius, num bottomRadius, num height,
{int segments = 16,
- GeometryGeneratorFlags flags,
- List<GeometryFilter> filters}) {
+ GeometryGeneratorFlags? flags,
+ List<GeometryFilter>? filters}) {
_topRadius = topRadius.toDouble();
_bottomRadius = bottomRadius.toDouble();
_height = height.toDouble();
@@ -34,7 +34,7 @@
// Sides
var base1 = 0;
- final int base2 = _segments + 1;
+ final base2 = _segments + 1;
for (var x = 0; x < _segments; ++x) {
indices[i++] = base1 + x;
indices[i++] = base1 + x + 1;
@@ -68,7 +68,7 @@
// Top
for (var x = 0; x <= _segments; ++x) {
- final double u = x / _segments;
+ final u = x / _segments;
positions[i++] = Vector3(_topRadius * math.cos(u * math.pi * 2.0),
_height * 0.5, _topRadius * math.sin(u * math.pi * 2.0));
@@ -76,7 +76,7 @@
// Bottom
for (var x = 0; x <= _segments; ++x) {
- final double u = x / _segments;
+ final u = x / _segments;
positions[i++] = Vector3(_bottomRadius * math.cos(u * math.pi * 2.0),
_height * -0.5, _bottomRadius * math.sin(u * math.pi * 2.0));
@@ -84,7 +84,7 @@
// Top cap
for (var x = 0; x < _segments; ++x) {
- final double u = x / _segments;
+ final u = x / _segments;
positions[i++] = Vector3(_topRadius * math.cos(u * math.pi * 2.0),
_height * 0.5, _topRadius * math.sin(u * math.pi * 2.0));
@@ -92,7 +92,7 @@
// Bottom cap
for (var x = 0; x < _segments; ++x) {
- final double u = x / _segments;
+ final u = x / _segments;
positions[i++] = Vector3(_bottomRadius * math.cos(u * math.pi * 2.0),
_height * -0.5, _bottomRadius * math.sin(u * math.pi * 2.0));
@@ -106,26 +106,26 @@
// Cylinder top
for (var x = 0; x <= _segments; ++x) {
- final double u = 1.0 - (x / _segments);
+ final u = 1.0 - (x / _segments);
texCoords[i++] = Vector2(u, 0.0);
}
// Cylinder bottom
for (var x = 0; x <= _segments; ++x) {
- final double u = 1.0 - (x / _segments);
+ final u = 1.0 - (x / _segments);
texCoords[i++] = Vector2(u, 1.0);
}
// Top cap
for (var x = 0; x < _segments; ++x) {
- final double r = (x / _segments) * math.pi * 2.0;
+ final r = (x / _segments) * math.pi * 2.0;
texCoords[i++] =
Vector2(math.cos(r) * 0.5 + 0.5, math.sin(r) * 0.5 + 0.5);
}
// Bottom cap
for (var x = 0; x < _segments; ++x) {
- final double r = (x / _segments) * math.pi * 2.0;
+ final r = (x / _segments) * math.pi * 2.0;
texCoords[i++] =
Vector2(math.cos(r) * 0.5 + 0.5, math.sin(r) * 0.5 + 0.5);
}
diff --git a/lib/src/vector_math_geometry/generators/geometry_generator.dart b/lib/src/vector_math_geometry/generators/geometry_generator.dart
index d7553b8..126276e 100644
--- a/lib/src/vector_math_geometry/generators/geometry_generator.dart
+++ b/lib/src/vector_math_geometry/generators/geometry_generator.dart
@@ -18,7 +18,7 @@
int get indexCount;
MeshGeometry createGeometry(
- {GeometryGeneratorFlags flags, List<GeometryFilter> filters}) {
+ {GeometryGeneratorFlags? flags, List<GeometryFilter>? filters}) {
flags ??= GeometryGeneratorFlags();
VertexAttrib positionAttrib;
@@ -26,12 +26,12 @@
VertexAttrib normalAttrib;
VertexAttrib tangentAttrib;
- Vector2List texCoordView;
- Vector3List positionView;
- Vector3List normalView;
+ Vector2List? texCoordView;
+ Vector3List? positionView;
+ Vector3List? normalView;
Vector4List tangentView;
- final List<VertexAttrib> attribs = <VertexAttrib>[];
+ final attribs = <VertexAttrib>[];
positionAttrib = VertexAttrib('POSITION', 3, 'float');
attribs.add(positionAttrib);
@@ -53,19 +53,19 @@
var mesh = MeshGeometry(vertexCount, attribs)
..indices = Uint16List(indexCount);
- generateIndices(mesh.indices);
+ generateIndices(mesh.indices!);
var view = mesh.getViewForAttrib('POSITION');
if (view is Vector3List) {
positionView = view;
- generateVertexPositions(positionView, mesh.indices);
+ generateVertexPositions(positionView!, mesh.indices!);
}
if (flags.texCoords || flags.tangents) {
view = mesh.getViewForAttrib('TEXCOORD0');
if (view is Vector2List) {
texCoordView = view;
- generateVertexTexCoords(texCoordView, positionView, mesh.indices);
+ generateVertexTexCoords(texCoordView!, positionView!, mesh.indices!);
}
}
@@ -73,7 +73,7 @@
view = mesh.getViewForAttrib('NORMAL');
if (view is Vector3List) {
normalView = view;
- generateVertexNormals(normalView, positionView, mesh.indices);
+ generateVertexNormals(normalView!, positionView!, mesh.indices!);
}
}
@@ -81,8 +81,8 @@
view = mesh.getViewForAttrib('TANGENT');
if (view is Vector4List) {
tangentView = view;
- generateVertexTangents(
- tangentView, positionView, normalView, texCoordView, mesh.indices);
+ generateVertexTangents(tangentView, positionView!, normalView!,
+ texCoordView!, mesh.indices!);
}
}
@@ -106,7 +106,7 @@
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
for (var i = 0; i < positions.length; ++i) {
- final Vector3 p = positions[i];
+ final p = positions[i];
// These are TERRIBLE texture coords, but it's better than nothing.
// Override this function and put better ones in place!
diff --git a/lib/src/vector_math_geometry/generators/ring_generator.dart b/lib/src/vector_math_geometry/generators/ring_generator.dart
index 0dc0924..e90f1fa 100644
--- a/lib/src/vector_math_geometry/generators/ring_generator.dart
+++ b/lib/src/vector_math_geometry/generators/ring_generator.dart
@@ -5,12 +5,12 @@
part of vector_math_geometry;
class RingGenerator extends GeometryGenerator {
- double _innerRadius;
- double _outerRadius;
- int _segments;
- double _thetaStart;
- double _thetaLength;
- bool _stripTextureCoordinates;
+ late final double _innerRadius;
+ late final double _outerRadius;
+ late final int _segments;
+ late final double _thetaStart;
+ late final double _thetaLength;
+ late final bool _stripTextureCoordinates;
@override
int get vertexCount => (_segments + 1) * 2;
@@ -19,8 +19,8 @@
int get indexCount => _segments * 3 * 2;
MeshGeometry createRing(double innerRadius, double outerRadius,
- {GeometryGeneratorFlags flags,
- List<GeometryFilter> filters,
+ {GeometryGeneratorFlags? flags,
+ List<GeometryFilter>? filters,
int segments = 64,
double thetaStart = 0.0,
double thetaLength = math.pi * 2.0,
@@ -36,10 +36,10 @@
@override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
- final Vector3 v = Vector3.zero();
+ final v = Vector3.zero();
var index = 0;
for (var i = 0; i <= _segments; i++) {
- final double percent = i / _segments;
+ final percent = i / _segments;
v
..x = _innerRadius * math.cos(_thetaStart + percent * _thetaLength)
..z = _innerRadius * math.sin(_thetaStart + percent * _thetaLength);
@@ -58,10 +58,10 @@
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
if (_stripTextureCoordinates) {
- final Vector2 v = Vector2.zero();
+ final v = Vector2.zero();
var index = 0;
for (var i = 0; i <= _segments; i++) {
- final double percent = i / _segments;
+ final percent = i / _segments;
v
..x = 0.0
..y = percent;
@@ -74,7 +74,7 @@
index++;
}
} else {
- final Vector2 v = Vector2.zero();
+ final v = Vector2.zero();
var index = 0;
for (var i = 0; i <= _segments; i++) {
var position = positions[index];
@@ -101,7 +101,7 @@
@override
void generateIndices(Uint16List indices) {
var index = 0;
- final int length = _segments * 2;
+ final length = _segments * 2;
for (var i = 0; i < length; i += 2) {
indices[index + 0] = i + 0;
indices[index + 1] = i + 1;
diff --git a/lib/src/vector_math_geometry/generators/sphere_generator.dart b/lib/src/vector_math_geometry/generators/sphere_generator.dart
index f0ee15b..23375de 100644
--- a/lib/src/vector_math_geometry/generators/sphere_generator.dart
+++ b/lib/src/vector_math_geometry/generators/sphere_generator.dart
@@ -5,9 +5,9 @@
part of vector_math_geometry;
class SphereGenerator extends GeometryGenerator {
- double _radius;
- int _latSegments;
- int _lonSegments;
+ late double _radius;
+ late int _latSegments;
+ late int _lonSegments;
@override
int get vertexCount => (_lonSegments + 1) * (_latSegments + 1);
@@ -18,8 +18,8 @@
MeshGeometry createSphere(num radius,
{int latSegments = 16,
int lonSegments = 16,
- GeometryGeneratorFlags flags,
- List<GeometryFilter> filters}) {
+ GeometryGeneratorFlags? flags,
+ List<GeometryFilter>? filters}) {
_radius = radius.toDouble();
_latSegments = latSegments;
_lonSegments = lonSegments;
@@ -31,8 +31,8 @@
void generateIndices(Uint16List indices) {
var i = 0;
for (var y = 0; y < _latSegments; ++y) {
- final int base1 = (_lonSegments + 1) * y;
- final int base2 = (_lonSegments + 1) * (y + 1);
+ final base1 = (_lonSegments + 1) * y;
+ final base2 = (_lonSegments + 1) * (y + 1);
for (var x = 0; x < _lonSegments; ++x) {
indices[i++] = base1 + x;
@@ -50,12 +50,12 @@
void generateVertexPositions(Vector3List positions, Uint16List indices) {
var i = 0;
for (var y = 0; y <= _latSegments; ++y) {
- final double v = y / _latSegments;
- final double sv = math.sin(v * math.pi);
- final double cv = math.cos(v * math.pi);
+ final v = y / _latSegments;
+ final sv = math.sin(v * math.pi);
+ final cv = math.cos(v * math.pi);
for (var x = 0; x <= _lonSegments; ++x) {
- final double u = x / _lonSegments;
+ final u = x / _lonSegments;
positions[i++] = Vector3(_radius * math.cos(u * math.pi * 2.0) * sv,
_radius * cv, _radius * math.sin(u * math.pi * 2.0) * sv);
@@ -68,10 +68,10 @@
Vector2List texCoords, Vector3List positions, Uint16List indices) {
var i = 0;
for (var y = 0; y <= _latSegments; ++y) {
- final double v = y / _latSegments;
+ final v = y / _latSegments;
for (var x = 0; x <= _lonSegments; ++x) {
- final double u = x / _lonSegments;
+ final u = x / _lonSegments;
texCoords[i++] = Vector2(u, v);
}
}
@@ -82,12 +82,12 @@
Vector3List normals, Vector3List positions, Uint16List indices) {
var i = 0;
for (var y = 0; y <= _latSegments; ++y) {
- final double v = y / _latSegments;
- final double sv = math.sin(v * math.pi);
- final double cv = math.cos(v * math.pi);
+ final v = y / _latSegments;
+ final sv = math.sin(v * math.pi);
+ final cv = math.cos(v * math.pi);
for (var x = 0; x <= _lonSegments; ++x) {
- final double u = x / _lonSegments;
+ final u = x / _lonSegments;
normals[i++] = Vector3(math.cos(u * math.pi * 2.0) * sv, cv,
math.sin(u * math.pi * 2.0) * sv);
diff --git a/lib/src/vector_math_geometry/mesh_geometry.dart b/lib/src/vector_math_geometry/mesh_geometry.dart
index 5062cfa..54b2f89 100644
--- a/lib/src/vector_math_geometry/mesh_geometry.dart
+++ b/lib/src/vector_math_geometry/mesh_geometry.dart
@@ -31,8 +31,8 @@
type = attrib.type;
VectorList<Vector> getView(Float32List buffer) {
- final int viewOffset = offset ~/ buffer.elementSizeInBytes;
- final int viewStride = stride ~/ buffer.elementSizeInBytes;
+ final viewOffset = offset ~/ buffer.elementSizeInBytes;
+ final viewStride = stride ~/ buffer.elementSizeInBytes;
switch (size) {
case 2:
return Vector2List.view(buffer, viewOffset, viewStride);
@@ -72,8 +72,8 @@
}
class MeshGeometry {
- Float32List buffer;
- Uint16List indices;
+ late final Float32List buffer;
+ Uint16List? indices;
final List<VertexAttrib> attribs;
final int length;
final int stride;
@@ -84,7 +84,7 @@
stride += a.elementSize * a.size;
}
var offset = 0;
- final List<VertexAttrib> attribs = <VertexAttrib>[];
+ final attribs = <VertexAttrib>[];
for (var a in attributes) {
attribs.add(VertexAttrib._resetStrideOffset(a, stride, offset));
offset += a.elementSize * a.size;
@@ -94,7 +94,7 @@
}
MeshGeometry._internal(this.length, this.stride, this.attribs,
- [Float32List externBuffer]) {
+ [Float32List? externBuffer]) {
buffer = externBuffer ??
Float32List((length * stride) ~/ Float32List.bytesPerElement);
}
@@ -109,14 +109,13 @@
// Copy the indices
if (mesh.indices != null) {
- indices = Uint16List(mesh.indices.length);
- indices.setAll(0, mesh.indices);
+ indices = Uint16List(mesh.indices!.length)..setAll(0, mesh.indices!);
}
}
factory MeshGeometry.fromJson(Map<String, Object> json) {
Float32List buffer;
- final Object jsonBuffer = json['buffer'];
+ final jsonBuffer = json['buffer'];
if (jsonBuffer is List<double>) {
buffer = Float32List.fromList(jsonBuffer);
} else {
@@ -124,7 +123,7 @@
jsonBuffer, 'json["buffer"]', 'Value type must be List<double>');
}
- final Object jsonAttribs = json['attribs'];
+ final jsonAttribs = json['attribs'];
Map<String, Object> jsonAttribsMap;
if (jsonAttribs is Map<String, Object>) {
jsonAttribsMap = jsonAttribs;
@@ -132,11 +131,11 @@
throw ArgumentError.value(jsonBuffer, 'json["attribs"]',
'Value type must be Map<String, Object>');
}
- List<VertexAttrib> attribs;
+ final attribs = <VertexAttrib>[];
var stride = 0;
for (var key in jsonAttribsMap.keys) {
VertexAttrib attrib;
- final Object jsonAttrib = jsonAttribsMap[key];
+ final jsonAttrib = jsonAttribsMap[key];
if (jsonAttrib is Map<String, Object>) {
attrib = attribFromJson(key, jsonAttrib);
attribs.add(attrib);
@@ -146,10 +145,10 @@
}
}
- final MeshGeometry mesh = MeshGeometry._internal(
+ final mesh = MeshGeometry._internal(
buffer.lengthInBytes ~/ stride, stride, attribs, buffer);
- final Object jsonIndices = json['indices'];
+ final jsonIndices = json['indices'];
if (jsonIndices is List<int>) {
mesh.indices = Uint16List.fromList(jsonIndices);
}
@@ -159,12 +158,12 @@
factory MeshGeometry.resetAttribs(
MeshGeometry inputMesh, List<VertexAttrib> attributes) {
- final MeshGeometry mesh = MeshGeometry(inputMesh.length, attributes)
+ final mesh = MeshGeometry(inputMesh.length, attributes)
..indices = inputMesh.indices;
// Copy over the attributes that were specified
for (var attrib in mesh.attribs) {
- final VertexAttrib inputAttrib = inputMesh.getAttrib(attrib.name);
+ final inputAttrib = inputMesh.getAttrib(attrib.name);
if (inputAttrib != null) {
if (inputAttrib.size != attrib.size ||
inputAttrib.type != attrib.type) {
@@ -172,8 +171,7 @@
'Attributes size or type is mismatched: ${attrib.name}');
}
- final VectorList<Vector> inputView =
- inputAttrib.getView(inputMesh.buffer);
+ final inputView = inputAttrib.getView(inputMesh.buffer);
// Copy [inputView] to a view from attrib
attrib.getView(mesh.buffer).copy(inputView);
@@ -184,26 +182,27 @@
}
factory MeshGeometry.combine(List<MeshGeometry> meshes) {
- if (meshes == null || meshes.length < 2) {
+ if (meshes.length < 2) {
throw Exception(
'Must provide at least two MeshGeometry instances to combine.');
}
// When combining meshes they must all have a matching set of VertexAttribs
- final MeshGeometry firstMesh = meshes[0];
+ final firstMesh = meshes[0];
var totalVerts = firstMesh.length;
- var totalIndices = firstMesh.indices != null ? firstMesh.indices.length : 0;
+ var totalIndices =
+ firstMesh.indices != null ? firstMesh.indices!.length : 0;
for (var i = 1; i < meshes.length; ++i) {
- final MeshGeometry srcMesh = meshes[i];
+ final srcMesh = meshes[i];
if (!firstMesh.attribsAreCompatible(srcMesh)) {
throw Exception(
'All meshes must have identical attributes to combine.');
}
totalVerts += srcMesh.length;
- totalIndices += srcMesh.indices != null ? srcMesh.indices.length : 0;
+ totalIndices += srcMesh.indices != null ? srcMesh.indices!.length : 0;
}
- final MeshGeometry mesh =
+ final mesh =
MeshGeometry._internal(totalVerts, firstMesh.stride, firstMesh.attribs);
if (totalIndices > 0) {
@@ -215,15 +214,15 @@
var indexOffset = 0;
var vertexOffset = 0;
for (var i = 0; i < meshes.length; ++i) {
- final MeshGeometry srcMesh = meshes[i];
+ final srcMesh = meshes[i];
mesh.buffer.setAll(bufferOffset, srcMesh.buffer);
if (totalIndices > 0) {
- for (var j = 0; j < srcMesh.indices.length; ++j) {
- mesh.indices[j + indexOffset] = srcMesh.indices[j] + vertexOffset;
+ for (var j = 0; j < srcMesh.indices!.length; ++j) {
+ mesh.indices![j + indexOffset] = srcMesh.indices![j] + vertexOffset;
}
vertexOffset += srcMesh.length;
- indexOffset += srcMesh.indices.length;
+ indexOffset += srcMesh.indices!.length;
}
bufferOffset += srcMesh.buffer.length;
@@ -232,10 +231,10 @@
return mesh;
}
- int get triangleVertexCount => indices != null ? indices.length : length;
+ int get triangleVertexCount => indices != null ? indices!.length : length;
- Map<String, Object> toJson() {
- final Map<String, Object> r = <String, Object>{};
+ Map<String, dynamic> toJson() {
+ final r = <String, dynamic>{};
r['attributes'] = attribs;
r['indices'] = indices;
r['vertices'] = buffer;
@@ -243,10 +242,10 @@
}
static VertexAttrib attribFromJson(String name, Map<String, Object> json) {
- final Object jsonSize = json['size'];
- final Object jsonType = json['type'];
- final Object jsonStride = json['stride'];
- final Object jsonOffset = json['offset'];
+ final jsonSize = json['size'];
+ final jsonType = json['type'];
+ final jsonStride = json['stride'];
+ final jsonOffset = json['offset'];
if (jsonSize is int &&
jsonType is String &&
jsonStride is int &&
@@ -254,11 +253,11 @@
return VertexAttrib._internal(
name, jsonSize, jsonType, jsonStride, jsonOffset);
} else {
- return null;
+ throw UnimplementedError();
}
}
- VertexAttrib getAttrib(String name) {
+ VertexAttrib? getAttrib(String name) {
for (var attrib in attribs) {
if (attrib.name == name) {
return attrib;
@@ -267,7 +266,7 @@
return null;
}
- VectorList<Vector> getViewForAttrib(String name) {
+ VectorList<Vector>? getViewForAttrib(String name) {
for (var attrib in attribs) {
if (attrib.name == name) {
return attrib.getView(buffer);
@@ -282,7 +281,7 @@
}
for (var attrib in attribs) {
- final VertexAttrib otherAttrib = mesh.getAttrib(attrib.name);
+ final otherAttrib = mesh.getAttrib(attrib.name);
if (otherAttrib == null) {
return false;
}
diff --git a/lib/src/vector_math_lists/scalar_list_view.dart b/lib/src/vector_math_lists/scalar_list_view.dart
index 4cd5f51..8c06e0f 100644
--- a/lib/src/vector_math_lists/scalar_list_view.dart
+++ b/lib/src/vector_math_lists/scalar_list_view.dart
@@ -19,7 +19,7 @@
Float32List get buffer => _buffer;
static int _listLength(int offset, int stride, int length) {
- final int width = stride == 0 ? 1 : stride;
+ final width = stride == 0 ? 1 : stride;
return offset + width * length;
}
@@ -69,7 +69,7 @@
/// Store [value] in the list at [index].
void store(int index, double value) {
- final int i = _elementIndexToBufferIndex(index);
+ final i = _elementIndexToBufferIndex(index);
_buffer[i] = value;
}
diff --git a/lib/src/vector_math_lists/vector2_list.dart b/lib/src/vector_math_lists/vector2_list.dart
index af9d456..8a582ed 100644
--- a/lib/src/vector_math_lists/vector2_list.dart
+++ b/lib/src/vector_math_lists/vector2_list.dart
@@ -27,7 +27,7 @@
/// Retrieves the vector at [index] and stores it in [vector].
@override
void load(int index, Vector2 vector) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
vector.storage[0] = _buffer[i + 0];
vector.storage[1] = _buffer[i + 1];
}
@@ -35,8 +35,8 @@
/// Store [vector] in the list at [index].
@override
void store(int index, Vector2 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
_buffer[i + 0] = storage[0];
_buffer[i + 1] = storage[1];
}
@@ -46,46 +46,46 @@
/// Set the vector at [index] to [x] and [y].
void setValues(int index, double x, double y) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
buffer[i + 0] = x;
buffer[i + 1] = y;
}
/// Add [vector] to the vector at [index].
void add(int index, Vector2 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] += storage[0];
buffer[i + 1] += storage[1];
}
/// Add [vector] scaled by [factor] to the vector at [index].
void addScaled(int index, Vector2 vector, double factor) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] += storage[0] * factor;
buffer[i + 1] += storage[1] * factor;
}
/// Substract [vector] from the vector at [index].
void sub(int index, Vector2 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] -= storage[0];
buffer[i + 1] -= storage[1];
}
/// Multiply the vector at [index] by [vector].
void multiply(int index, Vector2 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] *= storage[0];
buffer[i + 1] *= storage[1];
}
/// Scale the vector at [index] by [factor].
void scale(int index, double factor) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
buffer[i + 0] *= factor;
buffer[i + 1] *= factor;
}
diff --git a/lib/src/vector_math_lists/vector3_list.dart b/lib/src/vector_math_lists/vector3_list.dart
index 2d32b66..d7a1945 100644
--- a/lib/src/vector_math_lists/vector3_list.dart
+++ b/lib/src/vector_math_lists/vector3_list.dart
@@ -27,7 +27,7 @@
/// Retrieves the vector at [index] and stores it in [vector].
@override
void load(int index, Vector3 vector) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
vector.storage[0] = _buffer[i + 0];
vector.storage[1] = _buffer[i + 1];
vector.storage[2] = _buffer[i + 2];
@@ -36,8 +36,8 @@
/// Store [vector] in the list at [index].
@override
void store(int index, Vector3 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
_buffer[i + 0] = storage[0];
_buffer[i + 1] = storage[1];
_buffer[i + 2] = storage[2];
@@ -48,7 +48,7 @@
/// Set the vector at [index] to [x], [y], and [z].
void setValues(int index, double x, double y, double z) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
buffer[i + 0] = x;
buffer[i + 1] = y;
buffer[i + 2] = z;
@@ -56,8 +56,8 @@
/// Add [vector] to the vector at [index].
void add(int index, Vector3 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] += storage[0];
buffer[i + 1] += storage[1];
buffer[i + 2] += storage[2];
@@ -65,8 +65,8 @@
/// Add [vector] scaled by [factor] to the vector at [index].
void addScaled(int index, Vector3 vector, double factor) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] += storage[0] * factor;
buffer[i + 1] += storage[1] * factor;
buffer[i + 2] += storage[2] * factor;
@@ -74,8 +74,8 @@
/// Substract [vector] from the vector at [index].
void sub(int index, Vector3 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] -= storage[0];
buffer[i + 1] -= storage[1];
buffer[i + 2] -= storage[2];
@@ -83,8 +83,8 @@
/// Multiply the vector at [index] by [vector].
void multiply(int index, Vector3 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] *= storage[0];
buffer[i + 1] *= storage[1];
buffer[i + 2] *= storage[2];
@@ -92,7 +92,7 @@
/// Scale the vector at [index] by [factor].
void scale(int index, double factor) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
buffer[i + 0] *= factor;
buffer[i + 1] *= factor;
buffer[i + 2] *= factor;
diff --git a/lib/src/vector_math_lists/vector4_list.dart b/lib/src/vector_math_lists/vector4_list.dart
index a5b6512..860b747 100644
--- a/lib/src/vector_math_lists/vector4_list.dart
+++ b/lib/src/vector_math_lists/vector4_list.dart
@@ -27,7 +27,7 @@
/// Retrieves the vector at [index] and stores it in [vector].
@override
void load(int index, Vector4 vector) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
vector.storage[0] = _buffer[i + 0];
vector.storage[1] = _buffer[i + 1];
vector.storage[2] = _buffer[i + 2];
@@ -37,8 +37,8 @@
/// Store [vector] in the list at [index].
@override
void store(int index, Vector4 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
_buffer[i + 0] = storage[0];
_buffer[i + 1] = storage[1];
_buffer[i + 2] = storage[2];
@@ -50,7 +50,7 @@
/// Set the vector at [index] to [x], [y], [z], and [w].
void setValues(int index, double x, double y, double z, double w) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
buffer[i + 0] = x;
buffer[i + 1] = y;
buffer[i + 2] = z;
@@ -59,8 +59,8 @@
/// Add [vector] to the vector at [index].
void add(int index, Vector4 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] += storage[0];
buffer[i + 1] += storage[1];
buffer[i + 2] += storage[2];
@@ -69,8 +69,8 @@
/// Add [vector] scaled by [factor] to the vector at [index].
void addScaled(int index, Vector4 vector, double factor) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] += storage[0] * factor;
buffer[i + 1] += storage[1] * factor;
buffer[i + 2] += storage[2] * factor;
@@ -79,8 +79,8 @@
/// Substract [vector] from the vector at [index].
void sub(int index, Vector4 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] -= storage[0];
buffer[i + 1] -= storage[1];
buffer[i + 2] -= storage[2];
@@ -89,8 +89,8 @@
/// Multiply the vector at [index] by [vector].
void multiply(int index, Vector4 vector) {
- final int i = _vectorIndexToBufferIndex(index);
- final Float32List storage = vector.storage;
+ final i = _vectorIndexToBufferIndex(index);
+ final storage = vector.storage;
buffer[i + 0] *= storage[0];
buffer[i + 1] *= storage[1];
buffer[i + 2] *= storage[2];
@@ -99,7 +99,7 @@
/// Scale the vector at [index] by [factor].
void scale(int index, double factor) {
- final int i = _vectorIndexToBufferIndex(index);
+ final i = _vectorIndexToBufferIndex(index);
buffer[i + 0] *= factor;
buffer[i + 1] *= factor;
buffer[i + 2] *= factor;
diff --git a/lib/src/vector_math_lists/vector_list.dart b/lib/src/vector_math_lists/vector_list.dart
index 2c338b2..62e4b5a 100644
--- a/lib/src/vector_math_lists/vector_list.dart
+++ b/lib/src/vector_math_lists/vector_list.dart
@@ -20,7 +20,7 @@
Float32List get buffer => _buffer;
static int _listLength(int offset, int stride, int vectorLength, int length) {
- final int width = stride == 0 ? vectorLength : stride;
+ final width = stride == 0 ? vectorLength : stride;
return offset + width * length;
}
@@ -92,7 +92,7 @@
if (count == 0) {
count = math.min(length - offset, src.length - srcOffset);
}
- final int minVectorLength = math.min(_vectorLength, src._vectorLength);
+ final minVectorLength = math.min(_vectorLength, src._vectorLength);
for (var i = 0; i < count; i++) {
var index = _vectorIndexToBufferIndex(i + offset);
var srcIndex = src._vectorIndexToBufferIndex(i + srcOffset);
@@ -104,7 +104,7 @@
/// Retrieves the vector at [index].
T operator [](int index) {
- final T r = newVector();
+ final r = newVector();
load(index, r);
return r;
}
diff --git a/lib/src/vector_math_operations/matrix.dart b/lib/src/vector_math_operations/matrix.dart
index 18b9362..f3de442 100644
--- a/lib/src/vector_math_operations/matrix.dart
+++ b/lib/src/vector_math_operations/matrix.dart
@@ -9,40 +9,36 @@
class Matrix44Operations {
/// Compute the determinant of the 4x4 [matrix] starting at [offset].
static double determinant(Float32List matrix, int offset) {
- final double m0 = matrix[0 + offset];
- final double m1 = matrix[1 + offset];
- final double m2 = matrix[2 + offset];
- final double m3 = matrix[3 + offset];
- final double m4 = matrix[4 + offset];
- final double m5 = matrix[5 + offset];
- final double m6 = matrix[6 + offset];
- final double m7 = matrix[7 + offset];
+ final m0 = matrix[0 + offset];
+ final m1 = matrix[1 + offset];
+ final m2 = matrix[2 + offset];
+ final m3 = matrix[3 + offset];
+ final m4 = matrix[4 + offset];
+ final m5 = matrix[5 + offset];
+ final m6 = matrix[6 + offset];
+ final m7 = matrix[7 + offset];
- final double det2_01_01 = m0 * m5 - m1 * m4;
- final double det2_01_02 = m0 * m6 - m2 * m4;
- final double det2_01_03 = m0 * m7 - m3 * m4;
- final double det2_01_12 = m1 * m6 - m2 * m5;
- final double det2_01_13 = m1 * m7 - m3 * m5;
- final double det2_01_23 = m2 * m7 - m3 * m6;
+ final det2_01_01 = m0 * m5 - m1 * m4;
+ final det2_01_02 = m0 * m6 - m2 * m4;
+ final det2_01_03 = m0 * m7 - m3 * m4;
+ final det2_01_12 = m1 * m6 - m2 * m5;
+ final det2_01_13 = m1 * m7 - m3 * m5;
+ final det2_01_23 = m2 * m7 - m3 * m6;
- final double m8 = matrix[8 + offset];
- final double m9 = matrix[9 + offset];
- final double m10 = matrix[10 + offset];
- final double m11 = matrix[11 + offset];
+ final m8 = matrix[8 + offset];
+ final m9 = matrix[9 + offset];
+ final m10 = matrix[10 + offset];
+ final m11 = matrix[11 + offset];
- final double det3_201_012 =
- m8 * det2_01_12 - m9 * det2_01_02 + m10 * det2_01_01;
- final double det3_201_013 =
- m8 * det2_01_13 - m9 * det2_01_03 + m11 * det2_01_01;
- final double det3_201_023 =
- m8 * det2_01_23 - m10 * det2_01_03 + m11 * det2_01_02;
- final double det3_201_123 =
- m9 * det2_01_23 - m10 * det2_01_13 + m11 * det2_01_12;
+ final det3_201_012 = m8 * det2_01_12 - m9 * det2_01_02 + m10 * det2_01_01;
+ final det3_201_013 = m8 * det2_01_13 - m9 * det2_01_03 + m11 * det2_01_01;
+ final det3_201_023 = m8 * det2_01_23 - m10 * det2_01_03 + m11 * det2_01_02;
+ final det3_201_123 = m9 * det2_01_23 - m10 * det2_01_13 + m11 * det2_01_12;
- final double m12 = matrix[12 + offset];
- final double m13 = matrix[13 + offset];
- final double m14 = matrix[14 + offset];
- final double m15 = matrix[15 + offset];
+ final m12 = matrix[12 + offset];
+ final m13 = matrix[13 + offset];
+ final m14 = matrix[14 + offset];
+ final m15 = matrix[15 + offset];
return -det3_201_123 * m12 +
det3_201_023 * m13 -
@@ -53,59 +49,59 @@
/// Compute the determinant of the upper 3x3 of the 4x4 [matrix] starting at
/// [offset].
static double determinant33(Float32List matrix, int offset) {
- final double m0 = matrix[0 + offset];
- final double m1 = matrix[1 + offset];
- final double m2 = matrix[2 + offset];
- final double m4 = matrix[4 + offset];
- final double m5 = matrix[5 + offset];
- final double m6 = matrix[6 + offset];
- final double m8 = matrix[8 + offset];
- final double m9 = matrix[9 + offset];
- final double m10 = matrix[10 + offset];
- final double x = m0 * ((m5 * m10) - (m6 * m8));
- final double y = m1 * ((m4 * m10) - (m6 * m8));
- final double z = m2 * ((m4 * m9) - (m5 * m8));
+ final m0 = matrix[0 + offset];
+ final m1 = matrix[1 + offset];
+ final m2 = matrix[2 + offset];
+ final m4 = matrix[4 + offset];
+ final m5 = matrix[5 + offset];
+ final m6 = matrix[6 + offset];
+ final m8 = matrix[8 + offset];
+ final m9 = matrix[9 + offset];
+ final m10 = matrix[10 + offset];
+ final x = m0 * ((m5 * m10) - (m6 * m8));
+ final y = m1 * ((m4 * m10) - (m6 * m8));
+ final z = m2 * ((m4 * m9) - (m5 * m8));
return x - y + z;
}
/// Compute the inverse of the 4x4 [matrix] starting at [offset].
static double inverse(Float32List matrix, int offset) {
- final double a00 = matrix[0];
- final double a01 = matrix[1];
- final double a02 = matrix[2];
- final double a03 = matrix[3];
- final double a10 = matrix[4];
- final double a11 = matrix[5];
- final double a12 = matrix[6];
- final double a13 = matrix[7];
- final double a20 = matrix[8];
- final double a21 = matrix[9];
- final double a22 = matrix[10];
- final double a23 = matrix[11];
- final double a30 = matrix[12];
- final double a31 = matrix[13];
- final double a32 = matrix[14];
- final double a33 = matrix[15];
- final double b00 = a00 * a11 - a01 * a10;
- final double b01 = a00 * a12 - a02 * a10;
- final double b02 = a00 * a13 - a03 * a10;
- final double b03 = a01 * a12 - a02 * a11;
- final double b04 = a01 * a13 - a03 * a11;
- final double b05 = a02 * a13 - a03 * a12;
- final double b06 = a20 * a31 - a21 * a30;
- final double b07 = a20 * a32 - a22 * a30;
- final double b08 = a20 * a33 - a23 * a30;
- final double b09 = a21 * a32 - a22 * a31;
- final double b10 = a21 * a33 - a23 * a31;
- final double b11 = a22 * a33 - a23 * a32;
- final double det =
+ final a00 = matrix[0];
+ final a01 = matrix[1];
+ final a02 = matrix[2];
+ final a03 = matrix[3];
+ final a10 = matrix[4];
+ final a11 = matrix[5];
+ final a12 = matrix[6];
+ final a13 = matrix[7];
+ final a20 = matrix[8];
+ final a21 = matrix[9];
+ final a22 = matrix[10];
+ final a23 = matrix[11];
+ final a30 = matrix[12];
+ final a31 = matrix[13];
+ final a32 = matrix[14];
+ final a33 = matrix[15];
+ final b00 = a00 * a11 - a01 * a10;
+ final b01 = a00 * a12 - a02 * a10;
+ final b02 = a00 * a13 - a03 * a10;
+ final b03 = a01 * a12 - a02 * a11;
+ final b04 = a01 * a13 - a03 * a11;
+ final b05 = a02 * a13 - a03 * a12;
+ final b06 = a20 * a31 - a21 * a30;
+ final b07 = a20 * a32 - a22 * a30;
+ final b08 = a20 * a33 - a23 * a30;
+ final b09 = a21 * a32 - a22 * a31;
+ final b10 = a21 * a33 - a23 * a31;
+ final b11 = a22 * a33 - a23 * a32;
+ final det =
b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (det == 0.0) {
return det;
}
- final double invDet = 1.0 / det;
+ final invDet = 1.0 / det;
matrix[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
matrix[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
@@ -135,22 +131,22 @@
/// [out] = [a] * [b]; Starting at [outOffset], [aOffset], and [bOffset].
static void multiply(Float32List out, int outOffset, Float32List a,
int aOffset, Float32List b, int bOffset) {
- final double a00 = a[aOffset++];
- final double a01 = a[aOffset++];
- final double a02 = a[aOffset++];
- final double a03 = a[aOffset++];
- final double a10 = a[aOffset++];
- final double a11 = a[aOffset++];
- final double a12 = a[aOffset++];
- final double a13 = a[aOffset++];
- final double a20 = a[aOffset++];
- final double a21 = a[aOffset++];
- final double a22 = a[aOffset++];
- final double a23 = a[aOffset++];
- final double a30 = a[aOffset++];
- final double a31 = a[aOffset++];
- final double a32 = a[aOffset++];
- final double a33 = a[aOffset++];
+ final a00 = a[aOffset++];
+ final a01 = a[aOffset++];
+ final a02 = a[aOffset++];
+ final a03 = a[aOffset++];
+ final a10 = a[aOffset++];
+ final a11 = a[aOffset++];
+ final a12 = a[aOffset++];
+ final a13 = a[aOffset++];
+ final a20 = a[aOffset++];
+ final a21 = a[aOffset++];
+ final a22 = a[aOffset++];
+ final a23 = a[aOffset++];
+ final a30 = a[aOffset++];
+ final a31 = a[aOffset++];
+ final a32 = a[aOffset++];
+ final a33 = a[aOffset++];
var b0 = b[bOffset++];
var b1 = b[bOffset++];
@@ -200,29 +196,29 @@
/// starting at [matrixOffset]. Store result in [out] starting at [outOffset].
static void transform4(Float32List out, int outOffset, Float32List matrix,
int matrixOffset, Float32List vector, int vectorOffset) {
- final double x = vector[vectorOffset++];
- final double y = vector[vectorOffset++];
- final double z = vector[vectorOffset++];
- final double w = vector[vectorOffset++];
- final double m0 = matrix[matrixOffset];
- final double m4 = matrix[4 + matrixOffset];
- final double m8 = matrix[8 + matrixOffset];
- final double m12 = matrix[12 + matrixOffset];
+ final x = vector[vectorOffset++];
+ final y = vector[vectorOffset++];
+ final z = vector[vectorOffset++];
+ final w = vector[vectorOffset++];
+ final m0 = matrix[matrixOffset];
+ final m4 = matrix[4 + matrixOffset];
+ final m8 = matrix[8 + matrixOffset];
+ final m12 = matrix[12 + matrixOffset];
out[outOffset++] = m0 * x + m4 * y + m8 * z + m12 * w;
- final double m1 = matrix[1 + matrixOffset];
- final double m5 = matrix[5 + matrixOffset];
- final double m9 = matrix[9 + matrixOffset];
- final double m13 = matrix[13 + matrixOffset];
+ final m1 = matrix[1 + matrixOffset];
+ final m5 = matrix[5 + matrixOffset];
+ final m9 = matrix[9 + matrixOffset];
+ final m13 = matrix[13 + matrixOffset];
out[outOffset++] = m1 * x + m5 * y + m9 * z + m13 * w;
- final double m2 = matrix[2 + matrixOffset];
- final double m6 = matrix[6 + matrixOffset];
- final double m10 = matrix[10 + matrixOffset];
- final double m14 = matrix[14 + matrixOffset];
+ final m2 = matrix[2 + matrixOffset];
+ final m6 = matrix[6 + matrixOffset];
+ final m10 = matrix[10 + matrixOffset];
+ final m14 = matrix[14 + matrixOffset];
out[outOffset++] = m2 * x + m6 * y + m10 * z + m14 * w;
- final double m3 = matrix[3 + matrixOffset];
- final double m7 = matrix[7 + matrixOffset];
- final double m11 = matrix[11 + matrixOffset];
- final double m15 = matrix[15 + matrixOffset];
+ final m3 = matrix[3 + matrixOffset];
+ final m7 = matrix[7 + matrixOffset];
+ final m11 = matrix[11 + matrixOffset];
+ final m15 = matrix[15 + matrixOffset];
out[outOffset++] = m3 * x + m7 * y + m11 * z + m15 * w;
}
@@ -266,26 +262,26 @@
/// [out] = [A] * [B]; Starting at [outOffset], [aOffset], and [bOffset].
static void multiply(Float32x4List out, int outOffset, Float32x4List A,
int aOffset, Float32x4List B, int bOffset) {
- final Float32x4 a0 = A[aOffset++];
- final Float32x4 a1 = A[aOffset++];
- final Float32x4 a2 = A[aOffset++];
- final Float32x4 a3 = A[aOffset++];
- final Float32x4 b0 = B[bOffset++];
+ final a0 = A[aOffset++];
+ final a1 = A[aOffset++];
+ final a2 = A[aOffset++];
+ final a3 = A[aOffset++];
+ final b0 = B[bOffset++];
out[outOffset++] = b0.shuffle(Float32x4.xxxx) * a0 +
b0.shuffle(Float32x4.yyyy) * a1 +
b0.shuffle(Float32x4.zzzz) * a2 +
b0.shuffle(Float32x4.wwww) * a3;
- final Float32x4 b1 = B[bOffset++];
+ final b1 = B[bOffset++];
out[outOffset++] = b1.shuffle(Float32x4.xxxx) * a0 +
b1.shuffle(Float32x4.yyyy) * a1 +
b1.shuffle(Float32x4.zzzz) * a2 +
b1.shuffle(Float32x4.wwww) * a3;
- final Float32x4 b2 = B[bOffset++];
+ final b2 = B[bOffset++];
out[outOffset++] = b2.shuffle(Float32x4.xxxx) * a0 +
b2.shuffle(Float32x4.yyyy) * a1 +
b2.shuffle(Float32x4.zzzz) * a2 +
b2.shuffle(Float32x4.wwww) * a3;
- final Float32x4 b3 = B[bOffset++];
+ final b3 = B[bOffset++];
out[outOffset++] = b3.shuffle(Float32x4.xxxx) * a0 +
b3.shuffle(Float32x4.yyyy) * a1 +
b3.shuffle(Float32x4.zzzz) * a2 +
@@ -296,20 +292,20 @@
/// starting at [matrixOffset]. Store result in [out] starting at [outOffset].
static void transform4(Float32x4List out, int outOffset, Float32x4List matrix,
int matrixOffset, Float32x4List vector, int vectorOffset) {
- final Float32x4 v = vector[vectorOffset];
- final Float32x4 xxxx = v.shuffle(Float32x4.xxxx);
+ final v = vector[vectorOffset];
+ final xxxx = v.shuffle(Float32x4.xxxx);
var z = Float32x4.zero();
z += xxxx * matrix[0 + matrixOffset];
- final Float32x4 yyyy = v.shuffle(Float32x4.yyyy);
+ final yyyy = v.shuffle(Float32x4.yyyy);
z += yyyy * matrix[1 + matrixOffset];
- final Float32x4 zzzz = v.shuffle(Float32x4.zzzz);
+ final zzzz = v.shuffle(Float32x4.zzzz);
z += zzzz * matrix[2 + matrixOffset];
z += matrix[3 + matrixOffset];
out[0 + outOffset] = z;
}
static void zero(Float32x4List matrix, int offset) {
- final Float32x4 z = Float32x4.zero();
+ final z = Float32x4.zero();
matrix[offset++] = z;
matrix[offset++] = z;
matrix[offset++] = z;
diff --git a/pubspec.yaml b/pubspec.yaml
index 6a4b6b0..8ee0fe2 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -5,10 +5,14 @@
homepage: https://github.com/google/vector_math.dart
environment:
- sdk: '>=2.3.0 <3.0.0'
+ sdk: '>=2.9.0-1 <3.0.0'
dev_dependencies:
benchmark_harness: any
path: ^1.0.0
pedantic: ^1.0.0
test: ^1.6.0
+
+ build_runner: ^1.0.0
+ build_test: ^0.10.0
+ build_web_compilers: '>=1.2.0 <3.0.0'
diff --git a/test/aabb2_test.dart b/test/aabb2_test.dart
index d3dc130..62879f7 100644
--- a/test/aabb2_test.dart
+++ b/test/aabb2_test.dart
@@ -154,7 +154,7 @@
expect(a.max.x, equals(6.0));
expect(a.max.y, equals(4.0));
- final Vector2 c = $v2(0.0, 1.0);
+ final c = $v2(0.0, 1.0);
a.hullPoint(c);
diff --git a/test/aabb3_test.dart b/test/aabb3_test.dart
index b787912..7d6e6ec 100644
--- a/test/aabb3_test.dart
+++ b/test/aabb3_test.dart
@@ -304,7 +304,7 @@
expect(a.max.y, equals(4.0));
expect(a.max.z, equals(10.0));
- final Vector3 c = $v3(6.0, 0.0, 2.0);
+ final c = $v3(6.0, 0.0, 2.0);
a.hullPoint(c);
diff --git a/test/frustum_test.dart b/test/frustum_test.dart
index b50d9d0..35053b0 100644
--- a/test/frustum_test.dart
+++ b/test/frustum_test.dart
@@ -11,7 +11,7 @@
import 'test_utils.dart';
void testFrustumContainsVector3() {
- final Frustum frustum =
+ final frustum =
Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0));
expect(frustum.containsVector3($v3(0.0, 0.0, 0.0)), isFalse);
@@ -30,7 +30,7 @@
}
void testFrustumIntersectsWithSphere() {
- final Frustum frustum =
+ final frustum =
Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0));
expect(
@@ -120,7 +120,7 @@
}
void testFrustumIntersectsWithAabb3() {
- final Frustum frustum =
+ final frustum =
Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0));
expect(
@@ -162,7 +162,7 @@
}
void testFrustumCalculateCorners() {
- final Frustum frustum =
+ final frustum =
Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0));
final c0 = Vector3.zero();
diff --git a/test/geometry_test.dart b/test/geometry_test.dart
index 40e600b..32887ce 100644
--- a/test/geometry_test.dart
+++ b/test/geometry_test.dart
@@ -15,14 +15,14 @@
import 'test_utils.dart';
void testGenerateNormals() {
- final Vector3List positions = Vector3List.fromList([
+ final positions = Vector3List.fromList([
Vector3(-1.0, 1.0, 1.0),
Vector3(1.0, 1.0, 1.0),
Vector3(1.0, 1.0, -1.0),
Vector3(1.0, -1.0, 1.0),
]);
- final Uint16List indices = Uint16List.fromList([0, 1, 2, 3, 2, 1]);
+ final indices = Uint16List.fromList([0, 1, 2, 3, 2, 1]);
final normals = Vector3List(positions.length);
@@ -35,28 +35,28 @@
}
void testGenerateTangents() {
- final Vector3List positions = Vector3List.fromList([
+ final positions = Vector3List.fromList([
Vector3(-1.0, 1.0, 1.0),
Vector3(1.0, 1.0, 1.0),
Vector3(1.0, 1.0, -1.0),
Vector3(1.0, -1.0, 1.0),
]);
- final Vector3List normals = Vector3List.fromList([
+ final normals = Vector3List.fromList([
Vector3(0.0, 1.0, 0.0),
Vector3(0.70710, 0.70710, 0.0),
Vector3(0.70710, 0.70710, 0.0),
Vector3(1.0, 0.0, 0.0),
]);
- final Vector2List texCoords = Vector2List.fromList([
+ final texCoords = Vector2List.fromList([
Vector2(-1.0, 1.0),
Vector2(1.0, 1.0),
Vector2(1.0, -1.0),
Vector2(-1.0, 1.0),
]);
- final Uint16List indices = Uint16List.fromList([0, 1, 2, 3, 2, 1]);
+ final indices = Uint16List.fromList([0, 1, 2, 3, 2, 1]);
final tangents = Vector4List(positions.length);
diff --git a/test/matrix2_test.dart b/test/matrix2_test.dart
index 6fae198..26c02cf 100644
--- a/test/matrix2_test.dart
+++ b/test/matrix2_test.dart
@@ -80,9 +80,9 @@
}
void testMatrix2Dot() {
- final Matrix2 matrix = Matrix2(1.0, 2.0, 3.0, 4.0);
+ final matrix = Matrix2(1.0, 2.0, 3.0, 4.0);
- final Vector2 v = Vector2(3.0, 4.0);
+ final v = Vector2(3.0, 4.0);
expect(matrix.dotRow(0, v), equals(15.0));
expect(matrix.dotRow(1, v), equals(22.0));
@@ -101,15 +101,15 @@
}
void testMatrix2Solving() {
- final Matrix2 A = Matrix2(2.0, 2.0, 8.0, 20.0);
- final Matrix2 AA = Matrix2.fromList([2.0, 2.0, 8.0, 20.0]);
+ final A = Matrix2(2.0, 2.0, 8.0, 20.0);
+ final AA = Matrix2.fromList([2.0, 2.0, 8.0, 20.0]);
expect(A, equals(AA));
- final Vector2 b = Vector2(20.0, 64.0);
- final Vector2 result = Vector2.zero();
+ final b = Vector2(20.0, 64.0);
+ final result = Vector2.zero();
Matrix2.solve(A, result, b);
- final Vector2 backwards = A.transform(Vector2.copy(result));
+ final backwards = A.transform(Vector2.copy(result));
expect(backwards.x, equals(b.x));
expect(backwards.y, equals(b.y));
diff --git a/test/matrix3_test.dart b/test/matrix3_test.dart
index 4efe798..d3a247e 100644
--- a/test/matrix3_test.dart
+++ b/test/matrix3_test.dart
@@ -261,9 +261,9 @@
}
void testMatrix3Dot() {
- final Matrix3 matrix = Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
+ final matrix = Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
- final Vector3 v = Vector3(2.0, 3.0, 4.0);
+ final v = Vector3(2.0, 3.0, 4.0);
expect(matrix.dotRow(0, v), equals(42.0));
expect(matrix.dotRow(1, v), equals(51.0));
@@ -289,19 +289,19 @@
}
void testMatrix3Solving() {
- final Matrix3 A = Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0);
+ final A = Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0);
- final Vector3 b = Vector3(32.0, 64.0, 72.0);
- final Vector3 result = Vector3.zero();
+ final b = Vector3(32.0, 64.0, 72.0);
+ final result = Vector3.zero();
- final Vector2 b2 = Vector2(32.0, 64.0);
- final Vector2 result2 = Vector2.zero();
+ final b2 = Vector2(32.0, 64.0);
+ final result2 = Vector2.zero();
Matrix3.solve(A, result, b);
Matrix3.solve2(A, result2, b2);
- final Vector3 backwards = A.transform(Vector3.copy(result));
- final Vector2 backwards2 = A.transform2(Vector2.copy(result2));
+ final backwards = A.transform(Vector3.copy(result));
+ final backwards2 = A.transform2(Vector2.copy(result2));
expect(backwards.x, equals(b.x));
expect(backwards.y, equals(b.y));
diff --git a/test/matrix4_test.dart b/test/matrix4_test.dart
index ba04081..919f436 100644
--- a/test/matrix4_test.dart
+++ b/test/matrix4_test.dart
@@ -13,7 +13,7 @@
import 'test_utils.dart';
void testMatrix4InstacingFromFloat32List() {
- final Float32List float32List = Float32List.fromList([
+ final float32List = Float32List.fromList([
1.0,
2.0,
3.0,
@@ -31,8 +31,8 @@
15.0,
16.0
]);
- final Matrix4 input = Matrix4.fromFloat32List(float32List);
- final Matrix4 inputB = Matrix4.fromList(float32List);
+ final input = Matrix4.fromFloat32List(float32List);
+ final inputB = Matrix4.fromList(float32List);
expect(input, equals(inputB));
expect(input.storage[0], equals(1.0));
@@ -57,7 +57,7 @@
}
void testMatrix4InstacingFromByteBuffer() {
- final Float32List float32List = Float32List.fromList([
+ final float32List = Float32List.fromList([
1.0,
2.0,
3.0,
@@ -76,10 +76,9 @@
16.0,
17.0
]);
- final ByteBuffer buffer = float32List.buffer;
- final Matrix4 zeroOffset = Matrix4.fromBuffer(buffer, 0);
- final Matrix4 offsetVector =
- Matrix4.fromBuffer(buffer, Float32List.bytesPerElement);
+ final buffer = float32List.buffer;
+ final zeroOffset = Matrix4.fromBuffer(buffer, 0);
+ final offsetVector = Matrix4.fromBuffer(buffer, Float32List.bytesPerElement);
expect(zeroOffset.storage[0], equals(1.0));
expect(zeroOffset.storage[1], equals(2.0));
@@ -474,10 +473,10 @@
}
void testMatrix4Dot() {
- final Matrix4 matrix = Matrix4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,
- 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0);
+ final matrix = Matrix4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0,
+ 11.0, 12.0, 13.0, 14.0, 15.0, 16.0);
- final Vector4 v = Vector4(1.0, 2.0, 3.0, 4.0);
+ final v = Vector4(1.0, 2.0, 3.0, 4.0);
expect(matrix.dotRow(0, v), equals(90.0));
expect(matrix.dotRow(1, v), equals(100.0));
@@ -497,28 +496,27 @@
}
void testMatrix4Solving() {
- final Matrix4 A = Matrix4(2.0, 12.0, 8.0, 8.0, 20.0, 24.0, 26.0, 4.0, 8.0,
- 4.0, 60.0, 12.0, 16.0, 16.0, 14.0, 64.0);
+ final A = Matrix4(2.0, 12.0, 8.0, 8.0, 20.0, 24.0, 26.0, 4.0, 8.0, 4.0, 60.0,
+ 12.0, 16.0, 16.0, 14.0, 64.0);
- final Matrix3 A_small =
- Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0);
+ final A_small = Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0);
- final Vector4 b = Vector4(32.0, 64.0, 72.0, 8.0);
- final Vector4 result = Vector4.zero();
+ final b = Vector4(32.0, 64.0, 72.0, 8.0);
+ final result = Vector4.zero();
- final Vector3 b3 = Vector3(32.0, 64.0, 72.0);
- final Vector3 result3 = Vector3.zero();
+ final b3 = Vector3(32.0, 64.0, 72.0);
+ final result3 = Vector3.zero();
- final Vector2 b2 = Vector2(32.0, 64.0);
- final Vector2 result2 = Vector2.zero();
+ final b2 = Vector2(32.0, 64.0);
+ final result2 = Vector2.zero();
Matrix4.solve(A, result, b);
Matrix4.solve3(A, result3, b3);
Matrix4.solve2(A, result2, b2);
- final Vector4 backwards = A.transform(Vector4.copy(result));
- final Vector3 backwards3 = A.transform3(Vector3.copy(result3));
- final Vector2 backwards2 = A_small.transform2(Vector2.copy(result2));
+ final backwards = A.transform(Vector4.copy(result));
+ final backwards3 = A.transform3(Vector3.copy(result3));
+ final backwards2 = A_small.transform2(Vector2.copy(result2));
expect(backwards2.x, equals(b.x));
expect(backwards2.y, equals(b.y));
diff --git a/test/noise_test.dart b/test/noise_test.dart
index c6dc0c7..7f86b22 100644
--- a/test/noise_test.dart
+++ b/test/noise_test.dart
@@ -9,10 +9,10 @@
import 'package:vector_math/vector_math.dart';
void testSimplexNoise() {
- final SimplexNoise noise = SimplexNoise();
+ final noise = SimplexNoise();
- final values2D = List<double>(10);
- final values3D = List<double>(10);
+ final values2D = List<double>.filled(10, 0);
+ final values3D = List<double>.filled(10, 0);
// Cache several values at known coordinates
for (var i = 0; i < values2D.length; ++i) {
diff --git a/test/obb3_test.dart b/test/obb3_test.dart
index a6e0dc6..6be1306 100644
--- a/test/obb3_test.dart
+++ b/test/obb3_test.dart
@@ -303,14 +303,14 @@
}
void testIntersectionVector3() {
- //final Aabb3 parent = new Aabb3.minMax(_v(1.0,1.0,1.0), _v(8.0,8.0,8.0));
- final Obb3 parent = Obb3()
+ //final parent = new Aabb3.minMax(_v(1.0,1.0,1.0), _v(8.0,8.0,8.0));
+ final parent = Obb3()
..center.setValues(4.5, 4.5, 4.5)
..halfExtents.setValues(3.5, 3.5, 3.5);
- final Vector3 child = $v3(7.0, 7.0, 7.0);
- final Vector3 cutting = $v3(1.0, 2.0, 1.0);
- final Vector3 outside1 = $v3(-10.0, 10.0, 10.0);
- final Vector3 outside2 = $v3(4.5, 4.5, 9.0);
+ final child = $v3(7.0, 7.0, 7.0);
+ final cutting = $v3(1.0, 2.0, 1.0);
+ final outside1 = $v3(-10.0, 10.0, 10.0);
+ final outside2 = $v3(4.5, 4.5, 9.0);
expect(parent.intersectsWithVector3(child), isTrue);
expect(parent.intersectsWithVector3(cutting), isTrue);
@@ -327,22 +327,22 @@
}
void testIntersectionTriangle() {
- final Obb3 parent = Obb3();
+ final parent = Obb3();
parent.center.setValues(4.5, 4.5, 4.5);
parent.halfExtents.setValues(3.5, 3.5, 3.5);
- final Triangle child = Triangle.points(
+ final child = Triangle.points(
$v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0));
- final Triangle edge = Triangle.points(
+ final edge = Triangle.points(
$v3(1.0, 1.0, 1.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0));
- final Triangle cutting = Triangle.points(
+ final cutting = Triangle.points(
$v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(14.0, 14.0, 14.0));
- final Triangle outside = Triangle.points(
+ final outside = Triangle.points(
$v3(0.0, 0.0, 0.0), $v3(-3.0, -3.0, -3.0), $v3(-4.0, -4.0, -4.0));
- final Triangle parallel0 = Triangle.points(
+ final parallel0 = Triangle.points(
$v3(1.0, 0.0, 1.0), $v3(1.0, 10.0, 1.0), $v3(1.0, 0.0, 10.0));
- final Triangle parallel1 = Triangle.points(
+ final parallel1 = Triangle.points(
$v3(1.0, 4.5, 0.0), $v3(1.0, -1.0, 9.0), $v3(1.0, 10.0, 9.0));
- final Triangle parallel2 = Triangle.points(
+ final parallel2 = Triangle.points(
$v3(1.0, 10.0, 9.0), $v3(1.0, -1.0, 9.0), $v3(1.0, 4.5, 0.0));
expect(parent.intersectsWithTriangle(child), isTrue);
@@ -386,58 +386,58 @@
expect(parent.intersectsWithTriangle(parallel1), isTrue);
expect(parent.intersectsWithTriangle(parallel2), isTrue);
- final Obb3 obb = Obb3.centerExtentsAxes(
+ final obb = Obb3.centerExtentsAxes(
$v3(21.0, -36.400001525878906, 2.799999952316284),
$v3(0.25, 0.15000000596046448, 0.25),
$v3(0.0, 1.0, 0.0),
$v3(-1.0, 0.0, 0.0),
$v3(0.0, 0.0, 1.0));
- final Triangle triangle = Triangle.points(
+ final triangle = Triangle.points(
$v3(20.5, -36.5, 3.5), $v3(21.5, -36.5, 2.5), $v3(20.5, -36.5, 2.5));
expect(obb.intersectsWithTriangle(triangle), isTrue);
- final Obb3 obb2 = Obb3.centerExtentsAxes(
+ final obb2 = Obb3.centerExtentsAxes(
$v3(25.15829086303711, -36.27009201049805, 3.0299079418182373),
$v3(0.25, 0.15000000596046448, 0.25),
$v3(-0.7071067690849304, 0.7071067690849304, 0.0),
$v3(-0.7071067690849304, -0.7071067690849304, 0.0),
$v3(0.0, 0.0, 1.0));
- final Triangle triangle2 = Triangle.points(
+ final triangle2 = Triangle.points(
$v3(25.5, -36.5, 2.5), $v3(25.5, -35.5, 3.5), $v3(24.5, -36.5, 2.5));
- final Triangle triangle2_1 = Triangle.points($v3(24.5, -36.5, 2.5),
+ final triangle2_1 = Triangle.points($v3(24.5, -36.5, 2.5),
$v3(25.5, -35.5, 3.5), $v3(25.5, -36.5, 2.5)); // reverse normal direction
expect(obb2.intersectsWithTriangle(triangle2), isTrue);
expect(obb2.intersectsWithTriangle(triangle2_1), isTrue);
- final Obb3 obb3 = Obb3.centerExtentsAxes(
+ final obb3 = Obb3.centerExtentsAxes(
$v3(20.937196731567383, -37.599998474121094, 2.799999952316284),
$v3(0.25, 0.15000000596046448, 0.25),
$v3(0.0, -1.0, 0.0),
$v3(1.0, 0.0, 0.0),
$v3(0.0, 0.0, 1.0));
- final Triangle triangle3 = Triangle.points(
+ final triangle3 = Triangle.points(
$v3(20.5, -37.5, 3.5), $v3(20.5, -37.5, 2.5), $v3(21.5, -37.5, 2.5));
- final Triangle triangle3_1 = Triangle.points($v3(21.5, -37.5, 2.5),
+ final triangle3_1 = Triangle.points($v3(21.5, -37.5, 2.5),
$v3(20.5, -37.5, 2.5), $v3(20.5, -37.5, 3.5)); // reverse normal direction
expect(obb3.intersectsWithTriangle(triangle3), isTrue);
expect(obb3.intersectsWithTriangle(triangle3_1), isTrue);
- final Obb3 obb4 = Obb3.centerExtentsAxes(
+ final obb4 = Obb3.centerExtentsAxes(
$v3(19.242143630981445, -39.20925521850586, 2.549999952316284),
$v3(0.25, 0.15000000596046448, 0.25),
$v3(0.0, 1.0, 0.0),
$v3(-1.0, 0.0, 0.0),
$v3(0.0, 0.0, 1.0));
- final Triangle triangle4 = Triangle.points(
+ final triangle4 = Triangle.points(
$v3(18.5, -39.5, 2.5), $v3(19.5, -39.5, 2.5), $v3(19.5, -38.5, 2.5));
- final Triangle triangle4_1 = Triangle.points($v3(19.5, -38.5, 2.5),
+ final triangle4_1 = Triangle.points($v3(19.5, -38.5, 2.5),
$v3(19.5, -39.5, 2.5), $v3(18.5, -39.5, 2.5)); // reverse normal direction
- final Triangle triangle4_2 = Triangle.points(
+ final triangle4_2 = Triangle.points(
$v3(18.5, -39.5, 2.5), $v3(19.5, -38.5, 2.5), $v3(18.5, -38.5, 2.5));
- final Triangle triangle4_3 = Triangle.points($v3(18.5, -38.5, 2.5),
+ final triangle4_3 = Triangle.points($v3(18.5, -38.5, 2.5),
$v3(19.5, -38.5, 2.5), $v3(18.5, -39.5, 2.5)); // reverse normal direction
expect(obb4.intersectsWithTriangle(triangle4), isTrue);
diff --git a/test/opengl_matrix_test.dart b/test/opengl_matrix_test.dart
index 9225ba1..dcc8c81 100644
--- a/test/opengl_matrix_test.dart
+++ b/test/opengl_matrix_test.dart
@@ -61,10 +61,10 @@
}
void testPerspectiveMatrix() {
- final double fov = pi / 2;
- final double aspectRatio = 2.0;
- final double zNear = 1.0;
- final double zFar = 100.0;
+ final fov = pi / 2;
+ final aspectRatio = 2.0;
+ final zNear = 1.0;
+ final zFar = 100.0;
final perspective = makePerspectiveMatrix(fov, aspectRatio, zNear, zFar);
relativeTest(perspective.getColumn(0), Vector4(0.5, 0.0, 0.0, 0.0));
@@ -75,9 +75,9 @@
}
void testInfiniteMatrix() {
- final double fov = pi / 2;
- final double aspectRatio = 2.0;
- final double zNear = 1.0;
+ final fov = pi / 2;
+ final aspectRatio = 2.0;
+ final zNear = 1.0;
final infinite = makeInfiniteMatrix(fov, aspectRatio, zNear);
relativeTest(infinite.getColumn(0), Vector4(0.5, 0.0, 0.0, 0.0));
diff --git a/test/quaternion_test.dart b/test/quaternion_test.dart
index b75133d..2ba200a 100644
--- a/test/quaternion_test.dart
+++ b/test/quaternion_test.dart
@@ -13,8 +13,8 @@
import 'test_utils.dart';
void testQuaternionInstacinfFromFloat32List() {
- final Float32List float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0]);
- final Quaternion input = Quaternion.fromFloat32List(float32List);
+ final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0]);
+ final input = Quaternion.fromFloat32List(float32List);
expect(input.x, equals(1.0));
expect(input.y, equals(2.0));
@@ -23,11 +23,10 @@
}
void testQuaternionInstacingFromByteBuffer() {
- final Float32List float32List =
- Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0]);
- final ByteBuffer buffer = float32List.buffer;
- final Quaternion zeroOffset = Quaternion.fromBuffer(buffer, 0);
- final Quaternion offsetVector =
+ final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0]);
+ final buffer = float32List.buffer;
+ final zeroOffset = Quaternion.fromBuffer(buffer, 0);
+ final offsetVector =
Quaternion.fromBuffer(buffer, Float32List.bytesPerElement);
expect(zeroOffset.x, equals(1.0));
diff --git a/test/scalar_list_view_test.dart b/test/scalar_list_view_test.dart
index 6b1b036..e635a7f 100644
--- a/test/scalar_list_view_test.dart
+++ b/test/scalar_list_view_test.dart
@@ -40,10 +40,11 @@
}
void testScalarListViewFromList() {
- final input = List<double>(3);
- input[0] = 1.0;
- input[1] = 4.0;
- input[2] = 7.0;
+ final input = [
+ 1.0,
+ 4.0,
+ 7.0,
+ ];
final list = ScalarListView.fromList(input, 2, 3);
expect(list.buffer.length, 11);
expect(list.buffer[0], 0.0);
diff --git a/test/test_utils.dart b/test/test_utils.dart
index 6007f8b..7733111 100644
--- a/test/test_utils.dart
+++ b/test/test_utils.dart
@@ -15,14 +15,14 @@
Vector4 $v4(double x, double y, double z, double w) => Vector4(x, y, z, w);
void relativeTest(dynamic output, dynamic expectedOutput) {
- final num errorThreshold = 0.0005;
+ final errorThreshold = 0.0005;
final num error = relativeError(output, expectedOutput).abs();
expect(error >= errorThreshold, isFalse,
reason: '$output != $expectedOutput : relativeError = $error');
}
void absoluteTest(dynamic output, dynamic expectedOutput) {
- final num errorThreshold = 0.0005;
+ final errorThreshold = 0.0005;
final num error = absoluteError(output, expectedOutput).abs();
expect(error >= errorThreshold, isFalse,
reason: '$output != $expectedOutput : absoluteError = $error');
@@ -101,6 +101,8 @@
r = Vector3(values[0], values[1], values[2]);
} else if (values.length == 4) {
r = Vector4(values[0], values[1], values[2], values[3]);
+ } else {
+ throw UnimplementedError();
}
return r as T;
diff --git a/test/vector2_list_test.dart b/test/vector2_list_test.dart
index 78f0e99..51a5661 100644
--- a/test/vector2_list_test.dart
+++ b/test/vector2_list_test.dart
@@ -60,10 +60,11 @@
}
void testVector2ListFromList() {
- final input = List<Vector2>(3);
- input[0] = Vector2(1.0, 2.0);
- input[1] = Vector2(3.0, 4.0);
- input[2] = Vector2(5.0, 6.0);
+ final input = [
+ Vector2(1.0, 2.0),
+ Vector2(3.0, 4.0),
+ Vector2(5.0, 6.0),
+ ];
final list = Vector2List.fromList(input, 2, 5);
expect(list.buffer.length, 17);
expect(list.buffer[0], 0.0);
diff --git a/test/vector2_test.dart b/test/vector2_test.dart
index f66265a..b1b2239 100644
--- a/test/vector2_test.dart
+++ b/test/vector2_test.dart
@@ -34,8 +34,8 @@
}
void testVector2Add() {
- final Vector2 a = Vector2(5.0, 7.0);
- final Vector2 b = Vector2(3.0, 8.0);
+ final a = Vector2(5.0, 7.0);
+ final b = Vector2(3.0, 8.0);
a.add(b);
expect(a.x, equals(8.0));
@@ -47,8 +47,8 @@
}
void testVector2MinMax() {
- final Vector2 a = Vector2(5.0, 7.0);
- final Vector2 b = Vector2(3.0, 8.0);
+ final a = Vector2(5.0, 7.0);
+ final b = Vector2(3.0, 8.0);
final result = Vector2.zero();
@@ -62,8 +62,8 @@
}
void testVector2Mix() {
- final Vector2 a = Vector2(5.0, 7.0);
- final Vector2 b = Vector2(3.0, 8.0);
+ final a = Vector2(5.0, 7.0);
+ final b = Vector2(3.0, 8.0);
final result = Vector2.zero();
@@ -81,9 +81,9 @@
}
void testVector2DotProduct() {
- final Vector2 inputA = Vector2(0.417267069084370, 0.049654430325742);
- final Vector2 inputB = Vector2(0.944787189721646, 0.490864092468080);
- final double expectedOutput = 0.418602158442475;
+ final inputA = Vector2(0.417267069084370, 0.049654430325742);
+ final inputB = Vector2(0.944787189721646, 0.490864092468080);
+ final expectedOutput = 0.418602158442475;
relativeTest(dot2(inputA, inputB), expectedOutput);
relativeTest(dot2(inputB, inputA), expectedOutput);
}
@@ -105,8 +105,8 @@
}
void testVector2CrossProduct() {
- final Vector2 inputA = Vector2(0.417267069084370, 0.049654430325742);
- final Vector2 inputB = Vector2(0.944787189721646, 0.490864092468080);
+ final inputA = Vector2(0.417267069084370, 0.049654430325742);
+ final inputB = Vector2(0.944787189721646, 0.490864092468080);
final expectedOutputCross = inputA.x * inputB.y - inputA.y * inputB.x;
dynamic result;
result = cross2(inputA, inputB);
@@ -114,15 +114,15 @@
result = Vector2.zero();
cross2A(1.0, inputA, result as Vector2);
relativeTest(result, Vector2(-inputA.y, inputA.x));
- cross2B(inputA, 1.0, result as Vector2);
+ cross2B(inputA, 1.0, result);
relativeTest(result, Vector2(inputA.y, -inputA.x));
- cross2B(inputA, 1.0, result as Vector2);
+ cross2B(inputA, 1.0, result);
relativeTest(result, Vector2(inputA.y, -inputA.x));
}
void testVector2OrthogonalScale() {
- final Vector2 input = Vector2(0.5, 0.75);
- final Vector2 output = Vector2.zero();
+ final input = Vector2(0.5, 0.75);
+ final output = Vector2.zero();
input.scaleOrthogonalInto(2.0, output);
expect(output.x, equals(-1.5));
@@ -152,7 +152,7 @@
}
void testVector2Length() {
- final Vector2 a = Vector2(5.0, 7.0);
+ final a = Vector2(5.0, 7.0);
relativeTest(a.length, 8.6);
relativeTest(a.length2, 74.0);
diff --git a/test/vector3_list_test.dart b/test/vector3_list_test.dart
index 41cbbfc..c61ae2e 100644
--- a/test/vector3_list_test.dart
+++ b/test/vector3_list_test.dart
@@ -66,10 +66,11 @@
}
void testVector3ListFromList() {
- final input = List<Vector3>(3);
- input[0] = Vector3(1.0, 2.0, 3.0);
- input[1] = Vector3(4.0, 5.0, 6.0);
- input[2] = Vector3(7.0, 8.0, 9.0);
+ final input = [
+ Vector3(1.0, 2.0, 3.0),
+ Vector3(4.0, 5.0, 6.0),
+ Vector3(7.0, 8.0, 9.0),
+ ];
final list = Vector3List.fromList(input, 2, 5);
expect(list.buffer.length, 17);
expect(list.buffer[0], 0.0);
diff --git a/test/vector3_test.dart b/test/vector3_test.dart
index 6382c90..e704f57 100644
--- a/test/vector3_test.dart
+++ b/test/vector3_test.dart
@@ -13,8 +13,8 @@
import 'test_utils.dart';
void testVector3InstacinfFromFloat32List() {
- final Float32List float32List = Float32List.fromList([1.0, 2.0, 3.0]);
- final Vector3 input = Vector3.fromFloat32List(float32List);
+ final float32List = Float32List.fromList([1.0, 2.0, 3.0]);
+ final input = Vector3.fromFloat32List(float32List);
expect(input.x, equals(1.0));
expect(input.y, equals(2.0));
@@ -22,11 +22,10 @@
}
void testVector3InstacingFromByteBuffer() {
- final Float32List float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0]);
- final ByteBuffer buffer = float32List.buffer;
- final Vector3 zeroOffset = Vector3.fromBuffer(buffer, 0);
- final Vector3 offsetVector =
- Vector3.fromBuffer(buffer, Float32List.bytesPerElement);
+ final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0]);
+ final buffer = float32List.buffer;
+ final zeroOffset = Vector3.fromBuffer(buffer, 0);
+ final offsetVector = Vector3.fromBuffer(buffer, Float32List.bytesPerElement);
expect(zeroOffset.x, equals(1.0));
expect(zeroOffset.y, equals(2.0));
@@ -38,8 +37,8 @@
}
void testVector3Add() {
- final Vector3 a = Vector3(5.0, 7.0, 3.0);
- final Vector3 b = Vector3(3.0, 8.0, 2.0);
+ final a = Vector3(5.0, 7.0, 3.0);
+ final b = Vector3(3.0, 8.0, 2.0);
a.add(b);
expect(a.x, equals(8.0));
@@ -53,8 +52,8 @@
}
void testVector3MinMax() {
- final Vector3 a = Vector3(5.0, 7.0, -3.0);
- final Vector3 b = Vector3(3.0, 8.0, 2.0);
+ final a = Vector3(5.0, 7.0, -3.0);
+ final b = Vector3(3.0, 8.0, 2.0);
final result = Vector3.zero();
@@ -70,8 +69,8 @@
}
void testVector3Mix() {
- final Vector3 a = Vector3(5.0, 7.0, 3.0);
- final Vector3 b = Vector3(3.0, 8.0, 2.0);
+ final a = Vector3(5.0, 7.0, 3.0);
+ final b = Vector3(3.0, 8.0, 2.0);
final result = Vector3.zero();
@@ -208,7 +207,7 @@
}
void testVector3Length() {
- final Vector3 a = Vector3(5.0, 7.0, 3.0);
+ final a = Vector3(5.0, 7.0, 3.0);
relativeTest(a.length, 9.1104);
relativeTest(a.length2, 83.0);
diff --git a/test/vector4_list_test.dart b/test/vector4_list_test.dart
index 75007a0..6fbcac3 100644
--- a/test/vector4_list_test.dart
+++ b/test/vector4_list_test.dart
@@ -72,10 +72,11 @@
}
void testVector4ListFromList() {
- final input = List<Vector4>(3);
- input[0] = Vector4(1.0, 2.0, 3.0, 4.0);
- input[1] = Vector4(5.0, 6.0, 7.0, 8.0);
- input[2] = Vector4(9.0, 10.0, 11.0, 12.0);
+ final input = [
+ Vector4(1.0, 2.0, 3.0, 4.0),
+ Vector4(5.0, 6.0, 7.0, 8.0),
+ Vector4(9.0, 10.0, 11.0, 12.0),
+ ];
final list = Vector4List.fromList(input, 2, 5);
expect(list.buffer.length, 17);
expect(list.buffer[0], 0.0);
diff --git a/test/vector4_test.dart b/test/vector4_test.dart
index aad1fb9..ce20ce5 100644
--- a/test/vector4_test.dart
+++ b/test/vector4_test.dart
@@ -40,8 +40,8 @@
}
void testVector4Add() {
- final Vector4 a = Vector4(5.0, 7.0, 3.0, 10.0);
- final Vector4 b = Vector4(3.0, 8.0, 2.0, 2.0);
+ final a = Vector4(5.0, 7.0, 3.0, 10.0);
+ final b = Vector4(3.0, 8.0, 2.0, 2.0);
a.add(b);
expect(a.x, equals(8.0));
@@ -57,8 +57,8 @@
}
void testVector4MinMax() {
- final Vector4 a = Vector4(5.0, 7.0, -3.0, 10.0);
- final Vector4 b = Vector4(3.0, 8.0, 2.0, 2.0);
+ final a = Vector4(5.0, 7.0, -3.0, 10.0);
+ final b = Vector4(3.0, 8.0, 2.0, 2.0);
final result = Vector4.zero();
@@ -76,8 +76,8 @@
}
void testVector4Mix() {
- final Vector4 a = Vector4(5.0, 7.0, 3.0, 10.0);
- final Vector4 b = Vector4(3.0, 8.0, 2.0, 2.0);
+ final a = Vector4(5.0, 7.0, 3.0, 10.0);
+ final b = Vector4(3.0, 8.0, 2.0, 2.0);
final result = Vector4.zero();
@@ -125,7 +125,7 @@
}
void testVector4Length() {
- final Vector4 a = Vector4(5.0, 7.0, 3.0, 10.0);
+ final a = Vector4(5.0, 7.0, 3.0, 10.0);
relativeTest(a.length, 13.5277);
relativeTest(a.length2, 183.0);
diff --git a/tool/generate_vector_math_64.dart b/tool/generate_vector_math_64.dart
index 03eee72..2e57021 100644
--- a/tool/generate_vector_math_64.dart
+++ b/tool/generate_vector_math_64.dart
@@ -15,8 +15,8 @@
}
Future<void> generateVectorMath64() async {
- final Directory directory = Directory('lib/src/vector_math_64/');
- final File libraryFile = File('lib/vector_math_64.dart');
+ final directory = Directory('lib/src/vector_math_64/');
+ final libraryFile = File('lib/vector_math_64.dart');
if (await directory.exists()) {
await directory.delete(recursive: true);
@@ -38,18 +38,18 @@
}
Future<void> _processFile(String inputFileName) async {
- final File inputFile = File(inputFileName);
+ final inputFile = File(inputFileName);
- final String input = await inputFile.readAsString();
- final String output = _convertToVectorMath64(input);
+ final input = await inputFile.readAsString();
+ final output = _convertToVectorMath64(input);
- final String outputFileName =
+ final outputFileName =
inputFileName.replaceAll('vector_math', 'vector_math_64');
- final Directory dir = Directory(p.dirname(outputFileName));
+ final dir = Directory(p.dirname(outputFileName));
await dir.create(recursive: true);
- final File outputFile = File(outputFileName);
+ final outputFile = File(outputFileName);
await outputFile.writeAsString(output);
}