Merge pull request #182 from lexaknyazev/strong-mode
Strong mode and linter updates
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..3ab0961
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,4 @@
+analyzer:
+ strong-mode:
+ implicit-dynamic: False
+ implicit-casts: False
\ No newline at end of file
diff --git a/benchmark/matrix_bench.dart b/benchmark/matrix_bench.dart
index efbfc32..bdb45e9 100644
--- a/benchmark/matrix_bench.dart
+++ b/benchmark/matrix_bench.dart
@@ -19,6 +19,7 @@
new MatrixMultiplyBenchmark().report();
}
+ @override
void run() {
for (int i = 0; i < 200; i++) {
Matrix44Operations.multiply(C, 0, A, 0, B, 0);
@@ -36,6 +37,7 @@
new SIMDMatrixMultiplyBenchmark().report();
}
+ @override
void run() {
for (int i = 0; i < 200; i++) {
Matrix44SIMDOperations.multiply(C, 0, A, 0, B, 0);
@@ -53,6 +55,7 @@
new VectorTransformBenchmark().report();
}
+ @override
void run() {
for (int i = 0; i < 200; i++) {
Matrix44Operations.transform4(C, 0, A, 0, B, 0);
@@ -70,6 +73,7 @@
new SIMDVectorTransformBenchmark().report();
}
+ @override
void run() {
for (int i = 0; i < 200; i++) {
Matrix44SIMDOperations.transform4(C, 0, A, 0, B, 0);
@@ -89,6 +93,7 @@
new ViewMatrixBenchmark().report();
}
+ @override
void run() {
for (int i = 0; i < 100; i++) {
setViewMatrix(M, P, F, U);
@@ -96,7 +101,7 @@
}
}
-main() {
+void main() {
MatrixMultiplyBenchmark.main();
SIMDMatrixMultiplyBenchmark.main();
VectorTransformBenchmark.main();
diff --git a/bin/mesh_generator.dart b/bin/mesh_generator.dart
index 208591b..fefb449 100644
--- a/bin/mesh_generator.dart
+++ b/bin/mesh_generator.dart
@@ -7,63 +7,59 @@
import 'dart:convert';
import 'package:vector_math/vector_math_geometry.dart';
+typedef MeshGeometry GenerateFunction(List<String> args);
+
MeshGeometry generateCube(List<String> args) {
if (args.length != 3) {
return null;
}
- num width = double.parse(args[0]);
- num height = double.parse(args[1]);
- num depth = double.parse(args[2]);
- var generator = new CubeGenerator();
- MeshGeometry geometry = generator.createCube(width, height, depth);
- return geometry;
+ final double width = double.parse(args[0]);
+ final double height = double.parse(args[1]);
+ final double depth = double.parse(args[2]);
+ final CubeGenerator generator = new CubeGenerator();
+ return generator.createCube(width, height, depth);
}
MeshGeometry generateSphere(List<String> args) {
if (args.length != 1) {
return null;
}
- num radius = double.parse(args[0]);
- var generator = new SphereGenerator();
- MeshGeometry geometry = generator.createSphere(radius);
- return geometry;
+ final double radius = double.parse(args[0]);
+ final SphereGenerator generator = new SphereGenerator();
+ return generator.createSphere(radius);
}
MeshGeometry generateCircle(List<String> args) {
if (args.length != 1) {
return null;
}
- num radius = double.parse(args[0]);
- var generator = new CircleGenerator();
- MeshGeometry geometry = generator.createCircle(radius);
- return geometry;
+ final double radius = double.parse(args[0]);
+ final CircleGenerator generator = new CircleGenerator();
+ return generator.createCircle(radius);
}
MeshGeometry generateCylinder(List<String> args) {
if (args.length != 3) {
return null;
}
- num topRadius = double.parse(args[0]);
- num bottomRadius = double.parse(args[1]);
- num height = double.parse(args[2]);
- var generator = new CylinderGenerator();
- MeshGeometry geometry =
- generator.createCylinder(topRadius, bottomRadius, height);
- return geometry;
+ final double topRadius = double.parse(args[0]);
+ final double bottomRadius = double.parse(args[1]);
+ final double height = double.parse(args[2]);
+ final CylinderGenerator generator = new CylinderGenerator();
+ return generator.createCylinder(topRadius, bottomRadius, height);
}
MeshGeometry generateRing(List<String> args) {
if (args.length != 2) {
return null;
}
- num innerRadius = double.parse(args[0]);
- num outerRadius = double.parse(args[1]);
- var generator = new RingGenerator();
- MeshGeometry geometry = generator.createRing(innerRadius, outerRadius);
- return geometry;
+ final double innerRadius = double.parse(args[0]);
+ final double outerRadius = double.parse(args[1]);
+ final RingGenerator generator = new RingGenerator();
+ return generator.createRing(innerRadius, outerRadius);
}
-Map<String, Function> generators = {
+Map<String, GenerateFunction> generators = <String, GenerateFunction>{
'cube': generateCube,
'sphere': generateSphere,
'circle': generateCircle,
@@ -71,10 +67,10 @@
'ring': generateRing
};
-main(List<String> args_) {
- List<String> args = new List.from(args_, growable: true);
+void main(List<String> args_) {
+ final List<String> args = new List<String>.from(args_, growable: true);
- if (args.length == 0) {
+ if (args.isEmpty) {
print('mesh_generator.dart <type> [<arg0> ... <argN>]');
print('');
print('<type> = cube, sphere, cylinder');
@@ -86,13 +82,13 @@
print('');
return;
}
- var type = args.removeAt(0);
- var generator = generators[type];
+ final String type = args.removeAt(0);
+ final GenerateFunction generator = generators[type];
if (generator == null) {
print('Could not find generator for $type');
return;
}
- MeshGeometry geometry = generator(args);
+ final MeshGeometry geometry = generator(args);
if (geometry == null) {
print('Error generating geometry for $type');
return;
diff --git a/lib/hash.dart b/lib/hash.dart
index b355d2c..d5fbfb5 100644
--- a/lib/hash.dart
+++ b/lib/hash.dart
@@ -2,11 +2,11 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-/**
- * Generates a hash code for multiple [objects].
- */
-int hashObjects(Iterable objects) =>
- _finish(objects.fold(0, (h, i) => _combine(h, i.hashCode)));
+///
+/// Generates a hash code for multiple [objects].
+///
+int hashObjects(Iterable<Object> objects) =>
+ _finish(objects.fold<int>(0, (int h, Object i) => _combine(h, i.hashCode)));
// Jenkins hash functions
int _combine(int hash, int value) {
diff --git a/lib/src/vector_math/aabb2.dart b/lib/src/vector_math/aabb2.dart
index cc50ae8..1039aa4 100644
--- a/lib/src/vector_math/aabb2.dart
+++ b/lib/src/vector_math/aabb2.dart
@@ -78,8 +78,8 @@
/// Transform [this] by the transform [t].
void transform(Matrix3 t) {
- final center = new Vector2.zero();
- final halfExtents = new Vector2.zero();
+ final Vector2 center = new Vector2.zero();
+ final Vector2 halfExtents = new Vector2.zero();
copyCenterAndHalfExtents(center, halfExtents);
t
..transform2(center)
@@ -94,8 +94,8 @@
/// Rotate [this] by the rotation matrix [t].
void rotate(Matrix3 t) {
- final center = new Vector2.zero();
- final halfExtents = new Vector2.zero();
+ final Vector2 center = new Vector2.zero();
+ final Vector2 halfExtents = new Vector2.zero();
copyCenterAndHalfExtents(center, halfExtents);
t.absoluteRotate2(halfExtents);
_min
@@ -133,8 +133,8 @@
/// Return if [this] contains [other].
bool containsAabb2(Aabb2 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector2 otherMax = other._max;
+ final Vector2 otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -143,17 +143,16 @@
}
/// Return if [this] contains [other].
- bool containsVector2(Vector2 other) {
- return (_min.x < other.x) &&
- (_min.y < other.y) &&
- (_max.x > other.x) &&
- (_max.y > other.y);
- }
+ bool containsVector2(Vector2 other) =>
+ (_min.x < other.x) &&
+ (_min.y < other.y) &&
+ (_max.x > other.x) &&
+ (_max.y > other.y);
/// Return if [this] intersects with [other].
bool intersectsWithAabb2(Aabb2 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector2 otherMax = other._max;
+ final Vector2 otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
@@ -162,10 +161,9 @@
}
/// Return if [this] intersects with [other].
- bool intersectsWithVector2(Vector2 other) {
- return (_min.x <= other.x) &&
- (_min.y <= other.y) &&
- (_max.x >= other.x) &&
- (_max.y >= other.y);
- }
+ bool intersectsWithVector2(Vector2 other) =>
+ (_min.x <= other.x) &&
+ (_min.y <= other.y) &&
+ (_max.x >= other.x) &&
+ (_max.y >= other.y);
}
diff --git a/lib/src/vector_math/aabb3.dart b/lib/src/vector_math/aabb3.dart
index d9021e5..c7c1488 100644
--- a/lib/src/vector_math/aabb3.dart
+++ b/lib/src/vector_math/aabb3.dart
@@ -86,46 +86,46 @@
/// Set the AABB to enclose a [triangle].
void setTriangle(Triangle triangle) {
_min.setValues(
- Math.min(triangle._point0.x,
- Math.min(triangle._point1.x, triangle._point2.x)),
- Math.min(triangle._point0.y,
- Math.min(triangle._point1.y, triangle._point2.y)),
- Math.min(triangle._point0.z,
- Math.min(triangle._point1.z, triangle._point2.z)));
+ math.min(triangle._point0.x,
+ math.min(triangle._point1.x, triangle._point2.x)),
+ math.min(triangle._point0.y,
+ math.min(triangle._point1.y, triangle._point2.y)),
+ math.min(triangle._point0.z,
+ math.min(triangle._point1.z, triangle._point2.z)));
_max.setValues(
- Math.max(triangle._point0.x,
- Math.max(triangle._point1.x, triangle._point2.x)),
- Math.max(triangle._point0.y,
- Math.max(triangle._point1.y, triangle._point2.y)),
- Math.max(triangle._point0.z,
- Math.max(triangle._point1.z, triangle._point2.z)));
+ math.max(triangle._point0.x,
+ math.max(triangle._point1.x, triangle._point2.x)),
+ math.max(triangle._point0.y,
+ math.max(triangle._point1.y, triangle._point2.y)),
+ math.max(triangle._point0.z,
+ math.max(triangle._point1.z, triangle._point2.z)));
}
/// Set the AABB to enclose a [quad].
void setQuad(Quad quad) {
_min.setValues(
- Math.min(quad._point0.x,
- Math.min(quad._point1.x, Math.min(quad._point2.x, quad._point3.x))),
- Math.min(quad._point0.y,
- Math.min(quad._point1.y, Math.min(quad._point2.y, quad._point3.y))),
- Math.min(
+ math.min(quad._point0.x,
+ math.min(quad._point1.x, math.min(quad._point2.x, quad._point3.x))),
+ math.min(quad._point0.y,
+ math.min(quad._point1.y, math.min(quad._point2.y, quad._point3.y))),
+ math.min(
quad._point0.z,
- Math.min(
- quad._point1.z, Math.min(quad._point2.z, quad._point3.z))));
+ math.min(
+ quad._point1.z, math.min(quad._point2.z, quad._point3.z))));
_max.setValues(
- Math.max(quad._point0.x,
- Math.max(quad._point1.x, Math.max(quad._point2.x, quad._point3.x))),
- Math.max(quad._point0.y,
- Math.max(quad._point1.y, Math.max(quad._point2.y, quad._point3.y))),
- Math.max(
+ math.max(quad._point0.x,
+ math.max(quad._point1.x, math.max(quad._point2.x, quad._point3.x))),
+ math.max(quad._point0.y,
+ math.max(quad._point1.y, math.max(quad._point2.y, quad._point3.y))),
+ math.max(
quad._point0.z,
- Math.max(
- quad._point1.z, Math.max(quad._point2.z, quad._point3.z))));
+ math.max(
+ quad._point1.z, math.max(quad._point2.z, quad._point3.z))));
}
/// Set the AABB to enclose a [obb].
void setObb3(Obb3 obb) {
- final corner = new Vector3.zero();
+ final Vector3 corner = new Vector3.zero();
obb.copyCorner(0, corner);
_min.setFrom(corner);
@@ -156,23 +156,22 @@
/// Set the AABB to enclose a limited [ray] (or line segment) that is limited
/// by [limitMin] and [limitMax].
void setRay(Ray ray, double limitMin, double limitMax) {
- ray.copyAt(_min, limitMin);
- ray.copyAt(_max, limitMax);
+ ray..copyAt(_min, limitMin)..copyAt(_max, limitMax);
if (_max.x < _min.x) {
- final temp = _max.x;
+ final double temp = _max.x;
_max.x = _min.x;
_min.x = temp;
}
if (_max.y < _min.y) {
- final temp = _max.y;
+ final double temp = _max.y;
_max.y = _min.y;
_min.y = temp;
}
if (_max.z < _min.z) {
- final temp = _max.z;
+ final double temp = _max.z;
_max.z = _min.z;
_min.z = temp;
}
@@ -206,8 +205,8 @@
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- final center = new Vector3.zero();
- final halfExtents = new Vector3.zero();
+ final Vector3 center = new Vector3.zero();
+ final Vector3 halfExtents = new Vector3.zero();
copyCenterAndHalfExtents(center, halfExtents);
t
..transform3(center)
@@ -222,8 +221,8 @@
/// Rotate [this] by the rotation matrix [t].
void rotate(Matrix4 t) {
- final center = new Vector3.zero();
- final halfExtents = new Vector3.zero();
+ final Vector3 center = new Vector3.zero();
+ final Vector3 halfExtents = new Vector3.zero();
copyCenterAndHalfExtents(center, halfExtents);
t.absoluteRotate(halfExtents);
_min
@@ -287,8 +286,8 @@
/// Return if [this] contains [other].
bool containsAabb3(Aabb3 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector3 otherMax = other._max;
+ final Vector3 otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -300,21 +299,21 @@
/// Return if [this] contains [other].
bool containsSphere(Sphere other) {
- final boxExtends = new Vector3.all(other._radius);
- final sphereBox = new Aabb3.centerAndHalfExtents(other._center, boxExtends);
+ final Vector3 boxExtends = new Vector3.all(other._radius);
+ final Aabb3 sphereBox =
+ new Aabb3.centerAndHalfExtents(other._center, boxExtends);
return containsAabb3(sphereBox);
}
/// Return if [this] contains [other].
- bool containsVector3(Vector3 other) {
- return (_min.x < other.x) &&
- (_min.y < other.y) &&
- (_min.z < other.z) &&
- (_max.x > other.x) &&
- (_max.y > other.y) &&
- (_max.z > other.z);
- }
+ bool containsVector3(Vector3 other) =>
+ (_min.x < other.x) &&
+ (_min.y < other.y) &&
+ (_min.z < other.z) &&
+ (_max.x > other.x) &&
+ (_max.y > other.y) &&
+ (_max.z > other.z);
/// Return if [this] contains [other].
bool containsTriangle(Triangle other) =>
@@ -324,8 +323,8 @@
/// Return if [this] intersects with [other].
bool intersectsWithAabb3(Aabb3 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector3 otherMax = other._max;
+ final Vector3 otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
@@ -337,12 +336,12 @@
/// Return if [this] intersects with [other].
bool intersectsWithSphere(Sphere other) {
- final center = other._center;
- final radius = other._radius;
- var d = 0.0;
- var e = 0.0;
+ final Vector3 center = other._center;
+ final double radius = other._radius;
+ double d = 0.0;
+ double e = 0.0;
- for (var i = 0; i < 3; ++i) {
+ for (int i = 0; i < 3; ++i) {
if ((e = center[i] - _min[i]) < 0.0) {
if (e < -radius) {
return false;
@@ -364,29 +363,28 @@
}
/// Return if [this] intersects with [other].
- bool intersectsWithVector3(Vector3 other) {
- return (_min.x <= other.x) &&
- (_min.y <= other.y) &&
- (_min.z <= other.z) &&
- (_max.x >= other.x) &&
- (_max.y >= other.y) &&
- (_max.z >= other.z);
- }
+ bool intersectsWithVector3(Vector3 other) =>
+ (_min.x <= other.x) &&
+ (_min.y <= other.y) &&
+ (_min.z <= other.z) &&
+ (_max.x >= other.x) &&
+ (_max.y >= other.y) &&
+ (_max.z >= other.z);
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _aabbCenter = new Vector3.zero();
- static final _aabbHalfExtents = new Vector3.zero();
- static final _v0 = new Vector3.zero();
- static final _v1 = new Vector3.zero();
- static final _v2 = new Vector3.zero();
- static final _f0 = new Vector3.zero();
- static final _f1 = new Vector3.zero();
- static final _f2 = new Vector3.zero();
- static final _trianglePlane = new Plane();
+ static final Vector3 _aabbCenter = new Vector3.zero();
+ static final Vector3 _aabbHalfExtents = new Vector3.zero();
+ static final Vector3 _v0 = new Vector3.zero();
+ static final Vector3 _v1 = new Vector3.zero();
+ static final Vector3 _v2 = new Vector3.zero();
+ static final Vector3 _f0 = new Vector3.zero();
+ static final Vector3 _f1 = new Vector3.zero();
+ static final Vector3 _f2 = new Vector3.zero();
+ static final Plane _trianglePlane = new Plane();
- static final _u0 = new Vector3(1.0, 0.0, 0.0);
- static final _u1 = new Vector3(0.0, 1.0, 0.0);
- static final _u2 = new Vector3(0.0, 0.0, 1.0);
+ static final Vector3 _u0 = new Vector3(1.0, 0.0, 0.0);
+ static final Vector3 _u1 = new Vector3(0.0, 1.0, 0.0);
+ static final Vector3 _u2 = new 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
@@ -432,11 +430,11 @@
p0 = _v0.z * _f0.y - _v0.y * _f0.z;
p2 = _v2.z * _f0.y - _v2.y * _f0.z;
r = _aabbHalfExtents[1] * _f0.z.abs() + _aabbHalfExtents[2] * _f0.y.abs();
- if (Math.max(-Math.max(p0, p2), Math.min(p0, p2)) > r + epsilon) {
+ if (math.max(-math.max(p0, p2), math.min(p0, p2)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p2) - r;
+ a = math.min(p0, p2) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u0.crossInto(_f0, result.axis);
@@ -450,11 +448,11 @@
p0 = _v0.z * _f1.y - _v0.y * _f1.z;
p1 = _v1.z * _f1.y - _v1.y * _f1.z;
r = _aabbHalfExtents[1] * _f1.z.abs() + _aabbHalfExtents[2] * _f1.y.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u0.crossInto(_f1, result.axis);
@@ -468,11 +466,11 @@
p0 = _v0.z * _f2.y - _v0.y * _f2.z;
p1 = _v1.z * _f2.y - _v1.y * _f2.z;
r = _aabbHalfExtents[1] * _f2.z.abs() + _aabbHalfExtents[2] * _f2.y.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u0.crossInto(_f2, result.axis);
@@ -486,11 +484,11 @@
p0 = _v0.x * _f0.z - _v0.z * _f0.x;
p2 = _v2.x * _f0.z - _v2.z * _f0.x;
r = _aabbHalfExtents[0] * _f0.z.abs() + _aabbHalfExtents[2] * _f0.x.abs();
- if (Math.max(-Math.max(p0, p2), Math.min(p0, p2)) > r + epsilon) {
+ if (math.max(-math.max(p0, p2), math.min(p0, p2)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p2) - r;
+ a = math.min(p0, p2) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u1.crossInto(_f0, result.axis);
@@ -504,11 +502,11 @@
p0 = _v0.x * _f1.z - _v0.z * _f1.x;
p1 = _v1.x * _f1.z - _v1.z * _f1.x;
r = _aabbHalfExtents[0] * _f1.z.abs() + _aabbHalfExtents[2] * _f1.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u1.crossInto(_f1, result.axis);
@@ -522,11 +520,11 @@
p0 = _v0.x * _f2.z - _v0.z * _f2.x;
p1 = _v1.x * _f2.z - _v1.z * _f2.x;
r = _aabbHalfExtents[0] * _f2.z.abs() + _aabbHalfExtents[2] * _f2.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u1.crossInto(_f2, result.axis);
@@ -540,11 +538,11 @@
p0 = _v0.y * _f0.x - _v0.x * _f0.y;
p2 = _v2.y * _f0.x - _v2.x * _f0.y;
r = _aabbHalfExtents[0] * _f0.y.abs() + _aabbHalfExtents[1] * _f0.x.abs();
- if (Math.max(-Math.max(p0, p2), Math.min(p0, p2)) > r + epsilon) {
+ if (math.max(-math.max(p0, p2), math.min(p0, p2)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p2) - r;
+ a = math.min(p0, p2) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u2.crossInto(_f0, result.axis);
@@ -558,11 +556,11 @@
p0 = _v0.y * _f1.x - _v0.x * _f1.y;
p1 = _v1.y * _f1.x - _v1.x * _f1.y;
r = _aabbHalfExtents[0] * _f1.y.abs() + _aabbHalfExtents[1] * _f1.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u2.crossInto(_f1, result.axis);
@@ -576,11 +574,11 @@
p0 = _v0.y * _f2.x - _v0.x * _f2.y;
p1 = _v1.y * _f2.x - _v1.x * _f2.y;
r = _aabbHalfExtents[0] * _f2.y.abs() + _aabbHalfExtents[1] * _f2.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u2.crossInto(_f2, result.axis);
@@ -589,31 +587,31 @@
// Test the three axes corresponding to the face normals of AABB b (category 1). // Exit if...
// ... [-e0, e0] and [min(v0.x,v1.x,v2.x), max(v0.x,v1.x,v2.x)] do not overlap
- if (Math.max(_v0.x, Math.max(_v1.x, _v2.x)) < -_aabbHalfExtents[0] ||
- Math.min(_v0.x, Math.min(_v1.x, _v2.x)) > _aabbHalfExtents[0]) {
+ if (math.max(_v0.x, math.max(_v1.x, _v2.x)) < -_aabbHalfExtents[0] ||
+ math.min(_v0.x, math.min(_v1.x, _v2.x)) > _aabbHalfExtents[0]) {
return false;
}
- a = Math.min(_v0.x, Math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
+ a = math.min(_v0.x, math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(_u0);
}
// ... [-e1, e1] and [min(v0.y,v1.y,v2.y), max(v0.y,v1.y,v2.y)] do not overlap
- if (Math.max(_v0.y, Math.max(_v1.y, _v2.y)) < -_aabbHalfExtents[1] ||
- Math.min(_v0.y, Math.min(_v1.y, _v2.y)) > _aabbHalfExtents[1]) {
+ if (math.max(_v0.y, math.max(_v1.y, _v2.y)) < -_aabbHalfExtents[1] ||
+ math.min(_v0.y, math.min(_v1.y, _v2.y)) > _aabbHalfExtents[1]) {
return false;
}
- a = Math.min(_v0.y, Math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
+ a = math.min(_v0.y, math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(_u1);
}
// ... [-e2, e2] and [min(v0.z,v1.z,v2.z), max(v0.z,v1.z,v2.z)] do not overlap
- if (Math.max(_v0.z, Math.max(_v1.z, _v2.z)) < -_aabbHalfExtents[2] ||
- Math.min(_v0.z, Math.min(_v1.z, _v2.z)) > _aabbHalfExtents[2]) {
+ if (math.max(_v0.z, math.max(_v1.z, _v2.z)) < -_aabbHalfExtents[2] ||
+ math.min(_v0.z, math.min(_v1.z, _v2.z)) > _aabbHalfExtents[2]) {
return false;
}
- a = Math.min(_v0.z, Math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
+ a = math.min(_v0.z, math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(_u2);
@@ -635,14 +633,14 @@
copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents);
// Compute the projection interval radius of b onto L(t) = b.c + t * p.n
- double r = _aabbHalfExtents[0] * other.normal[0].abs() +
+ final double 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
- double s = other.normal.dot(_aabbCenter) - other.constant;
+ final double s = other.normal.dot(_aabbCenter) - other.constant;
// Intersection occurs when distance s falls within [-r,+r] interval
if (s.abs() <= r) {
- final a = s - r;
+ final double a = s - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(other.normal);
@@ -654,8 +652,8 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _quadTriangle0 = new Triangle();
- static final _quadTriangle1 = new Triangle();
+ static final Triangle _quadTriangle0 = new Triangle();
+ static final Triangle _quadTriangle1 = new Triangle();
/// Return if [this] intersects with [other].
/// [epsilon] allows the caller to specify a custum eplsilon value that should
diff --git a/lib/src/vector_math/colors.dart b/lib/src/vector_math/colors.dart
index 6b5a533..ff6a7d6 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 _hexStringFullRegex = new RegExp(
+ static final RegExp _hexStringFullRegex = new RegExp(
r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?',
caseSensitive: false);
- static final _hexStringSmallRegex = new RegExp(
+ static final RegExp _hexStringSmallRegex = new 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 fullMatch = _hexStringFullRegex.matchAsPrefix(value);
+ final Match fullMatch = _hexStringFullRegex.matchAsPrefix(value);
if (fullMatch != null) {
if (fullMatch[4] == null) {
- final r = int.parse(fullMatch[1], radix: 16);
- final g = int.parse(fullMatch[2], radix: 16);
- final b = int.parse(fullMatch[3], radix: 16);
+ 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);
fromRgba(r, g, b, 255, result);
return;
} else {
- 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);
+ 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);
fromRgba(r, g, b, a, result);
return;
}
}
- final smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
+ final Match smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
if (smallMatch != null) {
if (smallMatch[4] == null) {
- 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);
+ 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);
fromRgba(r, g, b, 255, result);
return;
} else {
- 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);
+ 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);
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 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 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 isShort = short &&
+ final bool isShort = short &&
((r >> 4) == (r & 0xF)) &&
((g >> 4) == (g & 0xF)) &&
((b >> 4) == (b & 0xF)) &&
(!alpha || (a >> 4) == (a & 0xF));
if (isShort) {
- final rgb = (r & 0xF).toRadixString(16) +
+ final String rgb = (r & 0xF).toRadixString(16) +
(g & 0xF).toRadixString(16) +
(b & 0xF).toRadixString(16);
return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb;
} else {
- final rgb = r.toRadixString(16).padLeft(2, '0') +
+ final String 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 a = foreground.a + (1.0 - foreground.a) * background.a;
- final factor = 1.0 / a;
+ final double a = foreground.a + (1.0 - foreground.a) * background.a;
+ final double factor = 1.0 / a;
- final r = factor *
+ final double r = factor *
(foreground.a * foreground.r +
(1.0 - foreground.a) * background.a * background.r);
- final g = factor *
+ final double g = factor *
(foreground.a * foreground.g +
(1.0 - foreground.a) * background.a * background.g);
- final b = factor *
+ final double 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 value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
+ final double value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
result
..r = value
@@ -139,12 +139,12 @@
/// the default value is 2.2.
static void linearToGamma(Vector4 linearColor, Vector4 gammaColor,
[double gamma = 2.2]) {
- final exponent = 1.0 / gamma;
+ final double exponent = 1.0 / gamma;
gammaColor
- ..r = Math.pow(linearColor.r, exponent)
- ..g = Math.pow(linearColor.g, exponent)
- ..b = Math.pow(linearColor.b, exponent)
+ ..r = math.pow(linearColor.r, exponent).toDouble()
+ ..g = math.pow(linearColor.g, exponent).toDouble()
+ ..b = math.pow(linearColor.b, exponent).toDouble()
..a = linearColor.a;
}
@@ -154,21 +154,21 @@
static void gammaToLinear(Vector4 gammaColor, Vector4 linearColor,
[double gamma = 2.2]) {
linearColor
- ..r = Math.pow(gammaColor.r, gamma)
- ..g = Math.pow(gammaColor.g, gamma)
- ..b = Math.pow(gammaColor.b, gamma)
+ ..r = math.pow(gammaColor.r, gamma).toDouble()
+ ..g = math.pow(gammaColor.g, gamma).toDouble()
+ ..b = math.pow(gammaColor.b, gamma).toDouble()
..a = gammaColor.a;
}
/// 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 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;
+ 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;
+ double h = 0.0;
if (max != min) {
if (max == rgbColor.r) {
@@ -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 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);
+ 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);
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 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;
+ 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;
+ double h = 0.0;
+ double s = 0.0;
if (max != min) {
- final d = max - min;
+ final double 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 q = hslColor.z < 0.5
+ final double q = hslColor.z < 0.5
? hslColor.z * (1.0 + hslColor.y)
: hslColor.z + hslColor.y - hslColor.z * hslColor.y;
- final p = 2.0 * hslColor.z - q;
+ final double p = 2.0 * hslColor.z - q;
- 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);
+ 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);
rgbColor.setValues(r, g, b, hslColor.a);
}
diff --git a/lib/src/vector_math/constants.dart b/lib/src/vector_math/constants.dart
index 3056dc1..e2c2840 100644
--- a/lib/src/vector_math/constants.dart
+++ b/lib/src/vector_math/constants.dart
@@ -5,7 +5,7 @@
part of vector_math;
/// Constant factor to convert and angle from degrees to radians.
-const double degrees2Radians = Math.PI / 180.0;
+const double degrees2Radians = math.PI / 180.0;
/// Constant factor to convert and angle from radians to degrees.
-const double radians2Degrees = 180.0 / Math.PI;
+const double radians2Degrees = 180.0 / math.PI;
diff --git a/lib/src/vector_math/error_helpers.dart b/lib/src/vector_math/error_helpers.dart
index ad46fa4..f57ba9d 100644
--- a/lib/src/vector_math/error_helpers.dart
+++ b/lib/src/vector_math/error_helpers.dart
@@ -7,21 +7,23 @@
/// Returns relative error between [calculated] and [correct].
/// The type of [calculated] and [correct] must match and can
/// be any vector, matrix, or quaternion.
-double relativeError(calculated, correct) {
+double relativeError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- double diff = (calculated - correct).abs();
+ final double diff = (calculated - correct).abs().toDouble();
return diff / correct;
}
+ // ignore: return_of_invalid_type
return calculated.relativeError(correct);
}
/// Returns absolute error between [calculated] and [correct].
/// The type of [calculated] and [correct] must match and can
/// be any vector, matrix, or quaternion.
-double absoluteError(calculated, correct) {
+double absoluteError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- double diff = (calculated - correct).abs();
+ final double diff = (calculated - correct).abs().toDouble();
return diff;
}
+ // ignore: return_of_invalid_type
return calculated.absoluteError(correct);
}
diff --git a/lib/src/vector_math/frustum.dart b/lib/src/vector_math/frustum.dart
index 0e1ac8d..1154eb9 100644
--- a/lib/src/vector_math/frustum.dart
+++ b/lib/src/vector_math/frustum.dart
@@ -59,11 +59,11 @@
/// Set [this] from [matrix].
void setFromMatrix(Matrix4 matrix) {
- var me = matrix.storage;
- var me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
- var me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
- var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
- var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
+ 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];
_plane0
..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12)
@@ -145,8 +145,8 @@
/// Check if [this] intersects with [sphere].
bool intersectsWithSphere(Sphere sphere) {
- final negativeRadius = -sphere._radius;
- final center = sphere.center;
+ final double negativeRadius = -sphere._radius;
+ final Vector3 center = sphere.center;
if (_plane0.distanceToVector3(center) < negativeRadius) {
return false;
@@ -197,7 +197,7 @@
}
bool _intersectsWithAabb3CheckPlane(Aabb3 aabb, Plane plane) {
- var outPx, outPy, outPz, outNx, outNy, outNz;
+ double outPx, outPy, outPz, outNx, outNy, outNz;
if (plane._normal.x < 0.0) {
outPx = aabb.min.x;
@@ -223,11 +223,11 @@
outNz = aabb.min.z;
}
- final d1 = plane._normal.x * outPx +
+ final double d1 = plane._normal.x * outPx +
plane._normal.y * outPy +
plane._normal.z * outPz +
plane._constant;
- final d2 = plane._normal.x * outNx +
+ final double d2 = plane._normal.x * outNx +
plane._normal.y * outNy +
plane._normal.z * outNz +
plane._constant;
diff --git a/lib/src/vector_math/matrix2.dart b/lib/src/vector_math/matrix2.dart
index db46150..d02adff 100644
--- a/lib/src/vector_math/matrix2.dart
+++ b/lib/src/vector_math/matrix2.dart
@@ -26,8 +26,9 @@
det = 1.0 / det;
}
- x.x = det * (a22 * bx - a12 * by);
- x.y = det * (a11 * by - a21 * bx);
+ x
+ ..x = det * (a22 * bx - a12 * by)
+ ..y = det * (a11 * by - a21 * bx);
}
/// Return index in storage for [row], [col] value.
@@ -42,7 +43,7 @@
}
/// Set value at [row], [col] to be [v].
- setEntry(int row, int col, double v) {
+ void setEntry(int row, int col, double v) {
assert((row >= 0) && (row < dimension));
assert((col >= 0) && (col < dimension));
@@ -54,10 +55,8 @@
new Matrix2.zero()..setValues(arg0, arg1, arg2, arg3);
/// New matrix from [values].
- factory Matrix2.fromList(List<double> values) {
- return new Matrix2.zero()
- ..setValues(values[0], values[1], values[2], values[3]);
- }
+ factory Matrix2.fromList(List<double> values) =>
+ new Matrix2.zero()..setValues(values[0], values[1], values[2], values[3]);
/// Zero matrix.
Matrix2.zero() : _m2storage = new Float32List(4);
@@ -90,8 +89,8 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector2 arg0, Vector2 arg1) {
- final arg0Storage = arg0._v2storage;
- final arg1Storage = arg1._v2storage;
+ final Float32List arg0Storage = arg0._v2storage;
+ final Float32List arg1Storage = arg1._v2storage;
_m2storage[0] = arg0Storage[0];
_m2storage[1] = arg0Storage[1];
_m2storage[2] = arg1Storage[0];
@@ -100,7 +99,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float32List argStorage = arg._m2storage;
_m2storage[3] = argStorage[3];
_m2storage[2] = argStorage[2];
_m2storage[1] = argStorage[1];
@@ -109,8 +108,8 @@
/// Set [this] to the outer product of [u] and [v].
void setOuter(Vector2 u, Vector2 v) {
- final uStorage = u._v2storage;
- final vStorage = v._v2storage;
+ final Float32List uStorage = u._v2storage;
+ final Float32List vStorage = v._v2storage;
_m2storage[0] = uStorage[0] * vStorage[0];
_m2storage[1] = uStorage[0] * vStorage[1];
_m2storage[2] = uStorage[1] * vStorage[0];
@@ -125,12 +124,13 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_m2storage[0] = argStorage[0];
_m2storage[3] = argStorage[1];
}
/// Returns a printable string
+ @override
String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n';
/// Dimension of the matrix.
@@ -145,14 +145,15 @@
}
/// Check if two matrices are the same.
- bool operator ==(other) {
- return (other is Matrix2) &&
- (_m2storage[0] == other._m2storage[0]) &&
- (_m2storage[1] == other._m2storage[1]) &&
- (_m2storage[2] == other._m2storage[2]) &&
- (_m2storage[3] == other._m2storage[3]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Matrix2) &&
+ (_m2storage[0] == other._m2storage[0]) &&
+ (_m2storage[1] == other._m2storage[1]) &&
+ (_m2storage[2] == other._m2storage[2]) &&
+ (_m2storage[3] == other._m2storage[3]);
+ @override
int get hashCode => quiver.hashObjects(_m2storage);
/// Returns row 0
@@ -169,15 +170,15 @@
/// Sets [row] of the matrix to values in [arg]
void setRow(int row, Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List 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 r = new Vector2.zero();
- final rStorage = r._v2storage;
+ final Vector2 r = new Vector2.zero();
+ final Float32List rStorage = r._v2storage;
rStorage[0] = _m2storage[index(row, 0)];
rStorage[1] = _m2storage[index(row, 1)];
return r;
@@ -185,17 +186,17 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector2 arg) {
- final argStorage = arg._v2storage;
- final entry = column * 2;
+ final Float32List argStorage = arg._v2storage;
+ final int entry = column * 2;
_m2storage[entry + 1] = argStorage[1];
_m2storage[entry + 0] = argStorage[0];
}
/// Gets the [column] of the matrix
Vector2 getColumn(int column) {
- final r = new Vector2.zero();
- final entry = column * 2;
- final rStorage = r._v2storage;
+ final Vector2 r = new Vector2.zero();
+ final int entry = column * 2;
+ final Float32List rStorage = r._v2storage;
rStorage[1] = _m2storage[entry + 1];
rStorage[0] = _m2storage[entry + 0];
return r;
@@ -206,7 +207,7 @@
/// Copy [this] into [arg].
Matrix2 copyInto(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float32List argStorage = arg._m2storage;
argStorage[0] = _m2storage[0];
argStorage[1] = _m2storage[1];
argStorage[2] = _m2storage[2];
@@ -215,14 +216,14 @@
}
/// Returns a new vector or matrix by multiplying [this] with [arg].
- operator *(dynamic arg) {
+ dynamic operator *(dynamic arg) {
if (arg is double) {
return scaled(arg);
}
if (arg is Vector2) {
return transformed(arg);
}
- if (arg.dimension == 2) {
+ if (arg is Matrix2) {
return multiplied(arg);
}
throw new ArgumentError(arg);
@@ -257,15 +258,15 @@
Matrix2 transposed() => clone()..transpose();
void transpose() {
- double temp = _m2storage[2];
+ final double temp = _m2storage[2];
_m2storage[2] = _m2storage[1];
_m2storage[1] = temp;
}
/// Returns the component wise absolute value of this.
Matrix2 absolute() {
- Matrix2 r = new Matrix2.zero();
- final rStorage = r._m2storage;
+ final Matrix2 r = new Matrix2.zero();
+ final Float32List rStorage = r._m2storage;
rStorage[0] = _m2storage[0].abs();
rStorage[1] = _m2storage[1].abs();
rStorage[2] = _m2storage[2].abs();
@@ -279,13 +280,13 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector2 v) {
- final vStorage = v._v2storage;
+ final Float32List 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 vStorage = v._v2storage;
+ final Float32List vStorage = v._v2storage;
return _m2storage[j * 2] * vStorage[0] +
_m2storage[(j * 2) + 1] * vStorage[1];
}
@@ -318,28 +319,28 @@
/// Returns relative error between [this] and [correct]
double relativeError(Matrix2 correct) {
- Matrix2 diff = correct - this;
- double correct_norm = correct.infinityNorm();
- double diff_norm = diff.infinityNorm();
+ final Matrix2 diff = correct - this;
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between [this] and [correct]
double absoluteError(Matrix2 correct) {
- double this_norm = infinityNorm();
- double correct_norm = correct.infinityNorm();
- double diff_norm = (this_norm - correct_norm).abs();
+ final double this_norm = infinityNorm();
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Invert the matrix. Returns the determinant.
double invert() {
- double det = determinant();
+ final double det = determinant();
if (det == 0.0) {
return 0.0;
}
- double invDet = 1.0 / det;
- double temp = _m2storage[0];
+ final double invDet = 1.0 / det;
+ final double temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * invDet;
_m2storage[1] = -_m2storage[1] * invDet;
_m2storage[2] = -_m2storage[2] * invDet;
@@ -349,13 +350,13 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix2 arg) {
- double det = arg.determinant();
+ final double det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- double invDet = 1.0 / det;
- final argStorage = arg._m2storage;
+ final double invDet = 1.0 / det;
+ final Float32List argStorage = arg._m2storage;
_m2storage[0] = argStorage[3] * invDet;
_m2storage[1] = -argStorage[1] * invDet;
_m2storage[2] = -argStorage[2] * invDet;
@@ -365,8 +366,8 @@
/// Turns the matrix into a rotation of [radians]
void setRotation(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m2storage[0] = c;
_m2storage[1] = s;
_m2storage[2] = -s;
@@ -375,7 +376,7 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- double temp = _m2storage[0];
+ final double temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * scale;
_m2storage[2] = -_m2storage[2] * scale;
_m2storage[1] = -_m2storage[1] * scale;
@@ -395,7 +396,7 @@
/// Add [o] to [this].
void add(Matrix2 o) {
- final oStorage = o._m2storage;
+ final Float32List oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] + oStorage[0];
_m2storage[1] = _m2storage[1] + oStorage[1];
_m2storage[2] = _m2storage[2] + oStorage[2];
@@ -404,7 +405,7 @@
/// Subtract [o] from [this].
void sub(Matrix2 o) {
- final oStorage = o._m2storage;
+ final Float32List oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] - oStorage[0];
_m2storage[1] = _m2storage[1] - oStorage[1];
_m2storage[2] = _m2storage[2] - oStorage[2];
@@ -421,15 +422,15 @@
/// Multiply [this] with [arg] and store it in [this].
void multiply(Matrix2 arg) {
- 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];
+ 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];
_m2storage[0] = (m00 * n00) + (m01 * n10);
_m2storage[2] = (m00 * n01) + (m01 * n11);
_m2storage[1] = (m10 * n00) + (m11 * n10);
@@ -441,11 +442,11 @@
/// Multiply a transposed [this] with [arg].
void transposeMultiply(Matrix2 arg) {
- final m00 = _m2storage[0];
- final m01 = _m2storage[1];
- final m10 = _m2storage[2];
- final m11 = _m2storage[3];
- final argStorage = arg._m2storage;
+ 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;
_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 +455,11 @@
/// Multiply [this] with a transposed [arg].
void multiplyTranspose(Matrix2 arg) {
- final m00 = _m2storage[0];
- final m01 = _m2storage[2];
- final m10 = _m2storage[1];
- final m11 = _m2storage[3];
- final argStorage = arg._m2storage;
+ 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;
_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,9 +469,11 @@
/// Transform [arg] of type [Vector2] using the transformation defined by
/// [this].
Vector2 transform(Vector2 arg) {
- final argStorage = arg._v2storage;
- final x = (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]);
- final y = (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]);
+ 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]);
argStorage[0] = x;
argStorage[1] = y;
return arg;
@@ -490,7 +493,7 @@
/// Copies [this] into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
array[i + 3] = _m2storage[3];
array[i + 2] = _m2storage[2];
array[i + 1] = _m2storage[1];
@@ -499,7 +502,7 @@
/// Copies elements from [array] into [this] starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- int i = offset;
+ final int 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 6f65541..a8f0e49 100644
--- a/lib/src/vector_math/matrix3.dart
+++ b/lib/src/vector_math/matrix3.dart
@@ -26,8 +26,9 @@
det = 1.0 / det;
}
- x.x = det * (a22 * bx - a12 * by);
- x.y = det * (a11 * by - a21 * bx);
+ x
+ ..x = det * (a22 * bx - a12 * by)
+ ..y = det * (a11 * by - a21 * bx);
}
/// Solve [A] * [x] = [b].
@@ -72,9 +73,10 @@
// Column0 dot -[b cross Column 1]
final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
- x.x = x_;
- x.y = y_;
- x.z = z_;
+ x
+ ..x = x_
+ ..y = y_
+ ..z = z_;
}
/// Return index in storage for [row], [col] value.
@@ -89,7 +91,7 @@
}
/// Set value at [row], [col] to be [v].
- setEntry(int row, int col, double v) {
+ void setEntry(int row, int col, double v) {
assert((row >= 0) && (row < dimension));
assert((col >= 0) && (col < dimension));
@@ -103,11 +105,9 @@
..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
/// New matrix from [values].
- factory Matrix3.fromList(List<double> values) {
- return new Matrix3.zero()
- ..setValues(values[0], values[1], values[2], values[3], values[4],
- values[5], values[6], values[7], values[8]);
- }
+ factory Matrix3.fromList(List<double> values) => new Matrix3.zero()
+ ..setValues(values[0], values[1], values[2], values[3], values[4],
+ values[5], values[6], values[7], values[8]);
/// Constructs a new [Matrix3] filled with zeros.
Matrix3.zero() : _m3storage = new Float32List(9);
@@ -154,9 +154,9 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector3 arg0, Vector3 arg1, Vector3 arg2) {
- final arg0Storage = arg0._v3storage;
- final arg1Storage = arg1._v3storage;
- final arg2Storage = arg2._v3storage;
+ final Float32List arg0Storage = arg0._v3storage;
+ final Float32List arg1Storage = arg1._v3storage;
+ final Float32List arg2Storage = arg2._v3storage;
_m3storage[0] = arg0Storage[0];
_m3storage[1] = arg0Storage[1];
_m3storage[2] = arg0Storage[2];
@@ -170,7 +170,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix3 arg) {
- final argStorage = arg._m3storage;
+ final Float32List argStorage = arg._m3storage;
_m3storage[8] = argStorage[8];
_m3storage[7] = argStorage[7];
_m3storage[6] = argStorage[6];
@@ -184,8 +184,8 @@
/// Set [this] to the outer product of [u] and [v].
void setOuter(Vector3 u, Vector3 v) {
- final uStorage = u._v3storage;
- final vStorage = v._v3storage;
+ final Float32List uStorage = u._v3storage;
+ final Float32List vStorage = v._v3storage;
_m3storage[0] = uStorage[0] * vStorage[0];
_m3storage[1] = uStorage[0] * vStorage[1];
_m3storage[2] = uStorage[0] * vStorage[2];
@@ -213,7 +213,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float32List argStorage = arg._m2storage;
_m3storage[0] = argStorage[0];
_m3storage[1] = argStorage[1];
_m3storage[3] = argStorage[2];
@@ -221,6 +221,7 @@
}
/// Returns a printable string
+ @override
String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n[2] ${getRow(2)}\n';
/// Dimension of the matrix.
@@ -235,19 +236,20 @@
}
/// Check if two matrices are the same.
- bool operator ==(other) {
- return (other is Matrix3) &&
- (_m3storage[0] == other._m3storage[0]) &&
- (_m3storage[1] == other._m3storage[1]) &&
- (_m3storage[2] == other._m3storage[2]) &&
- (_m3storage[3] == other._m3storage[3]) &&
- (_m3storage[4] == other._m3storage[4]) &&
- (_m3storage[5] == other._m3storage[5]) &&
- (_m3storage[6] == other._m3storage[6]) &&
- (_m3storage[7] == other._m3storage[7]) &&
- (_m3storage[8] == other._m3storage[8]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Matrix3) &&
+ (_m3storage[0] == other._m3storage[0]) &&
+ (_m3storage[1] == other._m3storage[1]) &&
+ (_m3storage[2] == other._m3storage[2]) &&
+ (_m3storage[3] == other._m3storage[3]) &&
+ (_m3storage[4] == other._m3storage[4]) &&
+ (_m3storage[5] == other._m3storage[5]) &&
+ (_m3storage[6] == other._m3storage[6]) &&
+ (_m3storage[7] == other._m3storage[7]) &&
+ (_m3storage[8] == other._m3storage[8]);
+ @override
int get hashCode => quiver.hashObjects(_m3storage);
/// Returns row 0
@@ -270,7 +272,7 @@
/// Assigns the [row] of to [arg].
void setRow(int row, Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_m3storage[index(row, 0)] = argStorage[0];
_m3storage[index(row, 1)] = argStorage[1];
_m3storage[index(row, 2)] = argStorage[2];
@@ -278,8 +280,8 @@
/// Gets the [row] of the matrix
Vector3 getRow(int row) {
- Vector3 r = new Vector3.zero();
- final rStorage = r._v3storage;
+ final Vector3 r = new Vector3.zero();
+ final Float32List rStorage = r._v3storage;
rStorage[0] = _m3storage[index(row, 0)];
rStorage[1] = _m3storage[index(row, 1)];
rStorage[2] = _m3storage[index(row, 2)];
@@ -288,8 +290,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector3 arg) {
- final argStorage = arg._v3storage;
- int entry = column * 3;
+ final Float32List argStorage = arg._v3storage;
+ final int entry = column * 3;
_m3storage[entry + 2] = argStorage[2];
_m3storage[entry + 1] = argStorage[1];
_m3storage[entry + 0] = argStorage[0];
@@ -297,9 +299,9 @@
/// Gets the [column] of the matrix
Vector3 getColumn(int column) {
- Vector3 r = new Vector3.zero();
- final rStorage = r._v3storage;
- int entry = column * 3;
+ final Vector3 r = new Vector3.zero();
+ final Float32List rStorage = r._v3storage;
+ final int entry = column * 3;
rStorage[2] = _m3storage[entry + 2];
rStorage[1] = _m3storage[entry + 1];
rStorage[0] = _m3storage[entry + 0];
@@ -311,7 +313,7 @@
/// Copy [this] into [arg].
Matrix3 copyInto(Matrix3 arg) {
- final argStorage = arg._m3storage;
+ final Float32List argStorage = arg._m3storage;
argStorage[0] = _m3storage[0];
argStorage[1] = _m3storage[1];
argStorage[2] = _m3storage[2];
@@ -325,14 +327,14 @@
}
/// Returns a new vector or matrix by multiplying [this] with [arg].
- operator *(dynamic arg) {
+ dynamic operator *(dynamic arg) {
if (arg is double) {
return scaled(arg);
}
if (arg is Vector3) {
return transformed(arg);
}
- if (arg.dimension == 3) {
+ if (arg is Matrix3) {
return multiplied(arg);
}
throw new ArgumentError(arg);
@@ -392,8 +394,8 @@
/// Returns the component wise absolute value of this.
Matrix3 absolute() {
- Matrix3 r = new Matrix3.zero();
- final rStorage = r._m3storage;
+ final Matrix3 r = new Matrix3.zero();
+ final Float32List rStorage = r._m3storage;
rStorage[0] = _m3storage[0].abs();
rStorage[1] = _m3storage[1].abs();
rStorage[2] = _m3storage[2].abs();
@@ -408,18 +410,18 @@
/// Returns the determinant of this matrix.
double determinant() {
- double x = _m3storage[0] *
+ final double x = _m3storage[0] *
((storage[4] * _m3storage[8]) - (storage[5] * _m3storage[7]));
- double y = _m3storage[1] *
+ final double y = _m3storage[1] *
((storage[3] * _m3storage[8]) - (storage[5] * _m3storage[6]));
- double z = _m3storage[2] *
+ final double z = _m3storage[2] *
((storage[3] * _m3storage[7]) - (storage[4] * _m3storage[6]));
return x - y + z;
}
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector3 v) {
- final vStorage = v._v3storage;
+ final Float32List vStorage = v._v3storage;
return _m3storage[i] * vStorage[0] +
_m3storage[3 + i] * vStorage[1] +
_m3storage[6 + i] * vStorage[2];
@@ -427,7 +429,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector3 v) {
- final vStorage = v._v3storage;
+ final Float32List vStorage = v._v3storage;
return _m3storage[j * 3] * vStorage[0] +
_m3storage[j * 3 + 1] * vStorage[1] +
_m3storage[j * 3 + 2] * vStorage[2];
@@ -472,17 +474,17 @@
/// Returns relative error between [this] and [correct]
double relativeError(Matrix3 correct) {
- Matrix3 diff = correct - this;
- double correct_norm = correct.infinityNorm();
- double diff_norm = diff.infinityNorm();
+ final Matrix3 diff = correct - this;
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between [this] and [correct]
double absoluteError(Matrix3 correct) {
- double this_norm = infinityNorm();
- double correct_norm = correct.infinityNorm();
- double diff_norm = (this_norm - correct_norm).abs();
+ final double this_norm = infinityNorm();
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
@@ -491,30 +493,30 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix3 arg) {
- final det = arg.determinant();
+ final double det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final invDet = 1.0 / det;
- final argStorage = arg._m3storage;
- final ix = invDet *
+ final double invDet = 1.0 / det;
+ final Float32List argStorage = arg._m3storage;
+ final double ix = invDet *
(argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]);
- final iy = invDet *
+ final double iy = invDet *
(argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]);
- final iz = invDet *
+ final double iz = invDet *
(argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]);
- final jx = invDet *
+ final double jx = invDet *
(argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]);
- final jy = invDet *
+ final double jy = invDet *
(argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]);
- final jz = invDet *
+ final double jz = invDet *
(argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]);
- final kx = invDet *
+ final double kx = invDet *
(argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]);
- final ky = invDet *
+ final double ky = invDet *
(argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]);
- final kz = invDet *
+ final double kz = invDet *
(argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]);
_m3storage[0] = ix;
_m3storage[1] = iy;
@@ -536,8 +538,8 @@
/// Turns the matrix into a rotation of [radians] around X
void setRotationX(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m3storage[0] = 1.0;
_m3storage[1] = 0.0;
_m3storage[2] = 0.0;
@@ -551,8 +553,8 @@
/// Turns the matrix into a rotation of [radians] around Y
void setRotationY(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = 0.0;
_m3storage[2] = s;
@@ -566,8 +568,8 @@
/// Turns the matrix into a rotation of [radians] around Z
void setRotationZ(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = s;
_m3storage[2] = 0.0;
@@ -581,15 +583,15 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- double m00 = _m3storage[0];
- double m01 = _m3storage[3];
- double m02 = _m3storage[6];
- double m10 = _m3storage[1];
- double m11 = _m3storage[4];
- double m12 = _m3storage[7];
- double m20 = _m3storage[2];
- double m21 = _m3storage[5];
- double m22 = _m3storage[8];
+ 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];
_m3storage[0] = (m11 * m22 - m12 * m21) * scale;
_m3storage[1] = (m12 * m20 - m10 * m22) * scale;
_m3storage[2] = (m10 * m21 - m11 * m20) * scale;
@@ -605,19 +607,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- double m00 = _m3storage[0].abs();
- double m01 = _m3storage[3].abs();
- double m02 = _m3storage[6].abs();
- double m10 = _m3storage[1].abs();
- double m11 = _m3storage[4].abs();
- double m12 = _m3storage[7].abs();
- double m20 = _m3storage[2].abs();
- double m21 = _m3storage[5].abs();
- double m22 = _m3storage[8].abs();
- final argStorage = arg._v3storage;
- final x = argStorage[0];
- final y = argStorage[1];
- final z = argStorage[2];
+ 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];
argStorage[0] = x * m00 + y * m01 + z * m02;
argStorage[1] = x * m10 + y * m11 + z * m12;
argStorage[2] = x * m20 + y * m21 + z * m22;
@@ -628,13 +630,13 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector2 absoluteRotate2(Vector2 arg) {
- double m00 = _m3storage[0].abs();
- double m01 = _m3storage[3].abs();
- double m10 = _m3storage[1].abs();
- double m11 = _m3storage[4].abs();
- final argStorage = arg._v2storage;
- final x = argStorage[0];
- final y = argStorage[1];
+ 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];
argStorage[0] = x * m00 + y * m01;
argStorage[1] = x * m10 + y * m11;
return arg;
@@ -642,11 +644,11 @@
/// Transforms [arg] with [this].
Vector2 transform2(Vector2 arg) {
- final argStorage = arg._v2storage;
- double x_ = (storage[0] * arg.storage[0]) +
+ final Float32List argStorage = arg._v2storage;
+ final double x_ = (storage[0] * arg.storage[0]) +
(storage[3] * arg.storage[1]) +
_m3storage[6];
- double y_ = (storage[1] * arg.storage[0]) +
+ final double y_ = (storage[1] * arg.storage[0]) +
(storage[4] * arg.storage[1]) +
_m3storage[7];
argStorage[0] = x_;
@@ -672,7 +674,7 @@
/// Add [o] to [this].
void add(Matrix3 o) {
- final oStorage = o._m3storage;
+ final Float32List oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] + oStorage[0];
_m3storage[1] = _m3storage[1] + oStorage[1];
_m3storage[2] = _m3storage[2] + oStorage[2];
@@ -686,7 +688,7 @@
/// Subtract [o] from [this].
void sub(Matrix3 o) {
- final oStorage = o._m3storage;
+ final Float32List oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] - oStorage[0];
_m3storage[1] = _m3storage[1] - oStorage[1];
_m3storage[2] = _m3storage[2] - oStorage[2];
@@ -722,7 +724,7 @@
final double m20 = _m3storage[2];
final double m21 = _m3storage[5];
final double m22 = _m3storage[8];
- final argStorage = arg._m3storage;
+ final Float32List argStorage = arg._m3storage;
final double n00 = argStorage[0];
final double n01 = argStorage[3];
final double n02 = argStorage[6];
@@ -747,16 +749,16 @@
Matrix3 multiplied(Matrix3 arg) => clone()..multiply(arg);
void transposeMultiply(Matrix3 arg) {
- double m00 = _m3storage[0];
- double m01 = _m3storage[1];
- double m02 = _m3storage[2];
- double m10 = _m3storage[3];
- double m11 = _m3storage[4];
- double m12 = _m3storage[5];
- double m20 = _m3storage[6];
- double m21 = _m3storage[7];
- double m22 = _m3storage[8];
- final argStorage = arg._m3storage;
+ 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;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * arg.storage[1]) + (m02 * arg.storage[2]);
_m3storage[3] =
@@ -778,16 +780,16 @@
}
void multiplyTranspose(Matrix3 arg) {
- double m00 = _m3storage[0];
- double m01 = _m3storage[3];
- double m02 = _m3storage[6];
- double m10 = _m3storage[1];
- double m11 = _m3storage[4];
- double m12 = _m3storage[7];
- double m20 = _m3storage[2];
- double m21 = _m3storage[5];
- double m22 = _m3storage[8];
- final argStorage = arg._m3storage;
+ 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;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * argStorage[3]) + (m02 * argStorage[6]);
_m3storage[3] =
@@ -811,19 +813,20 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// [this].
Vector3 transform(Vector3 arg) {
- final argStorage = arg._v3storage;
- double x_ = (storage[0] * argStorage[0]) +
+ final Float32List argStorage = arg._v3storage;
+ final double x_ = (storage[0] * argStorage[0]) +
(storage[3] * argStorage[1]) +
(storage[6] * argStorage[2]);
- double y_ = (storage[1] * argStorage[0]) +
+ final double y_ = (storage[1] * argStorage[0]) +
(storage[4] * argStorage[1]) +
(storage[7] * argStorage[2]);
- double z_ = (storage[2] * argStorage[0]) +
+ final double z_ = (storage[2] * argStorage[0]) +
(storage[5] * argStorage[1]) +
(storage[8] * argStorage[2]);
- arg.x = x_;
- arg.y = y_;
- arg.z = z_;
+ arg
+ ..x = x_
+ ..y = y_
+ ..z = z_;
return arg;
}
@@ -841,7 +844,7 @@
/// Copies [this] into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
array[i + 8] = _m3storage[8];
array[i + 7] = _m3storage[7];
array[i + 6] = _m3storage[6];
@@ -855,7 +858,7 @@
/// Copies elements from [array] into [this] starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
_m3storage[8] = array[i + 8];
_m3storage[7] = array[i + 7];
_m3storage[6] = array[i + 6];
@@ -869,8 +872,8 @@
/// Multiply [this] to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final v = new Vector3.array(array, j)..applyMatrix3(this);
+ for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final Vector3 v = new Vector3.array(array, j)..applyMatrix3(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -880,49 +883,53 @@
}
Vector3 get right {
- double x = _m3storage[0];
- double y = _m3storage[1];
- double z = _m3storage[2];
+ final double x = _m3storage[0];
+ final double y = _m3storage[1];
+ final double z = _m3storage[2];
return new Vector3(x, y, z);
}
Vector3 get up {
- double x = _m3storage[3];
- double y = _m3storage[4];
- double z = _m3storage[5];
+ final double x = _m3storage[3];
+ final double y = _m3storage[4];
+ final double z = _m3storage[5];
return new Vector3(x, y, z);
}
Vector3 get forward {
- double x = _m3storage[6];
- double y = _m3storage[7];
- double z = _m3storage[8];
+ final double x = _m3storage[6];
+ final double y = _m3storage[7];
+ final double z = _m3storage[8];
return new Vector3(x, y, z);
}
/// Is [this] the identity matrix?
- bool isIdentity() {
- return _m3storage[0] == 1.0 // col 1
- && _m3storage[1] == 0.0
- && _m3storage[2] == 0.0
- && _m3storage[3] == 0.0 // col 2
- && _m3storage[4] == 1.0
- && _m3storage[5] == 0.0
- && _m3storage[6] == 0.0 // col 3
- && _m3storage[7] == 0.0
- && _m3storage[8] == 1.0;
- }
+ bool isIdentity() =>
+ _m3storage[0] == 1.0 // col 1
+ &&
+ _m3storage[1] == 0.0 &&
+ _m3storage[2] == 0.0 &&
+ _m3storage[3] == 0.0 // col 2
+ &&
+ _m3storage[4] == 1.0 &&
+ _m3storage[5] == 0.0 &&
+ _m3storage[6] == 0.0 // col 3
+ &&
+ _m3storage[7] == 0.0 &&
+ _m3storage[8] == 1.0;
/// Is [this] the zero matrix?
- bool isZero() {
- return _m3storage[0] == 0.0 // col 1
- && _m3storage[1] == 0.0
- && _m3storage[2] == 0.0
- && _m3storage[3] == 0.0 // col 2
- && _m3storage[4] == 0.0
- && _m3storage[5] == 0.0
- && _m3storage[6] == 0.0 // col 3
- && _m3storage[7] == 0.0
- && _m3storage[8] == 0.0;
- }
+ bool isZero() =>
+ _m3storage[0] == 0.0 // col 1
+ &&
+ _m3storage[1] == 0.0 &&
+ _m3storage[2] == 0.0 &&
+ _m3storage[3] == 0.0 // col 2
+ &&
+ _m3storage[4] == 0.0 &&
+ _m3storage[5] == 0.0 &&
+ _m3storage[6] == 0.0 // col 3
+ &&
+ _m3storage[7] == 0.0 &&
+ _m3storage[8] == 0.0;
}
diff --git a/lib/src/vector_math/matrix4.dart b/lib/src/vector_math/matrix4.dart
index 0e3e4b4..94237e8 100644
--- a/lib/src/vector_math/matrix4.dart
+++ b/lib/src/vector_math/matrix4.dart
@@ -26,8 +26,9 @@
det = 1.0 / det;
}
- x.x = det * (a22 * bx - a12 * by);
- x.y = det * (a11 * by - a21 * bx);
+ x
+ ..x = det * (a22 * bx - a12 * by)
+ ..y = det * (a11 * by - a21 * bx);
}
/// Solve [A] * [x] = [b].
@@ -75,9 +76,10 @@
// Column0 dot -[b cross Column 1]
final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
- x.x = x_;
- x.y = y_;
- x.z = z_;
+ x
+ ..x = x_
+ ..y = y_
+ ..z = z_;
}
/// Solve [A] * [x] = [b].
@@ -123,29 +125,27 @@
det = 1.0 / det;
}
- x.x = det *
- ((a11 * b11 - a12 * b10 + a13 * b09) * bX -
- (a10 * b11 - a12 * b08 + a13 * b07) * bY +
- (a10 * b10 - a11 * b08 + a13 * b06) * bZ -
- (a10 * b09 - a11 * b07 + a12 * b06) * bW);
-
- x.y = det *
- -((a01 * b11 - a02 * b10 + a03 * b09) * bX -
- (a00 * b11 - a02 * b08 + a03 * b07) * bY +
- (a00 * b10 - a01 * b08 + a03 * b06) * bZ -
- (a00 * b09 - a01 * b07 + a02 * b06) * bW);
-
- x.z = det *
- ((a31 * b05 - a32 * b04 + a33 * b03) * bX -
- (a30 * b05 - a32 * b02 + a33 * b01) * bY +
- (a30 * b04 - a31 * b02 + a33 * b00) * bZ -
- (a30 * b03 - a31 * b01 + a32 * b00) * bW);
-
- x.w = det *
- -((a21 * b05 - a22 * b04 + a23 * b03) * bX -
- (a20 * b05 - a22 * b02 + a23 * b01) * bY +
- (a20 * b04 - a21 * b02 + a23 * b00) * bZ -
- (a20 * b03 - a21 * b01 + a22 * b00) * bW);
+ x
+ ..x = det *
+ ((a11 * b11 - a12 * b10 + a13 * b09) * bX -
+ (a10 * b11 - a12 * b08 + a13 * b07) * bY +
+ (a10 * b10 - a11 * b08 + a13 * b06) * bZ -
+ (a10 * b09 - a11 * b07 + a12 * b06) * bW)
+ ..y = det *
+ -((a01 * b11 - a02 * b10 + a03 * b09) * bX -
+ (a00 * b11 - a02 * b08 + a03 * b07) * bY +
+ (a00 * b10 - a01 * b08 + a03 * b06) * bZ -
+ (a00 * b09 - a01 * b07 + a02 * b06) * bW)
+ ..z = det *
+ ((a31 * b05 - a32 * b04 + a33 * b03) * bX -
+ (a30 * b05 - a32 * b02 + a33 * b01) * bY +
+ (a30 * b04 - a31 * b02 + a33 * b00) * bZ -
+ (a30 * b03 - a31 * b01 + a32 * b00) * bW)
+ ..w = det *
+ -((a21 * b05 - a22 * b04 + a23 * b03) * bX -
+ (a20 * b05 - a22 * b02 + a23 * b01) * bY +
+ (a20 * b04 - a21 * b02 + a23 * b00) * bZ -
+ (a20 * b03 - a21 * b01 + a22 * b00) * bW);
}
/// Return index in storage for [row], [col] value.
@@ -160,7 +160,7 @@
}
/// Set value at [row], [col] to be [v].
- setEntry(int row, int col, double v) {
+ void setEntry(int row, int col, double v) {
assert((row >= 0) && (row < dimension));
assert((col >= 0) && (col < dimension));
@@ -190,26 +190,24 @@
arg10, arg11, arg12, arg13, arg14, arg15);
/// New matrix from [values].
- factory Matrix4.fromList(List<double> values) {
- return new Matrix4.zero()
- ..setValues(
- values[0],
- values[1],
- values[2],
- values[3],
- values[4],
- values[5],
- values[6],
- values[7],
- values[8],
- values[9],
- values[10],
- values[11],
- values[12],
- values[13],
- values[14],
- values[15]);
- }
+ factory Matrix4.fromList(List<double> values) => new Matrix4.zero()
+ ..setValues(
+ values[0],
+ values[1],
+ values[2],
+ values[3],
+ values[4],
+ values[5],
+ values[6],
+ values[7],
+ values[8],
+ values[9],
+ values[10],
+ values[11],
+ values[12],
+ values[13],
+ values[14],
+ values[15]);
/// Zero matrix.
Matrix4.zero() : _m4storage = new Float32List(16);
@@ -222,8 +220,8 @@
/// Constructs a matrix that is the inverse of [other].
factory Matrix4.inverted(Matrix4 other) {
- Matrix4 r = new Matrix4.zero();
- double determinant = r.copyInverse(other);
+ final Matrix4 r = new Matrix4.zero();
+ final double determinant = r.copyInverse(other);
if (determinant == 0.0) {
throw new ArgumentError.value(
other, 'other', 'Matrix cannot be inverted');
@@ -268,9 +266,9 @@
/// Scale matrix.
factory Matrix4.diagonal3(Vector3 scale) {
- final m = new Matrix4.zero();
- final mStorage = m._m4storage;
- final scaleStorage = scale._v3storage;
+ final Matrix4 m = new Matrix4.zero();
+ final Float32List mStorage = m._m4storage;
+ final Float32List scaleStorage = scale._v3storage;
mStorage[15] = 1.0;
mStorage[10] = scaleStorage[2];
mStorage[5] = scaleStorage[1];
@@ -288,27 +286,26 @@
/// Skew matrix around X axis
factory Matrix4.skewX(double alpha) {
- final m = new Matrix4.identity();
- m._m4storage[4] = Math.tan(alpha);
+ final Matrix4 m = new Matrix4.identity();
+ m._m4storage[4] = math.tan(alpha);
return m;
}
/// Skew matrix around Y axis.
factory Matrix4.skewY(double beta) {
- final m = new Matrix4.identity();
- m._m4storage[1] = Math.tan(beta);
+ final Matrix4 m = new 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 m = new Matrix4.identity();
- m._m4storage[1] = Math.tan(beta);
- m._m4storage[4] = Math.tan(alpha);
+ final Matrix4 m = new Matrix4.identity();
+ m._m4storage[1] = math.tan(beta);
+ m._m4storage[4] = math.tan(alpha);
return m;
}
-
/// Constructs Matrix4 with given [Float32List] as [storage].
Matrix4.fromFloat32List(this._m4storage);
@@ -369,10 +366,10 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) {
- final arg0Storage = arg0._v4storage;
- final arg1Storage = arg1._v4storage;
- final arg2Storage = arg2._v4storage;
- final arg3Storage = arg3._v4storage;
+ final Float32List arg0Storage = arg0._v4storage;
+ final Float32List arg1Storage = arg1._v4storage;
+ final Float32List arg2Storage = arg2._v4storage;
+ final Float32List arg3Storage = arg3._v4storage;
_m4storage[0] = arg0Storage[0];
_m4storage[1] = arg0Storage[1];
_m4storage[2] = arg0Storage[2];
@@ -393,7 +390,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix4 arg) {
- final argStorage = arg._m4storage;
+ final Float32List argStorage = arg._m4storage;
_m4storage[15] = argStorage[15];
_m4storage[14] = argStorage[14];
_m4storage[13] = argStorage[13];
@@ -414,25 +411,25 @@
/// Sets the matrix from translation [arg0] and rotation [arg1].
void setFromTranslationRotation(Vector3 arg0, Quaternion arg1) {
- final arg1Storage = arg1._qStorage;
- double x = arg1Storage[0];
- double y = arg1Storage[1];
- double z = arg1Storage[2];
- double w = arg1Storage[3];
- double x2 = x + x;
- double y2 = y + y;
- double z2 = z + z;
- double xx = x * x2;
- double xy = x * y2;
- double xz = x * z2;
- double yy = y * y2;
- double yz = y * z2;
- double zz = z * z2;
- double wx = w * x2;
- double wy = w * y2;
- double wz = w * z2;
+ 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 arg0Storage = arg0._v3storage;
+ final Float32List arg0Storage = arg0._v3storage;
_m4storage[0] = 1.0 - (yy + zz);
_m4storage[1] = xy + wz;
_m4storage[2] = xz - wy;
@@ -460,7 +457,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float32List argStorage = arg._m2storage;
_m4storage[0] = argStorage[0];
_m4storage[1] = argStorage[1];
_m4storage[4] = argStorage[2];
@@ -469,7 +466,7 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_m4storage[0] = argStorage[0];
_m4storage[5] = argStorage[1];
_m4storage[10] = argStorage[2];
@@ -477,8 +474,8 @@
}
void setOuter(Vector4 u, Vector4 v) {
- final uStorage = u._v4storage;
- final vStorage = v._v4storage;
+ final Float32List uStorage = u._v4storage;
+ final Float32List vStorage = v._v4storage;
_m4storage[0] = uStorage[0] * vStorage[0];
_m4storage[1] = uStorage[0] * vStorage[1];
_m4storage[2] = uStorage[0] * vStorage[2];
@@ -498,6 +495,7 @@
}
/// Returns a printable string
+ @override
String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n'
'[2] ${getRow(2)}\n[3] ${getRow(3)}\n';
@@ -513,26 +511,27 @@
}
/// Check if two matrices are the same.
- bool operator ==(other) {
- return (other is Matrix4) &&
- (_m4storage[0] == other._m4storage[0]) &&
- (_m4storage[1] == other._m4storage[1]) &&
- (_m4storage[2] == other._m4storage[2]) &&
- (_m4storage[3] == other._m4storage[3]) &&
- (_m4storage[4] == other._m4storage[4]) &&
- (_m4storage[5] == other._m4storage[5]) &&
- (_m4storage[6] == other._m4storage[6]) &&
- (_m4storage[7] == other._m4storage[7]) &&
- (_m4storage[8] == other._m4storage[8]) &&
- (_m4storage[9] == other._m4storage[9]) &&
- (_m4storage[10] == other._m4storage[10]) &&
- (_m4storage[11] == other._m4storage[11]) &&
- (_m4storage[12] == other._m4storage[12]) &&
- (_m4storage[13] == other._m4storage[13]) &&
- (_m4storage[14] == other._m4storage[14]) &&
- (_m4storage[15] == other._m4storage[15]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Matrix4) &&
+ (_m4storage[0] == other._m4storage[0]) &&
+ (_m4storage[1] == other._m4storage[1]) &&
+ (_m4storage[2] == other._m4storage[2]) &&
+ (_m4storage[3] == other._m4storage[3]) &&
+ (_m4storage[4] == other._m4storage[4]) &&
+ (_m4storage[5] == other._m4storage[5]) &&
+ (_m4storage[6] == other._m4storage[6]) &&
+ (_m4storage[7] == other._m4storage[7]) &&
+ (_m4storage[8] == other._m4storage[8]) &&
+ (_m4storage[9] == other._m4storage[9]) &&
+ (_m4storage[10] == other._m4storage[10]) &&
+ (_m4storage[11] == other._m4storage[11]) &&
+ (_m4storage[12] == other._m4storage[12]) &&
+ (_m4storage[13] == other._m4storage[13]) &&
+ (_m4storage[14] == other._m4storage[14]) &&
+ (_m4storage[15] == other._m4storage[15]);
+ @override
int get hashCode => quiver.hashObjects(_m4storage);
/// Returns row 0
@@ -561,7 +560,7 @@
/// Assigns the [row] of the matrix [arg]
void setRow(int row, Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_m4storage[index(row, 0)] = argStorage[0];
_m4storage[index(row, 1)] = argStorage[1];
_m4storage[index(row, 2)] = argStorage[2];
@@ -570,8 +569,8 @@
/// Gets the [row] of the matrix
Vector4 getRow(int row) {
- Vector4 r = new Vector4.zero();
- final rStorage = r._v4storage;
+ final Vector4 r = new Vector4.zero();
+ final Float32List rStorage = r._v4storage;
rStorage[0] = _m4storage[index(row, 0)];
rStorage[1] = _m4storage[index(row, 1)];
rStorage[2] = _m4storage[index(row, 2)];
@@ -581,8 +580,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector4 arg) {
- int entry = column * 4;
- final argStorage = arg._v4storage;
+ final int entry = column * 4;
+ final Float32List argStorage = arg._v4storage;
_m4storage[entry + 3] = argStorage[3];
_m4storage[entry + 2] = argStorage[2];
_m4storage[entry + 1] = argStorage[1];
@@ -591,9 +590,9 @@
/// Gets the [column] of the matrix
Vector4 getColumn(int column) {
- Vector4 r = new Vector4.zero();
- final rStorage = r._v4storage;
- int entry = column * 4;
+ final Vector4 r = new Vector4.zero();
+ final Float32List rStorage = r._v4storage;
+ final int entry = column * 4;
rStorage[3] = _m4storage[entry + 3];
rStorage[2] = _m4storage[entry + 2];
rStorage[1] = _m4storage[entry + 1];
@@ -606,7 +605,7 @@
/// Copy into [arg].
Matrix4 copyInto(Matrix4 arg) {
- final argStorage = arg._m4storage;
+ final Float32List argStorage = arg._m4storage;
argStorage[0] = _m4storage[0];
argStorage[1] = _m4storage[1];
argStorage[2] = _m4storage[2];
@@ -640,7 +639,7 @@
if (arg is Vector3) {
return transformed3(arg);
}
- if (arg.dimension == 4) {
+ if (arg is Matrix4) {
return multiplied(arg);
}
throw new ArgumentError(arg);
@@ -653,33 +652,37 @@
Matrix4 operator -(Matrix4 arg) => clone()..sub(arg);
/// Translate this matrix by a [Vector3], [Vector4], or x,y,z
- void translate(x, [double y = 0.0, double z = 0.0]) {
+ void translate(dynamic x, [double y = 0.0, double z = 0.0]) {
double tx;
double ty;
double tz;
- double tw = x is Vector4 ? x.w : 1.0;
- if (x is Vector3 || x is Vector4) {
+ final double tw = x is Vector4 ? x.w : 1.0;
+ if (x is Vector3) {
tx = x.x;
ty = x.y;
tz = x.z;
- } else {
+ } else if (x is Vector4) {
+ tx = x.x;
+ ty = x.y;
+ tz = x.z;
+ } else if (x is double) {
tx = x;
ty = y;
tz = z;
}
- var t1 = _m4storage[0] * tx +
+ final double t1 = _m4storage[0] * tx +
_m4storage[4] * ty +
_m4storage[8] * tz +
_m4storage[12] * tw;
- var t2 = _m4storage[1] * tx +
+ final double t2 = _m4storage[1] * tx +
_m4storage[5] * ty +
_m4storage[9] * tz +
_m4storage[13] * tw;
- var t3 = _m4storage[2] * tx +
+ final double t3 = _m4storage[2] * tx +
_m4storage[6] * ty +
_m4storage[10] * tz +
_m4storage[14] * tw;
- var t4 = _m4storage[3] * tx +
+ final double t4 = _m4storage[3] * tx +
_m4storage[7] * ty +
_m4storage[11] * tz +
_m4storage[15] * tw;
@@ -691,16 +694,20 @@
/// Multiply [this] by a translation from the left.
/// The translation can be specified with a [Vector3], [Vector4], or x, y, z.
- void leftTranslate(x, [double y = 0.0, double z = 0.0]) {
+ void leftTranslate(dynamic x, [double y = 0.0, double z = 0.0]) {
double tx;
double ty;
double tz;
- double tw = x is Vector4 ? x.w : 1.0;
- if (x is Vector3 || x is Vector4) {
+ final double tw = x is Vector4 ? x.w : 1.0;
+ if (x is Vector3) {
tx = x.x;
ty = x.y;
tz = x.z;
- } else {
+ } else if (x is Vector4) {
+ tx = x.x;
+ ty = x.y;
+ tz = x.z;
+ } else if (x is double) {
tx = x;
ty = y;
tz = z;
@@ -733,35 +740,47 @@
/// Rotate this [angle] radians around [axis]
void rotate(Vector3 axis, double angle) {
- var len = axis.length;
- final axisStorage = axis._v3storage;
- var x = axisStorage[0] / len;
- var y = axisStorage[1] / len;
- var z = axisStorage[2] / len;
- var c = Math.cos(angle);
- var s = Math.sin(angle);
- var C = 1.0 - c;
- var m11 = x * x * C + c;
- var m12 = x * y * C - z * s;
- var m13 = x * z * C + y * s;
- var m21 = y * x * C + z * s;
- var m22 = y * y * C + c;
- var m23 = y * z * C - x * s;
- var m31 = z * x * C - y * s;
- var m32 = z * y * C + x * s;
- var m33 = z * z * C + c;
- var t1 = _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31;
- var t2 = _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31;
- var t3 = _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31;
- var t4 = _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31;
- var t5 = _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32;
- var t6 = _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32;
- var t7 = _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32;
- var t8 = _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32;
- var t9 = _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33;
- var t10 = _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33;
- var t11 = _m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33;
- var t12 = _m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33;
+ 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 =
+ _m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33;
+ final double t12 =
+ _m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -778,16 +797,16 @@
/// Rotate this [angle] radians around X
void rotateX(double angle) {
- double cosAngle = Math.cos(angle);
- double sinAngle = Math.sin(angle);
- var t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle;
- var t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle;
- var t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle;
- var t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle;
- var t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle;
- var t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle;
- var t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle;
- var t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle;
+ 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;
_m4storage[4] = t1;
_m4storage[5] = t2;
_m4storage[6] = t3;
@@ -800,16 +819,16 @@
/// Rotate this matrix [angle] radians around Y
void rotateY(double angle) {
- double cosAngle = Math.cos(angle);
- double sinAngle = Math.sin(angle);
- var t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle;
- var t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle;
- var t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle;
- var t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle;
- var t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle;
- var t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle;
- var t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle;
- var t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle;
+ 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;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -822,16 +841,16 @@
/// Rotate this matrix [angle] radians around Z
void rotateZ(double angle) {
- double cosAngle = Math.cos(angle);
- double sinAngle = Math.sin(angle);
- var t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle;
- var t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle;
- var t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle;
- var t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle;
- var t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle;
- var t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle;
- var t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle;
- var t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle;
+ 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;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -843,16 +862,20 @@
}
/// Scale this matrix by a [Vector3], [Vector4], or x,y,z
- void scale(x, [double y, double z]) {
+ void scale(dynamic x, [double y, double z]) {
double sx;
double sy;
double sz;
- double sw = x is Vector4 ? x.w : 1.0;
- if (x is Vector3 || x is Vector4) {
+ final double sw = x is Vector4 ? x.w : 1.0;
+ if (x is Vector3) {
sx = x.x;
sy = x.y;
sz = x.z;
- } else {
+ } else if (x is Vector4) {
+ sx = x.x;
+ sy = x.y;
+ sz = x.z;
+ } else if (x is double) {
sx = x;
sy = y == null ? x : y.toDouble();
sz = z == null ? x : z.toDouble();
@@ -877,7 +900,7 @@
/// Create a copy of [this] scaled by a [Vector3], [Vector4] or [x],[y], and
/// [z].
- Matrix4 scaled(x, [double y = null, double z = null]) =>
+ Matrix4 scaled(dynamic x, [double y = null, double z = null]) =>
clone()..scale(x, y, z);
/// Zeros [this].
@@ -947,8 +970,8 @@
/// Returns the component wise absolute value of this.
Matrix4 absolute() {
- Matrix4 r = new Matrix4.zero();
- final rStorage = r._m4storage;
+ final Matrix4 r = new Matrix4.zero();
+ final Float32List rStorage = r._m4storage;
rStorage[0] = _m4storage[0].abs();
rStorage[1] = _m4storage[1].abs();
rStorage[2] = _m4storage[2].abs();
@@ -970,28 +993,28 @@
/// Returns the determinant of this matrix.
double determinant() {
- double det2_01_01 =
+ final double det2_01_01 =
_m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4];
- double det2_01_02 =
+ final double det2_01_02 =
_m4storage[0] * _m4storage[6] - _m4storage[2] * _m4storage[4];
- double det2_01_03 =
+ final double det2_01_03 =
_m4storage[0] * _m4storage[7] - _m4storage[3] * _m4storage[4];
- double det2_01_12 =
+ final double det2_01_12 =
_m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5];
- double det2_01_13 =
+ final double det2_01_13 =
_m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5];
- double det2_01_23 =
+ final double det2_01_23 =
_m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6];
- double det3_201_012 = _m4storage[8] * det2_01_12 -
+ final double det3_201_012 = _m4storage[8] * det2_01_12 -
_m4storage[9] * det2_01_02 +
_m4storage[10] * det2_01_01;
- double det3_201_013 = _m4storage[8] * det2_01_13 -
+ final double det3_201_013 = _m4storage[8] * det2_01_13 -
_m4storage[9] * det2_01_03 +
_m4storage[11] * det2_01_01;
- double det3_201_023 = _m4storage[8] * det2_01_23 -
+ final double det3_201_023 = _m4storage[8] * det2_01_23 -
_m4storage[10] * det2_01_03 +
_m4storage[11] * det2_01_02;
- double det3_201_123 = _m4storage[9] * det2_01_23 -
+ final double det3_201_123 = _m4storage[9] * det2_01_23 -
_m4storage[10] * det2_01_13 +
_m4storage[11] * det2_01_12;
return -det3_201_123 * _m4storage[12] +
@@ -1002,7 +1025,7 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector4 v) {
- final vStorage = v._v4storage;
+ final Float32List vStorage = v._v4storage;
return _m4storage[i] * vStorage[0] +
_m4storage[4 + i] * vStorage[1] +
_m4storage[8 + i] * vStorage[2] +
@@ -1011,7 +1034,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector4 v) {
- final vStorage = v._v4storage;
+ final Float32List vStorage = v._v4storage;
return _m4storage[j * 4] * vStorage[0] +
_m4storage[j * 4 + 1] * vStorage[1] +
_m4storage[j * 4 + 2] * vStorage[2] +
@@ -1069,34 +1092,34 @@
/// Returns relative error between [this] and [correct]
double relativeError(Matrix4 correct) {
- Matrix4 diff = correct - this;
- double correct_norm = correct.infinityNorm();
- double diff_norm = diff.infinityNorm();
+ final Matrix4 diff = correct - this;
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between [this] and [correct]
double absoluteError(Matrix4 correct) {
- double this_norm = infinityNorm();
- double correct_norm = correct.infinityNorm();
- double diff_norm = (this_norm - correct_norm).abs();
+ final double this_norm = infinityNorm();
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Returns the translation vector from this homogeneous transformation matrix.
Vector3 getTranslation() {
- double z = _m4storage[14];
- double y = _m4storage[13];
- double x = _m4storage[12];
+ final double z = _m4storage[14];
+ final double y = _m4storage[13];
+ final double x = _m4storage[12];
return new Vector3(x, y, z);
}
/// Sets the translation vector in this homogeneous transformation matrix.
void setTranslation(Vector3 t) {
- final tStorage = t._v3storage;
- double z = tStorage[2];
- double y = tStorage[1];
- double x = tStorage[0];
+ final Float32List tStorage = t._v3storage;
+ final double z = tStorage[2];
+ final double y = tStorage[1];
+ final double x = tStorage[0];
_m4storage[14] = z;
_m4storage[13] = y;
_m4storage[12] = x;
@@ -1111,7 +1134,7 @@
/// Returns the rotation matrix from this homogeneous transformation matrix.
Matrix3 getRotation() {
- Matrix3 r = new Matrix3.zero();
+ final Matrix3 r = new Matrix3.zero();
copyRotation(r);
return r;
}
@@ -1119,7 +1142,7 @@
/// Copies the rotation matrix from this homogeneous transformation matrix
/// into [rotation].
void copyRotation(Matrix3 rotation) {
- final rStorage = rotation._m3storage;
+ final Float32List rStorage = rotation._m3storage;
rStorage[0] = _m4storage[0];
rStorage[1] = _m4storage[1];
rStorage[2] = _m4storage[2];
@@ -1133,7 +1156,7 @@
/// Sets the rotation matrix in this homogeneous transformation matrix.
void setRotation(Matrix3 r) {
- final rStorage = r._m3storage;
+ final Float32List rStorage = r._m3storage;
_m4storage[0] = rStorage[0];
_m4storage[1] = rStorage[1];
_m4storage[2] = rStorage[2];
@@ -1151,16 +1174,16 @@
/// Returns the max scale value of the 3 axes.
double getMaxScaleOnAxis() {
- final scaleXSq = _m4storage[0] * _m4storage[0] +
+ final double scaleXSq = _m4storage[0] * _m4storage[0] +
_m4storage[1] * _m4storage[1] +
_m4storage[2] * _m4storage[2];
- final scaleYSq = _m4storage[4] * _m4storage[4] +
+ final double scaleYSq = _m4storage[4] * _m4storage[4] +
_m4storage[5] * _m4storage[5] +
_m4storage[6] * _m4storage[6];
- final scaleZSq = _m4storage[8] * _m4storage[8] +
+ final double scaleZSq = _m4storage[8] * _m4storage[8] +
_m4storage[9] * _m4storage[9] +
_m4storage[10] * _m4storage[10];
- return Math.sqrt(Math.max(scaleXSq, Math.max(scaleYSq, scaleZSq)));
+ return math.sqrt(math.max(scaleXSq, math.max(scaleYSq, scaleZSq)));
}
/// Transposes just the upper 3x3 rotation matrix.
@@ -1191,42 +1214,42 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix4 arg) {
- final argStorage = arg._m4storage;
- double a00 = argStorage[0];
- double a01 = argStorage[1];
- double a02 = argStorage[2];
- double a03 = argStorage[3];
- double a10 = argStorage[4];
- double a11 = argStorage[5];
- double a12 = argStorage[6];
- double a13 = argStorage[7];
- double a20 = argStorage[8];
- double a21 = argStorage[9];
- double a22 = argStorage[10];
- double a23 = argStorage[11];
- double a30 = argStorage[12];
- double a31 = argStorage[13];
- double a32 = argStorage[14];
- double a33 = argStorage[15];
- var b00 = a00 * a11 - a01 * a10;
- var b01 = a00 * a12 - a02 * a10;
- var b02 = a00 * a13 - a03 * a10;
- var b03 = a01 * a12 - a02 * a11;
- var b04 = a01 * a13 - a03 * a11;
- var b05 = a02 * a13 - a03 * a12;
- var b06 = a20 * a31 - a21 * a30;
- var b07 = a20 * a32 - a22 * a30;
- var b08 = a20 * a33 - a23 * a30;
- var b09 = a21 * a32 - a22 * a31;
- var b10 = a21 * a33 - a23 * a31;
- var b11 = a22 * a33 - a23 * a32;
- var det =
+ 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 =
(b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06);
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- var invDet = 1.0 / det;
+ final double 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;
@@ -1247,11 +1270,11 @@
}
double invertRotation() {
- double det = determinant();
+ final double det = determinant();
if (det == 0.0) {
return 0.0;
}
- double invDet = 1.0 / det;
+ final double invDet = 1.0 / det;
double ix;
double iy;
double iz;
@@ -1293,8 +1316,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around X
void setRotationX(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m4storage[0] = 1.0;
_m4storage[1] = 0.0;
_m4storage[2] = 0.0;
@@ -1311,8 +1334,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Y
void setRotationY(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = 0.0;
_m4storage[2] = -s;
@@ -1329,8 +1352,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Z
void setRotationZ(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = s;
_m4storage[2] = 0.0;
@@ -1348,22 +1371,22 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
// Adapted from code by Richard Carling.
- double a1 = _m4storage[0];
- double b1 = _m4storage[4];
- double c1 = _m4storage[8];
- double d1 = _m4storage[12];
- double a2 = _m4storage[1];
- double b2 = _m4storage[5];
- double c2 = _m4storage[9];
- double d2 = _m4storage[13];
- double a3 = _m4storage[2];
- double b3 = _m4storage[6];
- double c3 = _m4storage[10];
- double d3 = _m4storage[14];
- double a4 = _m4storage[3];
- double b4 = _m4storage[7];
- double c4 = _m4storage[11];
- double d4 = _m4storage[15];
+ 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];
_m4storage[0] = (b2 * (c3 * d4 - c4 * d3) -
c2 * (b3 * d4 - b4 * d3) +
d2 * (b3 * c4 - b4 * c3)) *
@@ -1434,19 +1457,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- double m00 = _m4storage[0].abs();
- double m01 = _m4storage[4].abs();
- double m02 = _m4storage[8].abs();
- double m10 = _m4storage[1].abs();
- double m11 = _m4storage[5].abs();
- double m12 = _m4storage[9].abs();
- double m20 = _m4storage[2].abs();
- double m21 = _m4storage[6].abs();
- double m22 = _m4storage[10].abs();
- final argStorage = arg._v3storage;
- double x = argStorage[0];
- double y = argStorage[1];
- double z = argStorage[2];
+ 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];
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;
@@ -1455,7 +1478,7 @@
/// Adds [o] to [this].
void add(Matrix4 o) {
- final oStorage = o._m4storage;
+ final Float32List oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] + oStorage[0];
_m4storage[1] = _m4storage[1] + oStorage[1];
_m4storage[2] = _m4storage[2] + oStorage[2];
@@ -1476,7 +1499,7 @@
/// Subtracts [o] from [this].
void sub(Matrix4 o) {
- final oStorage = o._m4storage;
+ final Float32List oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] - oStorage[0];
_m4storage[1] = _m4storage[1] - oStorage[1];
_m4storage[2] = _m4storage[2] - oStorage[2];
@@ -1517,39 +1540,39 @@
/// Multiply [this] by [arg].
void multiply(Matrix4 arg) {
- 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];
+ 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];
_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);
@@ -1573,23 +1596,23 @@
/// Multiply a transposed [this] with [arg].
void transposeMultiply(Matrix4 arg) {
- double m00 = _m4storage[0];
- double m01 = _m4storage[1];
- double m02 = _m4storage[2];
- double m03 = _m4storage[3];
- double m10 = _m4storage[4];
- double m11 = _m4storage[5];
- double m12 = _m4storage[6];
- double m13 = _m4storage[7];
- double m20 = _m4storage[8];
- double m21 = _m4storage[9];
- double m22 = _m4storage[10];
- double m23 = _m4storage[11];
- double m30 = _m4storage[12];
- double m31 = _m4storage[13];
- double m32 = _m4storage[14];
- double m33 = _m4storage[15];
- final argStorage = arg._m4storage;
+ 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;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[1]) +
(m02 * argStorage[2]) +
@@ -1658,23 +1681,23 @@
/// Multiply [this] with a transposed [arg].
void multiplyTranspose(Matrix4 arg) {
- double m00 = _m4storage[0];
- double m01 = _m4storage[4];
- double m02 = _m4storage[8];
- double m03 = _m4storage[12];
- double m10 = _m4storage[1];
- double m11 = _m4storage[5];
- double m12 = _m4storage[9];
- double m13 = _m4storage[13];
- double m20 = _m4storage[2];
- double m21 = _m4storage[6];
- double m22 = _m4storage[10];
- double m23 = _m4storage[14];
- double m30 = _m4storage[3];
- double m31 = _m4storage[7];
- double m32 = _m4storage[11];
- double m33 = _m4storage[15];
- final argStorage = arg._m4storage;
+ 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;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[4]) +
(m02 * argStorage[8]) +
@@ -1743,23 +1766,27 @@
/// Decomposes [this] into [translation], [rotation] and [scale] components.
void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) {
- final v = new Vector3.zero();
- var sx = (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
- var sy = (v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
- var sz =
+ final Vector3 v = new Vector3.zero();
+ double sx =
+ (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
+ final double sy =
+ (v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
+ final double sz =
(v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length;
- if (determinant() < 0) sx = -sx;
+ if (determinant() < 0) {
+ sx = -sx;
+ }
translation._v3storage[0] = _m4storage[12];
translation._v3storage[1] = _m4storage[13];
translation._v3storage[2] = _m4storage[14];
- final invSX = 1.0 / sx;
- final invSY = 1.0 / sy;
- final invSZ = 1.0 / sz;
+ final double invSX = 1.0 / sx;
+ final double invSY = 1.0 / sy;
+ final double invSZ = 1.0 / sz;
- final m = new Matrix4.copy(this);
+ final Matrix4 m = new Matrix4.copy(this);
m._m4storage[0] *= invSX;
m._m4storage[1] *= invSX;
m._m4storage[2] *= invSX;
@@ -1779,14 +1806,14 @@
/// Rotate [arg] of type [Vector3] using the rotation defined by [this].
Vector3 rotate3(Vector3 arg) {
- final argStorage = arg._v3storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float32List argStorage = arg._v3storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]);
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]);
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]);
argStorage[0] = x_;
@@ -1809,16 +1836,16 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// [this].
Vector3 transform3(Vector3 arg) {
- final argStorage = arg._v3storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float32List argStorage = arg._v3storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
@@ -1843,20 +1870,20 @@
/// Transform [arg] of type [Vector4] using the transformation defined by
/// [this].
Vector4 transform(Vector4 arg) {
- final argStorage = arg._v4storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float32List argStorage = arg._v4storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
(_m4storage[12] * argStorage[3]);
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
(_m4storage[13] * argStorage[3]);
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
(_m4storage[14] * argStorage[3]);
- final w_ = (_m4storage[3] * argStorage[0]) +
+ final double w_ = (_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
(_m4storage[15] * argStorage[3]);
@@ -1870,20 +1897,20 @@
/// Transform [arg] of type [Vector3] using the perspective transformation
/// defined by [this].
Vector3 perspectiveTransform(Vector3 arg) {
- final argStorage = arg._v3storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float32List argStorage = arg._v3storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
- final w_ = 1.0 /
+ final double w_ = 1.0 /
((_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
@@ -1908,7 +1935,7 @@
/// Copies [this] into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
array[i + 15] = _m4storage[15];
array[i + 14] = _m4storage[14];
array[i + 13] = _m4storage[13];
@@ -1929,7 +1956,7 @@
/// Copies elements from [array] into [this] starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
_m4storage[15] = array[i + 15];
_m4storage[14] = array[i + 14];
_m4storage[13] = array[i + 13];
@@ -1950,8 +1977,8 @@
/// Multiply [this] to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final v = new Vector3.array(array, j)..applyMatrix4(this);
+ for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final Vector3 v = new Vector3.array(array, j)..applyMatrix4(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -1961,63 +1988,69 @@
}
Vector3 get right {
- double x = _m4storage[0];
- double y = _m4storage[1];
- double z = _m4storage[2];
+ final double x = _m4storage[0];
+ final double y = _m4storage[1];
+ final double z = _m4storage[2];
return new Vector3(x, y, z);
}
Vector3 get up {
- double x = _m4storage[4];
- double y = _m4storage[5];
- double z = _m4storage[6];
+ final double x = _m4storage[4];
+ final double y = _m4storage[5];
+ final double z = _m4storage[6];
return new Vector3(x, y, z);
}
Vector3 get forward {
- double x = _m4storage[8];
- double y = _m4storage[9];
- double z = _m4storage[10];
+ final double x = _m4storage[8];
+ final double y = _m4storage[9];
+ final double z = _m4storage[10];
return new Vector3(x, y, z);
}
/// Is [this] the identity matrix?
- bool isIdentity() {
- return _m4storage[0] == 1.0 // col 1
- && _m4storage[1] == 0.0
- && _m4storage[2] == 0.0
- && _m4storage[3] == 0.0
- && _m4storage[4] == 0.0 // col 2
- && _m4storage[5] == 1.0
- && _m4storage[6] == 0.0
- && _m4storage[7] == 0.0
- && _m4storage[8] == 0.0 // col 3
- && _m4storage[9] == 0.0
- && _m4storage[10] == 1.0
- && _m4storage[11] == 0.0
- && _m4storage[12] == 0.0 // col 4
- && _m4storage[13] == 0.0
- && _m4storage[14] == 0.0
- && _m4storage[15] == 1.0;
- }
+ bool isIdentity() =>
+ _m4storage[0] == 1.0 // col 1
+ &&
+ _m4storage[1] == 0.0 &&
+ _m4storage[2] == 0.0 &&
+ _m4storage[3] == 0.0 &&
+ _m4storage[4] == 0.0 // col 2
+ &&
+ _m4storage[5] == 1.0 &&
+ _m4storage[6] == 0.0 &&
+ _m4storage[7] == 0.0 &&
+ _m4storage[8] == 0.0 // col 3
+ &&
+ _m4storage[9] == 0.0 &&
+ _m4storage[10] == 1.0 &&
+ _m4storage[11] == 0.0 &&
+ _m4storage[12] == 0.0 // col 4
+ &&
+ _m4storage[13] == 0.0 &&
+ _m4storage[14] == 0.0 &&
+ _m4storage[15] == 1.0;
/// Is [this] the zero matrix?
- bool isZero() {
- return _m4storage[0] == 0.0 // col 1
- && _m4storage[1] == 0.0
- && _m4storage[2] == 0.0
- && _m4storage[3] == 0.0
- && _m4storage[4] == 0.0 // col 2
- && _m4storage[5] == 0.0
- && _m4storage[6] == 0.0
- && _m4storage[7] == 0.0
- && _m4storage[8] == 0.0 // col 3
- && _m4storage[9] == 0.0
- && _m4storage[10] == 0.0
- && _m4storage[11] == 0.0
- && _m4storage[12] == 0.0 // col 4
- && _m4storage[13] == 0.0
- && _m4storage[14] == 0.0
- && _m4storage[15] == 0.0;
- }
+ bool isZero() =>
+ _m4storage[0] == 0.0 // col 1
+ &&
+ _m4storage[1] == 0.0 &&
+ _m4storage[2] == 0.0 &&
+ _m4storage[3] == 0.0 &&
+ _m4storage[4] == 0.0 // col 2
+ &&
+ _m4storage[5] == 0.0 &&
+ _m4storage[6] == 0.0 &&
+ _m4storage[7] == 0.0 &&
+ _m4storage[8] == 0.0 // col 3
+ &&
+ _m4storage[9] == 0.0 &&
+ _m4storage[10] == 0.0 &&
+ _m4storage[11] == 0.0 &&
+ _m4storage[12] == 0.0 // col 4
+ &&
+ _m4storage[13] == 0.0 &&
+ _m4storage[14] == 0.0 &&
+ _m4storage[15] == 0.0;
}
diff --git a/lib/src/vector_math/obb3.dart b/lib/src/vector_math/obb3.dart
index d331d8d..47642c4 100644
--- a/lib/src/vector_math/obb3.dart
+++ b/lib/src/vector_math/obb3.dart
@@ -84,23 +84,29 @@
/// Rotate [this] by the rotation matrix [t].
void rotate(Matrix3 t) {
- t.transform(_axis0..scale(_halfExtents.x));
- t.transform(_axis1..scale(_halfExtents.y));
- t.transform(_axis2..scale(_halfExtents.z));
- _halfExtents.x = _axis0.normalize();
- _halfExtents.y = _axis1.normalize();
- _halfExtents.z = _axis2.normalize();
+ t
+ ..transform(_axis0..scale(_halfExtents.x))
+ ..transform(_axis1..scale(_halfExtents.y))
+ ..transform(_axis2..scale(_halfExtents.z));
+
+ _halfExtents
+ ..x = _axis0.normalize()
+ ..y = _axis1.normalize()
+ ..z = _axis2.normalize();
}
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- t.transform3(_center);
- t.rotate3(_axis0..scale(_halfExtents.x));
- t.rotate3(_axis1..scale(_halfExtents.y));
- t.rotate3(_axis2..scale(_halfExtents.z));
- _halfExtents.x = _axis0.normalize();
- _halfExtents.y = _axis1.normalize();
- _halfExtents.z = _axis2.normalize();
+ t
+ ..transform3(_center)
+ ..rotate3(_axis0..scale(_halfExtents.x))
+ ..rotate3(_axis1..scale(_halfExtents.y))
+ ..rotate3(_axis2..scale(_halfExtents.z));
+
+ _halfExtents
+ ..x = _axis0.normalize()
+ ..y = _axis1.normalize()
+ ..z = _axis2.normalize();
}
/// Store the corner with [cornerIndex] in [corner].
@@ -163,40 +169,41 @@
/// Find the closest point [q] on the OBB to the point [p] and store it in [q].
void closestPointTo(Vector3 p, Vector3 q) {
- final d = p - _center;
+ final Vector3 d = p - _center;
q.setFrom(_center);
- var dist = d.dot(_axis0);
- dist = dist.clamp(-_halfExtents.x, _halfExtents.x);
+ double dist = d.dot(_axis0);
+ dist = dist.clamp(-_halfExtents.x, _halfExtents.x).toDouble();
q.addScaled(_axis0, dist);
dist = d.dot(_axis1);
- dist = dist.clamp(-_halfExtents.y, _halfExtents.y);
+ dist = dist.clamp(-_halfExtents.y, _halfExtents.y).toDouble();
q.addScaled(_axis1, dist);
dist = d.dot(_axis2);
- dist = dist.clamp(-_halfExtents.z, _halfExtents.z);
+ dist = dist.clamp(-_halfExtents.z, _halfExtents.z).toDouble();
q.addScaled(_axis2, dist);
}
// Avoid allocating these instance on every call to intersectsWithObb3
- static final _r = new Matrix3.zero();
- static final _absR = new Matrix3.zero();
- static final _t = new Vector3.zero();
+ static final Matrix3 _r = new Matrix3.zero();
+ static final Matrix3 _absR = new Matrix3.zero();
+ static final Vector3 _t = new Vector3.zero();
/// Check for intersection between [this] and [other].
bool intersectsWithObb3(Obb3 other, [double epsilon = 1e-3]) {
// Compute rotation matrix expressing other in this's coordinate frame
- _r.setEntry(0, 0, _axis0.dot(other._axis0));
- _r.setEntry(1, 0, _axis1.dot(other._axis0));
- _r.setEntry(2, 0, _axis2.dot(other._axis0));
- _r.setEntry(0, 1, _axis0.dot(other._axis1));
- _r.setEntry(1, 1, _axis1.dot(other._axis1));
- _r.setEntry(2, 1, _axis2.dot(other._axis1));
- _r.setEntry(0, 2, _axis0.dot(other._axis2));
- _r.setEntry(1, 2, _axis1.dot(other._axis2));
- _r.setEntry(2, 2, _axis2.dot(other._axis2));
+ _r
+ ..setEntry(0, 0, _axis0.dot(other._axis0))
+ ..setEntry(1, 0, _axis1.dot(other._axis0))
+ ..setEntry(2, 0, _axis2.dot(other._axis0))
+ ..setEntry(0, 1, _axis0.dot(other._axis1))
+ ..setEntry(1, 1, _axis1.dot(other._axis1))
+ ..setEntry(2, 1, _axis2.dot(other._axis1))
+ ..setEntry(0, 2, _axis0.dot(other._axis2))
+ ..setEntry(1, 2, _axis1.dot(other._axis2))
+ ..setEntry(2, 2, _axis2.dot(other._axis2));
// Compute translation vector t
_t
@@ -209,8 +216,8 @@
// Compute common subexpressions. Add in an epsilon term to
// counteract arithmetic errors when two edges are parallel and
// their cross product is (near) null.
- for (var i = 0; i < 3; i++) {
- for (var j = 0; j < 3; j++) {
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
_absR.setEntry(i, j, _r.entry(i, j).abs() + epsilon);
}
}
@@ -219,7 +226,7 @@
double rb;
// Test axes L = A0, L = A1, L = A2
- for (var i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
ra = _halfExtents[i];
rb = other._halfExtents[0] * _absR.entry(i, 0) +
other._halfExtents[1] * _absR.entry(i, 1) +
@@ -231,7 +238,7 @@
}
// Test axes L = B0, L = B1, L = B2
- for (var i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
ra = _halfExtents[0] * _absR.entry(0, i) +
_halfExtents[1] * _absR.entry(1, i) +
_halfExtents[2] * _absR.entry(2, i);
@@ -332,23 +339,26 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _triangle = new Triangle();
- static final _aabb3 = new Aabb3();
- static final _zeroVector = new Vector3.zero();
+ static final Triangle _triangle = new Triangle();
+ static final Aabb3 _aabb3 = new Aabb3();
+ static final Vector3 _zeroVector = new Vector3.zero();
/// Return if [this] intersects with [other]
bool intersectsWithTriangle(Triangle other, {IntersectionResult result}) {
_triangle.copyFrom(other);
- _triangle.point0.sub(_center);
- _triangle.point0.setValues(_triangle.point0.dot(axis0),
- _triangle.point0.dot(axis1), _triangle.point0.dot(axis2));
- _triangle.point1.sub(_center);
- _triangle.point1.setValues(_triangle.point1.dot(axis0),
- _triangle.point1.dot(axis1), _triangle.point1.dot(axis2));
- _triangle.point2.sub(_center);
- _triangle.point2.setValues(_triangle.point2.dot(axis0),
- _triangle.point2.dot(axis1), _triangle.point2.dot(axis2));
+ _triangle.point0
+ ..sub(_center)
+ ..setValues(_triangle.point0.dot(axis0), _triangle.point0.dot(axis1),
+ _triangle.point0.dot(axis2));
+ _triangle.point1
+ ..sub(_center)
+ ..setValues(_triangle.point1.dot(axis0), _triangle.point1.dot(axis1),
+ _triangle.point1.dot(axis2));
+ _triangle.point2
+ ..sub(_center)
+ ..setValues(_triangle.point2.dot(axis0), _triangle.point2.dot(axis1),
+ _triangle.point2.dot(axis2));
_aabb3.setCenterAndHalfExtents(_zeroVector, _halfExtents);
@@ -356,15 +366,14 @@
}
// Avoid allocating these instance on every call to intersectsWithVector3
- static final _vector = new Vector3.zero();
+ static final Vector3 _vector = new Vector3.zero();
/// Return if [this] intersects with [other]
bool intersectsWithVector3(Vector3 other) {
- _vector.setFrom(other);
-
- _vector.sub(_center);
- _vector.setValues(
- _vector.dot(axis0), _vector.dot(axis1), _vector.dot(axis2));
+ _vector
+ ..setFrom(other)
+ ..sub(_center)
+ ..setValues(_vector.dot(axis0), _vector.dot(axis1), _vector.dot(axis2));
_aabb3.setCenterAndHalfExtents(_zeroVector, _halfExtents);
@@ -372,8 +381,8 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _quadTriangle0 = new Triangle();
- static final _quadTriangle1 = new Triangle();
+ static final Triangle _quadTriangle0 = new Triangle();
+ static final Triangle _quadTriangle1 = new Triangle();
/// Return if [this] intersects with [other]
bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
diff --git a/lib/src/vector_math/opengl.dart b/lib/src/vector_math/opengl.dart
index d46588d..1038ed3 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) {
- Vector3 right = forwardDirection.cross(upDirection)..normalize();
- Vector3 c1 = right;
- Vector3 c2 = upDirection;
- Vector3 c3 = -forwardDirection;
+ final Vector3 right = forwardDirection.cross(upDirection)..normalize();
+ final Vector3 c1 = right;
+ final Vector3 c2 = upDirection;
+ final Vector3 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,16 +74,13 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition,
Vector3 cameraFocusPosition, Vector3 upDirection) {
- Vector3 z = cameraPosition - cameraFocusPosition;
- z.normalize();
- Vector3 x = upDirection.cross(z);
- x.normalize();
- Vector3 y = z.cross(x);
- y.normalize();
+ final Vector3 z = (cameraPosition - cameraFocusPosition)..normalize();
+ final Vector3 x = upDirection.cross(z)..normalize();
+ final Vector3 y = z.cross(x)..normalize();
- double rotatedEyeX = -x.dot(cameraPosition);
- double rotatedEyeY = -y.dot(cameraPosition);
- double rotatedEyeZ = -z.dot(cameraPosition);
+ final double rotatedEyeX = -x.dot(cameraPosition);
+ final double rotatedEyeY = -y.dot(cameraPosition);
+ final double 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);
@@ -96,7 +93,7 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
Matrix4 makeViewMatrix(
Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setViewMatrix(r, cameraPosition, cameraFocusPosition, upDirection);
return r;
}
@@ -113,16 +110,17 @@
/// (always positive).
void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians,
double aspectRatio, double zNear, double zFar) {
- final double height = Math.tan(fovYRadians * 0.5);
+ final double height = math.tan(fovYRadians * 0.5);
final double width = height * aspectRatio;
final double near_minus_far = zNear - zFar;
- final Matrix4 view = perspectiveMatrix..setZero();
- view.setEntry(0, 0, 1.0 / width);
- view.setEntry(1, 1, 1.0 / height);
- view.setEntry(2, 2, (zFar + zNear) / near_minus_far);
- view.setEntry(3, 2, -1.0);
- view.setEntry(2, 3, (2.0 * zNear * zFar) / near_minus_far);
+ perspectiveMatrix
+ ..setZero()
+ ..setEntry(0, 0, 1.0 / width)
+ ..setEntry(1, 1, 1.0 / height)
+ ..setEntry(2, 2, (zFar + zNear) / near_minus_far)
+ ..setEntry(3, 2, -1.0)
+ ..setEntry(2, 3, (2.0 * zNear * zFar) / near_minus_far);
}
/// Constructs a new OpenGL perspective projection matrix.
@@ -137,7 +135,7 @@
/// (always positive).
Matrix4 makePerspectiveMatrix(
double fovYRadians, double aspectRatio, double zNear, double zFar) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setPerspectiveMatrix(r, fovYRadians, aspectRatio, zNear, zFar);
return r;
}
@@ -151,15 +149,16 @@
/// (always positive).
void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians,
double aspectRatio, double zNear) {
- final double height = Math.tan(fovYRadians * 0.5);
+ final double height = math.tan(fovYRadians * 0.5);
final double width = height * aspectRatio;
- final Matrix4 view = infiniteMatrix..setZero();
- view.setEntry(0, 0, 1.0 / width);
- view.setEntry(1, 1, 1.0 / height);
- view.setEntry(2, 2, -1.0);
- view.setEntry(3, 2, -1.0);
- view.setEntry(2, 3, -2.0 * zNear);
+ infiniteMatrix
+ ..setZero()
+ ..setEntry(0, 0, 1.0 / width)
+ ..setEntry(1, 1, 1.0 / height)
+ ..setEntry(2, 2, -1.0)
+ ..setEntry(3, 2, -1.0)
+ ..setEntry(2, 3, -2.0 * zNear);
}
/// Constructs a new OpenGL infinite projection matrix.
@@ -172,7 +171,7 @@
/// (always positive).
Matrix4 makeInfiniteMatrix(
double fovYRadians, double aspectRatio, double zNear) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setInfiniteMatrix(r, fovYRadians, aspectRatio, zNear);
return r;
}
@@ -187,18 +186,19 @@
/// planes.
void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right,
double bottom, double top, double near, double far) {
- double two_near = 2.0 * near;
- double right_minus_left = right - left;
- double top_minus_bottom = top - bottom;
- double far_minus_near = far - near;
- Matrix4 view = perspectiveMatrix..setZero();
- view.setEntry(0, 0, two_near / right_minus_left);
- view.setEntry(1, 1, two_near / top_minus_bottom);
- view.setEntry(0, 2, (right + left) / right_minus_left);
- view.setEntry(1, 2, (top + bottom) / top_minus_bottom);
- view.setEntry(2, 2, -(far + near) / far_minus_near);
- view.setEntry(3, 2, -1.0);
- view.setEntry(2, 3, -(two_near * far) / far_minus_near);
+ 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;
+ perspectiveMatrix
+ ..setZero()
+ ..setEntry(0, 0, two_near / right_minus_left)
+ ..setEntry(1, 1, two_near / top_minus_bottom)
+ ..setEntry(0, 2, (right + left) / right_minus_left)
+ ..setEntry(1, 2, (top + bottom) / top_minus_bottom)
+ ..setEntry(2, 2, -(far + near) / far_minus_near)
+ ..setEntry(3, 2, -1.0)
+ ..setEntry(2, 3, -(two_near * far) / far_minus_near);
}
/// Constructs a new OpenGL perspective projection matrix.
@@ -211,7 +211,7 @@
/// planes.
Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top,
double near, double far) {
- Matrix4 view = new Matrix4.zero();
+ final Matrix4 view = new Matrix4.zero();
setFrustumMatrix(view, left, right, bottom, top, near, far);
return view;
}
@@ -226,20 +226,21 @@
/// planes.
void setOrthographicMatrix(Matrix4 orthographicMatrix, double left,
double right, double bottom, double top, double near, double far) {
- double rml = right - left;
- double rpl = right + left;
- double tmb = top - bottom;
- double tpb = top + bottom;
- double fmn = far - near;
- double fpn = far + near;
- Matrix4 r = orthographicMatrix..setZero();
- r.setEntry(0, 0, 2.0 / rml);
- r.setEntry(1, 1, 2.0 / tmb);
- r.setEntry(2, 2, -2.0 / fmn);
- r.setEntry(0, 3, -rpl / rml);
- r.setEntry(1, 3, -tpb / tmb);
- r.setEntry(2, 3, -fpn / fmn);
- r.setEntry(3, 3, 1.0);
+ 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;
+ orthographicMatrix
+ ..setZero()
+ ..setEntry(0, 0, 2.0 / rml)
+ ..setEntry(1, 1, 2.0 / tmb)
+ ..setEntry(2, 2, -2.0 / fmn)
+ ..setEntry(0, 3, -rpl / rml)
+ ..setEntry(1, 3, -tpb / tmb)
+ ..setEntry(2, 3, -fpn / fmn)
+ ..setEntry(3, 3, 1.0);
}
/// Constructs a new OpenGL orthographic projection matrix.
@@ -252,7 +253,7 @@
/// planes.
Matrix4 makeOrthographicMatrix(double left, double right, double bottom,
double top, double near, double far) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setOrthographicMatrix(r, left, right, bottom, top, near, far);
return r;
}
@@ -260,14 +261,15 @@
/// Returns a transformation matrix that transforms points onto
/// the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) {
- Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- Matrix4 outer = new Matrix4.outer(v, v);
+ final Matrix4 outer = new Matrix4.outer(v, v);
Matrix4 r = new Matrix4.zero();
r = r - outer;
- Vector3 scaledNormal = (planeNormal.scaled(dot3(planePoint, planeNormal)));
- Vector4 T = new Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
- scaledNormal.storage[2], 1.0);
+ final Vector3 scaledNormal =
+ (planeNormal.scaled(dot3(planePoint, planeNormal)));
+ final Vector4 T = new Vector4(scaledNormal.storage[0],
+ scaledNormal.storage[1], scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
}
@@ -275,16 +277,15 @@
/// Returns a transformation matrix that transforms points by reflecting
/// them through the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
- Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- Matrix4 outer = new Matrix4.outer(v, v);
- outer.scale(2.0);
+ final Matrix4 outer = new Matrix4.outer(v, v)..scale(2.0);
Matrix4 r = new Matrix4.zero();
r = r - outer;
- double scale = 2.0 * planePoint.dot(planeNormal);
- Vector3 scaledNormal = (planeNormal.scaled(scale));
- Vector4 T = new Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
- scaledNormal.storage[2], 1.0);
+ final double scale = 2.0 * planePoint.dot(planeNormal);
+ final Vector3 scaledNormal = (planeNormal.scaled(scale));
+ final Vector4 T = new Vector4(scaledNormal.storage[0],
+ scaledNormal.storage[1], scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
}
@@ -333,19 +334,21 @@
}
// Copy camera matrix.
- Matrix4 invertedCameraMatrix = new Matrix4.copy(cameraMatrix);
+ final Matrix4 invertedCameraMatrix = new Matrix4.copy(cameraMatrix);
// Invert the camera matrix.
invertedCameraMatrix.invert();
// Determine intersection point.
- Vector4 v = new Vector4(pickX, pickY, pickZ, 1.0);
+ final Vector4 v =
+ new Vector4(pickX.toDouble(), pickY.toDouble(), pickZ.toDouble(), 1.0);
invertedCameraMatrix.transform(v);
if (v.w == 0.0) {
return false;
}
- double invW = 1.0 / v.w;
- pickWorld.x = v.x * invW;
- pickWorld.y = v.y * invW;
- pickWorld.z = v.z * invW;
+ final double invW = 1.0 / v.w;
+ pickWorld
+ ..x = v.x * invW
+ ..y = v.y * invW
+ ..z = v.z * invW;
return true;
}
diff --git a/lib/src/vector_math/plane.dart b/lib/src/vector_math/plane.dart
index b719ac4..a8b89c9 100644
--- a/lib/src/vector_math/plane.dart
+++ b/lib/src/vector_math/plane.dart
@@ -11,25 +11,26 @@
/// 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 cross = new Vector3.zero();
+ final Vector3 cross = new Vector3.zero();
b.normal.crossInto(c.normal, cross);
- final f = -a.normal.dot(cross);
+ final double f = -a.normal.dot(cross);
- final v1 = cross.scaled(a.constant);
+ final Vector3 v1 = cross.scaled(a.constant);
c.normal.crossInto(a.normal, cross);
- final v2 = cross.scaled(b.constant);
+ final Vector3 v2 = cross.scaled(b.constant);
a.normal.crossInto(b.normal, cross);
- final v3 = cross.scaled(c.constant);
+ final Vector3 v3 = cross.scaled(c.constant);
- result.x = (v1.x + v2.x + v3.x) / f;
- result.y = (v1.y + v2.y + v3.y) / f;
- result.z = (v1.z + v2.z + v3.z) / f;
+ result
+ ..x = (v1.x + v2.x + v3.x) / f
+ ..y = (v1.y + v2.y + v3.y) / f
+ ..z = (v1.z + v2.z + v3.z) / f;
}
Vector3 get normal => _normal;
@@ -63,12 +64,10 @@
}
void normalize() {
- var inverseLength = 1.0 / normal.length;
+ final double inverseLength = 1.0 / normal.length;
_normal.scale(inverseLength);
_constant *= inverseLength;
}
- double distanceToVector3(Vector3 point) {
- return _normal.dot(point) + _constant;
- }
+ double distanceToVector3(Vector3 point) => _normal.dot(point) + _constant;
}
diff --git a/lib/src/vector_math/quad.dart b/lib/src/vector_math/quad.dart
index 06442bf..fe78ad4 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 v0 = _point0.clone()..sub(_point1);
+ final Vector3 v0 = _point0.clone()..sub(_point1);
normal
..setFrom(_point2)
..sub(_point1)
@@ -74,10 +74,11 @@
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- t.transform3(_point0);
- t.transform3(_point1);
- t.transform3(_point2);
- t.transform3(_point3);
+ t
+ ..transform3(_point0)
+ ..transform3(_point1)
+ ..transform3(_point2)
+ ..transform3(_point3);
}
/// Translate [this] by [offset].
diff --git a/lib/src/vector_math/quaternion.dart b/lib/src/vector_math/quaternion.dart
index 54add8f..0370e11 100644
--- a/lib/src/vector_math/quaternion.dart
+++ b/lib/src/vector_math/quaternion.dart
@@ -64,7 +64,7 @@
/// Constructs a quaternion with a random rotation. The random number
/// generator [rn] is used to generate the random numbers for the rotation.
- factory Quaternion.random(Math.Random rn) =>
+ factory Quaternion.random(math.Random rn) =>
new Quaternion._()..setRandom(rn);
/// Constructs a quaternion set to the identity quaternion.
@@ -93,7 +93,7 @@
/// Copy [source] into [this].
void setFrom(Quaternion source) {
- final sourceStorage = source._qStorage;
+ final Float32List sourceStorage = source._qStorage;
_qStorage[0] = sourceStorage[0];
_qStorage[1] = sourceStorage[1];
_qStorage[2] = sourceStorage[2];
@@ -110,36 +110,36 @@
/// Set the quaternion with rotation of [radians] around [axis].
void setAxisAngle(Vector3 axis, double radians) {
- final len = axis.length;
+ final double len = axis.length;
if (len == 0.0) {
return;
}
- final halfSin = Math.sin(radians * 0.5) / len;
- final axisStorage = axis.storage;
+ final double halfSin = math.sin(radians * 0.5) / len;
+ final Float32List axisStorage = axis.storage;
_qStorage[0] = axisStorage[0] * halfSin;
_qStorage[1] = axisStorage[1] * halfSin;
_qStorage[2] = axisStorage[2] * halfSin;
- _qStorage[3] = Math.cos(radians * 0.5);
+ _qStorage[3] = math.cos(radians * 0.5);
}
/// Set the quaternion with rotation from a rotation matrix [rotationMatrix].
void setFromRotation(Matrix3 rotationMatrix) {
- final rotationMatrixStorage = rotationMatrix.storage;
- final trace = rotationMatrix.trace();
+ final Float32List rotationMatrixStorage = rotationMatrix.storage;
+ final double trace = rotationMatrix.trace();
if (trace > 0.0) {
- var s = Math.sqrt(trace + 1.0);
+ double s = math.sqrt(trace + 1.0);
_qStorage[3] = s * 0.5;
s = 0.5 / s;
_qStorage[0] = (rotationMatrixStorage[5] - rotationMatrixStorage[7]) * s;
_qStorage[1] = (rotationMatrixStorage[6] - rotationMatrixStorage[2]) * s;
_qStorage[2] = (rotationMatrixStorage[1] - rotationMatrixStorage[3]) * s;
} else {
- var i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
+ final int i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1)
: (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0);
- var j = (i + 1) % 3;
- var k = (i + 2) % 3;
- var s = Math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] -
+ final int j = (i + 1) % 3;
+ final int k = (i + 2) % 3;
+ double s = math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] -
rotationMatrixStorage[rotationMatrix.index(j, j)] -
rotationMatrixStorage[rotationMatrix.index(k, k)] +
1.0);
@@ -158,16 +158,16 @@
}
void setFromTwoVectors(Vector3 a, Vector3 b) {
- Vector3 v1 = a.normalized();
- Vector3 v2 = b.normalized();
+ final Vector3 v1 = a.normalized();
+ final Vector3 v2 = b.normalized();
- double c = v1.dot(v2);
- double angle = Math.acos(c);
+ final double c = v1.dot(v2);
+ double angle = math.acos(c);
Vector3 axis = v1.cross(v2);
if ((1.0 + c).abs() < 0.0005) {
// c \approx -1 indicates 180 degree rotation
- angle = Math.PI;
+ angle = math.PI;
// a and b are parallel in opposite directions. We need any
// vector as our rotation axis that is perpendicular.
@@ -190,18 +190,18 @@
/// Set the quaternion to a random rotation. The random number generator [rn]
/// is used to generate the random numbers for the rotation.
- void setRandom(Math.Random rn) {
+ void setRandom(math.Random rn) {
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// pg. 124-132.
- 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);
+ 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);
_qStorage[0] = s1 * r1;
_qStorage[1] = c1 * r1;
_qStorage[2] = s2 * r2;
@@ -211,19 +211,19 @@
/// Set the quaternion to the time derivative of [q] with angular velocity
/// [omega].
void setDQ(Quaternion q, Vector3 omega) {
- 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;
+ 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;
_qStorage[0] = _x * 0.5;
_qStorage[1] = _y * 0.5;
_qStorage[2] = _z * 0.5;
@@ -232,15 +232,15 @@
/// Set quaternion with rotation of [yaw], [pitch] and [roll].
void setEuler(double yaw, double pitch, double roll) {
- 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);
+ 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);
_qStorage[0] = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw;
_qStorage[1] = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw;
_qStorage[2] = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw;
@@ -249,11 +249,11 @@
/// Normalize [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_qStorage[0] *= d;
_qStorage[1] *= d;
_qStorage[2] *= d;
@@ -270,7 +270,7 @@
/// Invert [this].
void inverse() {
- final l = 1.0 / length2;
+ final double l = 1.0 / length2;
_qStorage[3] = _qStorage[3] * l;
_qStorage[2] = -_qStorage[2] * l;
_qStorage[1] = -_qStorage[1] * l;
@@ -287,36 +287,36 @@
Quaternion inverted() => clone()..inverse();
/// [radians] of rotation around the [axis] of the rotation.
- double get radians => 2.0 * Math.acos(_qStorage[3]);
+ double get radians => 2.0 * math.acos(_qStorage[3]);
/// [axis] of rotation.
Vector3 get axis {
- final den = 1.0 - (_qStorage[3] * _qStorage[3]);
+ final double den = 1.0 - (_qStorage[3] * _qStorage[3]);
if (den < 0.0005) {
// 0-angle rotation, so axis does not matter
return new Vector3.zero();
}
- final scale = 1.0 / Math.sqrt(den);
+ final double scale = 1.0 / math.sqrt(den);
return new Vector3(
_qStorage[0] * scale, _qStorage[1] * scale, _qStorage[2] * scale);
}
/// Length squared.
double get length2 {
- final x = _qStorage[0];
- final y = _qStorage[1];
- final z = _qStorage[2];
- final w = _qStorage[3];
+ final double x = _qStorage[0];
+ final double y = _qStorage[1];
+ final double z = _qStorage[2];
+ final double w = _qStorage[3];
return (x * x) + (y * y) + (z * z) + (w * w);
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Returns a copy of [v] rotated by quaternion.
Vector3 rotated(Vector3 v) {
- final out = v.clone();
+ final Vector3 out = v.clone();
rotate(out);
return out;
}
@@ -324,22 +324,22 @@
/// Rotates [v] by [this].
Vector3 rotate(Vector3 v) {
// conjugate(this) * [v,0] * this
- 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;
+ 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;
vStorage[2] = result_z;
vStorage[1] = result_y;
vStorage[0] = result_x;
@@ -348,7 +348,7 @@
/// Add [arg] to [this].
void add(Quaternion arg) {
- final argStorage = arg._qStorage;
+ final Float32List argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] + argStorage[0];
_qStorage[1] = _qStorage[1] + argStorage[1];
_qStorage[2] = _qStorage[2] + argStorage[2];
@@ -357,7 +357,7 @@
/// Subtracts [arg] from [this].
void sub(Quaternion arg) {
- final argStorage = arg._qStorage;
+ final Float32List argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] - argStorage[0];
_qStorage[1] = _qStorage[1] - argStorage[1];
_qStorage[2] = _qStorage[2] - argStorage[2];
@@ -377,15 +377,15 @@
/// [this] rotated by [other].
Quaternion operator *(Quaternion other) {
- double _w = _qStorage[3];
- double _z = _qStorage[2];
- double _y = _qStorage[1];
- double _x = _qStorage[0];
- final otherStorage = other._qStorage;
- double ow = otherStorage[3];
- double oz = otherStorage[2];
- double oy = otherStorage[1];
- double ox = otherStorage[0];
+ 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];
return new Quaternion(
_w * ox + _x * ow + _y * oz - _z * oy,
_w * oy + _y * ow + _z * ox - _x * oz,
@@ -416,32 +416,32 @@
/// Set [rotationMatrix] to a rotation matrix containing the same rotation as
/// [this].
Matrix3 copyRotationInto(Matrix3 rotationMatrix) {
- final d = length2;
+ final double d = length2;
assert(d != 0.0);
- final s = 2.0 / d;
+ final double s = 2.0 / d;
- final _x = _qStorage[0];
- final _y = _qStorage[1];
- final _z = _qStorage[2];
- final _w = _qStorage[3];
+ final double _x = _qStorage[0];
+ final double _y = _qStorage[1];
+ final double _z = _qStorage[2];
+ final double _w = _qStorage[3];
- final xs = _x * s;
- final ys = _y * s;
- final zs = _z * s;
+ final double xs = _x * s;
+ final double ys = _y * s;
+ final double zs = _z * s;
- final wx = _w * xs;
- final wy = _w * ys;
- final wz = _w * zs;
+ final double wx = _w * xs;
+ final double wy = _w * ys;
+ final double wz = _w * zs;
- final xx = _x * xs;
- final xy = _x * ys;
- final xz = _x * zs;
+ final double xx = _x * xs;
+ final double xy = _x * ys;
+ final double xz = _x * zs;
- final yy = _y * ys;
- final yz = _y * zs;
- final zz = _z * zs;
+ final double yy = _y * ys;
+ final double yz = _y * zs;
+ final double zz = _z * zs;
- final rotationMatrixStorage = rotationMatrix.storage;
+ final Float32List rotationMatrixStorage = rotationMatrix.storage;
rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0
rotationMatrixStorage[1] = xy + wz;
rotationMatrixStorage[2] = xz - wy;
@@ -455,22 +455,23 @@
}
/// Printable string.
+ @override
String toString() => '${_qStorage[0]}, ${_qStorage[1]},'
' ${_qStorage[2]} @ ${_qStorage[3]}';
/// Relative error between [this] and [correct].
double relativeError(Quaternion correct) {
- final diff = correct - this;
- final norm_diff = diff.length;
- final correct_norm = correct.length;
+ final Quaternion diff = correct - this;
+ final double norm_diff = diff.length;
+ final double correct_norm = correct.length;
return norm_diff / correct_norm;
}
/// Absolute error between [this] and [correct].
double absoluteError(Quaternion correct) {
- final this_norm = length;
- final correct_norm = correct.length;
- final norm_diff = (this_norm - correct_norm).abs();
+ final double this_norm = length;
+ final double correct_norm = correct.length;
+ final double 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 a2ca3cc..60efc11 100644
--- a/lib/src/vector_math/ray.dart
+++ b/lib/src/vector_math/ray.dart
@@ -51,19 +51,19 @@
/// 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 r = other._radius;
- final r2 = r * r;
- final l = other._center.clone()..sub(_origin);
- final s = l.dot(_direction);
- final l2 = l.dot(l);
+ 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);
if (s < 0 && l2 > r2) {
return null;
}
- final m2 = l2 - s * s;
+ final double m2 = l2 - s * s;
if (m2 > r2) {
return null;
}
- final q = Math.sqrt(r2 - m2);
+ final double 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 _e1 = new Vector3.zero();
- static final _e2 = new Vector3.zero();
- static final _q = new Vector3.zero();
- static final _s = new Vector3.zero();
- static final _r = new Vector3.zero();
+ static final Vector3 _e1 = new Vector3.zero();
+ static final Vector3 _e2 = new Vector3.zero();
+ static final Vector3 _q = new Vector3.zero();
+ static final Vector3 _s = new Vector3.zero();
+ static final Vector3 _r = new 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;
- final point0 = other._point0;
- final point1 = other._point1;
- final point2 = other._point2;
+ final Vector3 point0 = other._point0;
+ final Vector3 point1 = other._point1;
+ final Vector3 point2 = other._point2;
_e1
..setFrom(point1)
@@ -94,30 +94,30 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final a = _e1.dot(_q);
+ final double a = _e1.dot(_q);
if (a > -EPSILON && a < EPSILON) {
return null;
}
- final f = 1 / a;
+ final double f = 1 / a;
_s
..setFrom(_origin)
..sub(point0);
- final u = f * (_s.dot(_q));
+ final double u = f * (_s.dot(_q));
if (u < 0.0) {
return null;
}
_s.crossInto(_e1, _r);
- final v = f * (_direction.dot(_r));
+ final double v = f * (_direction.dot(_r));
if (v < -EPSILON || u + v > 1.0 + EPSILON) {
return null;
}
- final t = f * (_e2.dot(_r));
+ final double t = f * (_e2.dot(_r));
return t;
}
@@ -128,9 +128,9 @@
const double EPSILON = 10e-6;
// First triangle
- var point0 = other._point0;
- var point1 = other._point1;
- var point2 = other._point2;
+ Vector3 point0 = other._point0;
+ Vector3 point1 = other._point1;
+ Vector3 point2 = other._point2;
_e1
..setFrom(point1)
@@ -140,21 +140,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final a0 = _e1.dot(_q);
+ final double a0 = _e1.dot(_q);
if (!(a0 > -EPSILON && a0 < EPSILON)) {
- final f = 1 / a0;
+ final double f = 1 / a0;
_s
..setFrom(_origin)
..sub(point0);
- final u = f * (_s.dot(_q));
+ final double u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final v = f * (_direction.dot(_r));
+ final double v = f * (_direction.dot(_r));
if (!(v < -EPSILON || u + v > 1.0 + EPSILON)) {
- final t = f * (_e2.dot(_r));
+ final double t = f * (_e2.dot(_r));
return t;
}
@@ -174,21 +174,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final a1 = _e1.dot(_q);
+ final double a1 = _e1.dot(_q);
if (!(a1 > -EPSILON && a1 < EPSILON)) {
- final f = 1 / a1;
+ final double f = 1 / a1;
_s
..setFrom(_origin)
..sub(point0);
- final u = f * (_s.dot(_q));
+ final double u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final v = f * (_direction.dot(_r));
+ final double v = f * (_direction.dot(_r));
if (!(v < -EPSILON || u + v > 1.0 + EPSILON)) {
- final t = f * (_e2.dot(_r));
+ final double t = f * (_e2.dot(_r));
return t;
}
@@ -201,23 +201,23 @@
/// 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 otherMin = other.min;
- final otherMax = other.max;
+ final Vector3 otherMin = other.min;
+ final Vector3 otherMax = other.max;
- var tNear = -double.MAX_FINITE;
- var tFar = double.MAX_FINITE;
+ double tNear = -double.MAX_FINITE;
+ double tFar = double.MAX_FINITE;
- for (var i = 0; i < 3; ++i) {
+ for (int i = 0; i < 3; ++i) {
if (_direction[i] == 0.0) {
if (_origin[i] < otherMin[i] || _origin[i] > otherMax[i]) {
return null;
}
} else {
- var t1 = (otherMin[i] - _origin[i]) / _direction[i];
- var t2 = (otherMax[i] - _origin[i]) / _direction[i];
+ double t1 = (otherMin[i] - _origin[i]) / _direction[i];
+ double t2 = (otherMax[i] - _origin[i]) / _direction[i];
if (t1 > t2) {
- final temp = t1;
+ final double temp = t1;
t1 = t2;
t2 = temp;
}
diff --git a/lib/src/vector_math/sphere.dart b/lib/src/vector_math/sphere.dart
index d645287..0e9716d 100644
--- a/lib/src/vector_math/sphere.dart
+++ b/lib/src/vector_math/sphere.dart
@@ -38,18 +38,16 @@
}
/// Return if [this] contains [other].
- bool containsVector3(Vector3 other) {
- return other.distanceToSquared(center) < radius * radius;
- }
+ bool containsVector3(Vector3 other) =>
+ other.distanceToSquared(center) < radius * radius;
/// Return if [this] intersects with [other].
- bool intersectsWithVector3(Vector3 other) {
- return other.distanceToSquared(center) <= radius * radius;
- }
+ bool intersectsWithVector3(Vector3 other) =>
+ other.distanceToSquared(center) <= radius * radius;
/// Return if [this] intersects with [other].
bool intersectsWithSphere(Sphere other) {
- var radiusSum = radius + other.radius;
+ final double 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 0e695ba..a20aa40 100644
--- a/lib/src/vector_math/third_party/noise.dart
+++ b/lib/src/vector_math/third_party/noise.dart
@@ -27,54 +27,54 @@
*/
class SimplexNoise {
- static final _grad3 = <List<double>>[
- [1.0, 1.0, 0.0],
- [-1.0, 1.0, 0.0],
- [1.0, -1.0, 0.0],
- [-1.0, -1.0, 0.0],
- [1.0, 0.0, 1.0],
- [-1.0, 0.0, 1.0],
- [1.0, 0.0, -1.0],
- [-1.0, 0.0, -1.0],
- [0.0, 1.0, 1.0],
- [0.0, -1.0, 1.0],
- [0.0, 1.0, -1.0],
- [0.0, -1.0, -1.0]
+ static final List<List<double>> _grad3 = <List<double>>[
+ <double>[1.0, 1.0, 0.0],
+ <double>[-1.0, 1.0, 0.0],
+ <double>[1.0, -1.0, 0.0],
+ <double>[-1.0, -1.0, 0.0],
+ <double>[1.0, 0.0, 1.0],
+ <double>[-1.0, 0.0, 1.0],
+ <double>[1.0, 0.0, -1.0],
+ <double>[-1.0, 0.0, -1.0],
+ <double>[0.0, 1.0, 1.0],
+ <double>[0.0, -1.0, 1.0],
+ <double>[0.0, 1.0, -1.0],
+ <double>[0.0, -1.0, -1.0]
];
- static final _grad4 = <List<double>>[
- [0.0, 1.0, 1.0, 1.0],
- [0.0, 1.0, 1.0, -1.0],
- [0.0, 1.0, -1.0, 1.0],
- [0.0, 1.0, -1.0, -1.0],
- [0.0, -1.0, 1.0, 1.0],
- [0.0, -1.0, 1.0, -1.0],
- [0.0, -1.0, -1.0, 1.0],
- [0.0, -1.0, -1.0, -1.0],
- [1.0, 0.0, 1.0, 1.0],
- [1.0, 0.0, 1.0, -1.0],
- [1.0, 0.0, -1.0, 1.0],
- [1.0, 0.0, -1.0, -1.0],
- [-1.0, 0.0, 1.0, 1.0],
- [-1.0, 0.0, 1.0, -1.0],
- [-1.0, 0.0, -1.0, 1.0],
- [-1.0, 0.0, -1.0, -1.0],
- [1.0, 1.0, 0.0, 1.0],
- [1.0, 1.0, 0.0, -1.0],
- [1.0, -1.0, 0.0, 1.0],
- [1.0, -1.0, 0.0, -1.0],
- [-1.0, 1.0, 0.0, 1.0],
- [-1.0, 1.0, 0.0, -1.0],
- [-1.0, -1.0, 0.0, 1.0],
- [-1.0, -1.0, 0.0, -1.0],
- [1.0, 1.0, 1.0, 0.0],
- [1.0, 1.0, -1.0, 0.0],
- [1.0, -1.0, 1.0, 0.0],
- [1.0, -1.0, -1.0, 0.0],
- [-1.0, 1.0, 1.0, 0.0],
- [-1.0, 1.0, -1.0, 0.0],
- [-1.0, -1.0, 1.0, 0.0],
- [-1.0, -1.0, -1.0, 0.0]
+ static final List<List<double>> _grad4 = <List<double>>[
+ <double>[0.0, 1.0, 1.0, 1.0],
+ <double>[0.0, 1.0, 1.0, -1.0],
+ <double>[0.0, 1.0, -1.0, 1.0],
+ <double>[0.0, 1.0, -1.0, -1.0],
+ <double>[0.0, -1.0, 1.0, 1.0],
+ <double>[0.0, -1.0, 1.0, -1.0],
+ <double>[0.0, -1.0, -1.0, 1.0],
+ <double>[0.0, -1.0, -1.0, -1.0],
+ <double>[1.0, 0.0, 1.0, 1.0],
+ <double>[1.0, 0.0, 1.0, -1.0],
+ <double>[1.0, 0.0, -1.0, 1.0],
+ <double>[1.0, 0.0, -1.0, -1.0],
+ <double>[-1.0, 0.0, 1.0, 1.0],
+ <double>[-1.0, 0.0, 1.0, -1.0],
+ <double>[-1.0, 0.0, -1.0, 1.0],
+ <double>[-1.0, 0.0, -1.0, -1.0],
+ <double>[1.0, 1.0, 0.0, 1.0],
+ <double>[1.0, 1.0, 0.0, -1.0],
+ <double>[1.0, -1.0, 0.0, 1.0],
+ <double>[1.0, -1.0, 0.0, -1.0],
+ <double>[-1.0, 1.0, 0.0, 1.0],
+ <double>[-1.0, 1.0, 0.0, -1.0],
+ <double>[-1.0, -1.0, 0.0, 1.0],
+ <double>[-1.0, -1.0, 0.0, -1.0],
+ <double>[1.0, 1.0, 1.0, 0.0],
+ <double>[1.0, 1.0, -1.0, 0.0],
+ <double>[1.0, -1.0, 1.0, 0.0],
+ <double>[1.0, -1.0, -1.0, 0.0],
+ <double>[-1.0, 1.0, 1.0, 0.0],
+ <double>[-1.0, 1.0, -1.0, 0.0],
+ <double>[-1.0, -1.0, 1.0, 0.0],
+ <double>[-1.0, -1.0, -1.0, 0.0]
];
// To remove the need for index wrapping, double the permutation table length
@@ -82,12 +82,12 @@
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 double _F2 = 0.5 * (math.sqrt(3.0) - 1.0);
+ static final double _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 double _F4 = (math.sqrt(5.0) - 1.0) / 4.0;
+ static final double _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,29 +97,27 @@
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]) {
- if (r == null) {
- r = new Math.Random();
- }
- List<int> p =
- new List<int>.generate(256, (i) => r.nextInt(256), growable: false);
- _perm = new List<int>.generate(p.length * 2, (i) => p[i % p.length],
+ SimplexNoise([math.Random r]) {
+ r ??= new math.Random();
+ final List<int> p =
+ new List<int>.generate(256, (_) => r.nextInt(256), growable: false);
+ _perm = new List<int>.generate(p.length * 2, (int i) => p[i % p.length],
growable: false);
- _permMod12 = new List<int>.generate(_perm.length, (i) => _perm[i] % 12,
+ _permMod12 = new List<int>.generate(_perm.length, (int i) => _perm[i] % 12,
growable: false);
}
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
- double s = (xin + yin) * _F2; // Hairy factor for 2D
- int i = (xin + s).floor();
- int j = (yin + s).floor();
- double t = (i + j) * _G2;
- double X0 = i - t; // Unskew the cell origin back to (x,y) space
- double Y0 = j - t;
- double x0 = xin - X0; // The x,y distances from the cell origin
- double y0 = yin - Y0;
+ 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;
// 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
@@ -134,19 +132,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
- double x1 =
+ final double x1 =
x0 - i1 + _G2; // Offsets for middle corner in (x,y) unskewed coords
- double y1 = y0 - j1 + _G2;
- double x2 = x0 -
+ final double y1 = y0 - j1 + _G2;
+ final double x2 = x0 -
1.0 +
2.0 * _G2; // Offsets for last corner in (x,y) unskewed coords
- double y2 = y0 - 1.0 + 2.0 * _G2;
+ final double y2 = y0 - 1.0 + 2.0 * _G2;
// Work out the hashed gradient indices of the three simplex corners
- int ii = i & 255;
- int jj = j & 255;
- int gi0 = _permMod12[ii + _perm[jj]];
- int gi1 = _permMod12[ii + i1 + _perm[jj + j1]];
- int gi2 = _permMod12[ii + 1 + _perm[jj + 1]];
+ 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]];
// Calculate the contribution from the three corners
double t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0)
@@ -180,18 +178,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
- double s =
+ final double s =
(xin + yin + zin) * _F3; // Very nice and simple skew factor for 3D
- int i = (xin + s).floor();
- int j = (yin + s).floor();
- int k = (zin + s).floor();
- double t = (i + j + k) * _G3;
- double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
- double Y0 = j - t;
- double Z0 = k - t;
- double x0 = xin - X0; // The x,y,z distances from the cell origin
- double y0 = yin - Y0;
- double z0 = zin - Z0;
+ 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;
// 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
@@ -252,25 +250,26 @@
// 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.
- double x1 = x0 - i1 + _G3; // Offsets for second corner in (x,y,z) coords
- double y1 = y0 - j1 + _G3;
- double z1 = z0 - k1 + _G3;
- double x2 =
+ 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 =
x0 - i2 + 2.0 * _G3; // Offsets for third corner in (x,y,z) coords
- double y2 = y0 - j2 + 2.0 * _G3;
- double z2 = z0 - k2 + 2.0 * _G3;
- double x3 =
+ final double y2 = y0 - j2 + 2.0 * _G3;
+ final double z2 = z0 - k2 + 2.0 * _G3;
+ final double x3 =
x0 - 1.0 + 3.0 * _G3; // Offsets for last corner in (x,y,z) coords
- double y3 = y0 - 1.0 + 3.0 * _G3;
- double z3 = z0 - 1.0 + 3.0 * _G3;
+ final double y3 = y0 - 1.0 + 3.0 * _G3;
+ final double z3 = z0 - 1.0 + 3.0 * _G3;
// Work out the hashed gradient indices of the four simplex corners
- int ii = i & 255;
- int jj = j & 255;
- int kk = k & 255;
- int gi0 = _permMod12[ii + _perm[jj + _perm[kk]]];
- int gi1 = _permMod12[ii + i1 + _perm[jj + j1 + _perm[kk + k1]]];
- int gi2 = _permMod12[ii + i2 + _perm[jj + j2 + _perm[kk + k2]]];
- int gi3 = _permMod12[ii + 1 + _perm[jj + 1 + _perm[kk + 1]]];
+ 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]]];
// Calculate the contribution from the four corners
double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0)
@@ -309,20 +308,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
- double s = (x + y + z + w) * _F4; // Factor for 4D skewing
- int i = (x + s).floor();
- int j = (y + s).floor();
- int k = (z + s).floor();
- int l = (w + s).floor();
- double t = (i + j + k + l) * _G4; // Factor for 4D unskewing
- double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
- double Y0 = j - t;
- double Z0 = k - t;
- double W0 = l - t;
- double x0 = x - X0; // The x,y,z,w distances from the cell origin
- double y0 = y - Y0;
- double z0 = z - Z0;
- double w0 = w - W0;
+ 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;
// 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.
@@ -379,38 +378,39 @@
k3 = rankz >= 1 ? 1 : 0;
l3 = rankw >= 1 ? 1 : 0;
// The fifth corner has all coordinate offsets = 1, so no need to compute that.
- double x1 = x0 - i1 + _G4; // Offsets for second corner in (x,y,z,w) coords
- double y1 = y0 - j1 + _G4;
- double z1 = z0 - k1 + _G4;
- double w1 = w0 - l1 + _G4;
- double x2 =
+ 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 =
x0 - i2 + 2.0 * _G4; // Offsets for third corner in (x,y,z,w) coords
- double y2 = y0 - j2 + 2.0 * _G4;
- double z2 = z0 - k2 + 2.0 * _G4;
- double w2 = w0 - l2 + 2.0 * _G4;
- double x3 =
+ 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 =
x0 - i3 + 3.0 * _G4; // Offsets for fourth corner in (x,y,z,w) coords
- double y3 = y0 - j3 + 3.0 * _G4;
- double z3 = z0 - k3 + 3.0 * _G4;
- double w3 = w0 - l3 + 3.0 * _G4;
- double x4 =
+ 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 =
x0 - 1.0 + 4.0 * _G4; // Offsets for last corner in (x,y,z,w) coords
- double y4 = y0 - 1.0 + 4.0 * _G4;
- double z4 = z0 - 1.0 + 4.0 * _G4;
- double w4 = w0 - 1.0 + 4.0 * _G4;
+ 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;
// Work out the hashed gradient indices of the five simplex corners
- int ii = i & 255;
- int jj = j & 255;
- int kk = k & 255;
- int ll = l & 255;
- int gi0 = _perm[ii + _perm[jj + _perm[kk + _perm[ll]]]] % 32;
- int gi1 =
+ 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 =
_perm[ii + i1 + _perm[jj + j1 + _perm[kk + k1 + _perm[ll + l1]]]] % 32;
- int gi2 =
+ final int gi2 =
_perm[ii + i2 + _perm[jj + j2 + _perm[kk + k2 + _perm[ll + l2]]]] % 32;
- int gi3 =
+ final int gi3 =
_perm[ii + i3 + _perm[jj + j3 + _perm[kk + k3 + _perm[ll + l3]]]] % 32;
- int gi4 =
+ final int gi4 =
_perm[ii + 1 + _perm[jj + 1 + _perm[kk + 1 + _perm[ll + 1]]]] % 32;
// Calculate the contribution from the five corners
double 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 c1cf53d..fb486a6 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 v0 = point0.clone()..sub(point1);
+ final Vector3 v0 = point0.clone()..sub(point1);
normal
..setFrom(point2)
..sub(point1)
@@ -56,9 +56,7 @@
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- t.transform3(_point0);
- t.transform3(_point1);
- t.transform3(_point2);
+ t..transform3(_point0)..transform3(_point1)..transform3(_point2);
}
/// Translate [this] by [offset].
diff --git a/lib/src/vector_math/utilities.dart b/lib/src/vector_math/utilities.dart
index d48ea42..29cc2a2 100644
--- a/lib/src/vector_math/utilities.dart
+++ b/lib/src/vector_math/utilities.dart
@@ -5,39 +5,32 @@
part of vector_math;
/// Convert [radians] to degrees.
-double degrees(double radians) {
- return radians * radians2Degrees;
-}
+double degrees(double radians) => radians * radians2Degrees;
/// Convert [degrees] to radians.
-double radians(double degrees) {
- return degrees * degrees2Radians;
-}
+double radians(double degrees) => degrees * degrees2Radians;
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation. The computation is equivalent to the GLSL function mix.
-double mix(double min, double max, double a) {
- return min + a * (max - min);
-}
+double mix(double min, double max, double a) => min + a * (max - min);
/// Do a smooth step (hermite interpolation) interpolation with [edge0] and
/// [edge1] by [amount]. The computation is equivalent to the GLSL function
/// smoothstep.
double smoothStep(double edge0, double edge1, double amount) {
- final t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0);
+ final double t =
+ ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble();
return t * t * (3.0 - 2.0 * t);
}
/// Do a catmull rom spline interpolation with [edge0], [edge1], [edge2] and
/// [edge3] by [amount].
-double catmullRom(
- double edge0, double edge1, double edge2, double edge3, double amount) {
- return 0.5 *
- ((2.0 * edge1) +
- (-edge0 + edge2) * amount +
- (2.0 * edge0 - 5.0 * edge1 + 4.0 * edge2 - edge3) *
- (amount * amount) +
- (-edge0 + 3.0 * edge1 - 3.0 * edge2 + edge3) *
- (amount * amount * amount));
-}
+double catmullRom(double edge0, double edge1, double edge2, double edge3,
+ double amount) =>
+ 0.5 *
+ ((2.0 * edge1) +
+ (-edge0 + edge2) * amount +
+ (2.0 * edge0 - 5.0 * edge1 + 4.0 * edge2 - edge3) * (amount * amount) +
+ (-edge0 + 3.0 * edge1 - 3.0 * edge2 + edge3) *
+ (amount * amount * amount));
diff --git a/lib/src/vector_math/vector.dart b/lib/src/vector_math/vector.dart
index 057fffe..a6952a4 100644
--- a/lib/src/vector_math/vector.dart
+++ b/lib/src/vector_math/vector.dart
@@ -20,41 +20,51 @@
/// 2D cross product. double x vec2.
void cross2A(double x, Vector2 y, Vector2 out) {
- var tempy = x * y.x;
- out.x = -x * y.y;
- out.y = tempy;
+ final double tempy = x * y.x;
+ out
+ ..x = -x * y.y
+ ..y = tempy;
}
/// 2D cross product. vec2 x double.
void cross2B(Vector2 x, double y, Vector2 out) {
- var tempy = -y * x.x;
- out.x = y * x.y;
- out.y = tempy;
+ final double tempy = -y * x.x;
+ out
+ ..x = y * x.y
+ ..y = tempy;
}
/// Sets [u] and [v] to be two vectors orthogonal to each other and
/// [planeNormal].
void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) {
- if (planeNormal.z.abs() > Math.SQRT1_2) {
+ if (planeNormal.z.abs() > math.SQRT1_2) {
// choose u in y-z plane
- double a = planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
- double k = 1.0 / Math.sqrt(a);
- u.x = 0.0;
- u.y = -planeNormal.z * k;
- u.z = planeNormal.y * k;
- v.x = a * k;
- v.y = -planeNormal[0] * (planeNormal[1] * k);
- v.z = planeNormal[0] * (-planeNormal[2] * k);
+ final double a =
+ planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
+ final double k = 1.0 / math.sqrt(a);
+ u
+ ..x = 0.0
+ ..y = -planeNormal.z * k
+ ..z = planeNormal.y * k;
+
+ v
+ ..x = a * k
+ ..y = -planeNormal[0] * (planeNormal[1] * k)
+ ..z = planeNormal[0] * (-planeNormal[2] * k);
} else {
// choose u in x-y plane
- double a = planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
- double k = 1.0 / Math.sqrt(a);
- u.x = -planeNormal[1] * k;
- u.y = planeNormal[0] * k;
- u.z = 0.0;
- v.x = -planeNormal[2] * (planeNormal[0] * k);
- v.y = planeNormal[2] * (-planeNormal[1] * k);
- v.z = a * k;
+ final double a =
+ planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
+ final double k = 1.0 / math.sqrt(a);
+ u
+ ..x = -planeNormal[1] * k
+ ..y = planeNormal[0] * k
+ ..z = 0.0;
+
+ v
+ ..x = -planeNormal[2] * (planeNormal[0] * k)
+ ..y = planeNormal[2] * (-planeNormal[1] * k)
+ ..z = a * k;
}
}
diff --git a/lib/src/vector_math/vector2.dart b/lib/src/vector_math/vector2.dart
index d98ecec..30b6f13 100644
--- a/lib/src/vector_math/vector2.dart
+++ b/lib/src/vector_math/vector2.dart
@@ -9,25 +9,29 @@
final Float32List _v2storage;
/// The components of the vector.
+ @override
Float32List get storage => _v2storage;
/// Set the values of [result] to the minimum of [a] and [b] for each line.
static void min(Vector2 a, Vector2 b, Vector2 result) {
- result.x = Math.min(a.x, b.x);
- result.y = Math.min(a.y, b.y);
+ result
+ ..x = math.min(a.x, b.x)
+ ..y = math.min(a.y, b.y);
}
/// Set the values of [result] to the maximum of [a] and [b] for each line.
static void max(Vector2 a, Vector2 b, Vector2 result) {
- result.x = Math.max(a.x, b.x);
- result.y = Math.max(a.y, b.y);
+ result
+ ..x = math.max(a.x, b.x)
+ ..y = math.max(a.y, b.y);
}
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation and store the values in [result].
static void mix(Vector2 min, Vector2 max, double a, Vector2 result) {
- result.x = min.x + a * (max.x - min.x);
- result.y = min.y + a * (max.y - min.y);
+ result
+ ..x = min.x + a * (max.x - min.x)
+ ..y = min.y + a * (max.y - min.y);
}
/// Construct a new vector with the specified values.
@@ -56,8 +60,8 @@
/// 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]) {
- rng = rng == null ? new Math.Random() : rng;
+ factory Vector2.random([math.Random rng]) {
+ rng = rng == null ? new math.Random() : rng;
return new Vector2(rng.nextDouble(), rng.nextDouble());
}
@@ -75,7 +79,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector2 other) {
- final otherStorage = other._v2storage;
+ final Float32List otherStorage = other._v2storage;
_v2storage[1] = otherStorage[1];
_v2storage[0] = otherStorage[0];
}
@@ -87,15 +91,17 @@
}
/// Returns a printable string
+ @override
String toString() => '[${_v2storage[0]},${_v2storage[1]}]';
/// Check if two vectors are the same.
- bool operator ==(other) {
- return (other is Vector2) &&
- (_v2storage[0] == other._v2storage[0]) &&
- (_v2storage[1] == other._v2storage[1]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Vector2) &&
+ (_v2storage[0] == other._v2storage[0]) &&
+ (_v2storage[1] == other._v2storage[1]);
+ @override
int get hashCode => quiver.hashObjects(_v2storage);
/// Negate.
@@ -138,11 +144,11 @@
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Length squared.
double get length2 {
- var sum;
+ double sum;
sum = (_v2storage[0] * _v2storage[0]);
sum += (_v2storage[1] * _v2storage[1]);
return sum;
@@ -150,11 +156,11 @@
/// Normalize [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_v2storage[0] *= d;
_v2storage[1] *= d;
return l;
@@ -177,69 +183,67 @@
}
/// Distance from [this] to [arg]
- double distanceTo(Vector2 arg) => Math.sqrt(distanceToSquared(arg));
+ double distanceTo(Vector2 arg) => math.sqrt(distanceToSquared(arg));
/// Squared distance from [this] to [arg]
double distanceToSquared(Vector2 arg) {
- final dx = x - arg.x;
- final dy = y - arg.y;
+ final double dx = x - arg.x;
+ final double dy = y - arg.y;
return dx * dx + dy * dy;
}
/// Returns the angle between [this] vector and [other] in radians.
double angleTo(Vector2 other) {
- final otherStorage = other._v2storage;
- if (_v2storage[0] == otherStorage[0] &&
- _v2storage[1] == otherStorage[1]) {
+ final Float32List otherStorage = other._v2storage;
+ if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final d = dot(other);
+ final double d = dot(other);
- return Math.acos(d.clamp(-1.0, 1.0));
+ return math.acos(d.clamp(-1.0, 1.0));
}
/// Returns the signed angle between [this] and [other] in radians.
double angleToSigned(Vector2 other) {
- final otherStorage = other._v2storage;
- if (_v2storage[0] == otherStorage[0] &&
- _v2storage[1] == otherStorage[1]) {
+ final Float32List otherStorage = other._v2storage;
+ if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final s = cross(other);
- final c = dot(other);
+ final double s = cross(other);
+ final double c = dot(other);
- return Math.atan2(s, c);
+ return math.atan2(s, c);
}
/// Inner product.
double dot(Vector2 other) {
- final otherStorage = other._v2storage;
+ final Float32List otherStorage = other._v2storage;
double sum;
sum = _v2storage[0] * otherStorage[0];
sum += _v2storage[1] * otherStorage[1];
return sum;
}
- /**
- * Transforms [this] into the product of [this] as a row vector,
- * postmultiplied by matrix, [arg].
- * If [arg] is a rotation matrix, this is a computational shortcut for applying,
- * the inverse of the transformation.
- */
+ ///
+ /// Transforms [this] into the product of [this] as a row vector,
+ /// postmultiplied by matrix, [arg].
+ /// If [arg] is a rotation matrix, this is a computational shortcut for applying,
+ /// the inverse of the transformation.
+ ///
void postmultiply(Matrix2 arg) {
- final argStorage = arg.storage;
- double v0 = _v2storage[0];
- double v1 = _v2storage[1];
+ final Float32List argStorage = arg.storage;
+ final double v0 = _v2storage[0];
+ final double 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 otherStorage = other._v2storage;
+ final Float32List otherStorage = other._v2storage;
return _v2storage[0] * otherStorage[1] - _v2storage[1] * otherStorage[0];
}
@@ -259,15 +263,13 @@
/// Relative error between [this] and [correct]
double relativeError(Vector2 correct) {
- double correct_norm = correct.length;
- double diff_norm = (this - correct).length;
+ final double correct_norm = correct.length;
+ final double diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
/// Absolute error between [this] and [correct]
- double absoluteError(Vector2 correct) {
- return (this - correct).length;
- }
+ double absoluteError(Vector2 correct) => (this - correct).length;
/// True if any component is infinite.
bool get isInfinite {
@@ -287,35 +289,35 @@
/// Add [arg] to [this].
void add(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List 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 argStorage = arg._v2storage;
+ final Float32List 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 argStorage = arg._v2storage;
+ final Float32List 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 argStorage = arg._v2storage;
+ final Float32List 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 argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] / argStorage[0];
_v2storage[1] = _v2storage[1] / argStorage[1];
}
@@ -343,16 +345,18 @@
/// Clamp each entry n in [this] in the range [min[n]]-[max[n]].
void clamp(Vector2 min, Vector2 max) {
- var minStorage = min.storage;
- var maxStorage = max.storage;
- _v2storage[0] = _v2storage[0].clamp(minStorage[0], maxStorage[0]);
- _v2storage[1] = _v2storage[1].clamp(minStorage[1], maxStorage[1]);
+ final Float32List minStorage = min.storage;
+ final Float32List maxStorage = max.storage;
+ _v2storage[0] =
+ _v2storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
+ _v2storage[1] =
+ _v2storage[1].clamp(minStorage[1], maxStorage[1]).toDouble();
}
/// Clamp entries [this] in the range [min]-[max].
void clampScalar(double min, double max) {
- _v2storage[0] = _v2storage[0].clamp(min, max);
- _v2storage[1] = _v2storage[1].clamp(min, max);
+ _v2storage[0] = _v2storage[0].clamp(min, max).toDouble();
+ _v2storage[1] = _v2storage[1].clamp(min, max).toDouble();
}
/// Floor entries in [this].
@@ -388,7 +392,7 @@
/// Copy [this] into [arg]. Returns [arg].
Vector2 copyInto(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
argStorage[1] = _v2storage[1];
argStorage[0] = _v2storage[0];
return arg;
@@ -407,13 +411,13 @@
}
set xy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v2storage[0] = argStorage[0];
_v2storage[1] = argStorage[1];
}
set yx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List 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 3f5177d..d2644fa 100644
--- a/lib/src/vector_math/vector3.dart
+++ b/lib/src/vector_math/vector3.dart
@@ -9,28 +9,32 @@
final Float32List _v3storage;
/// The components of the vector.
+ @override
Float32List get storage => _v3storage;
/// Set the values of [result] to the minimum of [a] and [b] for each line.
static void min(Vector3 a, Vector3 b, Vector3 result) {
- result.x = Math.min(a.x, b.x);
- result.y = Math.min(a.y, b.y);
- result.z = Math.min(a.z, b.z);
+ result
+ ..x = math.min(a.x, b.x)
+ ..y = math.min(a.y, b.y)
+ ..z = math.min(a.z, b.z);
}
/// Set the values of [result] to the maximum of [a] and [b] for each line.
static void max(Vector3 a, Vector3 b, Vector3 result) {
- result.x = Math.max(a.x, b.x);
- result.y = Math.max(a.y, b.y);
- result.z = Math.max(a.z, b.z);
+ result
+ ..x = math.max(a.x, b.x)
+ ..y = math.max(a.y, b.y)
+ ..z = math.max(a.z, b.z);
}
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation and store the values in [result].
static void mix(Vector3 min, Vector3 max, double a, Vector3 result) {
- result.x = min.x + a * (max.x - min.x);
- result.y = min.y + a * (max.y - min.y);
- result.z = min.z + a * (max.z - min.z);
+ result
+ ..x = min.x + a * (max.x - min.x)
+ ..y = min.y + a * (max.y - min.y)
+ ..z = min.z + a * (max.z - min.z);
}
/// Construct a new vector with the specified values.
@@ -60,8 +64,8 @@
/// 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]) {
- rng = rng == null ? new Math.Random() : rng;
+ factory Vector3.random([math.Random rng]) {
+ rng = rng == null ? new math.Random() : rng;
return new Vector3(rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
}
@@ -81,7 +85,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector3 other) {
- final otherStorage = other._v3storage;
+ final Float32List otherStorage = other._v3storage;
_v3storage[0] = otherStorage[0];
_v3storage[1] = otherStorage[1];
_v3storage[2] = otherStorage[2];
@@ -95,16 +99,18 @@
}
/// Returns a printable string
+ @override
String toString() => '[${storage[0]},${storage[1]},${storage[2]}]';
/// Check if two vectors are the same.
- bool operator ==(other) {
- return (other is Vector3) &&
- (_v3storage[0] == other._v3storage[0]) &&
- (_v3storage[1] == other._v3storage[1]) &&
- (_v3storage[2] == other._v3storage[2]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Vector3) &&
+ (_v3storage[0] == other._v3storage[0]) &&
+ (_v3storage[1] == other._v3storage[1]) &&
+ (_v3storage[2] == other._v3storage[2]);
+ @override
int get hashCode => quiver.hashObjects(_v3storage);
/// Negate
@@ -148,7 +154,7 @@
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Length squared.
double get length2 {
@@ -161,11 +167,11 @@
/// Normalizes [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_v3storage[0] *= d;
_v3storage[1] *= d;
_v3storage[2] *= d;
@@ -189,45 +195,45 @@
}
/// Distance from [this] to [arg]
- double distanceTo(Vector3 arg) => Math.sqrt(distanceToSquared(arg));
+ double distanceTo(Vector3 arg) => math.sqrt(distanceToSquared(arg));
/// Squared distance from [this] to [arg]
double distanceToSquared(Vector3 arg) {
- final argStorage = arg._v3storage;
- final dx = _v3storage[0] - argStorage[0];
- final dy = _v3storage[1] - argStorage[1];
- final dz = _v3storage[2] - argStorage[2];
+ 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];
return dx * dx + dy * dy + dz * dz;
}
/// Returns the angle between [this] vector and [other] in radians.
double angleTo(Vector3 other) {
- final otherStorage = other._v3storage;
+ final Float32List otherStorage = other._v3storage;
if (_v3storage[0] == otherStorage[0] &&
_v3storage[1] == otherStorage[1] &&
_v3storage[2] == otherStorage[2]) {
return 0.0;
}
- final d = dot(other);
+ final double d = dot(other);
- return Math.acos(d.clamp(-1.0, 1.0));
+ return math.acos(d.clamp(-1.0, 1.0));
}
/// Returns the signed angle between [this] and [other] around [normal]
/// in radians.
double angleToSigned(Vector3 other, Vector3 normal) {
- final angle = angleTo(other);
- final c = cross(other);
- final d = c.dot(normal);
+ final double angle = angleTo(other);
+ final Vector3 c = cross(other);
+ final double d = c.dot(normal);
return d < 0.0 ? -angle : angle;
}
/// Inner product.
double dot(Vector3 other) {
- final otherStorage = other._v3storage;
+ final Float32List otherStorage = other._v3storage;
double sum;
sum = _v3storage[0] * otherStorage[0];
sum += _v3storage[1] * otherStorage[1];
@@ -240,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 argStorage = arg.storage;
- final v0 = _v3storage[0];
- final v1 = _v3storage[1];
- final v2 = _v3storage[2];
+ final Float32List argStorage = arg.storage;
+ final double v0 = _v3storage[0];
+ final double v1 = _v3storage[1];
+ final double v2 = _v3storage[2];
_v3storage[0] =
v0 * argStorage[0] + v1 * argStorage[1] + v2 * argStorage[2];
@@ -255,26 +261,26 @@
/// Cross product.
Vector3 cross(Vector3 other) {
- 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 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];
return new 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 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;
+ 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;
outStorage[0] = y * oz - z * oy;
outStorage[1] = z * ox - x * oz;
outStorage[2] = x * oy - y * ox;
@@ -291,11 +297,11 @@
/// Projects [this] using the projection matrix [arg]
void applyProjection(Matrix4 arg) {
- final argStorage = arg.storage;
- final x = _v3storage[0];
- final y = _v3storage[1];
- final z = _v3storage[2];
- final d = 1.0 /
+ 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 /
(argStorage[3] * x +
argStorage[7] * y +
argStorage[11] * z +
@@ -324,18 +330,18 @@
/// Applies a quaternion transform.
void applyQuaternion(Quaternion arg) {
- final argStorage = arg._qStorage;
- var v0 = _v3storage[0];
- var v1 = _v3storage[1];
- var v2 = _v3storage[2];
- var qx = argStorage[0];
- var qy = argStorage[1];
- var qz = argStorage[2];
- var qw = argStorage[3];
- var ix = qw * v0 + qy * v2 - qz * v1;
- var iy = qw * v1 + qz * v0 - qx * v2;
- var iz = qw * v2 + qx * v1 - qy * v0;
- var iw = -qx * v0 - qy * v1 - qz * v2;
+ 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;
_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;
@@ -343,10 +349,10 @@
/// Multiplies [this] by [arg].
void applyMatrix3(Matrix3 arg) {
- final argStorage = arg.storage;
- var v0 = _v3storage[0];
- var v1 = _v3storage[1];
- var v2 = _v3storage[2];
+ final Float32List argStorage = arg.storage;
+ final double v0 = _v3storage[0];
+ final double v1 = _v3storage[1];
+ final double v2 = _v3storage[2];
_v3storage[0] =
argStorage[0] * v0 + argStorage[3] * v1 + argStorage[6] * v2;
_v3storage[1] =
@@ -358,10 +364,10 @@
/// Multiplies [this] by a 4x3 subset of [arg]. Expects [arg] to be an affine
/// transformation matrix.
void applyMatrix4(Matrix4 arg) {
- final argStorage = arg.storage;
- var v0 = _v3storage[0];
- var v1 = _v3storage[1];
- var v2 = _v3storage[2];
+ final Float32List argStorage = arg.storage;
+ final double v0 = _v3storage[0];
+ final double v1 = _v3storage[1];
+ final double v2 = _v3storage[2];
_v3storage[0] = argStorage[0] * v0 +
argStorage[4] * v1 +
argStorage[8] * v2 +
@@ -378,15 +384,13 @@
/// Relative error between [this] and [correct]
double relativeError(Vector3 correct) {
- double correct_norm = correct.length;
- double diff_norm = (this - correct).length;
+ final double correct_norm = correct.length;
+ final double diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
/// Absolute error between [this] and [correct]
- double absoluteError(Vector3 correct) {
- return (this - correct).length;
- }
+ double absoluteError(Vector3 correct) => (this - correct).length;
/// True if any component is infinite.
bool get isInfinite {
@@ -408,7 +412,7 @@
/// Add [arg] to [this].
void add(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0];
_v3storage[1] = _v3storage[1] + argStorage[1];
_v3storage[2] = _v3storage[2] + argStorage[2];
@@ -416,7 +420,7 @@
/// Add [arg] scaled by [factor] to [this].
void addScaled(Vector3 arg, double factor) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0] * factor;
_v3storage[1] = _v3storage[1] + argStorage[1] * factor;
_v3storage[2] = _v3storage[2] + argStorage[2] * factor;
@@ -424,7 +428,7 @@
/// Subtract [arg] from [this].
void sub(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] - argStorage[0];
_v3storage[1] = _v3storage[1] - argStorage[1];
_v3storage[2] = _v3storage[2] - argStorage[2];
@@ -432,7 +436,7 @@
/// Multiply entries in [this] with entries in [arg].
void multiply(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] * argStorage[0];
_v3storage[1] = _v3storage[1] * argStorage[1];
_v3storage[2] = _v3storage[2] * argStorage[2];
@@ -440,7 +444,7 @@
/// Divide entries in [this] with entries in [arg].
void divide(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] / argStorage[0];
_v3storage[1] = _v3storage[1] / argStorage[1];
_v3storage[2] = _v3storage[2] / argStorage[2];
@@ -472,18 +476,21 @@
/// Clamp each entry n in [this] in the range [min[n]]-[max[n]].
void clamp(Vector3 min, Vector3 max) {
- final minStorage = min.storage;
- final maxStorage = max.storage;
- _v3storage[0] = _v3storage[0].clamp(minStorage[0], maxStorage[0]);
- _v3storage[1] = _v3storage[1].clamp(minStorage[1], maxStorage[1]);
- _v3storage[2] = _v3storage[2].clamp(minStorage[2], maxStorage[2]);
+ final Float32List minStorage = min.storage;
+ final Float32List maxStorage = max.storage;
+ _v3storage[0] =
+ _v3storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
+ _v3storage[1] =
+ _v3storage[1].clamp(minStorage[1], maxStorage[1]).toDouble();
+ _v3storage[2] =
+ _v3storage[2].clamp(minStorage[2], maxStorage[2]).toDouble();
}
/// Clamp entries in [this] in the range [min]-[max].
void clampScalar(double min, double max) {
- _v3storage[0] = _v3storage[0].clamp(min, max);
- _v3storage[1] = _v3storage[1].clamp(min, max);
- _v3storage[2] = _v3storage[2].clamp(min, max);
+ _v3storage[0] = _v3storage[0].clamp(min, max).toDouble();
+ _v3storage[1] = _v3storage[1].clamp(min, max).toDouble();
+ _v3storage[2] = _v3storage[2].clamp(min, max).toDouble();
}
/// Floor entries in [this].
@@ -525,7 +532,7 @@
/// Copy [this] into [arg].
Vector3 copyInto(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
argStorage[0] = _v3storage[0];
argStorage[1] = _v3storage[1];
argStorage[2] = _v3storage[2];
@@ -547,78 +554,78 @@
}
set xy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set yx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set zx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xyz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set xzy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set yxz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set yzx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[0] = argStorage[2];
}
set zxy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set zyx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List 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 72a2496..e1f312a 100644
--- a/lib/src/vector_math/vector4.dart
+++ b/lib/src/vector_math/vector4.dart
@@ -10,30 +10,34 @@
/// Set the values of [result] to the minimum of [a] and [b] for each line.
static void min(Vector4 a, Vector4 b, Vector4 result) {
- result.x = Math.min(a.x, b.x);
- result.y = Math.min(a.y, b.y);
- result.z = Math.min(a.z, b.z);
- result.w = Math.min(a.w, b.w);
+ result
+ ..x = math.min(a.x, b.x)
+ ..y = math.min(a.y, b.y)
+ ..z = math.min(a.z, b.z)
+ ..w = math.min(a.w, b.w);
}
/// Set the values of [result] to the maximum of [a] and [b] for each line.
static void max(Vector4 a, Vector4 b, Vector4 result) {
- result.x = Math.max(a.x, b.x);
- result.y = Math.max(a.y, b.y);
- result.z = Math.max(a.z, b.z);
- result.w = Math.max(a.w, b.w);
+ result
+ ..x = math.max(a.x, b.x)
+ ..y = math.max(a.y, b.y)
+ ..z = math.max(a.z, b.z)
+ ..w = math.max(a.w, b.w);
}
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation and store the values in [result].
static void mix(Vector4 min, Vector4 max, double a, Vector4 result) {
- result.x = min.x + a * (max.x - min.x);
- result.y = min.y + a * (max.y - min.y);
- result.z = min.z + a * (max.z - min.z);
- result.w = min.w + a * (max.w - min.w);
+ result
+ ..x = min.x + a * (max.x - min.x)
+ ..y = min.y + a * (max.y - min.y)
+ ..z = min.z + a * (max.z - min.z)
+ ..w = min.w + a * (max.w - min.w);
}
/// The components of the vector.
+ @override
Float32List get storage => _v4storage;
/// Construct a new vector with the specified values.
@@ -66,10 +70,10 @@
/// 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]) {
- rng = rng == null ? new Math.Random() : rng;
+ factory Vector4.random([math.Random rng]) {
+ rng = rng == null ? new math.Random() : rng;
return new Vector4(
- rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
+ rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
}
/// Set the values of the vector.
@@ -98,7 +102,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector4 other) {
- final otherStorage = other._v4storage;
+ final Float32List otherStorage = other._v4storage;
_v4storage[3] = otherStorage[3];
_v4storage[2] = otherStorage[2];
_v4storage[1] = otherStorage[1];
@@ -114,18 +118,20 @@
}
/// Returns a printable string
+ @override
String toString() => '${_v4storage[0]},${_v4storage[1]},'
'${_v4storage[2]},${_v4storage[3]}';
/// Check if two vectors are the same.
- bool operator ==(other) {
- return (other is Vector4) &&
- (_v4storage[0] == other._v4storage[0]) &&
- (_v4storage[1] == other._v4storage[1]) &&
- (_v4storage[2] == other._v4storage[2]) &&
- (_v4storage[3] == other._v4storage[3]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Vector4) &&
+ (_v4storage[0] == other._v4storage[0]) &&
+ (_v4storage[1] == other._v4storage[1]) &&
+ (_v4storage[2] == other._v4storage[2]) &&
+ (_v4storage[3] == other._v4storage[3]);
+ @override
int get hashCode => quiver.hashObjects(_v4storage);
/// Negate.
@@ -170,7 +176,7 @@
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Length squared.
double get length2 {
@@ -184,11 +190,11 @@
/// Normalizes [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_v4storage[0] *= d;
_v4storage[1] *= d;
_v4storage[2] *= d;
@@ -213,22 +219,22 @@
}
/// Distance from [this] to [arg]
- double distanceTo(Vector4 arg) => Math.sqrt(distanceToSquared(arg));
+ double distanceTo(Vector4 arg) => math.sqrt(distanceToSquared(arg));
/// Squared distance from [this] to [arg]
double distanceToSquared(Vector4 arg) {
- 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];
+ 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];
return dx * dx + dy * dy + dz * dz + dw * dw;
}
/// Inner product.
double dot(Vector4 other) {
- final otherStorage = other._v4storage;
+ final Float32List otherStorage = other._v4storage;
double sum;
sum = _v4storage[0] * otherStorage[0];
sum += _v4storage[1] * otherStorage[1];
@@ -239,11 +245,11 @@
/// Multiplies [this] by [arg].
void applyMatrix4(Matrix4 arg) {
- var v1 = _v4storage[0];
- var v2 = _v4storage[1];
- var v3 = _v4storage[2];
- var v4 = _v4storage[3];
- final argStorage = arg.storage;
+ 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;
_v4storage[0] = argStorage[0] * v1 +
argStorage[4] * v2 +
argStorage[8] * v3 +
@@ -264,15 +270,13 @@
/// Relative error between [this] and [correct]
double relativeError(Vector4 correct) {
- double correct_norm = correct.length;
- double diff_norm = (this - correct).length;
+ final double correct_norm = correct.length;
+ final double diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
/// Absolute error between [this] and [correct]
- double absoluteError(Vector4 correct) {
- return (this - correct).length;
- }
+ double absoluteError(Vector4 correct) => (this - correct).length;
/// True if any component is infinite.
bool get isInfinite {
@@ -295,7 +299,7 @@
}
void add(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0];
_v4storage[1] = _v4storage[1] + argStorage[1];
_v4storage[2] = _v4storage[2] + argStorage[2];
@@ -304,7 +308,7 @@
/// Add [arg] scaled by [factor] to [this].
void addScaled(Vector4 arg, double factor) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0] * factor;
_v4storage[1] = _v4storage[1] + argStorage[1] * factor;
_v4storage[2] = _v4storage[2] + argStorage[2] * factor;
@@ -313,7 +317,7 @@
/// Subtract [arg] from [this].
void sub(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] - argStorage[0];
_v4storage[1] = _v4storage[1] - argStorage[1];
_v4storage[2] = _v4storage[2] - argStorage[2];
@@ -322,7 +326,7 @@
/// Multiply [this] by [arg].
void multiply(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] * argStorage[0];
_v4storage[1] = _v4storage[1] * argStorage[1];
_v4storage[2] = _v4storage[2] * argStorage[2];
@@ -331,7 +335,7 @@
/// Divide [this] by [arg].
void div(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] / argStorage[0];
_v4storage[1] = _v4storage[1] / argStorage[1];
_v4storage[2] = _v4storage[2] / argStorage[2];
@@ -367,20 +371,24 @@
/// Clamp each entry n in [this] in the range [min[n]]-[max[n]].
void clamp(Vector4 min, Vector4 max) {
- final minStorage = min.storage;
- final maxStorage = max.storage;
- _v4storage[0] = _v4storage[0].clamp(minStorage[0], maxStorage[0]);
- _v4storage[1] = _v4storage[1].clamp(minStorage[1], maxStorage[1]);
- _v4storage[2] = _v4storage[2].clamp(minStorage[2], maxStorage[2]);
- _v4storage[3] = _v4storage[3].clamp(minStorage[3], maxStorage[3]);
+ final Float32List minStorage = min.storage;
+ final Float32List maxStorage = max.storage;
+ _v4storage[0] =
+ _v4storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
+ _v4storage[1] =
+ _v4storage[1].clamp(minStorage[1], maxStorage[1]).toDouble();
+ _v4storage[2] =
+ _v4storage[2].clamp(minStorage[2], maxStorage[2]).toDouble();
+ _v4storage[3] =
+ _v4storage[3].clamp(minStorage[3], maxStorage[3]).toDouble();
}
/// Clamp entries in [this] in the range [min]-[max].
void clampScalar(double min, double max) {
- _v4storage[0] = _v4storage[0].clamp(min, max);
- _v4storage[1] = _v4storage[1].clamp(min, max);
- _v4storage[2] = _v4storage[2].clamp(min, max);
- _v4storage[3] = _v4storage[3].clamp(min, max);
+ _v4storage[0] = _v4storage[0].clamp(min, max).toDouble();
+ _v4storage[1] = _v4storage[1].clamp(min, max).toDouble();
+ _v4storage[2] = _v4storage[2].clamp(min, max).toDouble();
+ _v4storage[3] = _v4storage[3].clamp(min, max).toDouble();
}
/// Floor entries in [this].
@@ -428,7 +436,7 @@
/// Copy [this]
Vector4 copyInto(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
argStorage[0] = _v4storage[0];
argStorage[1] = _v4storage[1];
argStorage[2] = _v4storage[2];
@@ -453,247 +461,247 @@
}
set xy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xw(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set yx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set yw(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set zx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set zw(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set wx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set wy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set wz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float32List argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xyz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set xyw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xzy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xzw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xwy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xwz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set yzx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set yzw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set ywx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set ywz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set zxy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set zxw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zyx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zyw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zwx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zwy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wyx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wyz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wzx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wzy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float32List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xyzw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -701,7 +709,7 @@
}
set xywz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -709,7 +717,7 @@
}
set xzyw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -717,7 +725,7 @@
}
set xzwy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -725,7 +733,7 @@
}
set xwyz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -733,7 +741,7 @@
}
set xwzy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -741,7 +749,7 @@
}
set yxzw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -749,7 +757,7 @@
}
set yxwz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -757,7 +765,7 @@
}
set yzxw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -765,7 +773,7 @@
}
set yzwx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -773,7 +781,7 @@
}
set ywxz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -781,7 +789,7 @@
}
set ywzx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -789,7 +797,7 @@
}
set zxyw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -797,7 +805,7 @@
}
set zxwy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -805,7 +813,7 @@
}
set zyxw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -813,7 +821,7 @@
}
set zywx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -821,7 +829,7 @@
}
set zwxy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -829,7 +837,7 @@
}
set zwyx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -837,7 +845,7 @@
}
set wxyz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -845,7 +853,7 @@
}
set wxzy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -853,7 +861,7 @@
}
set wyxz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -861,7 +869,7 @@
}
set wyzx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -869,7 +877,7 @@
}
set wzxy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -877,7 +885,7 @@
}
set wzyx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float32List 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 c0f86a1..11e4215 100644
--- a/lib/src/vector_math_64/aabb2.dart
+++ b/lib/src/vector_math_64/aabb2.dart
@@ -78,8 +78,8 @@
/// Transform [this] by the transform [t].
void transform(Matrix3 t) {
- final center = new Vector2.zero();
- final halfExtents = new Vector2.zero();
+ final Vector2 center = new Vector2.zero();
+ final Vector2 halfExtents = new Vector2.zero();
copyCenterAndHalfExtents(center, halfExtents);
t
..transform2(center)
@@ -94,8 +94,8 @@
/// Rotate [this] by the rotation matrix [t].
void rotate(Matrix3 t) {
- final center = new Vector2.zero();
- final halfExtents = new Vector2.zero();
+ final Vector2 center = new Vector2.zero();
+ final Vector2 halfExtents = new Vector2.zero();
copyCenterAndHalfExtents(center, halfExtents);
t.absoluteRotate2(halfExtents);
_min
@@ -133,8 +133,8 @@
/// Return if [this] contains [other].
bool containsAabb2(Aabb2 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector2 otherMax = other._max;
+ final Vector2 otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -143,17 +143,16 @@
}
/// Return if [this] contains [other].
- bool containsVector2(Vector2 other) {
- return (_min.x < other.x) &&
- (_min.y < other.y) &&
- (_max.x > other.x) &&
- (_max.y > other.y);
- }
+ bool containsVector2(Vector2 other) =>
+ (_min.x < other.x) &&
+ (_min.y < other.y) &&
+ (_max.x > other.x) &&
+ (_max.y > other.y);
/// Return if [this] intersects with [other].
bool intersectsWithAabb2(Aabb2 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector2 otherMax = other._max;
+ final Vector2 otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
@@ -162,10 +161,9 @@
}
/// Return if [this] intersects with [other].
- bool intersectsWithVector2(Vector2 other) {
- return (_min.x <= other.x) &&
- (_min.y <= other.y) &&
- (_max.x >= other.x) &&
- (_max.y >= other.y);
- }
+ bool intersectsWithVector2(Vector2 other) =>
+ (_min.x <= other.x) &&
+ (_min.y <= other.y) &&
+ (_max.x >= other.x) &&
+ (_max.y >= other.y);
}
diff --git a/lib/src/vector_math_64/aabb3.dart b/lib/src/vector_math_64/aabb3.dart
index ecd3f10..189cad5 100644
--- a/lib/src/vector_math_64/aabb3.dart
+++ b/lib/src/vector_math_64/aabb3.dart
@@ -86,46 +86,46 @@
/// Set the AABB to enclose a [triangle].
void setTriangle(Triangle triangle) {
_min.setValues(
- Math.min(triangle._point0.x,
- Math.min(triangle._point1.x, triangle._point2.x)),
- Math.min(triangle._point0.y,
- Math.min(triangle._point1.y, triangle._point2.y)),
- Math.min(triangle._point0.z,
- Math.min(triangle._point1.z, triangle._point2.z)));
+ math.min(triangle._point0.x,
+ math.min(triangle._point1.x, triangle._point2.x)),
+ math.min(triangle._point0.y,
+ math.min(triangle._point1.y, triangle._point2.y)),
+ math.min(triangle._point0.z,
+ math.min(triangle._point1.z, triangle._point2.z)));
_max.setValues(
- Math.max(triangle._point0.x,
- Math.max(triangle._point1.x, triangle._point2.x)),
- Math.max(triangle._point0.y,
- Math.max(triangle._point1.y, triangle._point2.y)),
- Math.max(triangle._point0.z,
- Math.max(triangle._point1.z, triangle._point2.z)));
+ math.max(triangle._point0.x,
+ math.max(triangle._point1.x, triangle._point2.x)),
+ math.max(triangle._point0.y,
+ math.max(triangle._point1.y, triangle._point2.y)),
+ math.max(triangle._point0.z,
+ math.max(triangle._point1.z, triangle._point2.z)));
}
/// Set the AABB to enclose a [quad].
void setQuad(Quad quad) {
_min.setValues(
- Math.min(quad._point0.x,
- Math.min(quad._point1.x, Math.min(quad._point2.x, quad._point3.x))),
- Math.min(quad._point0.y,
- Math.min(quad._point1.y, Math.min(quad._point2.y, quad._point3.y))),
- Math.min(
+ math.min(quad._point0.x,
+ math.min(quad._point1.x, math.min(quad._point2.x, quad._point3.x))),
+ math.min(quad._point0.y,
+ math.min(quad._point1.y, math.min(quad._point2.y, quad._point3.y))),
+ math.min(
quad._point0.z,
- Math.min(
- quad._point1.z, Math.min(quad._point2.z, quad._point3.z))));
+ math.min(
+ quad._point1.z, math.min(quad._point2.z, quad._point3.z))));
_max.setValues(
- Math.max(quad._point0.x,
- Math.max(quad._point1.x, Math.max(quad._point2.x, quad._point3.x))),
- Math.max(quad._point0.y,
- Math.max(quad._point1.y, Math.max(quad._point2.y, quad._point3.y))),
- Math.max(
+ math.max(quad._point0.x,
+ math.max(quad._point1.x, math.max(quad._point2.x, quad._point3.x))),
+ math.max(quad._point0.y,
+ math.max(quad._point1.y, math.max(quad._point2.y, quad._point3.y))),
+ math.max(
quad._point0.z,
- Math.max(
- quad._point1.z, Math.max(quad._point2.z, quad._point3.z))));
+ math.max(
+ quad._point1.z, math.max(quad._point2.z, quad._point3.z))));
}
/// Set the AABB to enclose a [obb].
void setObb3(Obb3 obb) {
- final corner = new Vector3.zero();
+ final Vector3 corner = new Vector3.zero();
obb.copyCorner(0, corner);
_min.setFrom(corner);
@@ -156,23 +156,22 @@
/// Set the AABB to enclose a limited [ray] (or line segment) that is limited
/// by [limitMin] and [limitMax].
void setRay(Ray ray, double limitMin, double limitMax) {
- ray.copyAt(_min, limitMin);
- ray.copyAt(_max, limitMax);
+ ray..copyAt(_min, limitMin)..copyAt(_max, limitMax);
if (_max.x < _min.x) {
- final temp = _max.x;
+ final double temp = _max.x;
_max.x = _min.x;
_min.x = temp;
}
if (_max.y < _min.y) {
- final temp = _max.y;
+ final double temp = _max.y;
_max.y = _min.y;
_min.y = temp;
}
if (_max.z < _min.z) {
- final temp = _max.z;
+ final double temp = _max.z;
_max.z = _min.z;
_min.z = temp;
}
@@ -206,8 +205,8 @@
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- final center = new Vector3.zero();
- final halfExtents = new Vector3.zero();
+ final Vector3 center = new Vector3.zero();
+ final Vector3 halfExtents = new Vector3.zero();
copyCenterAndHalfExtents(center, halfExtents);
t
..transform3(center)
@@ -222,8 +221,8 @@
/// Rotate [this] by the rotation matrix [t].
void rotate(Matrix4 t) {
- final center = new Vector3.zero();
- final halfExtents = new Vector3.zero();
+ final Vector3 center = new Vector3.zero();
+ final Vector3 halfExtents = new Vector3.zero();
copyCenterAndHalfExtents(center, halfExtents);
t.absoluteRotate(halfExtents);
_min
@@ -287,8 +286,8 @@
/// Return if [this] contains [other].
bool containsAabb3(Aabb3 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector3 otherMax = other._max;
+ final Vector3 otherMin = other._min;
return (_min.x < otherMin.x) &&
(_min.y < otherMin.y) &&
@@ -300,21 +299,21 @@
/// Return if [this] contains [other].
bool containsSphere(Sphere other) {
- final boxExtends = new Vector3.all(other._radius);
- final sphereBox = new Aabb3.centerAndHalfExtents(other._center, boxExtends);
+ final Vector3 boxExtends = new Vector3.all(other._radius);
+ final Aabb3 sphereBox =
+ new Aabb3.centerAndHalfExtents(other._center, boxExtends);
return containsAabb3(sphereBox);
}
/// Return if [this] contains [other].
- bool containsVector3(Vector3 other) {
- return (_min.x < other.x) &&
- (_min.y < other.y) &&
- (_min.z < other.z) &&
- (_max.x > other.x) &&
- (_max.y > other.y) &&
- (_max.z > other.z);
- }
+ bool containsVector3(Vector3 other) =>
+ (_min.x < other.x) &&
+ (_min.y < other.y) &&
+ (_min.z < other.z) &&
+ (_max.x > other.x) &&
+ (_max.y > other.y) &&
+ (_max.z > other.z);
/// Return if [this] contains [other].
bool containsTriangle(Triangle other) =>
@@ -324,8 +323,8 @@
/// Return if [this] intersects with [other].
bool intersectsWithAabb3(Aabb3 other) {
- final otherMax = other._max;
- final otherMin = other._min;
+ final Vector3 otherMax = other._max;
+ final Vector3 otherMin = other._min;
return (_min.x <= otherMax.x) &&
(_min.y <= otherMax.y) &&
@@ -337,12 +336,12 @@
/// Return if [this] intersects with [other].
bool intersectsWithSphere(Sphere other) {
- final center = other._center;
- final radius = other._radius;
- var d = 0.0;
- var e = 0.0;
+ final Vector3 center = other._center;
+ final double radius = other._radius;
+ double d = 0.0;
+ double e = 0.0;
- for (var i = 0; i < 3; ++i) {
+ for (int i = 0; i < 3; ++i) {
if ((e = center[i] - _min[i]) < 0.0) {
if (e < -radius) {
return false;
@@ -364,29 +363,28 @@
}
/// Return if [this] intersects with [other].
- bool intersectsWithVector3(Vector3 other) {
- return (_min.x <= other.x) &&
- (_min.y <= other.y) &&
- (_min.z <= other.z) &&
- (_max.x >= other.x) &&
- (_max.y >= other.y) &&
- (_max.z >= other.z);
- }
+ bool intersectsWithVector3(Vector3 other) =>
+ (_min.x <= other.x) &&
+ (_min.y <= other.y) &&
+ (_min.z <= other.z) &&
+ (_max.x >= other.x) &&
+ (_max.y >= other.y) &&
+ (_max.z >= other.z);
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _aabbCenter = new Vector3.zero();
- static final _aabbHalfExtents = new Vector3.zero();
- static final _v0 = new Vector3.zero();
- static final _v1 = new Vector3.zero();
- static final _v2 = new Vector3.zero();
- static final _f0 = new Vector3.zero();
- static final _f1 = new Vector3.zero();
- static final _f2 = new Vector3.zero();
- static final _trianglePlane = new Plane();
+ static final Vector3 _aabbCenter = new Vector3.zero();
+ static final Vector3 _aabbHalfExtents = new Vector3.zero();
+ static final Vector3 _v0 = new Vector3.zero();
+ static final Vector3 _v1 = new Vector3.zero();
+ static final Vector3 _v2 = new Vector3.zero();
+ static final Vector3 _f0 = new Vector3.zero();
+ static final Vector3 _f1 = new Vector3.zero();
+ static final Vector3 _f2 = new Vector3.zero();
+ static final Plane _trianglePlane = new Plane();
- static final _u0 = new Vector3(1.0, 0.0, 0.0);
- static final _u1 = new Vector3(0.0, 1.0, 0.0);
- static final _u2 = new Vector3(0.0, 0.0, 1.0);
+ static final Vector3 _u0 = new Vector3(1.0, 0.0, 0.0);
+ static final Vector3 _u1 = new Vector3(0.0, 1.0, 0.0);
+ static final Vector3 _u2 = new 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
@@ -432,11 +430,11 @@
p0 = _v0.z * _f0.y - _v0.y * _f0.z;
p2 = _v2.z * _f0.y - _v2.y * _f0.z;
r = _aabbHalfExtents[1] * _f0.z.abs() + _aabbHalfExtents[2] * _f0.y.abs();
- if (Math.max(-Math.max(p0, p2), Math.min(p0, p2)) > r + epsilon) {
+ if (math.max(-math.max(p0, p2), math.min(p0, p2)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p2) - r;
+ a = math.min(p0, p2) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u0.crossInto(_f0, result.axis);
@@ -450,11 +448,11 @@
p0 = _v0.z * _f1.y - _v0.y * _f1.z;
p1 = _v1.z * _f1.y - _v1.y * _f1.z;
r = _aabbHalfExtents[1] * _f1.z.abs() + _aabbHalfExtents[2] * _f1.y.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u0.crossInto(_f1, result.axis);
@@ -468,11 +466,11 @@
p0 = _v0.z * _f2.y - _v0.y * _f2.z;
p1 = _v1.z * _f2.y - _v1.y * _f2.z;
r = _aabbHalfExtents[1] * _f2.z.abs() + _aabbHalfExtents[2] * _f2.y.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u0.crossInto(_f2, result.axis);
@@ -486,11 +484,11 @@
p0 = _v0.x * _f0.z - _v0.z * _f0.x;
p2 = _v2.x * _f0.z - _v2.z * _f0.x;
r = _aabbHalfExtents[0] * _f0.z.abs() + _aabbHalfExtents[2] * _f0.x.abs();
- if (Math.max(-Math.max(p0, p2), Math.min(p0, p2)) > r + epsilon) {
+ if (math.max(-math.max(p0, p2), math.min(p0, p2)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p2) - r;
+ a = math.min(p0, p2) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u1.crossInto(_f0, result.axis);
@@ -504,11 +502,11 @@
p0 = _v0.x * _f1.z - _v0.z * _f1.x;
p1 = _v1.x * _f1.z - _v1.z * _f1.x;
r = _aabbHalfExtents[0] * _f1.z.abs() + _aabbHalfExtents[2] * _f1.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u1.crossInto(_f1, result.axis);
@@ -522,11 +520,11 @@
p0 = _v0.x * _f2.z - _v0.z * _f2.x;
p1 = _v1.x * _f2.z - _v1.z * _f2.x;
r = _aabbHalfExtents[0] * _f2.z.abs() + _aabbHalfExtents[2] * _f2.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u1.crossInto(_f2, result.axis);
@@ -540,11 +538,11 @@
p0 = _v0.y * _f0.x - _v0.x * _f0.y;
p2 = _v2.y * _f0.x - _v2.x * _f0.y;
r = _aabbHalfExtents[0] * _f0.y.abs() + _aabbHalfExtents[1] * _f0.x.abs();
- if (Math.max(-Math.max(p0, p2), Math.min(p0, p2)) > r + epsilon) {
+ if (math.max(-math.max(p0, p2), math.min(p0, p2)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p2) - r;
+ a = math.min(p0, p2) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u2.crossInto(_f0, result.axis);
@@ -558,11 +556,11 @@
p0 = _v0.y * _f1.x - _v0.x * _f1.y;
p1 = _v1.y * _f1.x - _v1.x * _f1.y;
r = _aabbHalfExtents[0] * _f1.y.abs() + _aabbHalfExtents[1] * _f1.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u2.crossInto(_f1, result.axis);
@@ -576,11 +574,11 @@
p0 = _v0.y * _f2.x - _v0.x * _f2.y;
p1 = _v1.y * _f2.x - _v1.x * _f2.y;
r = _aabbHalfExtents[0] * _f2.y.abs() + _aabbHalfExtents[1] * _f2.x.abs();
- if (Math.max(-Math.max(p0, p1), Math.min(p0, p1)) > r + epsilon) {
+ if (math.max(-math.max(p0, p1), math.min(p0, p1)) > r + epsilon) {
return false; // Axis is a separating axis
}
- a = Math.min(p0, p1) - r;
+ a = math.min(p0, p1) - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
_u2.crossInto(_f2, result.axis);
@@ -589,31 +587,31 @@
// Test the three axes corresponding to the face normals of AABB b (category 1). // Exit if...
// ... [-e0, e0] and [min(v0.x,v1.x,v2.x), max(v0.x,v1.x,v2.x)] do not overlap
- if (Math.max(_v0.x, Math.max(_v1.x, _v2.x)) < -_aabbHalfExtents[0] ||
- Math.min(_v0.x, Math.min(_v1.x, _v2.x)) > _aabbHalfExtents[0]) {
+ if (math.max(_v0.x, math.max(_v1.x, _v2.x)) < -_aabbHalfExtents[0] ||
+ math.min(_v0.x, math.min(_v1.x, _v2.x)) > _aabbHalfExtents[0]) {
return false;
}
- a = Math.min(_v0.x, Math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
+ a = math.min(_v0.x, math.min(_v1.x, _v2.x)) - _aabbHalfExtents[0];
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(_u0);
}
// ... [-e1, e1] and [min(v0.y,v1.y,v2.y), max(v0.y,v1.y,v2.y)] do not overlap
- if (Math.max(_v0.y, Math.max(_v1.y, _v2.y)) < -_aabbHalfExtents[1] ||
- Math.min(_v0.y, Math.min(_v1.y, _v2.y)) > _aabbHalfExtents[1]) {
+ if (math.max(_v0.y, math.max(_v1.y, _v2.y)) < -_aabbHalfExtents[1] ||
+ math.min(_v0.y, math.min(_v1.y, _v2.y)) > _aabbHalfExtents[1]) {
return false;
}
- a = Math.min(_v0.y, Math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
+ a = math.min(_v0.y, math.min(_v1.y, _v2.y)) - _aabbHalfExtents[1];
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(_u1);
}
// ... [-e2, e2] and [min(v0.z,v1.z,v2.z), max(v0.z,v1.z,v2.z)] do not overlap
- if (Math.max(_v0.z, Math.max(_v1.z, _v2.z)) < -_aabbHalfExtents[2] ||
- Math.min(_v0.z, Math.min(_v1.z, _v2.z)) > _aabbHalfExtents[2]) {
+ if (math.max(_v0.z, math.max(_v1.z, _v2.z)) < -_aabbHalfExtents[2] ||
+ math.min(_v0.z, math.min(_v1.z, _v2.z)) > _aabbHalfExtents[2]) {
return false;
}
- a = Math.min(_v0.z, Math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
+ a = math.min(_v0.z, math.min(_v1.z, _v2.z)) - _aabbHalfExtents[2];
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(_u2);
@@ -635,14 +633,14 @@
copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents);
// Compute the projection interval radius of b onto L(t) = b.c + t * p.n
- double r = _aabbHalfExtents[0] * other.normal[0].abs() +
+ final double 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
- double s = other.normal.dot(_aabbCenter) - other.constant;
+ final double s = other.normal.dot(_aabbCenter) - other.constant;
// Intersection occurs when distance s falls within [-r,+r] interval
if (s.abs() <= r) {
- final a = s - r;
+ final double a = s - r;
if (result != null && (result._depth == null || result._depth < a)) {
result._depth = a;
result.axis.setFrom(other.normal);
@@ -654,8 +652,8 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _quadTriangle0 = new Triangle();
- static final _quadTriangle1 = new Triangle();
+ static final Triangle _quadTriangle0 = new Triangle();
+ static final Triangle _quadTriangle1 = new Triangle();
/// Return if [this] intersects with [other].
/// [epsilon] allows the caller to specify a custum eplsilon value that should
diff --git a/lib/src/vector_math_64/colors.dart b/lib/src/vector_math_64/colors.dart
index d9917f6..d02ae4e 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 _hexStringFullRegex = new RegExp(
+ static final RegExp _hexStringFullRegex = new RegExp(
r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?',
caseSensitive: false);
- static final _hexStringSmallRegex = new RegExp(
+ static final RegExp _hexStringSmallRegex = new 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 fullMatch = _hexStringFullRegex.matchAsPrefix(value);
+ final Match fullMatch = _hexStringFullRegex.matchAsPrefix(value);
if (fullMatch != null) {
if (fullMatch[4] == null) {
- final r = int.parse(fullMatch[1], radix: 16);
- final g = int.parse(fullMatch[2], radix: 16);
- final b = int.parse(fullMatch[3], radix: 16);
+ 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);
fromRgba(r, g, b, 255, result);
return;
} else {
- 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);
+ 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);
fromRgba(r, g, b, a, result);
return;
}
}
- final smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
+ final Match smallMatch = _hexStringSmallRegex.matchAsPrefix(value);
if (smallMatch != null) {
if (smallMatch[4] == null) {
- 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);
+ 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);
fromRgba(r, g, b, 255, result);
return;
} else {
- 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);
+ 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);
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 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 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 isShort = short &&
+ final bool isShort = short &&
((r >> 4) == (r & 0xF)) &&
((g >> 4) == (g & 0xF)) &&
((b >> 4) == (b & 0xF)) &&
(!alpha || (a >> 4) == (a & 0xF));
if (isShort) {
- final rgb = (r & 0xF).toRadixString(16) +
+ final String rgb = (r & 0xF).toRadixString(16) +
(g & 0xF).toRadixString(16) +
(b & 0xF).toRadixString(16);
return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb;
} else {
- final rgb = r.toRadixString(16).padLeft(2, '0') +
+ final String 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 a = foreground.a + (1.0 - foreground.a) * background.a;
- final factor = 1.0 / a;
+ final double a = foreground.a + (1.0 - foreground.a) * background.a;
+ final double factor = 1.0 / a;
- final r = factor *
+ final double r = factor *
(foreground.a * foreground.r +
(1.0 - foreground.a) * background.a * background.r);
- final g = factor *
+ final double g = factor *
(foreground.a * foreground.g +
(1.0 - foreground.a) * background.a * background.g);
- final b = factor *
+ final double 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 value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
+ final double value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b;
result
..r = value
@@ -139,12 +139,12 @@
/// the default value is 2.2.
static void linearToGamma(Vector4 linearColor, Vector4 gammaColor,
[double gamma = 2.2]) {
- final exponent = 1.0 / gamma;
+ final double exponent = 1.0 / gamma;
gammaColor
- ..r = Math.pow(linearColor.r, exponent)
- ..g = Math.pow(linearColor.g, exponent)
- ..b = Math.pow(linearColor.b, exponent)
+ ..r = math.pow(linearColor.r, exponent).toDouble()
+ ..g = math.pow(linearColor.g, exponent).toDouble()
+ ..b = math.pow(linearColor.b, exponent).toDouble()
..a = linearColor.a;
}
@@ -154,21 +154,21 @@
static void gammaToLinear(Vector4 gammaColor, Vector4 linearColor,
[double gamma = 2.2]) {
linearColor
- ..r = Math.pow(gammaColor.r, gamma)
- ..g = Math.pow(gammaColor.g, gamma)
- ..b = Math.pow(gammaColor.b, gamma)
+ ..r = math.pow(gammaColor.r, gamma).toDouble()
+ ..g = math.pow(gammaColor.g, gamma).toDouble()
+ ..b = math.pow(gammaColor.b, gamma).toDouble()
..a = gammaColor.a;
}
/// 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 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;
+ 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;
+ double h = 0.0;
if (max != min) {
if (max == rgbColor.r) {
@@ -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 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);
+ 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);
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 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;
+ 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;
+ double h = 0.0;
+ double s = 0.0;
if (max != min) {
- final d = max - min;
+ final double 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 q = hslColor.z < 0.5
+ final double q = hslColor.z < 0.5
? hslColor.z * (1.0 + hslColor.y)
: hslColor.z + hslColor.y - hslColor.z * hslColor.y;
- final p = 2.0 * hslColor.z - q;
+ final double p = 2.0 * hslColor.z - q;
- 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);
+ 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);
rgbColor.setValues(r, g, b, hslColor.a);
}
diff --git a/lib/src/vector_math_64/constants.dart b/lib/src/vector_math_64/constants.dart
index 92114db..32c5fc2 100644
--- a/lib/src/vector_math_64/constants.dart
+++ b/lib/src/vector_math_64/constants.dart
@@ -5,7 +5,7 @@
part of vector_math_64;
/// Constant factor to convert and angle from degrees to radians.
-const double degrees2Radians = Math.PI / 180.0;
+const double degrees2Radians = math.PI / 180.0;
/// Constant factor to convert and angle from radians to degrees.
-const double radians2Degrees = 180.0 / Math.PI;
+const double radians2Degrees = 180.0 / math.PI;
diff --git a/lib/src/vector_math_64/error_helpers.dart b/lib/src/vector_math_64/error_helpers.dart
index 95f87ff..b1a43fa 100644
--- a/lib/src/vector_math_64/error_helpers.dart
+++ b/lib/src/vector_math_64/error_helpers.dart
@@ -7,21 +7,23 @@
/// Returns relative error between [calculated] and [correct].
/// The type of [calculated] and [correct] must match and can
/// be any vector, matrix, or quaternion.
-double relativeError(calculated, correct) {
+double relativeError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- double diff = (calculated - correct).abs();
+ final double diff = (calculated - correct).abs().toDouble();
return diff / correct;
}
+ // ignore: return_of_invalid_type
return calculated.relativeError(correct);
}
/// Returns absolute error between [calculated] and [correct].
/// The type of [calculated] and [correct] must match and can
/// be any vector, matrix, or quaternion.
-double absoluteError(calculated, correct) {
+double absoluteError(dynamic calculated, dynamic correct) {
if (calculated is num && correct is num) {
- double diff = (calculated - correct).abs();
+ final double diff = (calculated - correct).abs().toDouble();
return diff;
}
+ // ignore: return_of_invalid_type
return calculated.absoluteError(correct);
}
diff --git a/lib/src/vector_math_64/frustum.dart b/lib/src/vector_math_64/frustum.dart
index 5f0f9f5..600e1b1 100644
--- a/lib/src/vector_math_64/frustum.dart
+++ b/lib/src/vector_math_64/frustum.dart
@@ -59,11 +59,11 @@
/// Set [this] from [matrix].
void setFromMatrix(Matrix4 matrix) {
- var me = matrix.storage;
- var me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
- var me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
- var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
- var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
+ 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];
_plane0
..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12)
@@ -145,8 +145,8 @@
/// Check if [this] intersects with [sphere].
bool intersectsWithSphere(Sphere sphere) {
- final negativeRadius = -sphere._radius;
- final center = sphere.center;
+ final double negativeRadius = -sphere._radius;
+ final Vector3 center = sphere.center;
if (_plane0.distanceToVector3(center) < negativeRadius) {
return false;
@@ -197,7 +197,7 @@
}
bool _intersectsWithAabb3CheckPlane(Aabb3 aabb, Plane plane) {
- var outPx, outPy, outPz, outNx, outNy, outNz;
+ double outPx, outPy, outPz, outNx, outNy, outNz;
if (plane._normal.x < 0.0) {
outPx = aabb.min.x;
@@ -223,11 +223,11 @@
outNz = aabb.min.z;
}
- final d1 = plane._normal.x * outPx +
+ final double d1 = plane._normal.x * outPx +
plane._normal.y * outPy +
plane._normal.z * outPz +
plane._constant;
- final d2 = plane._normal.x * outNx +
+ final double d2 = plane._normal.x * outNx +
plane._normal.y * outNy +
plane._normal.z * outNz +
plane._constant;
diff --git a/lib/src/vector_math_64/matrix2.dart b/lib/src/vector_math_64/matrix2.dart
index 4c87128..5c965d4 100644
--- a/lib/src/vector_math_64/matrix2.dart
+++ b/lib/src/vector_math_64/matrix2.dart
@@ -26,8 +26,9 @@
det = 1.0 / det;
}
- x.x = det * (a22 * bx - a12 * by);
- x.y = det * (a11 * by - a21 * bx);
+ x
+ ..x = det * (a22 * bx - a12 * by)
+ ..y = det * (a11 * by - a21 * bx);
}
/// Return index in storage for [row], [col] value.
@@ -42,7 +43,7 @@
}
/// Set value at [row], [col] to be [v].
- setEntry(int row, int col, double v) {
+ void setEntry(int row, int col, double v) {
assert((row >= 0) && (row < dimension));
assert((col >= 0) && (col < dimension));
@@ -54,10 +55,8 @@
new Matrix2.zero()..setValues(arg0, arg1, arg2, arg3);
/// New matrix from [values].
- factory Matrix2.fromList(List<double> values) {
- return new Matrix2.zero()
- ..setValues(values[0], values[1], values[2], values[3]);
- }
+ factory Matrix2.fromList(List<double> values) =>
+ new Matrix2.zero()..setValues(values[0], values[1], values[2], values[3]);
/// Zero matrix.
Matrix2.zero() : _m2storage = new Float64List(4);
@@ -90,8 +89,8 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector2 arg0, Vector2 arg1) {
- final arg0Storage = arg0._v2storage;
- final arg1Storage = arg1._v2storage;
+ final Float64List arg0Storage = arg0._v2storage;
+ final Float64List arg1Storage = arg1._v2storage;
_m2storage[0] = arg0Storage[0];
_m2storage[1] = arg0Storage[1];
_m2storage[2] = arg1Storage[0];
@@ -100,7 +99,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float64List argStorage = arg._m2storage;
_m2storage[3] = argStorage[3];
_m2storage[2] = argStorage[2];
_m2storage[1] = argStorage[1];
@@ -109,8 +108,8 @@
/// Set [this] to the outer product of [u] and [v].
void setOuter(Vector2 u, Vector2 v) {
- final uStorage = u._v2storage;
- final vStorage = v._v2storage;
+ final Float64List uStorage = u._v2storage;
+ final Float64List vStorage = v._v2storage;
_m2storage[0] = uStorage[0] * vStorage[0];
_m2storage[1] = uStorage[0] * vStorage[1];
_m2storage[2] = uStorage[1] * vStorage[0];
@@ -125,12 +124,13 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_m2storage[0] = argStorage[0];
_m2storage[3] = argStorage[1];
}
/// Returns a printable string
+ @override
String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n';
/// Dimension of the matrix.
@@ -145,14 +145,15 @@
}
/// Check if two matrices are the same.
- bool operator ==(other) {
- return (other is Matrix2) &&
- (_m2storage[0] == other._m2storage[0]) &&
- (_m2storage[1] == other._m2storage[1]) &&
- (_m2storage[2] == other._m2storage[2]) &&
- (_m2storage[3] == other._m2storage[3]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Matrix2) &&
+ (_m2storage[0] == other._m2storage[0]) &&
+ (_m2storage[1] == other._m2storage[1]) &&
+ (_m2storage[2] == other._m2storage[2]) &&
+ (_m2storage[3] == other._m2storage[3]);
+ @override
int get hashCode => quiver.hashObjects(_m2storage);
/// Returns row 0
@@ -169,15 +170,15 @@
/// Sets [row] of the matrix to values in [arg]
void setRow(int row, Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List 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 r = new Vector2.zero();
- final rStorage = r._v2storage;
+ final Vector2 r = new Vector2.zero();
+ final Float64List rStorage = r._v2storage;
rStorage[0] = _m2storage[index(row, 0)];
rStorage[1] = _m2storage[index(row, 1)];
return r;
@@ -185,17 +186,17 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector2 arg) {
- final argStorage = arg._v2storage;
- final entry = column * 2;
+ final Float64List argStorage = arg._v2storage;
+ final int entry = column * 2;
_m2storage[entry + 1] = argStorage[1];
_m2storage[entry + 0] = argStorage[0];
}
/// Gets the [column] of the matrix
Vector2 getColumn(int column) {
- final r = new Vector2.zero();
- final entry = column * 2;
- final rStorage = r._v2storage;
+ final Vector2 r = new Vector2.zero();
+ final int entry = column * 2;
+ final Float64List rStorage = r._v2storage;
rStorage[1] = _m2storage[entry + 1];
rStorage[0] = _m2storage[entry + 0];
return r;
@@ -206,7 +207,7 @@
/// Copy [this] into [arg].
Matrix2 copyInto(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float64List argStorage = arg._m2storage;
argStorage[0] = _m2storage[0];
argStorage[1] = _m2storage[1];
argStorage[2] = _m2storage[2];
@@ -215,14 +216,14 @@
}
/// Returns a new vector or matrix by multiplying [this] with [arg].
- operator *(dynamic arg) {
+ dynamic operator *(dynamic arg) {
if (arg is double) {
return scaled(arg);
}
if (arg is Vector2) {
return transformed(arg);
}
- if (arg.dimension == 2) {
+ if (arg is Matrix2) {
return multiplied(arg);
}
throw new ArgumentError(arg);
@@ -257,15 +258,15 @@
Matrix2 transposed() => clone()..transpose();
void transpose() {
- double temp = _m2storage[2];
+ final double temp = _m2storage[2];
_m2storage[2] = _m2storage[1];
_m2storage[1] = temp;
}
/// Returns the component wise absolute value of this.
Matrix2 absolute() {
- Matrix2 r = new Matrix2.zero();
- final rStorage = r._m2storage;
+ final Matrix2 r = new Matrix2.zero();
+ final Float64List rStorage = r._m2storage;
rStorage[0] = _m2storage[0].abs();
rStorage[1] = _m2storage[1].abs();
rStorage[2] = _m2storage[2].abs();
@@ -279,13 +280,13 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector2 v) {
- final vStorage = v._v2storage;
+ final Float64List 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 vStorage = v._v2storage;
+ final Float64List vStorage = v._v2storage;
return _m2storage[j * 2] * vStorage[0] +
_m2storage[(j * 2) + 1] * vStorage[1];
}
@@ -318,28 +319,28 @@
/// Returns relative error between [this] and [correct]
double relativeError(Matrix2 correct) {
- Matrix2 diff = correct - this;
- double correct_norm = correct.infinityNorm();
- double diff_norm = diff.infinityNorm();
+ final Matrix2 diff = correct - this;
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between [this] and [correct]
double absoluteError(Matrix2 correct) {
- double this_norm = infinityNorm();
- double correct_norm = correct.infinityNorm();
- double diff_norm = (this_norm - correct_norm).abs();
+ final double this_norm = infinityNorm();
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Invert the matrix. Returns the determinant.
double invert() {
- double det = determinant();
+ final double det = determinant();
if (det == 0.0) {
return 0.0;
}
- double invDet = 1.0 / det;
- double temp = _m2storage[0];
+ final double invDet = 1.0 / det;
+ final double temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * invDet;
_m2storage[1] = -_m2storage[1] * invDet;
_m2storage[2] = -_m2storage[2] * invDet;
@@ -349,13 +350,13 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix2 arg) {
- double det = arg.determinant();
+ final double det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- double invDet = 1.0 / det;
- final argStorage = arg._m2storage;
+ final double invDet = 1.0 / det;
+ final Float64List argStorage = arg._m2storage;
_m2storage[0] = argStorage[3] * invDet;
_m2storage[1] = -argStorage[1] * invDet;
_m2storage[2] = -argStorage[2] * invDet;
@@ -365,8 +366,8 @@
/// Turns the matrix into a rotation of [radians]
void setRotation(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m2storage[0] = c;
_m2storage[1] = s;
_m2storage[2] = -s;
@@ -375,7 +376,7 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- double temp = _m2storage[0];
+ final double temp = _m2storage[0];
_m2storage[0] = _m2storage[3] * scale;
_m2storage[2] = -_m2storage[2] * scale;
_m2storage[1] = -_m2storage[1] * scale;
@@ -395,7 +396,7 @@
/// Add [o] to [this].
void add(Matrix2 o) {
- final oStorage = o._m2storage;
+ final Float64List oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] + oStorage[0];
_m2storage[1] = _m2storage[1] + oStorage[1];
_m2storage[2] = _m2storage[2] + oStorage[2];
@@ -404,7 +405,7 @@
/// Subtract [o] from [this].
void sub(Matrix2 o) {
- final oStorage = o._m2storage;
+ final Float64List oStorage = o._m2storage;
_m2storage[0] = _m2storage[0] - oStorage[0];
_m2storage[1] = _m2storage[1] - oStorage[1];
_m2storage[2] = _m2storage[2] - oStorage[2];
@@ -421,15 +422,15 @@
/// Multiply [this] with [arg] and store it in [this].
void multiply(Matrix2 arg) {
- 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];
+ 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];
_m2storage[0] = (m00 * n00) + (m01 * n10);
_m2storage[2] = (m00 * n01) + (m01 * n11);
_m2storage[1] = (m10 * n00) + (m11 * n10);
@@ -441,11 +442,11 @@
/// Multiply a transposed [this] with [arg].
void transposeMultiply(Matrix2 arg) {
- final m00 = _m2storage[0];
- final m01 = _m2storage[1];
- final m10 = _m2storage[2];
- final m11 = _m2storage[3];
- final argStorage = arg._m2storage;
+ 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;
_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 +455,11 @@
/// Multiply [this] with a transposed [arg].
void multiplyTranspose(Matrix2 arg) {
- final m00 = _m2storage[0];
- final m01 = _m2storage[2];
- final m10 = _m2storage[1];
- final m11 = _m2storage[3];
- final argStorage = arg._m2storage;
+ 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;
_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,9 +469,11 @@
/// Transform [arg] of type [Vector2] using the transformation defined by
/// [this].
Vector2 transform(Vector2 arg) {
- final argStorage = arg._v2storage;
- final x = (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]);
- final y = (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]);
+ 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]);
argStorage[0] = x;
argStorage[1] = y;
return arg;
@@ -490,7 +493,7 @@
/// Copies [this] into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
array[i + 3] = _m2storage[3];
array[i + 2] = _m2storage[2];
array[i + 1] = _m2storage[1];
@@ -499,7 +502,7 @@
/// Copies elements from [array] into [this] starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- int i = offset;
+ final int 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 2499d9a..f05f164 100644
--- a/lib/src/vector_math_64/matrix3.dart
+++ b/lib/src/vector_math_64/matrix3.dart
@@ -26,8 +26,9 @@
det = 1.0 / det;
}
- x.x = det * (a22 * bx - a12 * by);
- x.y = det * (a11 * by - a21 * bx);
+ x
+ ..x = det * (a22 * bx - a12 * by)
+ ..y = det * (a11 * by - a21 * bx);
}
/// Solve [A] * [x] = [b].
@@ -72,9 +73,10 @@
// Column0 dot -[b cross Column 1]
final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
- x.x = x_;
- x.y = y_;
- x.z = z_;
+ x
+ ..x = x_
+ ..y = y_
+ ..z = z_;
}
/// Return index in storage for [row], [col] value.
@@ -89,7 +91,7 @@
}
/// Set value at [row], [col] to be [v].
- setEntry(int row, int col, double v) {
+ void setEntry(int row, int col, double v) {
assert((row >= 0) && (row < dimension));
assert((col >= 0) && (col < dimension));
@@ -103,11 +105,9 @@
..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
/// New matrix from [values].
- factory Matrix3.fromList(List<double> values) {
- return new Matrix3.zero()
- ..setValues(values[0], values[1], values[2], values[3], values[4],
- values[5], values[6], values[7], values[8]);
- }
+ factory Matrix3.fromList(List<double> values) => new Matrix3.zero()
+ ..setValues(values[0], values[1], values[2], values[3], values[4],
+ values[5], values[6], values[7], values[8]);
/// Constructs a new [Matrix3] filled with zeros.
Matrix3.zero() : _m3storage = new Float64List(9);
@@ -154,9 +154,9 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector3 arg0, Vector3 arg1, Vector3 arg2) {
- final arg0Storage = arg0._v3storage;
- final arg1Storage = arg1._v3storage;
- final arg2Storage = arg2._v3storage;
+ final Float64List arg0Storage = arg0._v3storage;
+ final Float64List arg1Storage = arg1._v3storage;
+ final Float64List arg2Storage = arg2._v3storage;
_m3storage[0] = arg0Storage[0];
_m3storage[1] = arg0Storage[1];
_m3storage[2] = arg0Storage[2];
@@ -170,7 +170,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix3 arg) {
- final argStorage = arg._m3storage;
+ final Float64List argStorage = arg._m3storage;
_m3storage[8] = argStorage[8];
_m3storage[7] = argStorage[7];
_m3storage[6] = argStorage[6];
@@ -184,8 +184,8 @@
/// Set [this] to the outer product of [u] and [v].
void setOuter(Vector3 u, Vector3 v) {
- final uStorage = u._v3storage;
- final vStorage = v._v3storage;
+ final Float64List uStorage = u._v3storage;
+ final Float64List vStorage = v._v3storage;
_m3storage[0] = uStorage[0] * vStorage[0];
_m3storage[1] = uStorage[0] * vStorage[1];
_m3storage[2] = uStorage[0] * vStorage[2];
@@ -213,7 +213,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float64List argStorage = arg._m2storage;
_m3storage[0] = argStorage[0];
_m3storage[1] = argStorage[1];
_m3storage[3] = argStorage[2];
@@ -221,6 +221,7 @@
}
/// Returns a printable string
+ @override
String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n[2] ${getRow(2)}\n';
/// Dimension of the matrix.
@@ -235,19 +236,20 @@
}
/// Check if two matrices are the same.
- bool operator ==(other) {
- return (other is Matrix3) &&
- (_m3storage[0] == other._m3storage[0]) &&
- (_m3storage[1] == other._m3storage[1]) &&
- (_m3storage[2] == other._m3storage[2]) &&
- (_m3storage[3] == other._m3storage[3]) &&
- (_m3storage[4] == other._m3storage[4]) &&
- (_m3storage[5] == other._m3storage[5]) &&
- (_m3storage[6] == other._m3storage[6]) &&
- (_m3storage[7] == other._m3storage[7]) &&
- (_m3storage[8] == other._m3storage[8]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Matrix3) &&
+ (_m3storage[0] == other._m3storage[0]) &&
+ (_m3storage[1] == other._m3storage[1]) &&
+ (_m3storage[2] == other._m3storage[2]) &&
+ (_m3storage[3] == other._m3storage[3]) &&
+ (_m3storage[4] == other._m3storage[4]) &&
+ (_m3storage[5] == other._m3storage[5]) &&
+ (_m3storage[6] == other._m3storage[6]) &&
+ (_m3storage[7] == other._m3storage[7]) &&
+ (_m3storage[8] == other._m3storage[8]);
+ @override
int get hashCode => quiver.hashObjects(_m3storage);
/// Returns row 0
@@ -270,7 +272,7 @@
/// Assigns the [row] of to [arg].
void setRow(int row, Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_m3storage[index(row, 0)] = argStorage[0];
_m3storage[index(row, 1)] = argStorage[1];
_m3storage[index(row, 2)] = argStorage[2];
@@ -278,8 +280,8 @@
/// Gets the [row] of the matrix
Vector3 getRow(int row) {
- Vector3 r = new Vector3.zero();
- final rStorage = r._v3storage;
+ final Vector3 r = new Vector3.zero();
+ final Float64List rStorage = r._v3storage;
rStorage[0] = _m3storage[index(row, 0)];
rStorage[1] = _m3storage[index(row, 1)];
rStorage[2] = _m3storage[index(row, 2)];
@@ -288,8 +290,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector3 arg) {
- final argStorage = arg._v3storage;
- int entry = column * 3;
+ final Float64List argStorage = arg._v3storage;
+ final int entry = column * 3;
_m3storage[entry + 2] = argStorage[2];
_m3storage[entry + 1] = argStorage[1];
_m3storage[entry + 0] = argStorage[0];
@@ -297,9 +299,9 @@
/// Gets the [column] of the matrix
Vector3 getColumn(int column) {
- Vector3 r = new Vector3.zero();
- final rStorage = r._v3storage;
- int entry = column * 3;
+ final Vector3 r = new Vector3.zero();
+ final Float64List rStorage = r._v3storage;
+ final int entry = column * 3;
rStorage[2] = _m3storage[entry + 2];
rStorage[1] = _m3storage[entry + 1];
rStorage[0] = _m3storage[entry + 0];
@@ -311,7 +313,7 @@
/// Copy [this] into [arg].
Matrix3 copyInto(Matrix3 arg) {
- final argStorage = arg._m3storage;
+ final Float64List argStorage = arg._m3storage;
argStorage[0] = _m3storage[0];
argStorage[1] = _m3storage[1];
argStorage[2] = _m3storage[2];
@@ -325,14 +327,14 @@
}
/// Returns a new vector or matrix by multiplying [this] with [arg].
- operator *(dynamic arg) {
+ dynamic operator *(dynamic arg) {
if (arg is double) {
return scaled(arg);
}
if (arg is Vector3) {
return transformed(arg);
}
- if (arg.dimension == 3) {
+ if (arg is Matrix3) {
return multiplied(arg);
}
throw new ArgumentError(arg);
@@ -392,8 +394,8 @@
/// Returns the component wise absolute value of this.
Matrix3 absolute() {
- Matrix3 r = new Matrix3.zero();
- final rStorage = r._m3storage;
+ final Matrix3 r = new Matrix3.zero();
+ final Float64List rStorage = r._m3storage;
rStorage[0] = _m3storage[0].abs();
rStorage[1] = _m3storage[1].abs();
rStorage[2] = _m3storage[2].abs();
@@ -408,18 +410,18 @@
/// Returns the determinant of this matrix.
double determinant() {
- double x = _m3storage[0] *
+ final double x = _m3storage[0] *
((storage[4] * _m3storage[8]) - (storage[5] * _m3storage[7]));
- double y = _m3storage[1] *
+ final double y = _m3storage[1] *
((storage[3] * _m3storage[8]) - (storage[5] * _m3storage[6]));
- double z = _m3storage[2] *
+ final double z = _m3storage[2] *
((storage[3] * _m3storage[7]) - (storage[4] * _m3storage[6]));
return x - y + z;
}
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector3 v) {
- final vStorage = v._v3storage;
+ final Float64List vStorage = v._v3storage;
return _m3storage[i] * vStorage[0] +
_m3storage[3 + i] * vStorage[1] +
_m3storage[6 + i] * vStorage[2];
@@ -427,7 +429,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector3 v) {
- final vStorage = v._v3storage;
+ final Float64List vStorage = v._v3storage;
return _m3storage[j * 3] * vStorage[0] +
_m3storage[j * 3 + 1] * vStorage[1] +
_m3storage[j * 3 + 2] * vStorage[2];
@@ -472,17 +474,17 @@
/// Returns relative error between [this] and [correct]
double relativeError(Matrix3 correct) {
- Matrix3 diff = correct - this;
- double correct_norm = correct.infinityNorm();
- double diff_norm = diff.infinityNorm();
+ final Matrix3 diff = correct - this;
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between [this] and [correct]
double absoluteError(Matrix3 correct) {
- double this_norm = infinityNorm();
- double correct_norm = correct.infinityNorm();
- double diff_norm = (this_norm - correct_norm).abs();
+ final double this_norm = infinityNorm();
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
@@ -491,30 +493,30 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix3 arg) {
- final det = arg.determinant();
+ final double det = arg.determinant();
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- final invDet = 1.0 / det;
- final argStorage = arg._m3storage;
- final ix = invDet *
+ final double invDet = 1.0 / det;
+ final Float64List argStorage = arg._m3storage;
+ final double ix = invDet *
(argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]);
- final iy = invDet *
+ final double iy = invDet *
(argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]);
- final iz = invDet *
+ final double iz = invDet *
(argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]);
- final jx = invDet *
+ final double jx = invDet *
(argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]);
- final jy = invDet *
+ final double jy = invDet *
(argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]);
- final jz = invDet *
+ final double jz = invDet *
(argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]);
- final kx = invDet *
+ final double kx = invDet *
(argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]);
- final ky = invDet *
+ final double ky = invDet *
(argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]);
- final kz = invDet *
+ final double kz = invDet *
(argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]);
_m3storage[0] = ix;
_m3storage[1] = iy;
@@ -536,8 +538,8 @@
/// Turns the matrix into a rotation of [radians] around X
void setRotationX(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m3storage[0] = 1.0;
_m3storage[1] = 0.0;
_m3storage[2] = 0.0;
@@ -551,8 +553,8 @@
/// Turns the matrix into a rotation of [radians] around Y
void setRotationY(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = 0.0;
_m3storage[2] = s;
@@ -566,8 +568,8 @@
/// Turns the matrix into a rotation of [radians] around Z
void setRotationZ(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m3storage[0] = c;
_m3storage[1] = s;
_m3storage[2] = 0.0;
@@ -581,15 +583,15 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
- double m00 = _m3storage[0];
- double m01 = _m3storage[3];
- double m02 = _m3storage[6];
- double m10 = _m3storage[1];
- double m11 = _m3storage[4];
- double m12 = _m3storage[7];
- double m20 = _m3storage[2];
- double m21 = _m3storage[5];
- double m22 = _m3storage[8];
+ 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];
_m3storage[0] = (m11 * m22 - m12 * m21) * scale;
_m3storage[1] = (m12 * m20 - m10 * m22) * scale;
_m3storage[2] = (m10 * m21 - m11 * m20) * scale;
@@ -605,19 +607,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- double m00 = _m3storage[0].abs();
- double m01 = _m3storage[3].abs();
- double m02 = _m3storage[6].abs();
- double m10 = _m3storage[1].abs();
- double m11 = _m3storage[4].abs();
- double m12 = _m3storage[7].abs();
- double m20 = _m3storage[2].abs();
- double m21 = _m3storage[5].abs();
- double m22 = _m3storage[8].abs();
- final argStorage = arg._v3storage;
- final x = argStorage[0];
- final y = argStorage[1];
- final z = argStorage[2];
+ 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];
argStorage[0] = x * m00 + y * m01 + z * m02;
argStorage[1] = x * m10 + y * m11 + z * m12;
argStorage[2] = x * m20 + y * m21 + z * m22;
@@ -628,13 +630,13 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector2 absoluteRotate2(Vector2 arg) {
- double m00 = _m3storage[0].abs();
- double m01 = _m3storage[3].abs();
- double m10 = _m3storage[1].abs();
- double m11 = _m3storage[4].abs();
- final argStorage = arg._v2storage;
- final x = argStorage[0];
- final y = argStorage[1];
+ 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];
argStorage[0] = x * m00 + y * m01;
argStorage[1] = x * m10 + y * m11;
return arg;
@@ -642,11 +644,11 @@
/// Transforms [arg] with [this].
Vector2 transform2(Vector2 arg) {
- final argStorage = arg._v2storage;
- double x_ = (storage[0] * arg.storage[0]) +
+ final Float64List argStorage = arg._v2storage;
+ final double x_ = (storage[0] * arg.storage[0]) +
(storage[3] * arg.storage[1]) +
_m3storage[6];
- double y_ = (storage[1] * arg.storage[0]) +
+ final double y_ = (storage[1] * arg.storage[0]) +
(storage[4] * arg.storage[1]) +
_m3storage[7];
argStorage[0] = x_;
@@ -672,7 +674,7 @@
/// Add [o] to [this].
void add(Matrix3 o) {
- final oStorage = o._m3storage;
+ final Float64List oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] + oStorage[0];
_m3storage[1] = _m3storage[1] + oStorage[1];
_m3storage[2] = _m3storage[2] + oStorage[2];
@@ -686,7 +688,7 @@
/// Subtract [o] from [this].
void sub(Matrix3 o) {
- final oStorage = o._m3storage;
+ final Float64List oStorage = o._m3storage;
_m3storage[0] = _m3storage[0] - oStorage[0];
_m3storage[1] = _m3storage[1] - oStorage[1];
_m3storage[2] = _m3storage[2] - oStorage[2];
@@ -722,7 +724,7 @@
final double m20 = _m3storage[2];
final double m21 = _m3storage[5];
final double m22 = _m3storage[8];
- final argStorage = arg._m3storage;
+ final Float64List argStorage = arg._m3storage;
final double n00 = argStorage[0];
final double n01 = argStorage[3];
final double n02 = argStorage[6];
@@ -747,16 +749,16 @@
Matrix3 multiplied(Matrix3 arg) => clone()..multiply(arg);
void transposeMultiply(Matrix3 arg) {
- double m00 = _m3storage[0];
- double m01 = _m3storage[1];
- double m02 = _m3storage[2];
- double m10 = _m3storage[3];
- double m11 = _m3storage[4];
- double m12 = _m3storage[5];
- double m20 = _m3storage[6];
- double m21 = _m3storage[7];
- double m22 = _m3storage[8];
- final argStorage = arg._m3storage;
+ 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;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * arg.storage[1]) + (m02 * arg.storage[2]);
_m3storage[3] =
@@ -778,16 +780,16 @@
}
void multiplyTranspose(Matrix3 arg) {
- double m00 = _m3storage[0];
- double m01 = _m3storage[3];
- double m02 = _m3storage[6];
- double m10 = _m3storage[1];
- double m11 = _m3storage[4];
- double m12 = _m3storage[7];
- double m20 = _m3storage[2];
- double m21 = _m3storage[5];
- double m22 = _m3storage[8];
- final argStorage = arg._m3storage;
+ 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;
_m3storage[0] =
(m00 * argStorage[0]) + (m01 * argStorage[3]) + (m02 * argStorage[6]);
_m3storage[3] =
@@ -811,19 +813,20 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// [this].
Vector3 transform(Vector3 arg) {
- final argStorage = arg._v3storage;
- double x_ = (storage[0] * argStorage[0]) +
+ final Float64List argStorage = arg._v3storage;
+ final double x_ = (storage[0] * argStorage[0]) +
(storage[3] * argStorage[1]) +
(storage[6] * argStorage[2]);
- double y_ = (storage[1] * argStorage[0]) +
+ final double y_ = (storage[1] * argStorage[0]) +
(storage[4] * argStorage[1]) +
(storage[7] * argStorage[2]);
- double z_ = (storage[2] * argStorage[0]) +
+ final double z_ = (storage[2] * argStorage[0]) +
(storage[5] * argStorage[1]) +
(storage[8] * argStorage[2]);
- arg.x = x_;
- arg.y = y_;
- arg.z = z_;
+ arg
+ ..x = x_
+ ..y = y_
+ ..z = z_;
return arg;
}
@@ -841,7 +844,7 @@
/// Copies [this] into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
array[i + 8] = _m3storage[8];
array[i + 7] = _m3storage[7];
array[i + 6] = _m3storage[6];
@@ -855,7 +858,7 @@
/// Copies elements from [array] into [this] starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
_m3storage[8] = array[i + 8];
_m3storage[7] = array[i + 7];
_m3storage[6] = array[i + 6];
@@ -869,8 +872,8 @@
/// Multiply [this] to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final v = new Vector3.array(array, j)..applyMatrix3(this);
+ for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final Vector3 v = new Vector3.array(array, j)..applyMatrix3(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -880,49 +883,53 @@
}
Vector3 get right {
- double x = _m3storage[0];
- double y = _m3storage[1];
- double z = _m3storage[2];
+ final double x = _m3storage[0];
+ final double y = _m3storage[1];
+ final double z = _m3storage[2];
return new Vector3(x, y, z);
}
Vector3 get up {
- double x = _m3storage[3];
- double y = _m3storage[4];
- double z = _m3storage[5];
+ final double x = _m3storage[3];
+ final double y = _m3storage[4];
+ final double z = _m3storage[5];
return new Vector3(x, y, z);
}
Vector3 get forward {
- double x = _m3storage[6];
- double y = _m3storage[7];
- double z = _m3storage[8];
+ final double x = _m3storage[6];
+ final double y = _m3storage[7];
+ final double z = _m3storage[8];
return new Vector3(x, y, z);
}
/// Is [this] the identity matrix?
- bool isIdentity() {
- return _m3storage[0] == 1.0 // col 1
- && _m3storage[1] == 0.0
- && _m3storage[2] == 0.0
- && _m3storage[3] == 0.0 // col 2
- && _m3storage[4] == 1.0
- && _m3storage[5] == 0.0
- && _m3storage[6] == 0.0 // col 3
- && _m3storage[7] == 0.0
- && _m3storage[8] == 1.0;
- }
+ bool isIdentity() =>
+ _m3storage[0] == 1.0 // col 1
+ &&
+ _m3storage[1] == 0.0 &&
+ _m3storage[2] == 0.0 &&
+ _m3storage[3] == 0.0 // col 2
+ &&
+ _m3storage[4] == 1.0 &&
+ _m3storage[5] == 0.0 &&
+ _m3storage[6] == 0.0 // col 3
+ &&
+ _m3storage[7] == 0.0 &&
+ _m3storage[8] == 1.0;
/// Is [this] the zero matrix?
- bool isZero() {
- return _m3storage[0] == 0.0 // col 1
- && _m3storage[1] == 0.0
- && _m3storage[2] == 0.0
- && _m3storage[3] == 0.0 // col 2
- && _m3storage[4] == 0.0
- && _m3storage[5] == 0.0
- && _m3storage[6] == 0.0 // col 3
- && _m3storage[7] == 0.0
- && _m3storage[8] == 0.0;
- }
+ bool isZero() =>
+ _m3storage[0] == 0.0 // col 1
+ &&
+ _m3storage[1] == 0.0 &&
+ _m3storage[2] == 0.0 &&
+ _m3storage[3] == 0.0 // col 2
+ &&
+ _m3storage[4] == 0.0 &&
+ _m3storage[5] == 0.0 &&
+ _m3storage[6] == 0.0 // col 3
+ &&
+ _m3storage[7] == 0.0 &&
+ _m3storage[8] == 0.0;
}
diff --git a/lib/src/vector_math_64/matrix4.dart b/lib/src/vector_math_64/matrix4.dart
index 96e260e..5878c1a 100644
--- a/lib/src/vector_math_64/matrix4.dart
+++ b/lib/src/vector_math_64/matrix4.dart
@@ -26,8 +26,9 @@
det = 1.0 / det;
}
- x.x = det * (a22 * bx - a12 * by);
- x.y = det * (a11 * by - a21 * bx);
+ x
+ ..x = det * (a22 * bx - a12 * by)
+ ..y = det * (a11 * by - a21 * bx);
}
/// Solve [A] * [x] = [b].
@@ -75,9 +76,10 @@
// Column0 dot -[b cross Column 1]
final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);
- x.x = x_;
- x.y = y_;
- x.z = z_;
+ x
+ ..x = x_
+ ..y = y_
+ ..z = z_;
}
/// Solve [A] * [x] = [b].
@@ -123,29 +125,27 @@
det = 1.0 / det;
}
- x.x = det *
- ((a11 * b11 - a12 * b10 + a13 * b09) * bX -
- (a10 * b11 - a12 * b08 + a13 * b07) * bY +
- (a10 * b10 - a11 * b08 + a13 * b06) * bZ -
- (a10 * b09 - a11 * b07 + a12 * b06) * bW);
-
- x.y = det *
- -((a01 * b11 - a02 * b10 + a03 * b09) * bX -
- (a00 * b11 - a02 * b08 + a03 * b07) * bY +
- (a00 * b10 - a01 * b08 + a03 * b06) * bZ -
- (a00 * b09 - a01 * b07 + a02 * b06) * bW);
-
- x.z = det *
- ((a31 * b05 - a32 * b04 + a33 * b03) * bX -
- (a30 * b05 - a32 * b02 + a33 * b01) * bY +
- (a30 * b04 - a31 * b02 + a33 * b00) * bZ -
- (a30 * b03 - a31 * b01 + a32 * b00) * bW);
-
- x.w = det *
- -((a21 * b05 - a22 * b04 + a23 * b03) * bX -
- (a20 * b05 - a22 * b02 + a23 * b01) * bY +
- (a20 * b04 - a21 * b02 + a23 * b00) * bZ -
- (a20 * b03 - a21 * b01 + a22 * b00) * bW);
+ x
+ ..x = det *
+ ((a11 * b11 - a12 * b10 + a13 * b09) * bX -
+ (a10 * b11 - a12 * b08 + a13 * b07) * bY +
+ (a10 * b10 - a11 * b08 + a13 * b06) * bZ -
+ (a10 * b09 - a11 * b07 + a12 * b06) * bW)
+ ..y = det *
+ -((a01 * b11 - a02 * b10 + a03 * b09) * bX -
+ (a00 * b11 - a02 * b08 + a03 * b07) * bY +
+ (a00 * b10 - a01 * b08 + a03 * b06) * bZ -
+ (a00 * b09 - a01 * b07 + a02 * b06) * bW)
+ ..z = det *
+ ((a31 * b05 - a32 * b04 + a33 * b03) * bX -
+ (a30 * b05 - a32 * b02 + a33 * b01) * bY +
+ (a30 * b04 - a31 * b02 + a33 * b00) * bZ -
+ (a30 * b03 - a31 * b01 + a32 * b00) * bW)
+ ..w = det *
+ -((a21 * b05 - a22 * b04 + a23 * b03) * bX -
+ (a20 * b05 - a22 * b02 + a23 * b01) * bY +
+ (a20 * b04 - a21 * b02 + a23 * b00) * bZ -
+ (a20 * b03 - a21 * b01 + a22 * b00) * bW);
}
/// Return index in storage for [row], [col] value.
@@ -160,7 +160,7 @@
}
/// Set value at [row], [col] to be [v].
- setEntry(int row, int col, double v) {
+ void setEntry(int row, int col, double v) {
assert((row >= 0) && (row < dimension));
assert((col >= 0) && (col < dimension));
@@ -190,26 +190,24 @@
arg10, arg11, arg12, arg13, arg14, arg15);
/// New matrix from [values].
- factory Matrix4.fromList(List<double> values) {
- return new Matrix4.zero()
- ..setValues(
- values[0],
- values[1],
- values[2],
- values[3],
- values[4],
- values[5],
- values[6],
- values[7],
- values[8],
- values[9],
- values[10],
- values[11],
- values[12],
- values[13],
- values[14],
- values[15]);
- }
+ factory Matrix4.fromList(List<double> values) => new Matrix4.zero()
+ ..setValues(
+ values[0],
+ values[1],
+ values[2],
+ values[3],
+ values[4],
+ values[5],
+ values[6],
+ values[7],
+ values[8],
+ values[9],
+ values[10],
+ values[11],
+ values[12],
+ values[13],
+ values[14],
+ values[15]);
/// Zero matrix.
Matrix4.zero() : _m4storage = new Float64List(16);
@@ -222,8 +220,8 @@
/// Constructs a matrix that is the inverse of [other].
factory Matrix4.inverted(Matrix4 other) {
- Matrix4 r = new Matrix4.zero();
- double determinant = r.copyInverse(other);
+ final Matrix4 r = new Matrix4.zero();
+ final double determinant = r.copyInverse(other);
if (determinant == 0.0) {
throw new ArgumentError.value(
other, 'other', 'Matrix cannot be inverted');
@@ -268,9 +266,9 @@
/// Scale matrix.
factory Matrix4.diagonal3(Vector3 scale) {
- final m = new Matrix4.zero();
- final mStorage = m._m4storage;
- final scaleStorage = scale._v3storage;
+ final Matrix4 m = new Matrix4.zero();
+ final Float64List mStorage = m._m4storage;
+ final Float64List scaleStorage = scale._v3storage;
mStorage[15] = 1.0;
mStorage[10] = scaleStorage[2];
mStorage[5] = scaleStorage[1];
@@ -288,27 +286,26 @@
/// Skew matrix around X axis
factory Matrix4.skewX(double alpha) {
- final m = new Matrix4.identity();
- m._m4storage[4] = Math.tan(alpha);
+ final Matrix4 m = new Matrix4.identity();
+ m._m4storage[4] = math.tan(alpha);
return m;
}
/// Skew matrix around Y axis.
factory Matrix4.skewY(double beta) {
- final m = new Matrix4.identity();
- m._m4storage[1] = Math.tan(beta);
+ final Matrix4 m = new 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 m = new Matrix4.identity();
- m._m4storage[1] = Math.tan(beta);
- m._m4storage[4] = Math.tan(alpha);
+ final Matrix4 m = new Matrix4.identity();
+ m._m4storage[1] = math.tan(beta);
+ m._m4storage[4] = math.tan(alpha);
return m;
}
-
/// Constructs Matrix4 with given [Float64List] as [storage].
Matrix4.fromFloat64List(this._m4storage);
@@ -369,10 +366,10 @@
/// Sets the entire matrix to the column values.
void setColumns(Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) {
- final arg0Storage = arg0._v4storage;
- final arg1Storage = arg1._v4storage;
- final arg2Storage = arg2._v4storage;
- final arg3Storage = arg3._v4storage;
+ final Float64List arg0Storage = arg0._v4storage;
+ final Float64List arg1Storage = arg1._v4storage;
+ final Float64List arg2Storage = arg2._v4storage;
+ final Float64List arg3Storage = arg3._v4storage;
_m4storage[0] = arg0Storage[0];
_m4storage[1] = arg0Storage[1];
_m4storage[2] = arg0Storage[2];
@@ -393,7 +390,7 @@
/// Sets the entire matrix to the matrix in [arg].
void setFrom(Matrix4 arg) {
- final argStorage = arg._m4storage;
+ final Float64List argStorage = arg._m4storage;
_m4storage[15] = argStorage[15];
_m4storage[14] = argStorage[14];
_m4storage[13] = argStorage[13];
@@ -414,25 +411,25 @@
/// Sets the matrix from translation [arg0] and rotation [arg1].
void setFromTranslationRotation(Vector3 arg0, Quaternion arg1) {
- final arg1Storage = arg1._qStorage;
- double x = arg1Storage[0];
- double y = arg1Storage[1];
- double z = arg1Storage[2];
- double w = arg1Storage[3];
- double x2 = x + x;
- double y2 = y + y;
- double z2 = z + z;
- double xx = x * x2;
- double xy = x * y2;
- double xz = x * z2;
- double yy = y * y2;
- double yz = y * z2;
- double zz = z * z2;
- double wx = w * x2;
- double wy = w * y2;
- double wz = w * z2;
+ 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 arg0Storage = arg0._v3storage;
+ final Float64List arg0Storage = arg0._v3storage;
_m4storage[0] = 1.0 - (yy + zz);
_m4storage[1] = xy + wz;
_m4storage[2] = xz - wy;
@@ -460,7 +457,7 @@
/// Sets the upper 2x2 of the matrix to be [arg].
void setUpper2x2(Matrix2 arg) {
- final argStorage = arg._m2storage;
+ final Float64List argStorage = arg._m2storage;
_m4storage[0] = argStorage[0];
_m4storage[1] = argStorage[1];
_m4storage[4] = argStorage[2];
@@ -469,7 +466,7 @@
/// Sets the diagonal of the matrix to be [arg].
void setDiagonal(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_m4storage[0] = argStorage[0];
_m4storage[5] = argStorage[1];
_m4storage[10] = argStorage[2];
@@ -477,8 +474,8 @@
}
void setOuter(Vector4 u, Vector4 v) {
- final uStorage = u._v4storage;
- final vStorage = v._v4storage;
+ final Float64List uStorage = u._v4storage;
+ final Float64List vStorage = v._v4storage;
_m4storage[0] = uStorage[0] * vStorage[0];
_m4storage[1] = uStorage[0] * vStorage[1];
_m4storage[2] = uStorage[0] * vStorage[2];
@@ -498,6 +495,7 @@
}
/// Returns a printable string
+ @override
String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n'
'[2] ${getRow(2)}\n[3] ${getRow(3)}\n';
@@ -513,26 +511,27 @@
}
/// Check if two matrices are the same.
- bool operator ==(other) {
- return (other is Matrix4) &&
- (_m4storage[0] == other._m4storage[0]) &&
- (_m4storage[1] == other._m4storage[1]) &&
- (_m4storage[2] == other._m4storage[2]) &&
- (_m4storage[3] == other._m4storage[3]) &&
- (_m4storage[4] == other._m4storage[4]) &&
- (_m4storage[5] == other._m4storage[5]) &&
- (_m4storage[6] == other._m4storage[6]) &&
- (_m4storage[7] == other._m4storage[7]) &&
- (_m4storage[8] == other._m4storage[8]) &&
- (_m4storage[9] == other._m4storage[9]) &&
- (_m4storage[10] == other._m4storage[10]) &&
- (_m4storage[11] == other._m4storage[11]) &&
- (_m4storage[12] == other._m4storage[12]) &&
- (_m4storage[13] == other._m4storage[13]) &&
- (_m4storage[14] == other._m4storage[14]) &&
- (_m4storage[15] == other._m4storage[15]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Matrix4) &&
+ (_m4storage[0] == other._m4storage[0]) &&
+ (_m4storage[1] == other._m4storage[1]) &&
+ (_m4storage[2] == other._m4storage[2]) &&
+ (_m4storage[3] == other._m4storage[3]) &&
+ (_m4storage[4] == other._m4storage[4]) &&
+ (_m4storage[5] == other._m4storage[5]) &&
+ (_m4storage[6] == other._m4storage[6]) &&
+ (_m4storage[7] == other._m4storage[7]) &&
+ (_m4storage[8] == other._m4storage[8]) &&
+ (_m4storage[9] == other._m4storage[9]) &&
+ (_m4storage[10] == other._m4storage[10]) &&
+ (_m4storage[11] == other._m4storage[11]) &&
+ (_m4storage[12] == other._m4storage[12]) &&
+ (_m4storage[13] == other._m4storage[13]) &&
+ (_m4storage[14] == other._m4storage[14]) &&
+ (_m4storage[15] == other._m4storage[15]);
+ @override
int get hashCode => quiver.hashObjects(_m4storage);
/// Returns row 0
@@ -561,7 +560,7 @@
/// Assigns the [row] of the matrix [arg]
void setRow(int row, Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_m4storage[index(row, 0)] = argStorage[0];
_m4storage[index(row, 1)] = argStorage[1];
_m4storage[index(row, 2)] = argStorage[2];
@@ -570,8 +569,8 @@
/// Gets the [row] of the matrix
Vector4 getRow(int row) {
- Vector4 r = new Vector4.zero();
- final rStorage = r._v4storage;
+ final Vector4 r = new Vector4.zero();
+ final Float64List rStorage = r._v4storage;
rStorage[0] = _m4storage[index(row, 0)];
rStorage[1] = _m4storage[index(row, 1)];
rStorage[2] = _m4storage[index(row, 2)];
@@ -581,8 +580,8 @@
/// Assigns the [column] of the matrix [arg]
void setColumn(int column, Vector4 arg) {
- int entry = column * 4;
- final argStorage = arg._v4storage;
+ final int entry = column * 4;
+ final Float64List argStorage = arg._v4storage;
_m4storage[entry + 3] = argStorage[3];
_m4storage[entry + 2] = argStorage[2];
_m4storage[entry + 1] = argStorage[1];
@@ -591,9 +590,9 @@
/// Gets the [column] of the matrix
Vector4 getColumn(int column) {
- Vector4 r = new Vector4.zero();
- final rStorage = r._v4storage;
- int entry = column * 4;
+ final Vector4 r = new Vector4.zero();
+ final Float64List rStorage = r._v4storage;
+ final int entry = column * 4;
rStorage[3] = _m4storage[entry + 3];
rStorage[2] = _m4storage[entry + 2];
rStorage[1] = _m4storage[entry + 1];
@@ -606,7 +605,7 @@
/// Copy into [arg].
Matrix4 copyInto(Matrix4 arg) {
- final argStorage = arg._m4storage;
+ final Float64List argStorage = arg._m4storage;
argStorage[0] = _m4storage[0];
argStorage[1] = _m4storage[1];
argStorage[2] = _m4storage[2];
@@ -640,7 +639,7 @@
if (arg is Vector3) {
return transformed3(arg);
}
- if (arg.dimension == 4) {
+ if (arg is Matrix4) {
return multiplied(arg);
}
throw new ArgumentError(arg);
@@ -653,33 +652,37 @@
Matrix4 operator -(Matrix4 arg) => clone()..sub(arg);
/// Translate this matrix by a [Vector3], [Vector4], or x,y,z
- void translate(x, [double y = 0.0, double z = 0.0]) {
+ void translate(dynamic x, [double y = 0.0, double z = 0.0]) {
double tx;
double ty;
double tz;
- double tw = x is Vector4 ? x.w : 1.0;
- if (x is Vector3 || x is Vector4) {
+ final double tw = x is Vector4 ? x.w : 1.0;
+ if (x is Vector3) {
tx = x.x;
ty = x.y;
tz = x.z;
- } else {
+ } else if (x is Vector4) {
+ tx = x.x;
+ ty = x.y;
+ tz = x.z;
+ } else if (x is double) {
tx = x;
ty = y;
tz = z;
}
- var t1 = _m4storage[0] * tx +
+ final double t1 = _m4storage[0] * tx +
_m4storage[4] * ty +
_m4storage[8] * tz +
_m4storage[12] * tw;
- var t2 = _m4storage[1] * tx +
+ final double t2 = _m4storage[1] * tx +
_m4storage[5] * ty +
_m4storage[9] * tz +
_m4storage[13] * tw;
- var t3 = _m4storage[2] * tx +
+ final double t3 = _m4storage[2] * tx +
_m4storage[6] * ty +
_m4storage[10] * tz +
_m4storage[14] * tw;
- var t4 = _m4storage[3] * tx +
+ final double t4 = _m4storage[3] * tx +
_m4storage[7] * ty +
_m4storage[11] * tz +
_m4storage[15] * tw;
@@ -691,16 +694,20 @@
/// Multiply [this] by a translation from the left.
/// The translation can be specified with a [Vector3], [Vector4], or x, y, z.
- void leftTranslate(x, [double y = 0.0, double z = 0.0]) {
+ void leftTranslate(dynamic x, [double y = 0.0, double z = 0.0]) {
double tx;
double ty;
double tz;
- double tw = x is Vector4 ? x.w : 1.0;
- if (x is Vector3 || x is Vector4) {
+ final double tw = x is Vector4 ? x.w : 1.0;
+ if (x is Vector3) {
tx = x.x;
ty = x.y;
tz = x.z;
- } else {
+ } else if (x is Vector4) {
+ tx = x.x;
+ ty = x.y;
+ tz = x.z;
+ } else if (x is double) {
tx = x;
ty = y;
tz = z;
@@ -733,35 +740,47 @@
/// Rotate this [angle] radians around [axis]
void rotate(Vector3 axis, double angle) {
- var len = axis.length;
- final axisStorage = axis._v3storage;
- var x = axisStorage[0] / len;
- var y = axisStorage[1] / len;
- var z = axisStorage[2] / len;
- var c = Math.cos(angle);
- var s = Math.sin(angle);
- var C = 1.0 - c;
- var m11 = x * x * C + c;
- var m12 = x * y * C - z * s;
- var m13 = x * z * C + y * s;
- var m21 = y * x * C + z * s;
- var m22 = y * y * C + c;
- var m23 = y * z * C - x * s;
- var m31 = z * x * C - y * s;
- var m32 = z * y * C + x * s;
- var m33 = z * z * C + c;
- var t1 = _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31;
- var t2 = _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31;
- var t3 = _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31;
- var t4 = _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31;
- var t5 = _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32;
- var t6 = _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32;
- var t7 = _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32;
- var t8 = _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32;
- var t9 = _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33;
- var t10 = _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33;
- var t11 = _m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33;
- var t12 = _m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33;
+ 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 =
+ _m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33;
+ final double t12 =
+ _m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -778,16 +797,16 @@
/// Rotate this [angle] radians around X
void rotateX(double angle) {
- double cosAngle = Math.cos(angle);
- double sinAngle = Math.sin(angle);
- var t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle;
- var t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle;
- var t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle;
- var t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle;
- var t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle;
- var t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle;
- var t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle;
- var t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle;
+ 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;
_m4storage[4] = t1;
_m4storage[5] = t2;
_m4storage[6] = t3;
@@ -800,16 +819,16 @@
/// Rotate this matrix [angle] radians around Y
void rotateY(double angle) {
- double cosAngle = Math.cos(angle);
- double sinAngle = Math.sin(angle);
- var t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle;
- var t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle;
- var t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle;
- var t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle;
- var t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle;
- var t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle;
- var t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle;
- var t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle;
+ 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;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -822,16 +841,16 @@
/// Rotate this matrix [angle] radians around Z
void rotateZ(double angle) {
- double cosAngle = Math.cos(angle);
- double sinAngle = Math.sin(angle);
- var t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle;
- var t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle;
- var t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle;
- var t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle;
- var t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle;
- var t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle;
- var t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle;
- var t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle;
+ 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;
_m4storage[0] = t1;
_m4storage[1] = t2;
_m4storage[2] = t3;
@@ -843,16 +862,20 @@
}
/// Scale this matrix by a [Vector3], [Vector4], or x,y,z
- void scale(x, [double y, double z]) {
+ void scale(dynamic x, [double y, double z]) {
double sx;
double sy;
double sz;
- double sw = x is Vector4 ? x.w : 1.0;
- if (x is Vector3 || x is Vector4) {
+ final double sw = x is Vector4 ? x.w : 1.0;
+ if (x is Vector3) {
sx = x.x;
sy = x.y;
sz = x.z;
- } else {
+ } else if (x is Vector4) {
+ sx = x.x;
+ sy = x.y;
+ sz = x.z;
+ } else if (x is double) {
sx = x;
sy = y == null ? x : y.toDouble();
sz = z == null ? x : z.toDouble();
@@ -877,7 +900,7 @@
/// Create a copy of [this] scaled by a [Vector3], [Vector4] or [x],[y], and
/// [z].
- Matrix4 scaled(x, [double y = null, double z = null]) =>
+ Matrix4 scaled(dynamic x, [double y = null, double z = null]) =>
clone()..scale(x, y, z);
/// Zeros [this].
@@ -947,8 +970,8 @@
/// Returns the component wise absolute value of this.
Matrix4 absolute() {
- Matrix4 r = new Matrix4.zero();
- final rStorage = r._m4storage;
+ final Matrix4 r = new Matrix4.zero();
+ final Float64List rStorage = r._m4storage;
rStorage[0] = _m4storage[0].abs();
rStorage[1] = _m4storage[1].abs();
rStorage[2] = _m4storage[2].abs();
@@ -970,28 +993,28 @@
/// Returns the determinant of this matrix.
double determinant() {
- double det2_01_01 =
+ final double det2_01_01 =
_m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4];
- double det2_01_02 =
+ final double det2_01_02 =
_m4storage[0] * _m4storage[6] - _m4storage[2] * _m4storage[4];
- double det2_01_03 =
+ final double det2_01_03 =
_m4storage[0] * _m4storage[7] - _m4storage[3] * _m4storage[4];
- double det2_01_12 =
+ final double det2_01_12 =
_m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5];
- double det2_01_13 =
+ final double det2_01_13 =
_m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5];
- double det2_01_23 =
+ final double det2_01_23 =
_m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6];
- double det3_201_012 = _m4storage[8] * det2_01_12 -
+ final double det3_201_012 = _m4storage[8] * det2_01_12 -
_m4storage[9] * det2_01_02 +
_m4storage[10] * det2_01_01;
- double det3_201_013 = _m4storage[8] * det2_01_13 -
+ final double det3_201_013 = _m4storage[8] * det2_01_13 -
_m4storage[9] * det2_01_03 +
_m4storage[11] * det2_01_01;
- double det3_201_023 = _m4storage[8] * det2_01_23 -
+ final double det3_201_023 = _m4storage[8] * det2_01_23 -
_m4storage[10] * det2_01_03 +
_m4storage[11] * det2_01_02;
- double det3_201_123 = _m4storage[9] * det2_01_23 -
+ final double det3_201_123 = _m4storage[9] * det2_01_23 -
_m4storage[10] * det2_01_13 +
_m4storage[11] * det2_01_12;
return -det3_201_123 * _m4storage[12] +
@@ -1002,7 +1025,7 @@
/// Returns the dot product of row [i] and [v].
double dotRow(int i, Vector4 v) {
- final vStorage = v._v4storage;
+ final Float64List vStorage = v._v4storage;
return _m4storage[i] * vStorage[0] +
_m4storage[4 + i] * vStorage[1] +
_m4storage[8 + i] * vStorage[2] +
@@ -1011,7 +1034,7 @@
/// Returns the dot product of column [j] and [v].
double dotColumn(int j, Vector4 v) {
- final vStorage = v._v4storage;
+ final Float64List vStorage = v._v4storage;
return _m4storage[j * 4] * vStorage[0] +
_m4storage[j * 4 + 1] * vStorage[1] +
_m4storage[j * 4 + 2] * vStorage[2] +
@@ -1069,34 +1092,34 @@
/// Returns relative error between [this] and [correct]
double relativeError(Matrix4 correct) {
- Matrix4 diff = correct - this;
- double correct_norm = correct.infinityNorm();
- double diff_norm = diff.infinityNorm();
+ final Matrix4 diff = correct - this;
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = diff.infinityNorm();
return diff_norm / correct_norm;
}
/// Returns absolute error between [this] and [correct]
double absoluteError(Matrix4 correct) {
- double this_norm = infinityNorm();
- double correct_norm = correct.infinityNorm();
- double diff_norm = (this_norm - correct_norm).abs();
+ final double this_norm = infinityNorm();
+ final double correct_norm = correct.infinityNorm();
+ final double diff_norm = (this_norm - correct_norm).abs();
return diff_norm;
}
/// Returns the translation vector from this homogeneous transformation matrix.
Vector3 getTranslation() {
- double z = _m4storage[14];
- double y = _m4storage[13];
- double x = _m4storage[12];
+ final double z = _m4storage[14];
+ final double y = _m4storage[13];
+ final double x = _m4storage[12];
return new Vector3(x, y, z);
}
/// Sets the translation vector in this homogeneous transformation matrix.
void setTranslation(Vector3 t) {
- final tStorage = t._v3storage;
- double z = tStorage[2];
- double y = tStorage[1];
- double x = tStorage[0];
+ final Float64List tStorage = t._v3storage;
+ final double z = tStorage[2];
+ final double y = tStorage[1];
+ final double x = tStorage[0];
_m4storage[14] = z;
_m4storage[13] = y;
_m4storage[12] = x;
@@ -1111,7 +1134,7 @@
/// Returns the rotation matrix from this homogeneous transformation matrix.
Matrix3 getRotation() {
- Matrix3 r = new Matrix3.zero();
+ final Matrix3 r = new Matrix3.zero();
copyRotation(r);
return r;
}
@@ -1119,7 +1142,7 @@
/// Copies the rotation matrix from this homogeneous transformation matrix
/// into [rotation].
void copyRotation(Matrix3 rotation) {
- final rStorage = rotation._m3storage;
+ final Float64List rStorage = rotation._m3storage;
rStorage[0] = _m4storage[0];
rStorage[1] = _m4storage[1];
rStorage[2] = _m4storage[2];
@@ -1133,7 +1156,7 @@
/// Sets the rotation matrix in this homogeneous transformation matrix.
void setRotation(Matrix3 r) {
- final rStorage = r._m3storage;
+ final Float64List rStorage = r._m3storage;
_m4storage[0] = rStorage[0];
_m4storage[1] = rStorage[1];
_m4storage[2] = rStorage[2];
@@ -1151,16 +1174,16 @@
/// Returns the max scale value of the 3 axes.
double getMaxScaleOnAxis() {
- final scaleXSq = _m4storage[0] * _m4storage[0] +
+ final double scaleXSq = _m4storage[0] * _m4storage[0] +
_m4storage[1] * _m4storage[1] +
_m4storage[2] * _m4storage[2];
- final scaleYSq = _m4storage[4] * _m4storage[4] +
+ final double scaleYSq = _m4storage[4] * _m4storage[4] +
_m4storage[5] * _m4storage[5] +
_m4storage[6] * _m4storage[6];
- final scaleZSq = _m4storage[8] * _m4storage[8] +
+ final double scaleZSq = _m4storage[8] * _m4storage[8] +
_m4storage[9] * _m4storage[9] +
_m4storage[10] * _m4storage[10];
- return Math.sqrt(Math.max(scaleXSq, Math.max(scaleYSq, scaleZSq)));
+ return math.sqrt(math.max(scaleXSq, math.max(scaleYSq, scaleZSq)));
}
/// Transposes just the upper 3x3 rotation matrix.
@@ -1191,42 +1214,42 @@
/// Set this matrix to be the inverse of [arg]
double copyInverse(Matrix4 arg) {
- final argStorage = arg._m4storage;
- double a00 = argStorage[0];
- double a01 = argStorage[1];
- double a02 = argStorage[2];
- double a03 = argStorage[3];
- double a10 = argStorage[4];
- double a11 = argStorage[5];
- double a12 = argStorage[6];
- double a13 = argStorage[7];
- double a20 = argStorage[8];
- double a21 = argStorage[9];
- double a22 = argStorage[10];
- double a23 = argStorage[11];
- double a30 = argStorage[12];
- double a31 = argStorage[13];
- double a32 = argStorage[14];
- double a33 = argStorage[15];
- var b00 = a00 * a11 - a01 * a10;
- var b01 = a00 * a12 - a02 * a10;
- var b02 = a00 * a13 - a03 * a10;
- var b03 = a01 * a12 - a02 * a11;
- var b04 = a01 * a13 - a03 * a11;
- var b05 = a02 * a13 - a03 * a12;
- var b06 = a20 * a31 - a21 * a30;
- var b07 = a20 * a32 - a22 * a30;
- var b08 = a20 * a33 - a23 * a30;
- var b09 = a21 * a32 - a22 * a31;
- var b10 = a21 * a33 - a23 * a31;
- var b11 = a22 * a33 - a23 * a32;
- var det =
+ 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 =
(b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06);
if (det == 0.0) {
setFrom(arg);
return 0.0;
}
- var invDet = 1.0 / det;
+ final double 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;
@@ -1247,11 +1270,11 @@
}
double invertRotation() {
- double det = determinant();
+ final double det = determinant();
if (det == 0.0) {
return 0.0;
}
- double invDet = 1.0 / det;
+ final double invDet = 1.0 / det;
double ix;
double iy;
double iz;
@@ -1293,8 +1316,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around X
void setRotationX(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m4storage[0] = 1.0;
_m4storage[1] = 0.0;
_m4storage[2] = 0.0;
@@ -1311,8 +1334,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Y
void setRotationY(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = 0.0;
_m4storage[2] = -s;
@@ -1329,8 +1352,8 @@
/// Sets the upper 3x3 to a rotation of [radians] around Z
void setRotationZ(double radians) {
- double c = Math.cos(radians);
- double s = Math.sin(radians);
+ final double c = math.cos(radians);
+ final double s = math.sin(radians);
_m4storage[0] = c;
_m4storage[1] = s;
_m4storage[2] = 0.0;
@@ -1348,22 +1371,22 @@
/// Converts into Adjugate matrix and scales by [scale]
void scaleAdjoint(double scale) {
// Adapted from code by Richard Carling.
- double a1 = _m4storage[0];
- double b1 = _m4storage[4];
- double c1 = _m4storage[8];
- double d1 = _m4storage[12];
- double a2 = _m4storage[1];
- double b2 = _m4storage[5];
- double c2 = _m4storage[9];
- double d2 = _m4storage[13];
- double a3 = _m4storage[2];
- double b3 = _m4storage[6];
- double c3 = _m4storage[10];
- double d3 = _m4storage[14];
- double a4 = _m4storage[3];
- double b4 = _m4storage[7];
- double c4 = _m4storage[11];
- double d4 = _m4storage[15];
+ 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];
_m4storage[0] = (b2 * (c3 * d4 - c4 * d3) -
c2 * (b3 * d4 - b4 * d3) +
d2 * (b3 * c4 - b4 * c3)) *
@@ -1434,19 +1457,19 @@
/// Returns [arg].
/// Primarily used by AABB transformation code.
Vector3 absoluteRotate(Vector3 arg) {
- double m00 = _m4storage[0].abs();
- double m01 = _m4storage[4].abs();
- double m02 = _m4storage[8].abs();
- double m10 = _m4storage[1].abs();
- double m11 = _m4storage[5].abs();
- double m12 = _m4storage[9].abs();
- double m20 = _m4storage[2].abs();
- double m21 = _m4storage[6].abs();
- double m22 = _m4storage[10].abs();
- final argStorage = arg._v3storage;
- double x = argStorage[0];
- double y = argStorage[1];
- double z = argStorage[2];
+ 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];
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;
@@ -1455,7 +1478,7 @@
/// Adds [o] to [this].
void add(Matrix4 o) {
- final oStorage = o._m4storage;
+ final Float64List oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] + oStorage[0];
_m4storage[1] = _m4storage[1] + oStorage[1];
_m4storage[2] = _m4storage[2] + oStorage[2];
@@ -1476,7 +1499,7 @@
/// Subtracts [o] from [this].
void sub(Matrix4 o) {
- final oStorage = o._m4storage;
+ final Float64List oStorage = o._m4storage;
_m4storage[0] = _m4storage[0] - oStorage[0];
_m4storage[1] = _m4storage[1] - oStorage[1];
_m4storage[2] = _m4storage[2] - oStorage[2];
@@ -1517,39 +1540,39 @@
/// Multiply [this] by [arg].
void multiply(Matrix4 arg) {
- 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];
+ 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];
_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);
@@ -1573,23 +1596,23 @@
/// Multiply a transposed [this] with [arg].
void transposeMultiply(Matrix4 arg) {
- double m00 = _m4storage[0];
- double m01 = _m4storage[1];
- double m02 = _m4storage[2];
- double m03 = _m4storage[3];
- double m10 = _m4storage[4];
- double m11 = _m4storage[5];
- double m12 = _m4storage[6];
- double m13 = _m4storage[7];
- double m20 = _m4storage[8];
- double m21 = _m4storage[9];
- double m22 = _m4storage[10];
- double m23 = _m4storage[11];
- double m30 = _m4storage[12];
- double m31 = _m4storage[13];
- double m32 = _m4storage[14];
- double m33 = _m4storage[15];
- final argStorage = arg._m4storage;
+ 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;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[1]) +
(m02 * argStorage[2]) +
@@ -1658,23 +1681,23 @@
/// Multiply [this] with a transposed [arg].
void multiplyTranspose(Matrix4 arg) {
- double m00 = _m4storage[0];
- double m01 = _m4storage[4];
- double m02 = _m4storage[8];
- double m03 = _m4storage[12];
- double m10 = _m4storage[1];
- double m11 = _m4storage[5];
- double m12 = _m4storage[9];
- double m13 = _m4storage[13];
- double m20 = _m4storage[2];
- double m21 = _m4storage[6];
- double m22 = _m4storage[10];
- double m23 = _m4storage[14];
- double m30 = _m4storage[3];
- double m31 = _m4storage[7];
- double m32 = _m4storage[11];
- double m33 = _m4storage[15];
- final argStorage = arg._m4storage;
+ 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;
_m4storage[0] = (m00 * argStorage[0]) +
(m01 * argStorage[4]) +
(m02 * argStorage[8]) +
@@ -1743,23 +1766,27 @@
/// Decomposes [this] into [translation], [rotation] and [scale] components.
void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) {
- final v = new Vector3.zero();
- var sx = (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
- var sy = (v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
- var sz =
+ final Vector3 v = new Vector3.zero();
+ double sx =
+ (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
+ final double sy =
+ (v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
+ final double sz =
(v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length;
- if (determinant() < 0) sx = -sx;
+ if (determinant() < 0) {
+ sx = -sx;
+ }
translation._v3storage[0] = _m4storage[12];
translation._v3storage[1] = _m4storage[13];
translation._v3storage[2] = _m4storage[14];
- final invSX = 1.0 / sx;
- final invSY = 1.0 / sy;
- final invSZ = 1.0 / sz;
+ final double invSX = 1.0 / sx;
+ final double invSY = 1.0 / sy;
+ final double invSZ = 1.0 / sz;
- final m = new Matrix4.copy(this);
+ final Matrix4 m = new Matrix4.copy(this);
m._m4storage[0] *= invSX;
m._m4storage[1] *= invSX;
m._m4storage[2] *= invSX;
@@ -1779,14 +1806,14 @@
/// Rotate [arg] of type [Vector3] using the rotation defined by [this].
Vector3 rotate3(Vector3 arg) {
- final argStorage = arg._v3storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float64List argStorage = arg._v3storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]);
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]);
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]);
argStorage[0] = x_;
@@ -1809,16 +1836,16 @@
/// Transform [arg] of type [Vector3] using the transformation defined by
/// [this].
Vector3 transform3(Vector3 arg) {
- final argStorage = arg._v3storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float64List argStorage = arg._v3storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
@@ -1843,20 +1870,20 @@
/// Transform [arg] of type [Vector4] using the transformation defined by
/// [this].
Vector4 transform(Vector4 arg) {
- final argStorage = arg._v4storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float64List argStorage = arg._v4storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
(_m4storage[12] * argStorage[3]);
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
(_m4storage[13] * argStorage[3]);
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
(_m4storage[14] * argStorage[3]);
- final w_ = (_m4storage[3] * argStorage[0]) +
+ final double w_ = (_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
(_m4storage[15] * argStorage[3]);
@@ -1870,20 +1897,20 @@
/// Transform [arg] of type [Vector3] using the perspective transformation
/// defined by [this].
Vector3 perspectiveTransform(Vector3 arg) {
- final argStorage = arg._v3storage;
- final x_ = (_m4storage[0] * argStorage[0]) +
+ final Float64List argStorage = arg._v3storage;
+ final double x_ = (_m4storage[0] * argStorage[0]) +
(_m4storage[4] * argStorage[1]) +
(_m4storage[8] * argStorage[2]) +
_m4storage[12];
- final y_ = (_m4storage[1] * argStorage[0]) +
+ final double y_ = (_m4storage[1] * argStorage[0]) +
(_m4storage[5] * argStorage[1]) +
(_m4storage[9] * argStorage[2]) +
_m4storage[13];
- final z_ = (_m4storage[2] * argStorage[0]) +
+ final double z_ = (_m4storage[2] * argStorage[0]) +
(_m4storage[6] * argStorage[1]) +
(_m4storage[10] * argStorage[2]) +
_m4storage[14];
- final w_ = 1.0 /
+ final double w_ = 1.0 /
((_m4storage[3] * argStorage[0]) +
(_m4storage[7] * argStorage[1]) +
(_m4storage[11] * argStorage[2]) +
@@ -1908,7 +1935,7 @@
/// Copies [this] into [array] starting at [offset].
void copyIntoArray(List<num> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
array[i + 15] = _m4storage[15];
array[i + 14] = _m4storage[14];
array[i + 13] = _m4storage[13];
@@ -1929,7 +1956,7 @@
/// Copies elements from [array] into [this] starting at [offset].
void copyFromArray(List<double> array, [int offset = 0]) {
- int i = offset;
+ final int i = offset;
_m4storage[15] = array[i + 15];
_m4storage[14] = array[i + 14];
_m4storage[13] = array[i + 13];
@@ -1950,8 +1977,8 @@
/// Multiply [this] to each set of xyz values in [array] starting at [offset].
List<double> applyToVector3Array(List<double> array, [int offset = 0]) {
- for (var i = 0, j = offset; i < array.length; i += 3, j += 3) {
- final v = new Vector3.array(array, j)..applyMatrix4(this);
+ for (int i = 0, j = offset; i < array.length; i += 3, j += 3) {
+ final Vector3 v = new Vector3.array(array, j)..applyMatrix4(this);
array[j] = v.storage[0];
array[j + 1] = v.storage[1];
array[j + 2] = v.storage[2];
@@ -1961,63 +1988,69 @@
}
Vector3 get right {
- double x = _m4storage[0];
- double y = _m4storage[1];
- double z = _m4storage[2];
+ final double x = _m4storage[0];
+ final double y = _m4storage[1];
+ final double z = _m4storage[2];
return new Vector3(x, y, z);
}
Vector3 get up {
- double x = _m4storage[4];
- double y = _m4storage[5];
- double z = _m4storage[6];
+ final double x = _m4storage[4];
+ final double y = _m4storage[5];
+ final double z = _m4storage[6];
return new Vector3(x, y, z);
}
Vector3 get forward {
- double x = _m4storage[8];
- double y = _m4storage[9];
- double z = _m4storage[10];
+ final double x = _m4storage[8];
+ final double y = _m4storage[9];
+ final double z = _m4storage[10];
return new Vector3(x, y, z);
}
/// Is [this] the identity matrix?
- bool isIdentity() {
- return _m4storage[0] == 1.0 // col 1
- && _m4storage[1] == 0.0
- && _m4storage[2] == 0.0
- && _m4storage[3] == 0.0
- && _m4storage[4] == 0.0 // col 2
- && _m4storage[5] == 1.0
- && _m4storage[6] == 0.0
- && _m4storage[7] == 0.0
- && _m4storage[8] == 0.0 // col 3
- && _m4storage[9] == 0.0
- && _m4storage[10] == 1.0
- && _m4storage[11] == 0.0
- && _m4storage[12] == 0.0 // col 4
- && _m4storage[13] == 0.0
- && _m4storage[14] == 0.0
- && _m4storage[15] == 1.0;
- }
+ bool isIdentity() =>
+ _m4storage[0] == 1.0 // col 1
+ &&
+ _m4storage[1] == 0.0 &&
+ _m4storage[2] == 0.0 &&
+ _m4storage[3] == 0.0 &&
+ _m4storage[4] == 0.0 // col 2
+ &&
+ _m4storage[5] == 1.0 &&
+ _m4storage[6] == 0.0 &&
+ _m4storage[7] == 0.0 &&
+ _m4storage[8] == 0.0 // col 3
+ &&
+ _m4storage[9] == 0.0 &&
+ _m4storage[10] == 1.0 &&
+ _m4storage[11] == 0.0 &&
+ _m4storage[12] == 0.0 // col 4
+ &&
+ _m4storage[13] == 0.0 &&
+ _m4storage[14] == 0.0 &&
+ _m4storage[15] == 1.0;
/// Is [this] the zero matrix?
- bool isZero() {
- return _m4storage[0] == 0.0 // col 1
- && _m4storage[1] == 0.0
- && _m4storage[2] == 0.0
- && _m4storage[3] == 0.0
- && _m4storage[4] == 0.0 // col 2
- && _m4storage[5] == 0.0
- && _m4storage[6] == 0.0
- && _m4storage[7] == 0.0
- && _m4storage[8] == 0.0 // col 3
- && _m4storage[9] == 0.0
- && _m4storage[10] == 0.0
- && _m4storage[11] == 0.0
- && _m4storage[12] == 0.0 // col 4
- && _m4storage[13] == 0.0
- && _m4storage[14] == 0.0
- && _m4storage[15] == 0.0;
- }
+ bool isZero() =>
+ _m4storage[0] == 0.0 // col 1
+ &&
+ _m4storage[1] == 0.0 &&
+ _m4storage[2] == 0.0 &&
+ _m4storage[3] == 0.0 &&
+ _m4storage[4] == 0.0 // col 2
+ &&
+ _m4storage[5] == 0.0 &&
+ _m4storage[6] == 0.0 &&
+ _m4storage[7] == 0.0 &&
+ _m4storage[8] == 0.0 // col 3
+ &&
+ _m4storage[9] == 0.0 &&
+ _m4storage[10] == 0.0 &&
+ _m4storage[11] == 0.0 &&
+ _m4storage[12] == 0.0 // col 4
+ &&
+ _m4storage[13] == 0.0 &&
+ _m4storage[14] == 0.0 &&
+ _m4storage[15] == 0.0;
}
diff --git a/lib/src/vector_math_64/obb3.dart b/lib/src/vector_math_64/obb3.dart
index 6966714..8114cb0 100644
--- a/lib/src/vector_math_64/obb3.dart
+++ b/lib/src/vector_math_64/obb3.dart
@@ -84,23 +84,29 @@
/// Rotate [this] by the rotation matrix [t].
void rotate(Matrix3 t) {
- t.transform(_axis0..scale(_halfExtents.x));
- t.transform(_axis1..scale(_halfExtents.y));
- t.transform(_axis2..scale(_halfExtents.z));
- _halfExtents.x = _axis0.normalize();
- _halfExtents.y = _axis1.normalize();
- _halfExtents.z = _axis2.normalize();
+ t
+ ..transform(_axis0..scale(_halfExtents.x))
+ ..transform(_axis1..scale(_halfExtents.y))
+ ..transform(_axis2..scale(_halfExtents.z));
+
+ _halfExtents
+ ..x = _axis0.normalize()
+ ..y = _axis1.normalize()
+ ..z = _axis2.normalize();
}
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- t.transform3(_center);
- t.rotate3(_axis0..scale(_halfExtents.x));
- t.rotate3(_axis1..scale(_halfExtents.y));
- t.rotate3(_axis2..scale(_halfExtents.z));
- _halfExtents.x = _axis0.normalize();
- _halfExtents.y = _axis1.normalize();
- _halfExtents.z = _axis2.normalize();
+ t
+ ..transform3(_center)
+ ..rotate3(_axis0..scale(_halfExtents.x))
+ ..rotate3(_axis1..scale(_halfExtents.y))
+ ..rotate3(_axis2..scale(_halfExtents.z));
+
+ _halfExtents
+ ..x = _axis0.normalize()
+ ..y = _axis1.normalize()
+ ..z = _axis2.normalize();
}
/// Store the corner with [cornerIndex] in [corner].
@@ -163,40 +169,41 @@
/// Find the closest point [q] on the OBB to the point [p] and store it in [q].
void closestPointTo(Vector3 p, Vector3 q) {
- final d = p - _center;
+ final Vector3 d = p - _center;
q.setFrom(_center);
- var dist = d.dot(_axis0);
- dist = dist.clamp(-_halfExtents.x, _halfExtents.x);
+ double dist = d.dot(_axis0);
+ dist = dist.clamp(-_halfExtents.x, _halfExtents.x).toDouble();
q.addScaled(_axis0, dist);
dist = d.dot(_axis1);
- dist = dist.clamp(-_halfExtents.y, _halfExtents.y);
+ dist = dist.clamp(-_halfExtents.y, _halfExtents.y).toDouble();
q.addScaled(_axis1, dist);
dist = d.dot(_axis2);
- dist = dist.clamp(-_halfExtents.z, _halfExtents.z);
+ dist = dist.clamp(-_halfExtents.z, _halfExtents.z).toDouble();
q.addScaled(_axis2, dist);
}
// Avoid allocating these instance on every call to intersectsWithObb3
- static final _r = new Matrix3.zero();
- static final _absR = new Matrix3.zero();
- static final _t = new Vector3.zero();
+ static final Matrix3 _r = new Matrix3.zero();
+ static final Matrix3 _absR = new Matrix3.zero();
+ static final Vector3 _t = new Vector3.zero();
/// Check for intersection between [this] and [other].
bool intersectsWithObb3(Obb3 other, [double epsilon = 1e-3]) {
// Compute rotation matrix expressing other in this's coordinate frame
- _r.setEntry(0, 0, _axis0.dot(other._axis0));
- _r.setEntry(1, 0, _axis1.dot(other._axis0));
- _r.setEntry(2, 0, _axis2.dot(other._axis0));
- _r.setEntry(0, 1, _axis0.dot(other._axis1));
- _r.setEntry(1, 1, _axis1.dot(other._axis1));
- _r.setEntry(2, 1, _axis2.dot(other._axis1));
- _r.setEntry(0, 2, _axis0.dot(other._axis2));
- _r.setEntry(1, 2, _axis1.dot(other._axis2));
- _r.setEntry(2, 2, _axis2.dot(other._axis2));
+ _r
+ ..setEntry(0, 0, _axis0.dot(other._axis0))
+ ..setEntry(1, 0, _axis1.dot(other._axis0))
+ ..setEntry(2, 0, _axis2.dot(other._axis0))
+ ..setEntry(0, 1, _axis0.dot(other._axis1))
+ ..setEntry(1, 1, _axis1.dot(other._axis1))
+ ..setEntry(2, 1, _axis2.dot(other._axis1))
+ ..setEntry(0, 2, _axis0.dot(other._axis2))
+ ..setEntry(1, 2, _axis1.dot(other._axis2))
+ ..setEntry(2, 2, _axis2.dot(other._axis2));
// Compute translation vector t
_t
@@ -209,8 +216,8 @@
// Compute common subexpressions. Add in an epsilon term to
// counteract arithmetic errors when two edges are parallel and
// their cross product is (near) null.
- for (var i = 0; i < 3; i++) {
- for (var j = 0; j < 3; j++) {
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
_absR.setEntry(i, j, _r.entry(i, j).abs() + epsilon);
}
}
@@ -219,7 +226,7 @@
double rb;
// Test axes L = A0, L = A1, L = A2
- for (var i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
ra = _halfExtents[i];
rb = other._halfExtents[0] * _absR.entry(i, 0) +
other._halfExtents[1] * _absR.entry(i, 1) +
@@ -231,7 +238,7 @@
}
// Test axes L = B0, L = B1, L = B2
- for (var i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
ra = _halfExtents[0] * _absR.entry(0, i) +
_halfExtents[1] * _absR.entry(1, i) +
_halfExtents[2] * _absR.entry(2, i);
@@ -332,23 +339,26 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _triangle = new Triangle();
- static final _aabb3 = new Aabb3();
- static final _zeroVector = new Vector3.zero();
+ static final Triangle _triangle = new Triangle();
+ static final Aabb3 _aabb3 = new Aabb3();
+ static final Vector3 _zeroVector = new Vector3.zero();
/// Return if [this] intersects with [other]
bool intersectsWithTriangle(Triangle other, {IntersectionResult result}) {
_triangle.copyFrom(other);
- _triangle.point0.sub(_center);
- _triangle.point0.setValues(_triangle.point0.dot(axis0),
- _triangle.point0.dot(axis1), _triangle.point0.dot(axis2));
- _triangle.point1.sub(_center);
- _triangle.point1.setValues(_triangle.point1.dot(axis0),
- _triangle.point1.dot(axis1), _triangle.point1.dot(axis2));
- _triangle.point2.sub(_center);
- _triangle.point2.setValues(_triangle.point2.dot(axis0),
- _triangle.point2.dot(axis1), _triangle.point2.dot(axis2));
+ _triangle.point0
+ ..sub(_center)
+ ..setValues(_triangle.point0.dot(axis0), _triangle.point0.dot(axis1),
+ _triangle.point0.dot(axis2));
+ _triangle.point1
+ ..sub(_center)
+ ..setValues(_triangle.point1.dot(axis0), _triangle.point1.dot(axis1),
+ _triangle.point1.dot(axis2));
+ _triangle.point2
+ ..sub(_center)
+ ..setValues(_triangle.point2.dot(axis0), _triangle.point2.dot(axis1),
+ _triangle.point2.dot(axis2));
_aabb3.setCenterAndHalfExtents(_zeroVector, _halfExtents);
@@ -356,15 +366,14 @@
}
// Avoid allocating these instance on every call to intersectsWithVector3
- static final _vector = new Vector3.zero();
+ static final Vector3 _vector = new Vector3.zero();
/// Return if [this] intersects with [other]
bool intersectsWithVector3(Vector3 other) {
- _vector.setFrom(other);
-
- _vector.sub(_center);
- _vector.setValues(
- _vector.dot(axis0), _vector.dot(axis1), _vector.dot(axis2));
+ _vector
+ ..setFrom(other)
+ ..sub(_center)
+ ..setValues(_vector.dot(axis0), _vector.dot(axis1), _vector.dot(axis2));
_aabb3.setCenterAndHalfExtents(_zeroVector, _halfExtents);
@@ -372,8 +381,8 @@
}
// Avoid allocating these instance on every call to intersectsWithTriangle
- static final _quadTriangle0 = new Triangle();
- static final _quadTriangle1 = new Triangle();
+ static final Triangle _quadTriangle0 = new Triangle();
+ static final Triangle _quadTriangle1 = new Triangle();
/// Return if [this] intersects with [other]
bool intersectsWithQuad(Quad other, {IntersectionResult result}) {
diff --git a/lib/src/vector_math_64/opengl.dart b/lib/src/vector_math_64/opengl.dart
index b53dfaa..994cc31 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) {
- Vector3 right = forwardDirection.cross(upDirection)..normalize();
- Vector3 c1 = right;
- Vector3 c2 = upDirection;
- Vector3 c3 = -forwardDirection;
+ final Vector3 right = forwardDirection.cross(upDirection)..normalize();
+ final Vector3 c1 = right;
+ final Vector3 c2 = upDirection;
+ final Vector3 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,16 +74,13 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition,
Vector3 cameraFocusPosition, Vector3 upDirection) {
- Vector3 z = cameraPosition - cameraFocusPosition;
- z.normalize();
- Vector3 x = upDirection.cross(z);
- x.normalize();
- Vector3 y = z.cross(x);
- y.normalize();
+ final Vector3 z = (cameraPosition - cameraFocusPosition)..normalize();
+ final Vector3 x = upDirection.cross(z)..normalize();
+ final Vector3 y = z.cross(x)..normalize();
- double rotatedEyeX = -x.dot(cameraPosition);
- double rotatedEyeY = -y.dot(cameraPosition);
- double rotatedEyeZ = -z.dot(cameraPosition);
+ final double rotatedEyeX = -x.dot(cameraPosition);
+ final double rotatedEyeY = -y.dot(cameraPosition);
+ final double 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);
@@ -96,7 +93,7 @@
/// [upDirection] specifies the direction of the up vector (usually, +Y).
Matrix4 makeViewMatrix(
Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setViewMatrix(r, cameraPosition, cameraFocusPosition, upDirection);
return r;
}
@@ -113,16 +110,17 @@
/// (always positive).
void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians,
double aspectRatio, double zNear, double zFar) {
- final double height = Math.tan(fovYRadians * 0.5);
+ final double height = math.tan(fovYRadians * 0.5);
final double width = height * aspectRatio;
final double near_minus_far = zNear - zFar;
- final Matrix4 view = perspectiveMatrix..setZero();
- view.setEntry(0, 0, 1.0 / width);
- view.setEntry(1, 1, 1.0 / height);
- view.setEntry(2, 2, (zFar + zNear) / near_minus_far);
- view.setEntry(3, 2, -1.0);
- view.setEntry(2, 3, (2.0 * zNear * zFar) / near_minus_far);
+ perspectiveMatrix
+ ..setZero()
+ ..setEntry(0, 0, 1.0 / width)
+ ..setEntry(1, 1, 1.0 / height)
+ ..setEntry(2, 2, (zFar + zNear) / near_minus_far)
+ ..setEntry(3, 2, -1.0)
+ ..setEntry(2, 3, (2.0 * zNear * zFar) / near_minus_far);
}
/// Constructs a new OpenGL perspective projection matrix.
@@ -137,7 +135,7 @@
/// (always positive).
Matrix4 makePerspectiveMatrix(
double fovYRadians, double aspectRatio, double zNear, double zFar) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setPerspectiveMatrix(r, fovYRadians, aspectRatio, zNear, zFar);
return r;
}
@@ -151,15 +149,16 @@
/// (always positive).
void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians,
double aspectRatio, double zNear) {
- final double height = Math.tan(fovYRadians * 0.5);
+ final double height = math.tan(fovYRadians * 0.5);
final double width = height * aspectRatio;
- final Matrix4 view = infiniteMatrix..setZero();
- view.setEntry(0, 0, 1.0 / width);
- view.setEntry(1, 1, 1.0 / height);
- view.setEntry(2, 2, -1.0);
- view.setEntry(3, 2, -1.0);
- view.setEntry(2, 3, -2.0 * zNear);
+ infiniteMatrix
+ ..setZero()
+ ..setEntry(0, 0, 1.0 / width)
+ ..setEntry(1, 1, 1.0 / height)
+ ..setEntry(2, 2, -1.0)
+ ..setEntry(3, 2, -1.0)
+ ..setEntry(2, 3, -2.0 * zNear);
}
/// Constructs a new OpenGL infinite projection matrix.
@@ -172,7 +171,7 @@
/// (always positive).
Matrix4 makeInfiniteMatrix(
double fovYRadians, double aspectRatio, double zNear) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setInfiniteMatrix(r, fovYRadians, aspectRatio, zNear);
return r;
}
@@ -187,18 +186,19 @@
/// planes.
void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right,
double bottom, double top, double near, double far) {
- double two_near = 2.0 * near;
- double right_minus_left = right - left;
- double top_minus_bottom = top - bottom;
- double far_minus_near = far - near;
- Matrix4 view = perspectiveMatrix..setZero();
- view.setEntry(0, 0, two_near / right_minus_left);
- view.setEntry(1, 1, two_near / top_minus_bottom);
- view.setEntry(0, 2, (right + left) / right_minus_left);
- view.setEntry(1, 2, (top + bottom) / top_minus_bottom);
- view.setEntry(2, 2, -(far + near) / far_minus_near);
- view.setEntry(3, 2, -1.0);
- view.setEntry(2, 3, -(two_near * far) / far_minus_near);
+ 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;
+ perspectiveMatrix
+ ..setZero()
+ ..setEntry(0, 0, two_near / right_minus_left)
+ ..setEntry(1, 1, two_near / top_minus_bottom)
+ ..setEntry(0, 2, (right + left) / right_minus_left)
+ ..setEntry(1, 2, (top + bottom) / top_minus_bottom)
+ ..setEntry(2, 2, -(far + near) / far_minus_near)
+ ..setEntry(3, 2, -1.0)
+ ..setEntry(2, 3, -(two_near * far) / far_minus_near);
}
/// Constructs a new OpenGL perspective projection matrix.
@@ -211,7 +211,7 @@
/// planes.
Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top,
double near, double far) {
- Matrix4 view = new Matrix4.zero();
+ final Matrix4 view = new Matrix4.zero();
setFrustumMatrix(view, left, right, bottom, top, near, far);
return view;
}
@@ -226,20 +226,21 @@
/// planes.
void setOrthographicMatrix(Matrix4 orthographicMatrix, double left,
double right, double bottom, double top, double near, double far) {
- double rml = right - left;
- double rpl = right + left;
- double tmb = top - bottom;
- double tpb = top + bottom;
- double fmn = far - near;
- double fpn = far + near;
- Matrix4 r = orthographicMatrix..setZero();
- r.setEntry(0, 0, 2.0 / rml);
- r.setEntry(1, 1, 2.0 / tmb);
- r.setEntry(2, 2, -2.0 / fmn);
- r.setEntry(0, 3, -rpl / rml);
- r.setEntry(1, 3, -tpb / tmb);
- r.setEntry(2, 3, -fpn / fmn);
- r.setEntry(3, 3, 1.0);
+ 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;
+ orthographicMatrix
+ ..setZero()
+ ..setEntry(0, 0, 2.0 / rml)
+ ..setEntry(1, 1, 2.0 / tmb)
+ ..setEntry(2, 2, -2.0 / fmn)
+ ..setEntry(0, 3, -rpl / rml)
+ ..setEntry(1, 3, -tpb / tmb)
+ ..setEntry(2, 3, -fpn / fmn)
+ ..setEntry(3, 3, 1.0);
}
/// Constructs a new OpenGL orthographic projection matrix.
@@ -252,7 +253,7 @@
/// planes.
Matrix4 makeOrthographicMatrix(double left, double right, double bottom,
double top, double near, double far) {
- Matrix4 r = new Matrix4.zero();
+ final Matrix4 r = new Matrix4.zero();
setOrthographicMatrix(r, left, right, bottom, top, near, far);
return r;
}
@@ -260,14 +261,15 @@
/// Returns a transformation matrix that transforms points onto
/// the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) {
- Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- Matrix4 outer = new Matrix4.outer(v, v);
+ final Matrix4 outer = new Matrix4.outer(v, v);
Matrix4 r = new Matrix4.zero();
r = r - outer;
- Vector3 scaledNormal = (planeNormal.scaled(dot3(planePoint, planeNormal)));
- Vector4 T = new Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
- scaledNormal.storage[2], 1.0);
+ final Vector3 scaledNormal =
+ (planeNormal.scaled(dot3(planePoint, planeNormal)));
+ final Vector4 T = new Vector4(scaledNormal.storage[0],
+ scaledNormal.storage[1], scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
}
@@ -275,16 +277,15 @@
/// Returns a transformation matrix that transforms points by reflecting
/// them through the plane specified with [planeNormal] and [planePoint].
Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
- Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
+ final Vector4 v = new Vector4(planeNormal.storage[0], planeNormal.storage[1],
planeNormal.storage[2], 0.0);
- Matrix4 outer = new Matrix4.outer(v, v);
- outer.scale(2.0);
+ final Matrix4 outer = new Matrix4.outer(v, v)..scale(2.0);
Matrix4 r = new Matrix4.zero();
r = r - outer;
- double scale = 2.0 * planePoint.dot(planeNormal);
- Vector3 scaledNormal = (planeNormal.scaled(scale));
- Vector4 T = new Vector4(scaledNormal.storage[0], scaledNormal.storage[1],
- scaledNormal.storage[2], 1.0);
+ final double scale = 2.0 * planePoint.dot(planeNormal);
+ final Vector3 scaledNormal = (planeNormal.scaled(scale));
+ final Vector4 T = new Vector4(scaledNormal.storage[0],
+ scaledNormal.storage[1], scaledNormal.storage[2], 1.0);
r.setColumn(3, T);
return r;
}
@@ -333,19 +334,21 @@
}
// Copy camera matrix.
- Matrix4 invertedCameraMatrix = new Matrix4.copy(cameraMatrix);
+ final Matrix4 invertedCameraMatrix = new Matrix4.copy(cameraMatrix);
// Invert the camera matrix.
invertedCameraMatrix.invert();
// Determine intersection point.
- Vector4 v = new Vector4(pickX, pickY, pickZ, 1.0);
+ final Vector4 v =
+ new Vector4(pickX.toDouble(), pickY.toDouble(), pickZ.toDouble(), 1.0);
invertedCameraMatrix.transform(v);
if (v.w == 0.0) {
return false;
}
- double invW = 1.0 / v.w;
- pickWorld.x = v.x * invW;
- pickWorld.y = v.y * invW;
- pickWorld.z = v.z * invW;
+ final double invW = 1.0 / v.w;
+ pickWorld
+ ..x = v.x * invW
+ ..y = v.y * invW
+ ..z = v.z * invW;
return true;
}
diff --git a/lib/src/vector_math_64/plane.dart b/lib/src/vector_math_64/plane.dart
index c11d87d..2ad5b8a 100644
--- a/lib/src/vector_math_64/plane.dart
+++ b/lib/src/vector_math_64/plane.dart
@@ -11,25 +11,26 @@
/// 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 cross = new Vector3.zero();
+ final Vector3 cross = new Vector3.zero();
b.normal.crossInto(c.normal, cross);
- final f = -a.normal.dot(cross);
+ final double f = -a.normal.dot(cross);
- final v1 = cross.scaled(a.constant);
+ final Vector3 v1 = cross.scaled(a.constant);
c.normal.crossInto(a.normal, cross);
- final v2 = cross.scaled(b.constant);
+ final Vector3 v2 = cross.scaled(b.constant);
a.normal.crossInto(b.normal, cross);
- final v3 = cross.scaled(c.constant);
+ final Vector3 v3 = cross.scaled(c.constant);
- result.x = (v1.x + v2.x + v3.x) / f;
- result.y = (v1.y + v2.y + v3.y) / f;
- result.z = (v1.z + v2.z + v3.z) / f;
+ result
+ ..x = (v1.x + v2.x + v3.x) / f
+ ..y = (v1.y + v2.y + v3.y) / f
+ ..z = (v1.z + v2.z + v3.z) / f;
}
Vector3 get normal => _normal;
@@ -63,12 +64,10 @@
}
void normalize() {
- var inverseLength = 1.0 / normal.length;
+ final double inverseLength = 1.0 / normal.length;
_normal.scale(inverseLength);
_constant *= inverseLength;
}
- double distanceToVector3(Vector3 point) {
- return _normal.dot(point) + _constant;
- }
+ double distanceToVector3(Vector3 point) => _normal.dot(point) + _constant;
}
diff --git a/lib/src/vector_math_64/quad.dart b/lib/src/vector_math_64/quad.dart
index ab5da13..ea605f7 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 v0 = _point0.clone()..sub(_point1);
+ final Vector3 v0 = _point0.clone()..sub(_point1);
normal
..setFrom(_point2)
..sub(_point1)
@@ -74,10 +74,11 @@
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- t.transform3(_point0);
- t.transform3(_point1);
- t.transform3(_point2);
- t.transform3(_point3);
+ t
+ ..transform3(_point0)
+ ..transform3(_point1)
+ ..transform3(_point2)
+ ..transform3(_point3);
}
/// Translate [this] by [offset].
diff --git a/lib/src/vector_math_64/quaternion.dart b/lib/src/vector_math_64/quaternion.dart
index 22126ec..5681555 100644
--- a/lib/src/vector_math_64/quaternion.dart
+++ b/lib/src/vector_math_64/quaternion.dart
@@ -64,7 +64,7 @@
/// Constructs a quaternion with a random rotation. The random number
/// generator [rn] is used to generate the random numbers for the rotation.
- factory Quaternion.random(Math.Random rn) =>
+ factory Quaternion.random(math.Random rn) =>
new Quaternion._()..setRandom(rn);
/// Constructs a quaternion set to the identity quaternion.
@@ -93,7 +93,7 @@
/// Copy [source] into [this].
void setFrom(Quaternion source) {
- final sourceStorage = source._qStorage;
+ final Float64List sourceStorage = source._qStorage;
_qStorage[0] = sourceStorage[0];
_qStorage[1] = sourceStorage[1];
_qStorage[2] = sourceStorage[2];
@@ -110,36 +110,36 @@
/// Set the quaternion with rotation of [radians] around [axis].
void setAxisAngle(Vector3 axis, double radians) {
- final len = axis.length;
+ final double len = axis.length;
if (len == 0.0) {
return;
}
- final halfSin = Math.sin(radians * 0.5) / len;
- final axisStorage = axis.storage;
+ final double halfSin = math.sin(radians * 0.5) / len;
+ final Float64List axisStorage = axis.storage;
_qStorage[0] = axisStorage[0] * halfSin;
_qStorage[1] = axisStorage[1] * halfSin;
_qStorage[2] = axisStorage[2] * halfSin;
- _qStorage[3] = Math.cos(radians * 0.5);
+ _qStorage[3] = math.cos(radians * 0.5);
}
/// Set the quaternion with rotation from a rotation matrix [rotationMatrix].
void setFromRotation(Matrix3 rotationMatrix) {
- final rotationMatrixStorage = rotationMatrix.storage;
- final trace = rotationMatrix.trace();
+ final Float64List rotationMatrixStorage = rotationMatrix.storage;
+ final double trace = rotationMatrix.trace();
if (trace > 0.0) {
- var s = Math.sqrt(trace + 1.0);
+ double s = math.sqrt(trace + 1.0);
_qStorage[3] = s * 0.5;
s = 0.5 / s;
_qStorage[0] = (rotationMatrixStorage[5] - rotationMatrixStorage[7]) * s;
_qStorage[1] = (rotationMatrixStorage[6] - rotationMatrixStorage[2]) * s;
_qStorage[2] = (rotationMatrixStorage[1] - rotationMatrixStorage[3]) * s;
} else {
- var i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
+ final int i = rotationMatrixStorage[0] < rotationMatrixStorage[4]
? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1)
: (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0);
- var j = (i + 1) % 3;
- var k = (i + 2) % 3;
- var s = Math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] -
+ final int j = (i + 1) % 3;
+ final int k = (i + 2) % 3;
+ double s = math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] -
rotationMatrixStorage[rotationMatrix.index(j, j)] -
rotationMatrixStorage[rotationMatrix.index(k, k)] +
1.0);
@@ -158,16 +158,16 @@
}
void setFromTwoVectors(Vector3 a, Vector3 b) {
- Vector3 v1 = a.normalized();
- Vector3 v2 = b.normalized();
+ final Vector3 v1 = a.normalized();
+ final Vector3 v2 = b.normalized();
- double c = v1.dot(v2);
- double angle = Math.acos(c);
+ final double c = v1.dot(v2);
+ double angle = math.acos(c);
Vector3 axis = v1.cross(v2);
if ((1.0 + c).abs() < 0.0005) {
// c \approx -1 indicates 180 degree rotation
- angle = Math.PI;
+ angle = math.PI;
// a and b are parallel in opposite directions. We need any
// vector as our rotation axis that is perpendicular.
@@ -190,18 +190,18 @@
/// Set the quaternion to a random rotation. The random number generator [rn]
/// is used to generate the random numbers for the rotation.
- void setRandom(Math.Random rn) {
+ void setRandom(math.Random rn) {
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// pg. 124-132.
- 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);
+ 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);
_qStorage[0] = s1 * r1;
_qStorage[1] = c1 * r1;
_qStorage[2] = s2 * r2;
@@ -211,19 +211,19 @@
/// Set the quaternion to the time derivative of [q] with angular velocity
/// [omega].
void setDQ(Quaternion q, Vector3 omega) {
- 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;
+ 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;
_qStorage[0] = _x * 0.5;
_qStorage[1] = _y * 0.5;
_qStorage[2] = _z * 0.5;
@@ -232,15 +232,15 @@
/// Set quaternion with rotation of [yaw], [pitch] and [roll].
void setEuler(double yaw, double pitch, double roll) {
- 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);
+ 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);
_qStorage[0] = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw;
_qStorage[1] = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw;
_qStorage[2] = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw;
@@ -249,11 +249,11 @@
/// Normalize [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_qStorage[0] *= d;
_qStorage[1] *= d;
_qStorage[2] *= d;
@@ -270,7 +270,7 @@
/// Invert [this].
void inverse() {
- final l = 1.0 / length2;
+ final double l = 1.0 / length2;
_qStorage[3] = _qStorage[3] * l;
_qStorage[2] = -_qStorage[2] * l;
_qStorage[1] = -_qStorage[1] * l;
@@ -287,36 +287,36 @@
Quaternion inverted() => clone()..inverse();
/// [radians] of rotation around the [axis] of the rotation.
- double get radians => 2.0 * Math.acos(_qStorage[3]);
+ double get radians => 2.0 * math.acos(_qStorage[3]);
/// [axis] of rotation.
Vector3 get axis {
- final den = 1.0 - (_qStorage[3] * _qStorage[3]);
+ final double den = 1.0 - (_qStorage[3] * _qStorage[3]);
if (den < 0.0005) {
// 0-angle rotation, so axis does not matter
return new Vector3.zero();
}
- final scale = 1.0 / Math.sqrt(den);
+ final double scale = 1.0 / math.sqrt(den);
return new Vector3(
_qStorage[0] * scale, _qStorage[1] * scale, _qStorage[2] * scale);
}
/// Length squared.
double get length2 {
- final x = _qStorage[0];
- final y = _qStorage[1];
- final z = _qStorage[2];
- final w = _qStorage[3];
+ final double x = _qStorage[0];
+ final double y = _qStorage[1];
+ final double z = _qStorage[2];
+ final double w = _qStorage[3];
return (x * x) + (y * y) + (z * z) + (w * w);
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Returns a copy of [v] rotated by quaternion.
Vector3 rotated(Vector3 v) {
- final out = v.clone();
+ final Vector3 out = v.clone();
rotate(out);
return out;
}
@@ -324,22 +324,22 @@
/// Rotates [v] by [this].
Vector3 rotate(Vector3 v) {
// conjugate(this) * [v,0] * this
- 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;
+ 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;
vStorage[2] = result_z;
vStorage[1] = result_y;
vStorage[0] = result_x;
@@ -348,7 +348,7 @@
/// Add [arg] to [this].
void add(Quaternion arg) {
- final argStorage = arg._qStorage;
+ final Float64List argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] + argStorage[0];
_qStorage[1] = _qStorage[1] + argStorage[1];
_qStorage[2] = _qStorage[2] + argStorage[2];
@@ -357,7 +357,7 @@
/// Subtracts [arg] from [this].
void sub(Quaternion arg) {
- final argStorage = arg._qStorage;
+ final Float64List argStorage = arg._qStorage;
_qStorage[0] = _qStorage[0] - argStorage[0];
_qStorage[1] = _qStorage[1] - argStorage[1];
_qStorage[2] = _qStorage[2] - argStorage[2];
@@ -377,15 +377,15 @@
/// [this] rotated by [other].
Quaternion operator *(Quaternion other) {
- double _w = _qStorage[3];
- double _z = _qStorage[2];
- double _y = _qStorage[1];
- double _x = _qStorage[0];
- final otherStorage = other._qStorage;
- double ow = otherStorage[3];
- double oz = otherStorage[2];
- double oy = otherStorage[1];
- double ox = otherStorage[0];
+ 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];
return new Quaternion(
_w * ox + _x * ow + _y * oz - _z * oy,
_w * oy + _y * ow + _z * ox - _x * oz,
@@ -416,32 +416,32 @@
/// Set [rotationMatrix] to a rotation matrix containing the same rotation as
/// [this].
Matrix3 copyRotationInto(Matrix3 rotationMatrix) {
- final d = length2;
+ final double d = length2;
assert(d != 0.0);
- final s = 2.0 / d;
+ final double s = 2.0 / d;
- final _x = _qStorage[0];
- final _y = _qStorage[1];
- final _z = _qStorage[2];
- final _w = _qStorage[3];
+ final double _x = _qStorage[0];
+ final double _y = _qStorage[1];
+ final double _z = _qStorage[2];
+ final double _w = _qStorage[3];
- final xs = _x * s;
- final ys = _y * s;
- final zs = _z * s;
+ final double xs = _x * s;
+ final double ys = _y * s;
+ final double zs = _z * s;
- final wx = _w * xs;
- final wy = _w * ys;
- final wz = _w * zs;
+ final double wx = _w * xs;
+ final double wy = _w * ys;
+ final double wz = _w * zs;
- final xx = _x * xs;
- final xy = _x * ys;
- final xz = _x * zs;
+ final double xx = _x * xs;
+ final double xy = _x * ys;
+ final double xz = _x * zs;
- final yy = _y * ys;
- final yz = _y * zs;
- final zz = _z * zs;
+ final double yy = _y * ys;
+ final double yz = _y * zs;
+ final double zz = _z * zs;
- final rotationMatrixStorage = rotationMatrix.storage;
+ final Float64List rotationMatrixStorage = rotationMatrix.storage;
rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0
rotationMatrixStorage[1] = xy + wz;
rotationMatrixStorage[2] = xz - wy;
@@ -455,22 +455,23 @@
}
/// Printable string.
+ @override
String toString() => '${_qStorage[0]}, ${_qStorage[1]},'
' ${_qStorage[2]} @ ${_qStorage[3]}';
/// Relative error between [this] and [correct].
double relativeError(Quaternion correct) {
- final diff = correct - this;
- final norm_diff = diff.length;
- final correct_norm = correct.length;
+ final Quaternion diff = correct - this;
+ final double norm_diff = diff.length;
+ final double correct_norm = correct.length;
return norm_diff / correct_norm;
}
/// Absolute error between [this] and [correct].
double absoluteError(Quaternion correct) {
- final this_norm = length;
- final correct_norm = correct.length;
- final norm_diff = (this_norm - correct_norm).abs();
+ final double this_norm = length;
+ final double correct_norm = correct.length;
+ final double 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 afdcdb9..d79e6dc 100644
--- a/lib/src/vector_math_64/ray.dart
+++ b/lib/src/vector_math_64/ray.dart
@@ -51,19 +51,19 @@
/// 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 r = other._radius;
- final r2 = r * r;
- final l = other._center.clone()..sub(_origin);
- final s = l.dot(_direction);
- final l2 = l.dot(l);
+ 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);
if (s < 0 && l2 > r2) {
return null;
}
- final m2 = l2 - s * s;
+ final double m2 = l2 - s * s;
if (m2 > r2) {
return null;
}
- final q = Math.sqrt(r2 - m2);
+ final double 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 _e1 = new Vector3.zero();
- static final _e2 = new Vector3.zero();
- static final _q = new Vector3.zero();
- static final _s = new Vector3.zero();
- static final _r = new Vector3.zero();
+ static final Vector3 _e1 = new Vector3.zero();
+ static final Vector3 _e2 = new Vector3.zero();
+ static final Vector3 _q = new Vector3.zero();
+ static final Vector3 _s = new Vector3.zero();
+ static final Vector3 _r = new 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;
- final point0 = other._point0;
- final point1 = other._point1;
- final point2 = other._point2;
+ final Vector3 point0 = other._point0;
+ final Vector3 point1 = other._point1;
+ final Vector3 point2 = other._point2;
_e1
..setFrom(point1)
@@ -94,30 +94,30 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final a = _e1.dot(_q);
+ final double a = _e1.dot(_q);
if (a > -EPSILON && a < EPSILON) {
return null;
}
- final f = 1 / a;
+ final double f = 1 / a;
_s
..setFrom(_origin)
..sub(point0);
- final u = f * (_s.dot(_q));
+ final double u = f * (_s.dot(_q));
if (u < 0.0) {
return null;
}
_s.crossInto(_e1, _r);
- final v = f * (_direction.dot(_r));
+ final double v = f * (_direction.dot(_r));
if (v < -EPSILON || u + v > 1.0 + EPSILON) {
return null;
}
- final t = f * (_e2.dot(_r));
+ final double t = f * (_e2.dot(_r));
return t;
}
@@ -128,9 +128,9 @@
const double EPSILON = 10e-6;
// First triangle
- var point0 = other._point0;
- var point1 = other._point1;
- var point2 = other._point2;
+ Vector3 point0 = other._point0;
+ Vector3 point1 = other._point1;
+ Vector3 point2 = other._point2;
_e1
..setFrom(point1)
@@ -140,21 +140,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final a0 = _e1.dot(_q);
+ final double a0 = _e1.dot(_q);
if (!(a0 > -EPSILON && a0 < EPSILON)) {
- final f = 1 / a0;
+ final double f = 1 / a0;
_s
..setFrom(_origin)
..sub(point0);
- final u = f * (_s.dot(_q));
+ final double u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final v = f * (_direction.dot(_r));
+ final double v = f * (_direction.dot(_r));
if (!(v < -EPSILON || u + v > 1.0 + EPSILON)) {
- final t = f * (_e2.dot(_r));
+ final double t = f * (_e2.dot(_r));
return t;
}
@@ -174,21 +174,21 @@
..sub(point0);
_direction.crossInto(_e2, _q);
- final a1 = _e1.dot(_q);
+ final double a1 = _e1.dot(_q);
if (!(a1 > -EPSILON && a1 < EPSILON)) {
- final f = 1 / a1;
+ final double f = 1 / a1;
_s
..setFrom(_origin)
..sub(point0);
- final u = f * (_s.dot(_q));
+ final double u = f * (_s.dot(_q));
if (u >= 0.0) {
_s.crossInto(_e1, _r);
- final v = f * (_direction.dot(_r));
+ final double v = f * (_direction.dot(_r));
if (!(v < -EPSILON || u + v > 1.0 + EPSILON)) {
- final t = f * (_e2.dot(_r));
+ final double t = f * (_e2.dot(_r));
return t;
}
@@ -201,23 +201,23 @@
/// 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 otherMin = other.min;
- final otherMax = other.max;
+ final Vector3 otherMin = other.min;
+ final Vector3 otherMax = other.max;
- var tNear = -double.MAX_FINITE;
- var tFar = double.MAX_FINITE;
+ double tNear = -double.MAX_FINITE;
+ double tFar = double.MAX_FINITE;
- for (var i = 0; i < 3; ++i) {
+ for (int i = 0; i < 3; ++i) {
if (_direction[i] == 0.0) {
if (_origin[i] < otherMin[i] || _origin[i] > otherMax[i]) {
return null;
}
} else {
- var t1 = (otherMin[i] - _origin[i]) / _direction[i];
- var t2 = (otherMax[i] - _origin[i]) / _direction[i];
+ double t1 = (otherMin[i] - _origin[i]) / _direction[i];
+ double t2 = (otherMax[i] - _origin[i]) / _direction[i];
if (t1 > t2) {
- final temp = t1;
+ final double 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 76737dc..e8f1707 100644
--- a/lib/src/vector_math_64/sphere.dart
+++ b/lib/src/vector_math_64/sphere.dart
@@ -38,18 +38,16 @@
}
/// Return if [this] contains [other].
- bool containsVector3(Vector3 other) {
- return other.distanceToSquared(center) < radius * radius;
- }
+ bool containsVector3(Vector3 other) =>
+ other.distanceToSquared(center) < radius * radius;
/// Return if [this] intersects with [other].
- bool intersectsWithVector3(Vector3 other) {
- return other.distanceToSquared(center) <= radius * radius;
- }
+ bool intersectsWithVector3(Vector3 other) =>
+ other.distanceToSquared(center) <= radius * radius;
/// Return if [this] intersects with [other].
bool intersectsWithSphere(Sphere other) {
- var radiusSum = radius + other.radius;
+ final double 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 bb1b81f..60be2ea 100644
--- a/lib/src/vector_math_64/third_party/noise.dart
+++ b/lib/src/vector_math_64/third_party/noise.dart
@@ -27,54 +27,54 @@
*/
class SimplexNoise {
- static final _grad3 = <List<double>>[
- [1.0, 1.0, 0.0],
- [-1.0, 1.0, 0.0],
- [1.0, -1.0, 0.0],
- [-1.0, -1.0, 0.0],
- [1.0, 0.0, 1.0],
- [-1.0, 0.0, 1.0],
- [1.0, 0.0, -1.0],
- [-1.0, 0.0, -1.0],
- [0.0, 1.0, 1.0],
- [0.0, -1.0, 1.0],
- [0.0, 1.0, -1.0],
- [0.0, -1.0, -1.0]
+ static final List<List<double>> _grad3 = <List<double>>[
+ <double>[1.0, 1.0, 0.0],
+ <double>[-1.0, 1.0, 0.0],
+ <double>[1.0, -1.0, 0.0],
+ <double>[-1.0, -1.0, 0.0],
+ <double>[1.0, 0.0, 1.0],
+ <double>[-1.0, 0.0, 1.0],
+ <double>[1.0, 0.0, -1.0],
+ <double>[-1.0, 0.0, -1.0],
+ <double>[0.0, 1.0, 1.0],
+ <double>[0.0, -1.0, 1.0],
+ <double>[0.0, 1.0, -1.0],
+ <double>[0.0, -1.0, -1.0]
];
- static final _grad4 = <List<double>>[
- [0.0, 1.0, 1.0, 1.0],
- [0.0, 1.0, 1.0, -1.0],
- [0.0, 1.0, -1.0, 1.0],
- [0.0, 1.0, -1.0, -1.0],
- [0.0, -1.0, 1.0, 1.0],
- [0.0, -1.0, 1.0, -1.0],
- [0.0, -1.0, -1.0, 1.0],
- [0.0, -1.0, -1.0, -1.0],
- [1.0, 0.0, 1.0, 1.0],
- [1.0, 0.0, 1.0, -1.0],
- [1.0, 0.0, -1.0, 1.0],
- [1.0, 0.0, -1.0, -1.0],
- [-1.0, 0.0, 1.0, 1.0],
- [-1.0, 0.0, 1.0, -1.0],
- [-1.0, 0.0, -1.0, 1.0],
- [-1.0, 0.0, -1.0, -1.0],
- [1.0, 1.0, 0.0, 1.0],
- [1.0, 1.0, 0.0, -1.0],
- [1.0, -1.0, 0.0, 1.0],
- [1.0, -1.0, 0.0, -1.0],
- [-1.0, 1.0, 0.0, 1.0],
- [-1.0, 1.0, 0.0, -1.0],
- [-1.0, -1.0, 0.0, 1.0],
- [-1.0, -1.0, 0.0, -1.0],
- [1.0, 1.0, 1.0, 0.0],
- [1.0, 1.0, -1.0, 0.0],
- [1.0, -1.0, 1.0, 0.0],
- [1.0, -1.0, -1.0, 0.0],
- [-1.0, 1.0, 1.0, 0.0],
- [-1.0, 1.0, -1.0, 0.0],
- [-1.0, -1.0, 1.0, 0.0],
- [-1.0, -1.0, -1.0, 0.0]
+ static final List<List<double>> _grad4 = <List<double>>[
+ <double>[0.0, 1.0, 1.0, 1.0],
+ <double>[0.0, 1.0, 1.0, -1.0],
+ <double>[0.0, 1.0, -1.0, 1.0],
+ <double>[0.0, 1.0, -1.0, -1.0],
+ <double>[0.0, -1.0, 1.0, 1.0],
+ <double>[0.0, -1.0, 1.0, -1.0],
+ <double>[0.0, -1.0, -1.0, 1.0],
+ <double>[0.0, -1.0, -1.0, -1.0],
+ <double>[1.0, 0.0, 1.0, 1.0],
+ <double>[1.0, 0.0, 1.0, -1.0],
+ <double>[1.0, 0.0, -1.0, 1.0],
+ <double>[1.0, 0.0, -1.0, -1.0],
+ <double>[-1.0, 0.0, 1.0, 1.0],
+ <double>[-1.0, 0.0, 1.0, -1.0],
+ <double>[-1.0, 0.0, -1.0, 1.0],
+ <double>[-1.0, 0.0, -1.0, -1.0],
+ <double>[1.0, 1.0, 0.0, 1.0],
+ <double>[1.0, 1.0, 0.0, -1.0],
+ <double>[1.0, -1.0, 0.0, 1.0],
+ <double>[1.0, -1.0, 0.0, -1.0],
+ <double>[-1.0, 1.0, 0.0, 1.0],
+ <double>[-1.0, 1.0, 0.0, -1.0],
+ <double>[-1.0, -1.0, 0.0, 1.0],
+ <double>[-1.0, -1.0, 0.0, -1.0],
+ <double>[1.0, 1.0, 1.0, 0.0],
+ <double>[1.0, 1.0, -1.0, 0.0],
+ <double>[1.0, -1.0, 1.0, 0.0],
+ <double>[1.0, -1.0, -1.0, 0.0],
+ <double>[-1.0, 1.0, 1.0, 0.0],
+ <double>[-1.0, 1.0, -1.0, 0.0],
+ <double>[-1.0, -1.0, 1.0, 0.0],
+ <double>[-1.0, -1.0, -1.0, 0.0]
];
// To remove the need for index wrapping, double the permutation table length
@@ -82,12 +82,12 @@
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 double _F2 = 0.5 * (math.sqrt(3.0) - 1.0);
+ static final double _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 double _F4 = (math.sqrt(5.0) - 1.0) / 4.0;
+ static final double _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,29 +97,27 @@
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]) {
- if (r == null) {
- r = new Math.Random();
- }
- List<int> p =
- new List<int>.generate(256, (i) => r.nextInt(256), growable: false);
- _perm = new List<int>.generate(p.length * 2, (i) => p[i % p.length],
+ SimplexNoise([math.Random r]) {
+ r ??= new math.Random();
+ final List<int> p =
+ new List<int>.generate(256, (_) => r.nextInt(256), growable: false);
+ _perm = new List<int>.generate(p.length * 2, (int i) => p[i % p.length],
growable: false);
- _permMod12 = new List<int>.generate(_perm.length, (i) => _perm[i] % 12,
+ _permMod12 = new List<int>.generate(_perm.length, (int i) => _perm[i] % 12,
growable: false);
}
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
- double s = (xin + yin) * _F2; // Hairy factor for 2D
- int i = (xin + s).floor();
- int j = (yin + s).floor();
- double t = (i + j) * _G2;
- double X0 = i - t; // Unskew the cell origin back to (x,y) space
- double Y0 = j - t;
- double x0 = xin - X0; // The x,y distances from the cell origin
- double y0 = yin - Y0;
+ 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;
// 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
@@ -134,19 +132,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
- double x1 =
+ final double x1 =
x0 - i1 + _G2; // Offsets for middle corner in (x,y) unskewed coords
- double y1 = y0 - j1 + _G2;
- double x2 = x0 -
+ final double y1 = y0 - j1 + _G2;
+ final double x2 = x0 -
1.0 +
2.0 * _G2; // Offsets for last corner in (x,y) unskewed coords
- double y2 = y0 - 1.0 + 2.0 * _G2;
+ final double y2 = y0 - 1.0 + 2.0 * _G2;
// Work out the hashed gradient indices of the three simplex corners
- int ii = i & 255;
- int jj = j & 255;
- int gi0 = _permMod12[ii + _perm[jj]];
- int gi1 = _permMod12[ii + i1 + _perm[jj + j1]];
- int gi2 = _permMod12[ii + 1 + _perm[jj + 1]];
+ 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]];
// Calculate the contribution from the three corners
double t0 = 0.5 - x0 * x0 - y0 * y0;
if (t0 < 0)
@@ -180,18 +178,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
- double s =
+ final double s =
(xin + yin + zin) * _F3; // Very nice and simple skew factor for 3D
- int i = (xin + s).floor();
- int j = (yin + s).floor();
- int k = (zin + s).floor();
- double t = (i + j + k) * _G3;
- double X0 = i - t; // Unskew the cell origin back to (x,y,z) space
- double Y0 = j - t;
- double Z0 = k - t;
- double x0 = xin - X0; // The x,y,z distances from the cell origin
- double y0 = yin - Y0;
- double z0 = zin - Z0;
+ 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;
// 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
@@ -252,25 +250,26 @@
// 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.
- double x1 = x0 - i1 + _G3; // Offsets for second corner in (x,y,z) coords
- double y1 = y0 - j1 + _G3;
- double z1 = z0 - k1 + _G3;
- double x2 =
+ 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 =
x0 - i2 + 2.0 * _G3; // Offsets for third corner in (x,y,z) coords
- double y2 = y0 - j2 + 2.0 * _G3;
- double z2 = z0 - k2 + 2.0 * _G3;
- double x3 =
+ final double y2 = y0 - j2 + 2.0 * _G3;
+ final double z2 = z0 - k2 + 2.0 * _G3;
+ final double x3 =
x0 - 1.0 + 3.0 * _G3; // Offsets for last corner in (x,y,z) coords
- double y3 = y0 - 1.0 + 3.0 * _G3;
- double z3 = z0 - 1.0 + 3.0 * _G3;
+ final double y3 = y0 - 1.0 + 3.0 * _G3;
+ final double z3 = z0 - 1.0 + 3.0 * _G3;
// Work out the hashed gradient indices of the four simplex corners
- int ii = i & 255;
- int jj = j & 255;
- int kk = k & 255;
- int gi0 = _permMod12[ii + _perm[jj + _perm[kk]]];
- int gi1 = _permMod12[ii + i1 + _perm[jj + j1 + _perm[kk + k1]]];
- int gi2 = _permMod12[ii + i2 + _perm[jj + j2 + _perm[kk + k2]]];
- int gi3 = _permMod12[ii + 1 + _perm[jj + 1 + _perm[kk + 1]]];
+ 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]]];
// Calculate the contribution from the four corners
double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
if (t0 < 0)
@@ -309,20 +308,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
- double s = (x + y + z + w) * _F4; // Factor for 4D skewing
- int i = (x + s).floor();
- int j = (y + s).floor();
- int k = (z + s).floor();
- int l = (w + s).floor();
- double t = (i + j + k + l) * _G4; // Factor for 4D unskewing
- double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
- double Y0 = j - t;
- double Z0 = k - t;
- double W0 = l - t;
- double x0 = x - X0; // The x,y,z,w distances from the cell origin
- double y0 = y - Y0;
- double z0 = z - Z0;
- double w0 = w - W0;
+ 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;
// 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.
@@ -379,38 +378,39 @@
k3 = rankz >= 1 ? 1 : 0;
l3 = rankw >= 1 ? 1 : 0;
// The fifth corner has all coordinate offsets = 1, so no need to compute that.
- double x1 = x0 - i1 + _G4; // Offsets for second corner in (x,y,z,w) coords
- double y1 = y0 - j1 + _G4;
- double z1 = z0 - k1 + _G4;
- double w1 = w0 - l1 + _G4;
- double x2 =
+ 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 =
x0 - i2 + 2.0 * _G4; // Offsets for third corner in (x,y,z,w) coords
- double y2 = y0 - j2 + 2.0 * _G4;
- double z2 = z0 - k2 + 2.0 * _G4;
- double w2 = w0 - l2 + 2.0 * _G4;
- double x3 =
+ 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 =
x0 - i3 + 3.0 * _G4; // Offsets for fourth corner in (x,y,z,w) coords
- double y3 = y0 - j3 + 3.0 * _G4;
- double z3 = z0 - k3 + 3.0 * _G4;
- double w3 = w0 - l3 + 3.0 * _G4;
- double x4 =
+ 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 =
x0 - 1.0 + 4.0 * _G4; // Offsets for last corner in (x,y,z,w) coords
- double y4 = y0 - 1.0 + 4.0 * _G4;
- double z4 = z0 - 1.0 + 4.0 * _G4;
- double w4 = w0 - 1.0 + 4.0 * _G4;
+ 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;
// Work out the hashed gradient indices of the five simplex corners
- int ii = i & 255;
- int jj = j & 255;
- int kk = k & 255;
- int ll = l & 255;
- int gi0 = _perm[ii + _perm[jj + _perm[kk + _perm[ll]]]] % 32;
- int gi1 =
+ 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 =
_perm[ii + i1 + _perm[jj + j1 + _perm[kk + k1 + _perm[ll + l1]]]] % 32;
- int gi2 =
+ final int gi2 =
_perm[ii + i2 + _perm[jj + j2 + _perm[kk + k2 + _perm[ll + l2]]]] % 32;
- int gi3 =
+ final int gi3 =
_perm[ii + i3 + _perm[jj + j3 + _perm[kk + k3 + _perm[ll + l3]]]] % 32;
- int gi4 =
+ final int gi4 =
_perm[ii + 1 + _perm[jj + 1 + _perm[kk + 1 + _perm[ll + 1]]]] % 32;
// Calculate the contribution from the five corners
double 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 e41938e..9ea99b4 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 v0 = point0.clone()..sub(point1);
+ final Vector3 v0 = point0.clone()..sub(point1);
normal
..setFrom(point2)
..sub(point1)
@@ -56,9 +56,7 @@
/// Transform [this] by the transform [t].
void transform(Matrix4 t) {
- t.transform3(_point0);
- t.transform3(_point1);
- t.transform3(_point2);
+ t..transform3(_point0)..transform3(_point1)..transform3(_point2);
}
/// Translate [this] by [offset].
diff --git a/lib/src/vector_math_64/utilities.dart b/lib/src/vector_math_64/utilities.dart
index 3426ddf..ca46e00 100644
--- a/lib/src/vector_math_64/utilities.dart
+++ b/lib/src/vector_math_64/utilities.dart
@@ -5,39 +5,32 @@
part of vector_math_64;
/// Convert [radians] to degrees.
-double degrees(double radians) {
- return radians * radians2Degrees;
-}
+double degrees(double radians) => radians * radians2Degrees;
/// Convert [degrees] to radians.
-double radians(double degrees) {
- return degrees * degrees2Radians;
-}
+double radians(double degrees) => degrees * degrees2Radians;
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation. The computation is equivalent to the GLSL function mix.
-double mix(double min, double max, double a) {
- return min + a * (max - min);
-}
+double mix(double min, double max, double a) => min + a * (max - min);
/// Do a smooth step (hermite interpolation) interpolation with [edge0] and
/// [edge1] by [amount]. The computation is equivalent to the GLSL function
/// smoothstep.
double smoothStep(double edge0, double edge1, double amount) {
- final t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0);
+ final double t =
+ ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble();
return t * t * (3.0 - 2.0 * t);
}
/// Do a catmull rom spline interpolation with [edge0], [edge1], [edge2] and
/// [edge3] by [amount].
-double catmullRom(
- double edge0, double edge1, double edge2, double edge3, double amount) {
- return 0.5 *
- ((2.0 * edge1) +
- (-edge0 + edge2) * amount +
- (2.0 * edge0 - 5.0 * edge1 + 4.0 * edge2 - edge3) *
- (amount * amount) +
- (-edge0 + 3.0 * edge1 - 3.0 * edge2 + edge3) *
- (amount * amount * amount));
-}
+double catmullRom(double edge0, double edge1, double edge2, double edge3,
+ double amount) =>
+ 0.5 *
+ ((2.0 * edge1) +
+ (-edge0 + edge2) * amount +
+ (2.0 * edge0 - 5.0 * edge1 + 4.0 * edge2 - edge3) * (amount * amount) +
+ (-edge0 + 3.0 * edge1 - 3.0 * edge2 + edge3) *
+ (amount * amount * amount));
diff --git a/lib/src/vector_math_64/vector.dart b/lib/src/vector_math_64/vector.dart
index 26cf85e..09e6428 100644
--- a/lib/src/vector_math_64/vector.dart
+++ b/lib/src/vector_math_64/vector.dart
@@ -20,41 +20,51 @@
/// 2D cross product. double x vec2.
void cross2A(double x, Vector2 y, Vector2 out) {
- var tempy = x * y.x;
- out.x = -x * y.y;
- out.y = tempy;
+ final double tempy = x * y.x;
+ out
+ ..x = -x * y.y
+ ..y = tempy;
}
/// 2D cross product. vec2 x double.
void cross2B(Vector2 x, double y, Vector2 out) {
- var tempy = -y * x.x;
- out.x = y * x.y;
- out.y = tempy;
+ final double tempy = -y * x.x;
+ out
+ ..x = y * x.y
+ ..y = tempy;
}
/// Sets [u] and [v] to be two vectors orthogonal to each other and
/// [planeNormal].
void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) {
- if (planeNormal.z.abs() > Math.SQRT1_2) {
+ if (planeNormal.z.abs() > math.SQRT1_2) {
// choose u in y-z plane
- double a = planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
- double k = 1.0 / Math.sqrt(a);
- u.x = 0.0;
- u.y = -planeNormal.z * k;
- u.z = planeNormal.y * k;
- v.x = a * k;
- v.y = -planeNormal[0] * (planeNormal[1] * k);
- v.z = planeNormal[0] * (-planeNormal[2] * k);
+ final double a =
+ planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z;
+ final double k = 1.0 / math.sqrt(a);
+ u
+ ..x = 0.0
+ ..y = -planeNormal.z * k
+ ..z = planeNormal.y * k;
+
+ v
+ ..x = a * k
+ ..y = -planeNormal[0] * (planeNormal[1] * k)
+ ..z = planeNormal[0] * (-planeNormal[2] * k);
} else {
// choose u in x-y plane
- double a = planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
- double k = 1.0 / Math.sqrt(a);
- u.x = -planeNormal[1] * k;
- u.y = planeNormal[0] * k;
- u.z = 0.0;
- v.x = -planeNormal[2] * (planeNormal[0] * k);
- v.y = planeNormal[2] * (-planeNormal[1] * k);
- v.z = a * k;
+ final double a =
+ planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y;
+ final double k = 1.0 / math.sqrt(a);
+ u
+ ..x = -planeNormal[1] * k
+ ..y = planeNormal[0] * k
+ ..z = 0.0;
+
+ v
+ ..x = -planeNormal[2] * (planeNormal[0] * k)
+ ..y = planeNormal[2] * (-planeNormal[1] * k)
+ ..z = a * k;
}
}
diff --git a/lib/src/vector_math_64/vector2.dart b/lib/src/vector_math_64/vector2.dart
index 7e4e6e1..ef90099 100644
--- a/lib/src/vector_math_64/vector2.dart
+++ b/lib/src/vector_math_64/vector2.dart
@@ -9,25 +9,29 @@
final Float64List _v2storage;
/// The components of the vector.
+ @override
Float64List get storage => _v2storage;
/// Set the values of [result] to the minimum of [a] and [b] for each line.
static void min(Vector2 a, Vector2 b, Vector2 result) {
- result.x = Math.min(a.x, b.x);
- result.y = Math.min(a.y, b.y);
+ result
+ ..x = math.min(a.x, b.x)
+ ..y = math.min(a.y, b.y);
}
/// Set the values of [result] to the maximum of [a] and [b] for each line.
static void max(Vector2 a, Vector2 b, Vector2 result) {
- result.x = Math.max(a.x, b.x);
- result.y = Math.max(a.y, b.y);
+ result
+ ..x = math.max(a.x, b.x)
+ ..y = math.max(a.y, b.y);
}
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation and store the values in [result].
static void mix(Vector2 min, Vector2 max, double a, Vector2 result) {
- result.x = min.x + a * (max.x - min.x);
- result.y = min.y + a * (max.y - min.y);
+ result
+ ..x = min.x + a * (max.x - min.x)
+ ..y = min.y + a * (max.y - min.y);
}
/// Construct a new vector with the specified values.
@@ -56,8 +60,8 @@
/// 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]) {
- rng = rng == null ? new Math.Random() : rng;
+ factory Vector2.random([math.Random rng]) {
+ rng = rng == null ? new math.Random() : rng;
return new Vector2(rng.nextDouble(), rng.nextDouble());
}
@@ -75,7 +79,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector2 other) {
- final otherStorage = other._v2storage;
+ final Float64List otherStorage = other._v2storage;
_v2storage[1] = otherStorage[1];
_v2storage[0] = otherStorage[0];
}
@@ -87,15 +91,17 @@
}
/// Returns a printable string
+ @override
String toString() => '[${_v2storage[0]},${_v2storage[1]}]';
/// Check if two vectors are the same.
- bool operator ==(other) {
- return (other is Vector2) &&
- (_v2storage[0] == other._v2storage[0]) &&
- (_v2storage[1] == other._v2storage[1]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Vector2) &&
+ (_v2storage[0] == other._v2storage[0]) &&
+ (_v2storage[1] == other._v2storage[1]);
+ @override
int get hashCode => quiver.hashObjects(_v2storage);
/// Negate.
@@ -138,11 +144,11 @@
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Length squared.
double get length2 {
- var sum;
+ double sum;
sum = (_v2storage[0] * _v2storage[0]);
sum += (_v2storage[1] * _v2storage[1]);
return sum;
@@ -150,11 +156,11 @@
/// Normalize [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_v2storage[0] *= d;
_v2storage[1] *= d;
return l;
@@ -177,69 +183,67 @@
}
/// Distance from [this] to [arg]
- double distanceTo(Vector2 arg) => Math.sqrt(distanceToSquared(arg));
+ double distanceTo(Vector2 arg) => math.sqrt(distanceToSquared(arg));
/// Squared distance from [this] to [arg]
double distanceToSquared(Vector2 arg) {
- final dx = x - arg.x;
- final dy = y - arg.y;
+ final double dx = x - arg.x;
+ final double dy = y - arg.y;
return dx * dx + dy * dy;
}
/// Returns the angle between [this] vector and [other] in radians.
double angleTo(Vector2 other) {
- final otherStorage = other._v2storage;
- if (_v2storage[0] == otherStorage[0] &&
- _v2storage[1] == otherStorage[1]) {
+ final Float64List otherStorage = other._v2storage;
+ if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final d = dot(other);
+ final double d = dot(other);
- return Math.acos(d.clamp(-1.0, 1.0));
+ return math.acos(d.clamp(-1.0, 1.0));
}
/// Returns the signed angle between [this] and [other] in radians.
double angleToSigned(Vector2 other) {
- final otherStorage = other._v2storage;
- if (_v2storage[0] == otherStorage[0] &&
- _v2storage[1] == otherStorage[1]) {
+ final Float64List otherStorage = other._v2storage;
+ if (_v2storage[0] == otherStorage[0] && _v2storage[1] == otherStorage[1]) {
return 0.0;
}
- final s = cross(other);
- final c = dot(other);
+ final double s = cross(other);
+ final double c = dot(other);
- return Math.atan2(s, c);
+ return math.atan2(s, c);
}
/// Inner product.
double dot(Vector2 other) {
- final otherStorage = other._v2storage;
+ final Float64List otherStorage = other._v2storage;
double sum;
sum = _v2storage[0] * otherStorage[0];
sum += _v2storage[1] * otherStorage[1];
return sum;
}
- /**
- * Transforms [this] into the product of [this] as a row vector,
- * postmultiplied by matrix, [arg].
- * If [arg] is a rotation matrix, this is a computational shortcut for applying,
- * the inverse of the transformation.
- */
+ ///
+ /// Transforms [this] into the product of [this] as a row vector,
+ /// postmultiplied by matrix, [arg].
+ /// If [arg] is a rotation matrix, this is a computational shortcut for applying,
+ /// the inverse of the transformation.
+ ///
void postmultiply(Matrix2 arg) {
- final argStorage = arg.storage;
- double v0 = _v2storage[0];
- double v1 = _v2storage[1];
+ final Float64List argStorage = arg.storage;
+ final double v0 = _v2storage[0];
+ final double 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 otherStorage = other._v2storage;
+ final Float64List otherStorage = other._v2storage;
return _v2storage[0] * otherStorage[1] - _v2storage[1] * otherStorage[0];
}
@@ -259,15 +263,13 @@
/// Relative error between [this] and [correct]
double relativeError(Vector2 correct) {
- double correct_norm = correct.length;
- double diff_norm = (this - correct).length;
+ final double correct_norm = correct.length;
+ final double diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
/// Absolute error between [this] and [correct]
- double absoluteError(Vector2 correct) {
- return (this - correct).length;
- }
+ double absoluteError(Vector2 correct) => (this - correct).length;
/// True if any component is infinite.
bool get isInfinite {
@@ -287,35 +289,35 @@
/// Add [arg] to [this].
void add(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List 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 argStorage = arg._v2storage;
+ final Float64List 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 argStorage = arg._v2storage;
+ final Float64List 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 argStorage = arg._v2storage;
+ final Float64List 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 argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] / argStorage[0];
_v2storage[1] = _v2storage[1] / argStorage[1];
}
@@ -343,16 +345,18 @@
/// Clamp each entry n in [this] in the range [min[n]]-[max[n]].
void clamp(Vector2 min, Vector2 max) {
- var minStorage = min.storage;
- var maxStorage = max.storage;
- _v2storage[0] = _v2storage[0].clamp(minStorage[0], maxStorage[0]);
- _v2storage[1] = _v2storage[1].clamp(minStorage[1], maxStorage[1]);
+ final Float64List minStorage = min.storage;
+ final Float64List maxStorage = max.storage;
+ _v2storage[0] =
+ _v2storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
+ _v2storage[1] =
+ _v2storage[1].clamp(minStorage[1], maxStorage[1]).toDouble();
}
/// Clamp entries [this] in the range [min]-[max].
void clampScalar(double min, double max) {
- _v2storage[0] = _v2storage[0].clamp(min, max);
- _v2storage[1] = _v2storage[1].clamp(min, max);
+ _v2storage[0] = _v2storage[0].clamp(min, max).toDouble();
+ _v2storage[1] = _v2storage[1].clamp(min, max).toDouble();
}
/// Floor entries in [this].
@@ -388,7 +392,7 @@
/// Copy [this] into [arg]. Returns [arg].
Vector2 copyInto(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
argStorage[1] = _v2storage[1];
argStorage[0] = _v2storage[0];
return arg;
@@ -407,13 +411,13 @@
}
set xy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v2storage[0] = argStorage[0];
_v2storage[1] = argStorage[1];
}
set yx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List 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 40dc376..a356ed4 100644
--- a/lib/src/vector_math_64/vector3.dart
+++ b/lib/src/vector_math_64/vector3.dart
@@ -9,28 +9,32 @@
final Float64List _v3storage;
/// The components of the vector.
+ @override
Float64List get storage => _v3storage;
/// Set the values of [result] to the minimum of [a] and [b] for each line.
static void min(Vector3 a, Vector3 b, Vector3 result) {
- result.x = Math.min(a.x, b.x);
- result.y = Math.min(a.y, b.y);
- result.z = Math.min(a.z, b.z);
+ result
+ ..x = math.min(a.x, b.x)
+ ..y = math.min(a.y, b.y)
+ ..z = math.min(a.z, b.z);
}
/// Set the values of [result] to the maximum of [a] and [b] for each line.
static void max(Vector3 a, Vector3 b, Vector3 result) {
- result.x = Math.max(a.x, b.x);
- result.y = Math.max(a.y, b.y);
- result.z = Math.max(a.z, b.z);
+ result
+ ..x = math.max(a.x, b.x)
+ ..y = math.max(a.y, b.y)
+ ..z = math.max(a.z, b.z);
}
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation and store the values in [result].
static void mix(Vector3 min, Vector3 max, double a, Vector3 result) {
- result.x = min.x + a * (max.x - min.x);
- result.y = min.y + a * (max.y - min.y);
- result.z = min.z + a * (max.z - min.z);
+ result
+ ..x = min.x + a * (max.x - min.x)
+ ..y = min.y + a * (max.y - min.y)
+ ..z = min.z + a * (max.z - min.z);
}
/// Construct a new vector with the specified values.
@@ -60,8 +64,8 @@
/// 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]) {
- rng = rng == null ? new Math.Random() : rng;
+ factory Vector3.random([math.Random rng]) {
+ rng = rng == null ? new math.Random() : rng;
return new Vector3(rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
}
@@ -81,7 +85,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector3 other) {
- final otherStorage = other._v3storage;
+ final Float64List otherStorage = other._v3storage;
_v3storage[0] = otherStorage[0];
_v3storage[1] = otherStorage[1];
_v3storage[2] = otherStorage[2];
@@ -95,16 +99,18 @@
}
/// Returns a printable string
+ @override
String toString() => '[${storage[0]},${storage[1]},${storage[2]}]';
/// Check if two vectors are the same.
- bool operator ==(other) {
- return (other is Vector3) &&
- (_v3storage[0] == other._v3storage[0]) &&
- (_v3storage[1] == other._v3storage[1]) &&
- (_v3storage[2] == other._v3storage[2]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Vector3) &&
+ (_v3storage[0] == other._v3storage[0]) &&
+ (_v3storage[1] == other._v3storage[1]) &&
+ (_v3storage[2] == other._v3storage[2]);
+ @override
int get hashCode => quiver.hashObjects(_v3storage);
/// Negate
@@ -148,7 +154,7 @@
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Length squared.
double get length2 {
@@ -161,11 +167,11 @@
/// Normalizes [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_v3storage[0] *= d;
_v3storage[1] *= d;
_v3storage[2] *= d;
@@ -189,45 +195,45 @@
}
/// Distance from [this] to [arg]
- double distanceTo(Vector3 arg) => Math.sqrt(distanceToSquared(arg));
+ double distanceTo(Vector3 arg) => math.sqrt(distanceToSquared(arg));
/// Squared distance from [this] to [arg]
double distanceToSquared(Vector3 arg) {
- final argStorage = arg._v3storage;
- final dx = _v3storage[0] - argStorage[0];
- final dy = _v3storage[1] - argStorage[1];
- final dz = _v3storage[2] - argStorage[2];
+ 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];
return dx * dx + dy * dy + dz * dz;
}
/// Returns the angle between [this] vector and [other] in radians.
double angleTo(Vector3 other) {
- final otherStorage = other._v3storage;
+ final Float64List otherStorage = other._v3storage;
if (_v3storage[0] == otherStorage[0] &&
_v3storage[1] == otherStorage[1] &&
_v3storage[2] == otherStorage[2]) {
return 0.0;
}
- final d = dot(other);
+ final double d = dot(other);
- return Math.acos(d.clamp(-1.0, 1.0));
+ return math.acos(d.clamp(-1.0, 1.0));
}
/// Returns the signed angle between [this] and [other] around [normal]
/// in radians.
double angleToSigned(Vector3 other, Vector3 normal) {
- final angle = angleTo(other);
- final c = cross(other);
- final d = c.dot(normal);
+ final double angle = angleTo(other);
+ final Vector3 c = cross(other);
+ final double d = c.dot(normal);
return d < 0.0 ? -angle : angle;
}
/// Inner product.
double dot(Vector3 other) {
- final otherStorage = other._v3storage;
+ final Float64List otherStorage = other._v3storage;
double sum;
sum = _v3storage[0] * otherStorage[0];
sum += _v3storage[1] * otherStorage[1];
@@ -240,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 argStorage = arg.storage;
- final v0 = _v3storage[0];
- final v1 = _v3storage[1];
- final v2 = _v3storage[2];
+ final Float64List argStorage = arg.storage;
+ final double v0 = _v3storage[0];
+ final double v1 = _v3storage[1];
+ final double v2 = _v3storage[2];
_v3storage[0] =
v0 * argStorage[0] + v1 * argStorage[1] + v2 * argStorage[2];
@@ -255,26 +261,26 @@
/// Cross product.
Vector3 cross(Vector3 other) {
- 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 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];
return new 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 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;
+ 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;
outStorage[0] = y * oz - z * oy;
outStorage[1] = z * ox - x * oz;
outStorage[2] = x * oy - y * ox;
@@ -291,11 +297,11 @@
/// Projects [this] using the projection matrix [arg]
void applyProjection(Matrix4 arg) {
- final argStorage = arg.storage;
- final x = _v3storage[0];
- final y = _v3storage[1];
- final z = _v3storage[2];
- final d = 1.0 /
+ 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 /
(argStorage[3] * x +
argStorage[7] * y +
argStorage[11] * z +
@@ -324,18 +330,18 @@
/// Applies a quaternion transform.
void applyQuaternion(Quaternion arg) {
- final argStorage = arg._qStorage;
- var v0 = _v3storage[0];
- var v1 = _v3storage[1];
- var v2 = _v3storage[2];
- var qx = argStorage[0];
- var qy = argStorage[1];
- var qz = argStorage[2];
- var qw = argStorage[3];
- var ix = qw * v0 + qy * v2 - qz * v1;
- var iy = qw * v1 + qz * v0 - qx * v2;
- var iz = qw * v2 + qx * v1 - qy * v0;
- var iw = -qx * v0 - qy * v1 - qz * v2;
+ 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;
_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;
@@ -343,10 +349,10 @@
/// Multiplies [this] by [arg].
void applyMatrix3(Matrix3 arg) {
- final argStorage = arg.storage;
- var v0 = _v3storage[0];
- var v1 = _v3storage[1];
- var v2 = _v3storage[2];
+ final Float64List argStorage = arg.storage;
+ final double v0 = _v3storage[0];
+ final double v1 = _v3storage[1];
+ final double v2 = _v3storage[2];
_v3storage[0] =
argStorage[0] * v0 + argStorage[3] * v1 + argStorage[6] * v2;
_v3storage[1] =
@@ -358,10 +364,10 @@
/// Multiplies [this] by a 4x3 subset of [arg]. Expects [arg] to be an affine
/// transformation matrix.
void applyMatrix4(Matrix4 arg) {
- final argStorage = arg.storage;
- var v0 = _v3storage[0];
- var v1 = _v3storage[1];
- var v2 = _v3storage[2];
+ final Float64List argStorage = arg.storage;
+ final double v0 = _v3storage[0];
+ final double v1 = _v3storage[1];
+ final double v2 = _v3storage[2];
_v3storage[0] = argStorage[0] * v0 +
argStorage[4] * v1 +
argStorage[8] * v2 +
@@ -378,15 +384,13 @@
/// Relative error between [this] and [correct]
double relativeError(Vector3 correct) {
- double correct_norm = correct.length;
- double diff_norm = (this - correct).length;
+ final double correct_norm = correct.length;
+ final double diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
/// Absolute error between [this] and [correct]
- double absoluteError(Vector3 correct) {
- return (this - correct).length;
- }
+ double absoluteError(Vector3 correct) => (this - correct).length;
/// True if any component is infinite.
bool get isInfinite {
@@ -408,7 +412,7 @@
/// Add [arg] to [this].
void add(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0];
_v3storage[1] = _v3storage[1] + argStorage[1];
_v3storage[2] = _v3storage[2] + argStorage[2];
@@ -416,7 +420,7 @@
/// Add [arg] scaled by [factor] to [this].
void addScaled(Vector3 arg, double factor) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] + argStorage[0] * factor;
_v3storage[1] = _v3storage[1] + argStorage[1] * factor;
_v3storage[2] = _v3storage[2] + argStorage[2] * factor;
@@ -424,7 +428,7 @@
/// Subtract [arg] from [this].
void sub(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] - argStorage[0];
_v3storage[1] = _v3storage[1] - argStorage[1];
_v3storage[2] = _v3storage[2] - argStorage[2];
@@ -432,7 +436,7 @@
/// Multiply entries in [this] with entries in [arg].
void multiply(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] * argStorage[0];
_v3storage[1] = _v3storage[1] * argStorage[1];
_v3storage[2] = _v3storage[2] * argStorage[2];
@@ -440,7 +444,7 @@
/// Divide entries in [this] with entries in [arg].
void divide(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = _v3storage[0] / argStorage[0];
_v3storage[1] = _v3storage[1] / argStorage[1];
_v3storage[2] = _v3storage[2] / argStorage[2];
@@ -472,18 +476,21 @@
/// Clamp each entry n in [this] in the range [min[n]]-[max[n]].
void clamp(Vector3 min, Vector3 max) {
- final minStorage = min.storage;
- final maxStorage = max.storage;
- _v3storage[0] = _v3storage[0].clamp(minStorage[0], maxStorage[0]);
- _v3storage[1] = _v3storage[1].clamp(minStorage[1], maxStorage[1]);
- _v3storage[2] = _v3storage[2].clamp(minStorage[2], maxStorage[2]);
+ final Float64List minStorage = min.storage;
+ final Float64List maxStorage = max.storage;
+ _v3storage[0] =
+ _v3storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
+ _v3storage[1] =
+ _v3storage[1].clamp(minStorage[1], maxStorage[1]).toDouble();
+ _v3storage[2] =
+ _v3storage[2].clamp(minStorage[2], maxStorage[2]).toDouble();
}
/// Clamp entries in [this] in the range [min]-[max].
void clampScalar(double min, double max) {
- _v3storage[0] = _v3storage[0].clamp(min, max);
- _v3storage[1] = _v3storage[1].clamp(min, max);
- _v3storage[2] = _v3storage[2].clamp(min, max);
+ _v3storage[0] = _v3storage[0].clamp(min, max).toDouble();
+ _v3storage[1] = _v3storage[1].clamp(min, max).toDouble();
+ _v3storage[2] = _v3storage[2].clamp(min, max).toDouble();
}
/// Floor entries in [this].
@@ -525,7 +532,7 @@
/// Copy [this] into [arg].
Vector3 copyInto(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
argStorage[0] = _v3storage[0];
argStorage[1] = _v3storage[1];
argStorage[2] = _v3storage[2];
@@ -547,78 +554,78 @@
}
set xy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set yx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
}
set zx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v3storage[2] = argStorage[0];
_v3storage[1] = argStorage[1];
}
set xyz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[1] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set xzy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[0] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set yxz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[2] = argStorage[2];
}
set yzx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[1] = argStorage[0];
_v3storage[2] = argStorage[1];
_v3storage[0] = argStorage[2];
}
set zxy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v3storage[2] = argStorage[0];
_v3storage[0] = argStorage[1];
_v3storage[1] = argStorage[2];
}
set zyx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List 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 e2d09df..5e27501 100644
--- a/lib/src/vector_math_64/vector4.dart
+++ b/lib/src/vector_math_64/vector4.dart
@@ -10,30 +10,34 @@
/// Set the values of [result] to the minimum of [a] and [b] for each line.
static void min(Vector4 a, Vector4 b, Vector4 result) {
- result.x = Math.min(a.x, b.x);
- result.y = Math.min(a.y, b.y);
- result.z = Math.min(a.z, b.z);
- result.w = Math.min(a.w, b.w);
+ result
+ ..x = math.min(a.x, b.x)
+ ..y = math.min(a.y, b.y)
+ ..z = math.min(a.z, b.z)
+ ..w = math.min(a.w, b.w);
}
/// Set the values of [result] to the maximum of [a] and [b] for each line.
static void max(Vector4 a, Vector4 b, Vector4 result) {
- result.x = Math.max(a.x, b.x);
- result.y = Math.max(a.y, b.y);
- result.z = Math.max(a.z, b.z);
- result.w = Math.max(a.w, b.w);
+ result
+ ..x = math.max(a.x, b.x)
+ ..y = math.max(a.y, b.y)
+ ..z = math.max(a.z, b.z)
+ ..w = math.max(a.w, b.w);
}
/// Interpolate between [min] and [max] with the amount of [a] using a linear
/// interpolation and store the values in [result].
static void mix(Vector4 min, Vector4 max, double a, Vector4 result) {
- result.x = min.x + a * (max.x - min.x);
- result.y = min.y + a * (max.y - min.y);
- result.z = min.z + a * (max.z - min.z);
- result.w = min.w + a * (max.w - min.w);
+ result
+ ..x = min.x + a * (max.x - min.x)
+ ..y = min.y + a * (max.y - min.y)
+ ..z = min.z + a * (max.z - min.z)
+ ..w = min.w + a * (max.w - min.w);
}
/// The components of the vector.
+ @override
Float64List get storage => _v4storage;
/// Construct a new vector with the specified values.
@@ -66,10 +70,10 @@
/// 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]) {
- rng = rng == null ? new Math.Random() : rng;
+ factory Vector4.random([math.Random rng]) {
+ rng = rng == null ? new math.Random() : rng;
return new Vector4(
- rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
+ rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble());
}
/// Set the values of the vector.
@@ -98,7 +102,7 @@
/// Set the values by copying them from [other].
void setFrom(Vector4 other) {
- final otherStorage = other._v4storage;
+ final Float64List otherStorage = other._v4storage;
_v4storage[3] = otherStorage[3];
_v4storage[2] = otherStorage[2];
_v4storage[1] = otherStorage[1];
@@ -114,18 +118,20 @@
}
/// Returns a printable string
+ @override
String toString() => '${_v4storage[0]},${_v4storage[1]},'
'${_v4storage[2]},${_v4storage[3]}';
/// Check if two vectors are the same.
- bool operator ==(other) {
- return (other is Vector4) &&
- (_v4storage[0] == other._v4storage[0]) &&
- (_v4storage[1] == other._v4storage[1]) &&
- (_v4storage[2] == other._v4storage[2]) &&
- (_v4storage[3] == other._v4storage[3]);
- }
+ @override
+ bool operator ==(Object other) =>
+ (other is Vector4) &&
+ (_v4storage[0] == other._v4storage[0]) &&
+ (_v4storage[1] == other._v4storage[1]) &&
+ (_v4storage[2] == other._v4storage[2]) &&
+ (_v4storage[3] == other._v4storage[3]);
+ @override
int get hashCode => quiver.hashObjects(_v4storage);
/// Negate.
@@ -170,7 +176,7 @@
}
/// Length.
- double get length => Math.sqrt(length2);
+ double get length => math.sqrt(length2);
/// Length squared.
double get length2 {
@@ -184,11 +190,11 @@
/// Normalizes [this].
double normalize() {
- double l = length;
+ final double l = length;
if (l == 0.0) {
return 0.0;
}
- var d = 1.0 / l;
+ final double d = 1.0 / l;
_v4storage[0] *= d;
_v4storage[1] *= d;
_v4storage[2] *= d;
@@ -213,22 +219,22 @@
}
/// Distance from [this] to [arg]
- double distanceTo(Vector4 arg) => Math.sqrt(distanceToSquared(arg));
+ double distanceTo(Vector4 arg) => math.sqrt(distanceToSquared(arg));
/// Squared distance from [this] to [arg]
double distanceToSquared(Vector4 arg) {
- 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];
+ 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];
return dx * dx + dy * dy + dz * dz + dw * dw;
}
/// Inner product.
double dot(Vector4 other) {
- final otherStorage = other._v4storage;
+ final Float64List otherStorage = other._v4storage;
double sum;
sum = _v4storage[0] * otherStorage[0];
sum += _v4storage[1] * otherStorage[1];
@@ -239,11 +245,11 @@
/// Multiplies [this] by [arg].
void applyMatrix4(Matrix4 arg) {
- var v1 = _v4storage[0];
- var v2 = _v4storage[1];
- var v3 = _v4storage[2];
- var v4 = _v4storage[3];
- final argStorage = arg.storage;
+ 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;
_v4storage[0] = argStorage[0] * v1 +
argStorage[4] * v2 +
argStorage[8] * v3 +
@@ -264,15 +270,13 @@
/// Relative error between [this] and [correct]
double relativeError(Vector4 correct) {
- double correct_norm = correct.length;
- double diff_norm = (this - correct).length;
+ final double correct_norm = correct.length;
+ final double diff_norm = (this - correct).length;
return diff_norm / correct_norm;
}
/// Absolute error between [this] and [correct]
- double absoluteError(Vector4 correct) {
- return (this - correct).length;
- }
+ double absoluteError(Vector4 correct) => (this - correct).length;
/// True if any component is infinite.
bool get isInfinite {
@@ -295,7 +299,7 @@
}
void add(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0];
_v4storage[1] = _v4storage[1] + argStorage[1];
_v4storage[2] = _v4storage[2] + argStorage[2];
@@ -304,7 +308,7 @@
/// Add [arg] scaled by [factor] to [this].
void addScaled(Vector4 arg, double factor) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] + argStorage[0] * factor;
_v4storage[1] = _v4storage[1] + argStorage[1] * factor;
_v4storage[2] = _v4storage[2] + argStorage[2] * factor;
@@ -313,7 +317,7 @@
/// Subtract [arg] from [this].
void sub(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] - argStorage[0];
_v4storage[1] = _v4storage[1] - argStorage[1];
_v4storage[2] = _v4storage[2] - argStorage[2];
@@ -322,7 +326,7 @@
/// Multiply [this] by [arg].
void multiply(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] * argStorage[0];
_v4storage[1] = _v4storage[1] * argStorage[1];
_v4storage[2] = _v4storage[2] * argStorage[2];
@@ -331,7 +335,7 @@
/// Divide [this] by [arg].
void div(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = _v4storage[0] / argStorage[0];
_v4storage[1] = _v4storage[1] / argStorage[1];
_v4storage[2] = _v4storage[2] / argStorage[2];
@@ -367,20 +371,24 @@
/// Clamp each entry n in [this] in the range [min[n]]-[max[n]].
void clamp(Vector4 min, Vector4 max) {
- final minStorage = min.storage;
- final maxStorage = max.storage;
- _v4storage[0] = _v4storage[0].clamp(minStorage[0], maxStorage[0]);
- _v4storage[1] = _v4storage[1].clamp(minStorage[1], maxStorage[1]);
- _v4storage[2] = _v4storage[2].clamp(minStorage[2], maxStorage[2]);
- _v4storage[3] = _v4storage[3].clamp(minStorage[3], maxStorage[3]);
+ final Float64List minStorage = min.storage;
+ final Float64List maxStorage = max.storage;
+ _v4storage[0] =
+ _v4storage[0].clamp(minStorage[0], maxStorage[0]).toDouble();
+ _v4storage[1] =
+ _v4storage[1].clamp(minStorage[1], maxStorage[1]).toDouble();
+ _v4storage[2] =
+ _v4storage[2].clamp(minStorage[2], maxStorage[2]).toDouble();
+ _v4storage[3] =
+ _v4storage[3].clamp(minStorage[3], maxStorage[3]).toDouble();
}
/// Clamp entries in [this] in the range [min]-[max].
void clampScalar(double min, double max) {
- _v4storage[0] = _v4storage[0].clamp(min, max);
- _v4storage[1] = _v4storage[1].clamp(min, max);
- _v4storage[2] = _v4storage[2].clamp(min, max);
- _v4storage[3] = _v4storage[3].clamp(min, max);
+ _v4storage[0] = _v4storage[0].clamp(min, max).toDouble();
+ _v4storage[1] = _v4storage[1].clamp(min, max).toDouble();
+ _v4storage[2] = _v4storage[2].clamp(min, max).toDouble();
+ _v4storage[3] = _v4storage[3].clamp(min, max).toDouble();
}
/// Floor entries in [this].
@@ -428,7 +436,7 @@
/// Copy [this]
Vector4 copyInto(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
argStorage[0] = _v4storage[0];
argStorage[1] = _v4storage[1];
argStorage[2] = _v4storage[2];
@@ -453,247 +461,247 @@
}
set xy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set xz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xw(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set yx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set yz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set yw(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set zx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set zy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set zw(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
}
set wx(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
}
set wy(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
}
set wz(Vector2 arg) {
- final argStorage = arg._v2storage;
+ final Float64List argStorage = arg._v2storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
}
set xyz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set xyw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xzy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xzw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set xwy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xwz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set yxw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set yzx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set yzw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set ywx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set ywz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set zxy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set zxw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zyx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zyw(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
}
set zwx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set zwy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set wxz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wyx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wyz(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
}
set wzx(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
}
set wzy(Vector3 arg) {
- final argStorage = arg._v3storage;
+ final Float64List argStorage = arg._v3storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
}
set xyzw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -701,7 +709,7 @@
}
set xywz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -709,7 +717,7 @@
}
set xzyw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -717,7 +725,7 @@
}
set xzwy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -725,7 +733,7 @@
}
set xwyz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -733,7 +741,7 @@
}
set xwzy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[0] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -741,7 +749,7 @@
}
set yxzw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -749,7 +757,7 @@
}
set yxwz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -757,7 +765,7 @@
}
set yzxw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -765,7 +773,7 @@
}
set yzwx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -773,7 +781,7 @@
}
set ywxz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -781,7 +789,7 @@
}
set ywzx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[1] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -789,7 +797,7 @@
}
set zxyw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -797,7 +805,7 @@
}
set zxwy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -805,7 +813,7 @@
}
set zyxw(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -813,7 +821,7 @@
}
set zywx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[3] = argStorage[2];
@@ -821,7 +829,7 @@
}
set zwxy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -829,7 +837,7 @@
}
set zwyx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[2] = argStorage[0];
_v4storage[3] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -837,7 +845,7 @@
}
set wxyz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[1] = argStorage[2];
@@ -845,7 +853,7 @@
}
set wxzy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[0] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -853,7 +861,7 @@
}
set wyxz(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -861,7 +869,7 @@
}
set wyzx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[1] = argStorage[1];
_v4storage[2] = argStorage[2];
@@ -869,7 +877,7 @@
}
set wzxy(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List argStorage = arg._v4storage;
_v4storage[3] = argStorage[0];
_v4storage[2] = argStorage[1];
_v4storage[0] = argStorage[2];
@@ -877,7 +885,7 @@
}
set wzyx(Vector4 arg) {
- final argStorage = arg._v4storage;
+ final Float64List 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 81a9a61..afd26ed 100644
--- a/lib/src/vector_math_geometry/filters/barycentric_filter.dart
+++ b/lib/src/vector_math_geometry/filters/barycentric_filter.dart
@@ -5,23 +5,32 @@
part of vector_math_geometry;
class BarycentricFilter extends GeometryFilter {
+ @override
List<VertexAttrib> get generates =>
- [new VertexAttrib('BARYCENTRIC', 3, 'float')];
+ <VertexAttrib>[new VertexAttrib('BARYCENTRIC', 3, 'float')];
+ @override
MeshGeometry filter(MeshGeometry mesh) {
- List<VertexAttrib> newAttribs =
+ final List<VertexAttrib> newAttribs =
new List<VertexAttrib>.from(mesh.attribs, growable: true);
if (mesh.getAttrib('BARYCENTRIC') == null) {
newAttribs.add(new VertexAttrib('BARYCENTRIC', 3, 'float'));
}
- MeshGeometry output =
+ final MeshGeometry output =
new MeshGeometry(mesh.triangleVertexCount, newAttribs);
- Vector3List barycentricCoords = output.getViewForAttrib('BARYCENTRIC');
- List<VectorList> srcAttribs = new List<VectorList>();
- List<VectorList> destAttribs = new List<VectorList>();
+ Vector3List barycentricCoords;
+ final VectorList<Vector> view = output.getViewForAttrib('BARYCENTRIC');
+ if (view is Vector3List) {
+ barycentricCoords = view;
+ } else {
+ return null;
+ }
+
+ final List<VectorList<Vector>> srcAttribs = <VectorList<Vector>>[];
+ final List<VectorList<Vector>> destAttribs = <VectorList<Vector>>[];
for (VertexAttrib attrib in mesh.attribs) {
if (attrib.name == 'BARYCENTRIC') {
continue;
@@ -31,9 +40,9 @@
destAttribs.add(output.getViewForAttrib(attrib.name));
}
- Vector3 b0 = new Vector3(1.0, 0.0, 0.0);
- Vector3 b1 = new Vector3(0.0, 1.0, 0.0);
- Vector3 b2 = new Vector3(0.0, 0.0, 1.0);
+ final Vector3 b0 = new Vector3(1.0, 0.0, 0.0);
+ final Vector3 b1 = new Vector3(0.0, 1.0, 0.0);
+ final Vector3 b2 = new Vector3(0.0, 0.0, 1.0);
int i0, i1, i2;
diff --git a/lib/src/vector_math_geometry/filters/color_filter.dart b/lib/src/vector_math_geometry/filters/color_filter.dart
index 8cd5902..4ac043a 100644
--- a/lib/src/vector_math_geometry/filters/color_filter.dart
+++ b/lib/src/vector_math_geometry/filters/color_filter.dart
@@ -7,26 +7,32 @@
class ColorFilter extends GeometryFilter {
Vector4 color;
- List<VertexAttrib> get generates => [new VertexAttrib('COLOR', 4, 'float')];
+ ColorFilter(this.color);
- ColorFilter(Vector4 this.color);
+ @override
+ List<VertexAttrib> get generates =>
+ <VertexAttrib>[new VertexAttrib('COLOR', 4, 'float')];
+ @override
MeshGeometry filter(MeshGeometry mesh) {
MeshGeometry output;
if (mesh.getAttrib('COLOR') == null) {
- List<VertexAttrib> attributes = new List<VertexAttrib>();
- attributes.addAll(mesh.attribs);
- attributes.add(new VertexAttrib('COLOR', 4, 'float'));
+ final List<VertexAttrib> attributes = <VertexAttrib>[]
+ ..addAll(mesh.attribs)
+ ..add(new VertexAttrib('COLOR', 4, 'float'));
output = new MeshGeometry.resetAttribs(mesh, attributes);
} else {
output = new MeshGeometry.copy(mesh);
}
- Vector4List colors = output.getViewForAttrib('COLOR');
- for (int i = 0; i < colors.length; ++i) {
- colors[i] = color;
+ final VectorList<Vector> colors = output.getViewForAttrib('COLOR');
+ if (colors is Vector4List) {
+ for (int i = 0; i < colors.length; ++i) {
+ colors[i] = color;
+ }
+ return output;
+ } else {
+ return null;
}
-
- return output;
}
}
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 6da8eb1..41b8d87 100644
--- a/lib/src/vector_math_geometry/filters/flat_shade_filter.dart
+++ b/lib/src/vector_math_geometry/filters/flat_shade_filter.dart
@@ -5,30 +5,42 @@
part of vector_math_geometry;
class FlatShadeFilter extends GeometryFilter {
- List<VertexAttrib> get requires => [new VertexAttrib('POSITION', 3, 'float')];
- List<VertexAttrib> get generates => [new VertexAttrib('NORMAL', 3, 'float')];
+ @override
+ List<VertexAttrib> get requires =>
+ <VertexAttrib>[new VertexAttrib('POSITION', 3, 'float')];
+ @override
+ List<VertexAttrib> get generates =>
+ <VertexAttrib>[new VertexAttrib('NORMAL', 3, 'float')];
+
+ @override
MeshGeometry filter(MeshGeometry mesh) {
- List<VertexAttrib> newAttribs =
+ final List<VertexAttrib> newAttribs =
new List<VertexAttrib>.from(mesh.attribs, growable: true);
if (mesh.getAttrib('NORMAL') == null) {
newAttribs.add(new VertexAttrib('NORMAL', 3, 'float'));
}
- MeshGeometry output =
+ final MeshGeometry output =
new MeshGeometry(mesh.triangleVertexCount, newAttribs);
- Vector3 p0 = new Vector3.zero(),
+ final Vector3 p0 = new Vector3.zero(),
p1 = new Vector3.zero(),
p2 = new Vector3.zero();
- Vector3List srcPosition = mesh.getViewForAttrib('POSITION');
- Vector3List destPosition = output.getViewForAttrib('POSITION');
- Vector3List normals = output.getViewForAttrib('NORMAL');
+ final VectorList<Vector> srcPosition = mesh.getViewForAttrib('POSITION');
+ final VectorList<Vector> destPosition = output.getViewForAttrib('POSITION');
+ final VectorList<Vector> normals = output.getViewForAttrib('NORMAL');
- List<VectorList> srcAttribs = new List<VectorList>();
- List<VectorList> destAttribs = new List<VectorList>();
+ if (srcPosition is! Vector3List ||
+ destPosition is! Vector3List ||
+ normals is! Vector3List) {
+ return null;
+ }
+
+ final List<VectorList<Vector>> srcAttribs = <VectorList<Vector>>[];
+ final List<VectorList<Vector>> destAttribs = <VectorList<Vector>>[];
for (VertexAttrib attrib in mesh.attribs) {
if (attrib.name == 'POSITION' || attrib.name == 'NORMAL') {
continue;
@@ -39,13 +51,11 @@
}
for (int i = 0; i < output.length; i += 3) {
- int i0 = mesh.indices[i];
- int i1 = mesh.indices[i + 1];
- int i2 = mesh.indices[i + 2];
+ final int i0 = mesh.indices[i];
+ final int i1 = mesh.indices[i + 1];
+ final int i2 = mesh.indices[i + 2];
- srcPosition.load(i0, p0);
- srcPosition.load(i1, p1);
- srcPosition.load(i2, p2);
+ srcPosition..load(i0, p0)..load(i1, p1)..load(i2, p2);
destPosition[i] = p0;
destPosition[i + 1] = p1;
diff --git a/lib/src/vector_math_geometry/filters/geometry_filter.dart b/lib/src/vector_math_geometry/filters/geometry_filter.dart
index 78068b5..f678719 100644
--- a/lib/src/vector_math_geometry/filters/geometry_filter.dart
+++ b/lib/src/vector_math_geometry/filters/geometry_filter.dart
@@ -6,17 +6,20 @@
abstract class GeometryFilter {
bool get inplace => false;
- List<VertexAttrib> get requires => [];
- List<VertexAttrib> get generates => [];
+ List<VertexAttrib> get requires => <VertexAttrib>[];
+ List<VertexAttrib> get generates => <VertexAttrib>[];
/// Returns a copy of the mesh with any filter transforms applied.
MeshGeometry filter(MeshGeometry mesh);
}
abstract class InplaceGeometryFilter extends GeometryFilter {
+ @override
bool get inplace => true;
+
+ @override
MeshGeometry filter(MeshGeometry mesh) {
- MeshGeometry output = new MeshGeometry.copy(mesh);
+ final MeshGeometry output = new 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 0a2a4a1..8d2e6bc 100644
--- a/lib/src/vector_math_geometry/filters/invert_filter.dart
+++ b/lib/src/vector_math_geometry/filters/invert_filter.dart
@@ -5,6 +5,7 @@
part of vector_math_geometry;
class InvertFilter extends InplaceGeometryFilter {
+ @override
void filterInplace(MeshGeometry mesh) {
// TODO: Do the tangents need to be inverted? Maybe just the W component?
// TODO: Should modify in-place be allowed, or should it be required
@@ -12,13 +13,13 @@
// Swap all the triangle indices
for (int i = 0; i < mesh.indices.length; i += 3) {
- int tmp = mesh.indices[i];
+ final int tmp = mesh.indices[i];
mesh.indices[i] = mesh.indices[i + 2];
mesh.indices[i + 2] = tmp;
}
- Vector3List normals = mesh.getViewForAttrib('NORMAL');
- if (normals != null) {
+ final VectorList<Vector> normals = mesh.getViewForAttrib('NORMAL');
+ if (normals is Vector3List) {
for (int 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 a09b174..bb3db62 100644
--- a/lib/src/vector_math_geometry/filters/transform_filter.dart
+++ b/lib/src/vector_math_geometry/filters/transform_filter.dart
@@ -6,14 +6,20 @@
class TransformFilter extends InplaceGeometryFilter {
Matrix4 transform;
- List<VertexAttrib> get requires => [new VertexAttrib('POSITION', 3, 'float')];
- TransformFilter(Matrix4 this.transform);
+ TransformFilter(this.transform);
+ @override
+ List<VertexAttrib> get requires =>
+ <VertexAttrib>[new VertexAttrib('POSITION', 3, 'float')];
+
+ @override
void filterInplace(MeshGeometry mesh) {
- Vector3List position = mesh.getViewForAttrib('POSITION');
- if (position != null) {
+ final VectorList<Vector> position = mesh.getViewForAttrib('POSITION');
+ if (position is Vector3List) {
for (int i = 0; i < position.length; ++i) {
+ // multiplication always returns Vector3 here
+ // ignore: invalid_assignment
position[i] = transform * position[i];
}
}
diff --git a/lib/src/vector_math_geometry/generators/attribute_generators.dart b/lib/src/vector_math_geometry/generators/attribute_generators.dart
index c53c86f..415942c 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) {
- Vector3 p0 = new Vector3.zero(),
+ final Vector3 p0 = new Vector3.zero(),
p1 = new Vector3.zero(),
p2 = new Vector3.zero(),
norm = new Vector3.zero();
@@ -17,10 +17,8 @@
// Loop through every polygon, find it's normal, and add that to the vertex
// normals.
for (int i = 0; i < indices.length; i += 3) {
- int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
- positions.load(i0, p0);
- positions.load(i1, p1);
- positions.load(i2, p2);
+ final int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
+ positions..load(i0, p0)..load(i1, p1)..load(i2, p2);
p1.sub(p0);
p2.sub(p0);
@@ -59,7 +57,7 @@
/// http://www.terathon.com/code/tangent.html
void generateTangents(Vector4List tangents, Vector3List positions,
Vector3List normals, Vector2List texCoords, Uint16List indices) {
- Vector3 p0 = new Vector3.zero(),
+ final Vector3 p0 = new Vector3.zero(),
p1 = new Vector3.zero(),
p2 = new Vector3.zero(),
n = new Vector3.zero(),
@@ -67,24 +65,20 @@
udir = new Vector3.zero(),
vdir = new Vector3.zero();
- Vector2 uv0 = new Vector2.zero(),
+ final Vector2 uv0 = new Vector2.zero(),
uv1 = new Vector2.zero(),
uv2 = new Vector2.zero();
- Vector4 tan = new Vector4.zero();
+ final Vector4 tan = new Vector4.zero();
- Vector3List tan0 = new Vector3List(positions.length),
+ final Vector3List tan0 = new Vector3List(positions.length),
tan1 = new Vector3List(positions.length);
for (int i = 0; i < indices.length; i += 3) {
- int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2];
- positions.load(i0, p0);
- positions.load(i1, p1);
- positions.load(i2, p2);
+ final int 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);
- texCoords.load(i1, uv1);
- texCoords.load(i2, uv2);
+ texCoords..load(i0, uv0)..load(i1, uv1)..load(i2, uv2);
p1.sub(p0);
p2.sub(p0);
@@ -92,7 +86,7 @@
uv1.sub(uv0);
uv2.sub(uv0);
- double r = 1.0 / (uv1.x * uv2.y - uv2.x * uv1.y);
+ final double 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);
@@ -128,7 +122,7 @@
tan1.load(i, p1);
n.crossInto(t, p2);
- double sign = (p2.dot(p1) < 0.0) ? -1.0 : 1.0;
+ final double 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 9803f2c..d49a01c 100644
--- a/lib/src/vector_math_geometry/generators/circle_generator.dart
+++ b/lib/src/vector_math_geometry/generators/circle_generator.dart
@@ -10,15 +10,18 @@
double _thetaStart;
double _thetaLength;
+ @override
int get vertexCount => _segments + 2;
+
+ @override
int get indexCount => (_segments) * 3;
MeshGeometry createCircle(double radius,
- {flags: null,
- filters: null,
- segments: 64,
- thetaStart: 0.0,
- thetaLength: Math.PI * 2.0}) {
+ {GeometryGeneratorFlags flags: null,
+ List<GeometryFilter> filters: null,
+ int segments: 64,
+ double thetaStart: 0.0,
+ double thetaLength: math.PI * 2.0}) {
_radius = radius;
_segments = segments;
_thetaStart = thetaStart;
@@ -26,37 +29,42 @@
return createGeometry(flags: flags, filters: filters);
}
+ @override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
- Vector3 v = new Vector3.zero();
+ final Vector3 v = new Vector3.zero();
positions[0] = v;
int index = 1;
for (int i = 0; i <= _segments; i++) {
- double percent = i / _segments;
- v.x = _radius * Math.cos(_thetaStart + percent * _thetaLength);
- v.z = _radius * Math.sin(_thetaStart + percent * _thetaLength);
+ final double percent = i / _segments;
+ v
+ ..x = _radius * math.cos(_thetaStart + percent * _thetaLength)
+ ..z = _radius * math.sin(_thetaStart + percent * _thetaLength);
positions[index] = v;
index++;
}
assert(index == vertexCount);
}
+ @override
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
- Vector2 v = new Vector2(0.5, 0.5);
+ final Vector2 v = new Vector2(0.5, 0.5);
texCoords[0] = v;
int index = 1;
for (int i = 0; i <= _segments; i++) {
- Vector3 position = positions[index];
- double x = (position.x / (_radius + 1.0)) * 0.5;
- double y = (position.z / (_radius + 1.0)) * 0.5;
- v.x = x + 0.5;
- v.y = y + 0.5;
+ 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;
+ v
+ ..x = x + 0.5
+ ..y = y + 0.5;
texCoords[index] = v;
index++;
}
assert(index == vertexCount);
}
+ @override
void generateIndices(Uint16List indices) {
int index = 0;
for (int i = 1; i <= _segments; i++) {
diff --git a/lib/src/vector_math_geometry/generators/cube_generator.dart b/lib/src/vector_math_geometry/generators/cube_generator.dart
index 3d379a9..b0948a7 100644
--- a/lib/src/vector_math_geometry/generators/cube_generator.dart
+++ b/lib/src/vector_math_geometry/generators/cube_generator.dart
@@ -9,11 +9,15 @@
double _height;
double _depth;
+ @override
int get vertexCount => 24;
+
+ @override
int get indexCount => 36;
MeshGeometry createCube(num width, num height, num depth,
- {flags: null, filters: null}) {
+ {GeometryGeneratorFlags flags: null,
+ List<GeometryFilter> filters: null}) {
_width = width.toDouble();
_height = height.toDouble();
_depth = depth.toDouble();
@@ -21,8 +25,9 @@
return createGeometry(flags: flags, filters: filters);
}
+ @override
void generateIndices(Uint16List indices) {
- indices.setAll(0, [
+ indices.setAll(0, <int>[
0,
1,
2,
@@ -62,6 +67,7 @@
]);
}
+ @override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
// Front
positions[0] = new Vector3(_width, _height, _depth);
@@ -100,6 +106,7 @@
positions[23] = new Vector3(_width, -_height, _depth);
}
+ @override
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
// Front
diff --git a/lib/src/vector_math_geometry/generators/cylinder_generator.dart b/lib/src/vector_math_geometry/generators/cylinder_generator.dart
index dc40992..1cb4045 100644
--- a/lib/src/vector_math_geometry/generators/cylinder_generator.dart
+++ b/lib/src/vector_math_geometry/generators/cylinder_generator.dart
@@ -10,11 +10,16 @@
double _height;
int _segments;
+ @override
int get vertexCount => ((_segments + 1) * 2) + (_segments * 2);
+
+ @override
int get indexCount => (_segments * 6) + ((_segments - 2) * 6);
MeshGeometry createCylinder(num topRadius, num bottomRadius, num height,
- {int segments: 16, flags: null, filters: null}) {
+ {int segments: 16,
+ GeometryGeneratorFlags flags: null,
+ List<GeometryFilter> filters: null}) {
_topRadius = topRadius.toDouble();
_bottomRadius = bottomRadius.toDouble();
_height = height.toDouble();
@@ -23,12 +28,13 @@
return createGeometry(flags: flags, filters: filters);
}
+ @override
void generateIndices(Uint16List indices) {
int i = 0;
// Sides
int base1 = 0;
- int base2 = _segments + 1;
+ final int base2 = _segments + 1;
for (int x = 0; x < _segments; ++x) {
indices[i++] = base1 + x;
indices[i++] = base1 + x + 1;
@@ -56,70 +62,72 @@
}
}
+ @override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
int i = 0;
// Top
for (int x = 0; x <= _segments; ++x) {
- double u = x / _segments;
+ final double u = x / _segments;
- positions[i++] = new Vector3(_topRadius * Math.cos(u * Math.PI * 2.0),
- _height * 0.5, _topRadius * Math.sin(u * Math.PI * 2.0));
+ positions[i++] = new Vector3(_topRadius * math.cos(u * math.PI * 2.0),
+ _height * 0.5, _topRadius * math.sin(u * math.PI * 2.0));
}
// Bottom
for (int x = 0; x <= _segments; ++x) {
- double u = x / _segments;
+ final double u = x / _segments;
- positions[i++] = new Vector3(_bottomRadius * Math.cos(u * Math.PI * 2.0),
- _height * -0.5, _bottomRadius * Math.sin(u * Math.PI * 2.0));
+ positions[i++] = new Vector3(_bottomRadius * math.cos(u * math.PI * 2.0),
+ _height * -0.5, _bottomRadius * math.sin(u * math.PI * 2.0));
}
// Top cap
for (int x = 0; x < _segments; ++x) {
- double u = x / _segments;
+ final double u = x / _segments;
- positions[i++] = new Vector3(_topRadius * Math.cos(u * Math.PI * 2.0),
- _height * 0.5, _topRadius * Math.sin(u * Math.PI * 2.0));
+ positions[i++] = new Vector3(_topRadius * math.cos(u * math.PI * 2.0),
+ _height * 0.5, _topRadius * math.sin(u * math.PI * 2.0));
}
// Bottom cap
for (int x = 0; x < _segments; ++x) {
- double u = x / _segments;
+ final double u = x / _segments;
- positions[i++] = new Vector3(_bottomRadius * Math.cos(u * Math.PI * 2.0),
- _height * -0.5, _bottomRadius * Math.sin(u * Math.PI * 2.0));
+ positions[i++] = new Vector3(_bottomRadius * math.cos(u * math.PI * 2.0),
+ _height * -0.5, _bottomRadius * math.sin(u * math.PI * 2.0));
}
}
+ @override
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
int i = 0;
// Cylinder top
for (int x = 0; x <= _segments; ++x) {
- double u = 1.0 - (x / _segments);
+ final double u = 1.0 - (x / _segments);
texCoords[i++] = new Vector2(u, 0.0);
}
// Cylinder bottom
for (int x = 0; x <= _segments; ++x) {
- double u = 1.0 - (x / _segments);
+ final double u = 1.0 - (x / _segments);
texCoords[i++] = new Vector2(u, 1.0);
}
// Top cap
for (int x = 0; x < _segments; ++x) {
- double r = (x / _segments) * Math.PI * 2.0;
+ final double r = (x / _segments) * math.PI * 2.0;
texCoords[i++] =
- new Vector2((Math.cos(r) * 0.5 + 0.5), (Math.sin(r) * 0.5 + 0.5));
+ new Vector2((math.cos(r) * 0.5 + 0.5), (math.sin(r) * 0.5 + 0.5));
}
// Bottom cap
for (int x = 0; x < _segments; ++x) {
- double r = (x / _segments) * Math.PI * 2.0;
+ final double r = (x / _segments) * math.PI * 2.0;
texCoords[i++] =
- new Vector2((Math.cos(r) * 0.5 + 0.5), (Math.sin(r) * 0.5 + 0.5));
+ new 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 9f8d035..6a2171a 100644
--- a/lib/src/vector_math_geometry/generators/geometry_generator.dart
+++ b/lib/src/vector_math_geometry/generators/geometry_generator.dart
@@ -18,8 +18,9 @@
int get indexCount;
MeshGeometry createGeometry(
- {GeometryGeneratorFlags flags: null, List filters: null}) {
- if (flags == null) flags = new GeometryGeneratorFlags();
+ {GeometryGeneratorFlags flags: null,
+ List<GeometryFilter> filters: null}) {
+ flags ??= new GeometryGeneratorFlags();
VertexAttrib positionAttrib;
VertexAttrib texCoordAttrib;
@@ -31,7 +32,7 @@
Vector3List normalView;
Vector4List tangentView;
- List<VertexAttrib> attribs = new List<VertexAttrib>();
+ final List<VertexAttrib> attribs = <VertexAttrib>[];
positionAttrib = new VertexAttrib('POSITION', 3, 'float');
attribs.add(positionAttrib);
@@ -51,33 +52,44 @@
attribs.add(tangentAttrib);
}
- MeshGeometry mesh = new MeshGeometry(vertexCount, attribs);
-
- mesh.indices = new Uint16List(indexCount);
+ MeshGeometry mesh = new MeshGeometry(vertexCount, attribs)
+ ..indices = new Uint16List(indexCount);
generateIndices(mesh.indices);
- positionView = mesh.getViewForAttrib('POSITION');
- generateVertexPositions(positionView, mesh.indices);
+ VectorList<Vector> view = mesh.getViewForAttrib('POSITION');
+ if (view is Vector3List) {
+ positionView = view;
+ generateVertexPositions(positionView, mesh.indices);
+ }
if (flags.texCoords || flags.tangents) {
- texCoordView = mesh.getViewForAttrib('TEXCOORD0');
- generateVertexTexCoords(texCoordView, positionView, mesh.indices);
+ view = mesh.getViewForAttrib('TEXCOORD0');
+ if (view is Vector2List) {
+ texCoordView = view;
+ generateVertexTexCoords(texCoordView, positionView, mesh.indices);
+ }
}
if (flags.normals || flags.tangents) {
- normalView = mesh.getViewForAttrib('NORMAL');
- generateVertexNormals(normalView, positionView, mesh.indices);
+ view = mesh.getViewForAttrib('NORMAL');
+ if (view is Vector3List) {
+ normalView = view;
+ generateVertexNormals(normalView, positionView, mesh.indices);
+ }
}
if (flags.tangents) {
- tangentView = mesh.getViewForAttrib('TANGENT');
- generateVertexTangents(
- tangentView, positionView, normalView, texCoordView, mesh.indices);
+ view = mesh.getViewForAttrib('TANGENT');
+ if (view is Vector4List) {
+ tangentView = view;
+ generateVertexTangents(
+ tangentView, positionView, normalView, texCoordView, mesh.indices);
+ }
}
if (filters != null) {
- for (var filter in filters) {
- if (filter.inplace) {
+ for (GeometryFilter filter in filters) {
+ if (filter.inplace && filter is InplaceGeometryFilter) {
filter.filterInplace(mesh);
} else {
mesh = filter.filter(mesh);
@@ -95,7 +107,7 @@
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
for (int i = 0; i < positions.length; ++i) {
- Vector3 p = positions[i];
+ final Vector3 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 fa00860..d49bc71 100644
--- a/lib/src/vector_math_geometry/generators/ring_generator.dart
+++ b/lib/src/vector_math_geometry/generators/ring_generator.dart
@@ -12,16 +12,19 @@
double _thetaLength;
bool _stripTextureCoordinates;
+ @override
int get vertexCount => (_segments + 1) * 2;
+
+ @override
int get indexCount => (_segments) * 3 * 2;
MeshGeometry createRing(double innerRadius, double outerRadius,
- {flags: null,
- filters: null,
- segments: 64,
- thetaStart: 0.0,
- thetaLength: Math.PI * 2.0,
- stripTextureCoordinates: true}) {
+ {GeometryGeneratorFlags flags: null,
+ List<GeometryFilter> filters: null,
+ int segments: 64,
+ double thetaStart: 0.0,
+ double thetaLength: math.PI * 2.0,
+ bool stripTextureCoordinates: true}) {
_innerRadius = innerRadius;
_outerRadius = outerRadius;
_segments = segments;
@@ -31,55 +34,63 @@
return createGeometry(flags: flags, filters: filters);
}
+ @override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
- Vector3 v = new Vector3.zero();
+ final Vector3 v = new Vector3.zero();
int index = 0;
for (int i = 0; i <= _segments; i++) {
- double percent = i / _segments;
- v.x = _innerRadius * Math.cos(_thetaStart + percent * _thetaLength);
- v.z = _innerRadius * Math.sin(_thetaStart + percent * _thetaLength);
+ final double percent = i / _segments;
+ v
+ ..x = _innerRadius * math.cos(_thetaStart + percent * _thetaLength)
+ ..z = _innerRadius * math.sin(_thetaStart + percent * _thetaLength);
positions[index] = v;
index++;
- v.x = _outerRadius * Math.cos(_thetaStart + percent * _thetaLength);
- v.z = _outerRadius * Math.sin(_thetaStart + percent * _thetaLength);
+ v
+ ..x = _outerRadius * math.cos(_thetaStart + percent * _thetaLength)
+ ..z = _outerRadius * math.sin(_thetaStart + percent * _thetaLength);
positions[index] = v;
index++;
}
assert(index == vertexCount);
}
+ @override
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
if (_stripTextureCoordinates) {
- Vector2 v = new Vector2.zero();
+ final Vector2 v = new Vector2.zero();
int index = 0;
for (int i = 0; i <= _segments; i++) {
- double percent = i / _segments;
- v.x = 0.0;
- v.y = percent;
+ final double percent = i / _segments;
+ v
+ ..x = 0.0
+ ..y = percent;
texCoords[index] = v;
index++;
- v.x = 1.0;
- v.y = percent;
+ v
+ ..x = 1.0
+ ..y = percent;
texCoords[index] = v;
index++;
}
} else {
- Vector2 v = new Vector2.zero();
+ final Vector2 v = new Vector2.zero();
int index = 0;
for (int i = 0; i <= _segments; i++) {
Vector3 position = positions[index];
double x = (position.x / (_outerRadius + 1.0)) * 0.5;
double y = (position.z / (_outerRadius + 1.0)) * 0.5;
- v.x = x + 0.5;
- v.y = y + 0.5;
+ v
+ ..x = x + 0.5
+ ..y = y + 0.5;
texCoords[index] = v;
index++;
position = positions[index];
x = (position.x / (_outerRadius + 1.0)) * 0.5;
y = (position.z / (_outerRadius + 1.0)) * 0.5;
- v.x = x + 0.5;
- v.y = y + 0.5;
+ v
+ ..x = x + 0.5
+ ..y = y + 0.5;
texCoords[index] = v;
index++;
}
@@ -87,9 +98,10 @@
}
}
+ @override
void generateIndices(Uint16List indices) {
int index = 0;
- int length = _segments * 2;
+ final int length = _segments * 2;
for (int 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 e7d15e3..fdb4eca 100644
--- a/lib/src/vector_math_geometry/generators/sphere_generator.dart
+++ b/lib/src/vector_math_geometry/generators/sphere_generator.dart
@@ -9,11 +9,17 @@
int _latSegments;
int _lonSegments;
+ @override
int get vertexCount => (_lonSegments + 1) * (_latSegments + 1);
+
+ @override
int get indexCount => 6 * _lonSegments * _latSegments;
MeshGeometry createSphere(num radius,
- {int latSegments: 16, int lonSegments: 16, flags: null, filters: null}) {
+ {int latSegments: 16,
+ int lonSegments: 16,
+ GeometryGeneratorFlags flags: null,
+ List<GeometryFilter> filters: null}) {
_radius = radius.toDouble();
_latSegments = latSegments;
_lonSegments = lonSegments;
@@ -21,11 +27,12 @@
return createGeometry(flags: flags, filters: filters);
}
+ @override
void generateIndices(Uint16List indices) {
int i = 0;
for (int y = 0; y < _latSegments; ++y) {
- int base1 = (_lonSegments + 1) * y;
- int base2 = (_lonSegments + 1) * (y + 1);
+ final int base1 = (_lonSegments + 1) * y;
+ final int base2 = (_lonSegments + 1) * (y + 1);
for (int x = 0; x < _lonSegments; ++x) {
indices[i++] = base1 + x;
@@ -39,48 +46,51 @@
}
}
+ @override
void generateVertexPositions(Vector3List positions, Uint16List indices) {
int i = 0;
for (int y = 0; y <= _latSegments; ++y) {
- double v = y / _latSegments;
- double sv = Math.sin(v * Math.PI);
- double cv = Math.cos(v * Math.PI);
+ final double v = y / _latSegments;
+ final double sv = math.sin(v * math.PI);
+ final double cv = math.cos(v * math.PI);
for (int x = 0; x <= _lonSegments; ++x) {
- double u = x / _lonSegments;
+ final double u = x / _lonSegments;
- positions[i++] = new Vector3(_radius * Math.cos(u * Math.PI * 2.0) * sv,
- _radius * cv, _radius * Math.sin(u * Math.PI * 2.0) * sv);
+ positions[i++] = new Vector3(_radius * math.cos(u * math.PI * 2.0) * sv,
+ _radius * cv, _radius * math.sin(u * math.PI * 2.0) * sv);
}
}
}
+ @override
void generateVertexTexCoords(
Vector2List texCoords, Vector3List positions, Uint16List indices) {
int i = 0;
for (int y = 0; y <= _latSegments; ++y) {
- double v = y / _latSegments;
+ final double v = y / _latSegments;
for (int x = 0; x <= _lonSegments; ++x) {
- double u = x / _lonSegments;
+ final double u = x / _lonSegments;
texCoords[i++] = new Vector2(u, v);
}
}
}
+ @override
void generateVertexNormals(
Vector3List normals, Vector3List positions, Uint16List indices) {
int i = 0;
for (int y = 0; y <= _latSegments; ++y) {
- double v = y / _latSegments;
- double sv = Math.sin(v * Math.PI);
- double cv = Math.cos(v * Math.PI);
+ final double v = y / _latSegments;
+ final double sv = math.sin(v * math.PI);
+ final double cv = math.cos(v * math.PI);
for (int x = 0; x <= _lonSegments; ++x) {
- double u = x / _lonSegments;
+ final double u = x / _lonSegments;
- normals[i++] = new Vector3(Math.cos(u * Math.PI * 2.0) * sv, cv,
- Math.sin(u * Math.PI * 2.0) * sv);
+ normals[i++] = new 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 314b61e..5eedb53 100644
--- a/lib/src/vector_math_geometry/mesh_geometry.dart
+++ b/lib/src/vector_math_geometry/mesh_geometry.dart
@@ -30,9 +30,9 @@
size = attrib.size,
type = attrib.type;
- VectorList getView(Float32List buffer) {
- int viewOffset = offset ~/ buffer.elementSizeInBytes;
- int viewStride = stride ~/ buffer.elementSizeInBytes;
+ VectorList<Vector> getView(Float32List buffer) {
+ final int viewOffset = offset ~/ buffer.elementSizeInBytes;
+ final int viewStride = stride ~/ buffer.elementSizeInBytes;
switch (size) {
case 2:
return new Vector2List.view(buffer, viewOffset, viewStride);
@@ -45,9 +45,7 @@
}
}
- String get format {
- return '$type$size';
- }
+ String get format => '$type$size';
int get elementSize {
switch (type) {
@@ -63,16 +61,14 @@
}
}
- Map toJson() {
- return {
- 'format': format,
- 'name': name,
- 'offset': offset,
- 'stride': stride,
- 'size': size,
- 'type': type
- };
- }
+ Map<String, Object> toJson() => <String, Object>{
+ 'format': format,
+ 'name': name,
+ 'offset': offset,
+ 'stride': stride,
+ 'size': size,
+ 'type': type
+ };
}
class MeshGeometry {
@@ -88,7 +84,7 @@
stride += a.elementSize * a.size;
}
int offset = 0;
- List<VertexAttrib> attribs = new List<VertexAttrib>();
+ final List<VertexAttrib> attribs = <VertexAttrib>[];
for (VertexAttrib a in attributes) {
attribs.add(new VertexAttrib._resetStrideOffset(a, stride, offset));
offset += a.elementSize * a.size;
@@ -97,8 +93,7 @@
return new MeshGeometry._internal(length, stride, attribs);
}
- MeshGeometry._internal(
- int this.length, int this.stride, List<VertexAttrib> this.attribs,
+ MeshGeometry._internal(this.length, this.stride, this.attribs,
[Float32List externBuffer]) {
if (externBuffer == null) {
buffer =
@@ -123,27 +118,44 @@
}
}
- int get triangleVertexCount => indices != null ? indices.length : length;
+ factory MeshGeometry.fromJson(Map<String, Object> json) {
+ Float32List buffer;
+ final Object jsonBuffer = json["buffer"];
+ if (jsonBuffer is List<double>) {
+ buffer = new Float32List.fromList(jsonBuffer);
+ } else {
+ throw new ArgumentError.value(
+ jsonBuffer, 'json["buffer"]', 'Value type must be List<double>');
+ }
- factory MeshGeometry.fromJson(Map json) {
- Float32List buffer = new Float32List.fromList(json["buffer"]);
-
- Map jsonAttribs = json["attribs"];
+ final Object jsonAttribs = json["attribs"];
+ Map<String, Object> jsonAttribsMap;
+ if (jsonAttribs is Map<String, Object>) {
+ jsonAttribsMap = jsonAttribs;
+ } else {
+ throw new ArgumentError.value(jsonBuffer, 'json["attribs"]',
+ 'Value type must be Map<String, Object>');
+ }
List<VertexAttrib> attribs;
int stride = 0;
- for (String key in jsonAttribs.keys) {
- VertexAttrib attrib = attribFromJson(key, jsonAttribs[key]);
- attribs.add(attrib);
- if (stride == 0) {
- stride = attrib.stride;
+ for (String key in jsonAttribsMap.keys) {
+ VertexAttrib attrib;
+ final Object jsonAttrib = jsonAttribsMap[key];
+ if (jsonAttrib is Map<String, Object>) {
+ attrib = attribFromJson(key, jsonAttrib);
+ attribs.add(attrib);
+ if (stride == 0) {
+ stride = attrib.stride;
+ }
}
}
- MeshGeometry mesh = new MeshGeometry._internal(
+ final MeshGeometry mesh = new MeshGeometry._internal(
buffer.lengthInBytes ~/ stride, stride, attribs, buffer);
- if (json.containsKey("indices")) {
- mesh.indices = new Uint16List.fromList(json["indices"]);
+ final Object jsonIndices = json["indices"];
+ if (jsonIndices is List<int>) {
+ mesh.indices = new Uint16List.fromList(jsonIndices);
}
return mesh;
@@ -151,12 +163,12 @@
factory MeshGeometry.resetAttribs(
MeshGeometry inputMesh, List<VertexAttrib> attributes) {
- MeshGeometry mesh = new MeshGeometry(inputMesh.length, attributes);
- mesh.indices = inputMesh.indices;
+ final MeshGeometry mesh = new MeshGeometry(inputMesh.length, attributes)
+ ..indices = inputMesh.indices;
// Copy over the attributes that were specified
for (VertexAttrib attrib in mesh.attribs) {
- VertexAttrib inputAttrib = inputMesh.getAttrib(attrib.name);
+ final VertexAttrib inputAttrib = inputMesh.getAttrib(attrib.name);
if (inputAttrib != null) {
if (inputAttrib.size != attrib.size ||
inputAttrib.type != attrib.type) {
@@ -164,9 +176,11 @@
"Attributes size or type is mismatched: ${attrib.name}");
}
- var inputView = inputAttrib.getView(inputMesh.buffer);
- var outputView = attrib.getView(mesh.buffer);
- outputView.copy(inputView);
+ final VectorList<Vector> inputView =
+ inputAttrib.getView(inputMesh.buffer);
+
+ // Copy [inputView] to a view from attrib
+ attrib.getView(mesh.buffer).copy(inputView);
}
}
@@ -180,11 +194,11 @@
}
// When combining meshes they must all have a matching set of VertexAttribs
- MeshGeometry firstMesh = meshes[0];
+ final MeshGeometry firstMesh = meshes[0];
int totalVerts = firstMesh.length;
int totalIndices = firstMesh.indices != null ? firstMesh.indices.length : 0;
for (int i = 1; i < meshes.length; ++i) {
- MeshGeometry srcMesh = meshes[i];
+ final MeshGeometry srcMesh = meshes[i];
if (!firstMesh.attribsAreCompatible(srcMesh)) {
throw new Exception(
"All meshes must have identical attributes to combine.");
@@ -193,7 +207,7 @@
totalIndices += srcMesh.indices != null ? srcMesh.indices.length : 0;
}
- MeshGeometry mesh = new MeshGeometry._internal(
+ final MeshGeometry mesh = new MeshGeometry._internal(
totalVerts, firstMesh.stride, firstMesh.attribs);
if (totalIndices > 0) {
@@ -204,7 +218,7 @@
int bufferOffset = 0;
int indexOffset = 0;
for (int i = 0; i < meshes.length; ++i) {
- MeshGeometry srcMesh = meshes[i];
+ final MeshGeometry srcMesh = meshes[i];
mesh.buffer.setAll(bufferOffset, srcMesh.buffer);
if (totalIndices > 0) {
@@ -220,29 +234,46 @@
return mesh;
}
- Map toJson() {
- Map r = {};
+ int get triangleVertexCount => indices != null ? indices.length : length;
+
+ Map<String, Object> toJson() {
+ final Map<String, Object> r = <String, Object>{};
r['attributes'] = attribs;
r['indices'] = indices;
r['vertices'] = buffer;
return r;
}
- static VertexAttrib attribFromJson(String name, Map json) {
- return new VertexAttrib._internal(
- name, json["size"], json["type"], json["stride"], json["offset"]);
+ 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"];
+ if (jsonSize is int &&
+ jsonType is String &&
+ jsonStride is int &&
+ jsonOffset is int) {
+ return new VertexAttrib._internal(
+ name, jsonSize, jsonType, jsonStride, jsonOffset);
+ } else {
+ return null;
+ }
}
VertexAttrib getAttrib(String name) {
for (VertexAttrib attrib in attribs) {
- if (attrib.name == name) return attrib;
+ if (attrib.name == name) {
+ return attrib;
+ }
}
return null;
}
- VectorList getViewForAttrib(String name) {
+ VectorList<Vector> getViewForAttrib(String name) {
for (VertexAttrib attrib in attribs) {
- if (attrib.name == name) return attrib.getView(buffer);
+ if (attrib.name == name) {
+ return attrib.getView(buffer);
+ }
}
return null;
}
@@ -253,7 +284,7 @@
}
for (VertexAttrib attrib in attribs) {
- VertexAttrib otherAttrib = mesh.getAttrib(attrib.name);
+ final VertexAttrib 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 499e555..7c7cc4f 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) {
- int width = stride == 0 ? 1 : stride;
+ final int width = stride == 0 ? 1 : stride;
return offset + width * length;
}
@@ -51,13 +51,11 @@
ScalarListView.view(Float32List buffer, [int offset = 0, int stride = 0])
: _offset = offset,
_stride = stride == 0 ? 1 : stride,
- _length = (buffer.length - Math.max(0, offset - stride)) ~/
+ _length = (buffer.length - math.max(0, offset - stride)) ~/
(stride == 0 ? 1 : stride),
_buffer = buffer;
- int _elementIndexToBufferIndex(int index) {
- return _offset + _stride * index;
- }
+ int _elementIndexToBufferIndex(int index) => _offset + _stride * index;
/// Retrieves the value at [index].
double operator [](int index) => load(index);
@@ -69,7 +67,7 @@
/// Store [value] in the list at [index].
void store(int index, double value) {
- final i = _elementIndexToBufferIndex(index);
+ final int 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 a84fc15..df1eabe 100644
--- a/lib/src/vector_math_lists/vector2_list.dart
+++ b/lib/src/vector_math_lists/vector2_list.dart
@@ -22,21 +22,21 @@
: super.view(buffer, 2, offset, stride);
@override
- Vector2 newVector() {
- return new Vector2.zero();
- }
+ Vector2 newVector() => new Vector2.zero();
/// Retrieves the vector at [index] and stores it in [vector].
+ @override
void load(int index, Vector2 vector) {
- final i = _vectorIndexToBufferIndex(index);
+ final int i = _vectorIndexToBufferIndex(index);
vector.storage[0] = _buffer[i + 0];
vector.storage[1] = _buffer[i + 1];
}
/// Store [vector] in the list at [index].
+ @override
void store(int index, Vector2 vector) {
- final i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
+ final int 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
+ final int 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 c75c6ce..bd99b18 100644
--- a/lib/src/vector_math_lists/vector3_list.dart
+++ b/lib/src/vector_math_lists/vector3_list.dart
@@ -22,22 +22,22 @@
: super.view(buffer, 3, offset, stride);
@override
- Vector3 newVector() {
- return new Vector3.zero();
- }
+ Vector3 newVector() => new Vector3.zero();
/// Retrieves the vector at [index] and stores it in [vector].
+ @override
void load(int index, Vector3 vector) {
- final i = _vectorIndexToBufferIndex(index);
+ final int i = _vectorIndexToBufferIndex(index);
vector.storage[0] = _buffer[i + 0];
vector.storage[1] = _buffer[i + 1];
vector.storage[2] = _buffer[i + 2];
}
/// Store [vector] in the list at [index].
+ @override
void store(int index, Vector3 vector) {
- final i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
+ final int 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
+ final int 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 6b26112..09c16d1 100644
--- a/lib/src/vector_math_lists/vector4_list.dart
+++ b/lib/src/vector_math_lists/vector4_list.dart
@@ -22,13 +22,12 @@
: super.view(buffer, 4, offset, stride);
@override
- Vector4 newVector() {
- return new Vector4.zero();
- }
+ Vector4 newVector() => new Vector4.zero();
/// Retrieves the vector at [index] and stores it in [vector].
+ @override
void load(int index, Vector4 vector) {
- final i = _vectorIndexToBufferIndex(index);
+ final int i = _vectorIndexToBufferIndex(index);
vector.storage[0] = _buffer[i + 0];
vector.storage[1] = _buffer[i + 1];
vector.storage[2] = _buffer[i + 2];
@@ -36,9 +35,10 @@
}
/// Store [vector] in the list at [index].
+ @override
void store(int index, Vector4 vector) {
- final i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
+ final int 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
- final storage = vector.storage;
+ final int i = _vectorIndexToBufferIndex(index);
+ final Float32List 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 i = _vectorIndexToBufferIndex(index);
+ final int 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 a92fd33..d77256a 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) {
- int width = stride == 0 ? vectorLength : stride;
+ final int width = stride == 0 ? vectorLength : stride;
return offset + width * length;
}
@@ -42,7 +42,7 @@
/// Create a new vector list from a list of vectors that have a size of
/// [vectorLength]. Optionally it is possible to specify an [offset] in the
/// [buffer] and a [stride] between each vector.
- VectorList.fromList(List list, int vectorLength,
+ VectorList.fromList(List<T> list, int vectorLength,
[int offset = 0, int stride = 0])
: _vectorLength = vectorLength,
_offset = offset,
@@ -66,7 +66,7 @@
: _vectorLength = vectorLength,
_offset = offset,
_stride = stride == 0 ? vectorLength : stride,
- _length = (buffer.length - Math.max(0, offset - stride)) ~/
+ _length = (buffer.length - math.max(0, offset - stride)) ~/
(stride == 0 ? vectorLength : stride),
_buffer = buffer {
if (_stride < _vectorLength) {
@@ -74,9 +74,7 @@
}
}
- int _vectorIndexToBufferIndex(int index) {
- return _offset + _stride * index;
- }
+ int _vectorIndexToBufferIndex(int index) => _offset + _stride * index;
/// Create a new instance of [T].
T newVector();
@@ -89,11 +87,12 @@
/// Copy a range of [count] vectors beginning at [srcOffset] from [src] into
/// this list starting at [offset].
- void copy(VectorList src, {int srcOffset: 0, int offset: 0, int count: 0}) {
+ void copy(VectorList<T> src,
+ {int srcOffset: 0, int offset: 0, int count: 0}) {
if (count == 0) {
- count = Math.min(length - offset, src.length - srcOffset);
+ count = math.min(length - offset, src.length - srcOffset);
}
- int minVectorLength = Math.min(_vectorLength, src._vectorLength);
+ final int minVectorLength = math.min(_vectorLength, src._vectorLength);
for (int i = 0; i < count; i++) {
int index = _vectorIndexToBufferIndex(i + offset);
int srcIndex = src._vectorIndexToBufferIndex(i + srcOffset);
@@ -105,7 +104,7 @@
/// Retrieves the vector at [index].
T operator [](int index) {
- var r = newVector();
+ final T 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 f00d207..d893325 100644
--- a/lib/src/vector_math_operations/matrix.dart
+++ b/lib/src/vector_math_operations/matrix.dart
@@ -9,36 +9,40 @@
class Matrix44Operations {
/// Compute the determinant of the 4x4 [matrix] starting at [offset].
static double determinant(Float32List matrix, int offset) {
- double m0 = matrix[0 + offset];
- double m1 = matrix[1 + offset];
- double m2 = matrix[2 + offset];
- double m3 = matrix[3 + offset];
- double m4 = matrix[4 + offset];
- double m5 = matrix[5 + offset];
- double m6 = matrix[6 + offset];
- double m7 = matrix[7 + 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];
- double det2_01_01 = m0 * m5 - m1 * m4;
- double det2_01_02 = m0 * m6 - m2 * m4;
- double det2_01_03 = m0 * m7 - m3 * m4;
- double det2_01_12 = m1 * m6 - m2 * m5;
- double det2_01_13 = m1 * m7 - m3 * m5;
- double det2_01_23 = m2 * m7 - m3 * m6;
+ 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;
- double m8 = matrix[8 + offset];
- double m9 = matrix[9 + offset];
- double m10 = matrix[10 + offset];
- double m11 = matrix[11 + offset];
+ final double m8 = matrix[8 + offset];
+ final double m9 = matrix[9 + offset];
+ final double m10 = matrix[10 + offset];
+ final double m11 = matrix[11 + offset];
- double det3_201_012 = m8 * det2_01_12 - m9 * det2_01_02 + m10 * det2_01_01;
- double det3_201_013 = m8 * det2_01_13 - m9 * det2_01_03 + m11 * det2_01_01;
- double det3_201_023 = m8 * det2_01_23 - m10 * det2_01_03 + m11 * det2_01_02;
- double det3_201_123 = m9 * det2_01_23 - m10 * det2_01_13 + m11 * det2_01_12;
+ 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;
- double m12 = matrix[12 + offset];
- double m13 = matrix[13 + offset];
- double m14 = matrix[14 + offset];
- double m15 = matrix[15 + offset];
+ final double m12 = matrix[12 + offset];
+ final double m13 = matrix[13 + offset];
+ final double m14 = matrix[14 + offset];
+ final double m15 = matrix[15 + offset];
return -det3_201_123 * m12 +
det3_201_023 * m13 -
@@ -49,59 +53,59 @@
/// Compute the determinant of the upper 3x3 of the 4x4 [matrix] starting at
/// [offset].
static double determinant33(Float32List matrix, int offset) {
- double m0 = matrix[0 + offset];
- double m1 = matrix[1 + offset];
- double m2 = matrix[2 + offset];
- double m4 = matrix[4 + offset];
- double m5 = matrix[5 + offset];
- double m6 = matrix[6 + offset];
- double m8 = matrix[8 + offset];
- double m9 = matrix[9 + offset];
- double m10 = matrix[10 + offset];
- double x = m0 * ((m5 * m10) - (m6 * m8));
- double y = m1 * ((m4 * m10) - (m6 * m8));
- double z = m2 * ((m4 * m9) - (m5 * m8));
+ 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));
return x - y + z;
}
/// Compute the inverse of the 4x4 [matrix] starting at [offset].
static double inverse(Float32List matrix, int offset) {
- double a00 = matrix[0];
- double a01 = matrix[1];
- double a02 = matrix[2];
- double a03 = matrix[3];
- double a10 = matrix[4];
- double a11 = matrix[5];
- double a12 = matrix[6];
- double a13 = matrix[7];
- double a20 = matrix[8];
- double a21 = matrix[9];
- double a22 = matrix[10];
- double a23 = matrix[11];
- double a30 = matrix[12];
- double a31 = matrix[13];
- double a32 = matrix[14];
- double a33 = matrix[15];
- double b00 = a00 * a11 - a01 * a10;
- double b01 = a00 * a12 - a02 * a10;
- double b02 = a00 * a13 - a03 * a10;
- double b03 = a01 * a12 - a02 * a11;
- double b04 = a01 * a13 - a03 * a11;
- double b05 = a02 * a13 - a03 * a12;
- double b06 = a20 * a31 - a21 * a30;
- double b07 = a20 * a32 - a22 * a30;
- double b08 = a20 * a33 - a23 * a30;
- double b09 = a21 * a32 - a22 * a31;
- double b10 = a21 * a33 - a23 * a31;
- double b11 = a22 * a33 - a23 * a32;
- double det =
+ 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 =
(b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06);
if (det == 0.0) {
return det;
}
- var invDet = 1.0 / det;
+ final double invDet = 1.0 / det;
matrix[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
matrix[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
@@ -131,27 +135,27 @@
/// [out] = [a] * [b]; Starting at [outOffset], [aOffset], and [bOffset].
static void multiply(Float32List out, int outOffset, Float32List a,
int aOffset, Float32List b, int bOffset) {
- var a00 = a[aOffset++];
- var a01 = a[aOffset++];
- var a02 = a[aOffset++];
- var a03 = a[aOffset++];
- var a10 = a[aOffset++];
- var a11 = a[aOffset++];
- var a12 = a[aOffset++];
- var a13 = a[aOffset++];
- var a20 = a[aOffset++];
- var a21 = a[aOffset++];
- var a22 = a[aOffset++];
- var a23 = a[aOffset++];
- var a30 = a[aOffset++];
- var a31 = a[aOffset++];
- var a32 = a[aOffset++];
- var a33 = a[aOffset++];
+ 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++];
- var b0 = b[bOffset++];
- var b1 = b[bOffset++];
- var b2 = b[bOffset++];
- var b3 = b[bOffset++];
+ double b0 = b[bOffset++];
+ double b1 = b[bOffset++];
+ double b2 = b[bOffset++];
+ double b3 = b[bOffset++];
out[outOffset++] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[outOffset++] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[outOffset++] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
@@ -196,29 +200,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) {
- var x = vector[vectorOffset++];
- var y = vector[vectorOffset++];
- var z = vector[vectorOffset++];
- var w = vector[vectorOffset++];
- double m0 = matrix[matrixOffset];
- double m4 = matrix[4 + matrixOffset];
- double m8 = matrix[8 + matrixOffset];
- double m12 = matrix[12 + matrixOffset];
+ 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];
out[outOffset++] = (m0 * x + m4 * y + m8 * z + m12 * w);
- double m1 = matrix[1 + matrixOffset];
- double m5 = matrix[5 + matrixOffset];
- double m9 = matrix[9 + matrixOffset];
- double m13 = matrix[13 + matrixOffset];
+ final double m1 = matrix[1 + matrixOffset];
+ final double m5 = matrix[5 + matrixOffset];
+ final double m9 = matrix[9 + matrixOffset];
+ final double m13 = matrix[13 + matrixOffset];
out[outOffset++] = (m1 * x + m5 * y + m9 * z + m13 * w);
- double m2 = matrix[2 + matrixOffset];
- double m6 = matrix[6 + matrixOffset];
- double m10 = matrix[10 + matrixOffset];
- double m14 = matrix[14 + matrixOffset];
+ final double m2 = matrix[2 + matrixOffset];
+ final double m6 = matrix[6 + matrixOffset];
+ final double m10 = matrix[10 + matrixOffset];
+ final double m14 = matrix[14 + matrixOffset];
out[outOffset++] = (m2 * x + m6 * y + m10 * z + m14 * w);
- double m3 = matrix[3 + matrixOffset];
- double m7 = matrix[7 + matrixOffset];
- double m11 = matrix[11 + matrixOffset];
- double m15 = matrix[15 + matrixOffset];
+ final double m3 = matrix[3 + matrixOffset];
+ final double m7 = matrix[7 + matrixOffset];
+ final double m11 = matrix[11 + matrixOffset];
+ final double m15 = matrix[15 + matrixOffset];
out[outOffset++] = (m3 * x + m7 * y + m11 * z + m15 * w);
}
@@ -262,26 +266,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) {
- var a0 = A[aOffset++];
- var a1 = A[aOffset++];
- var a2 = A[aOffset++];
- var a3 = A[aOffset++];
- var b0 = B[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++];
out[outOffset++] = b0.shuffle(Float32x4.XXXX) * a0 +
b0.shuffle(Float32x4.YYYY) * a1 +
b0.shuffle(Float32x4.ZZZZ) * a2 +
b0.shuffle(Float32x4.WWWW) * a3;
- var b1 = B[bOffset++];
+ final Float32x4 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;
- var b2 = B[bOffset++];
+ final Float32x4 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;
- var b3 = B[bOffset++];
+ final Float32x4 b3 = B[bOffset++];
out[outOffset++] = b3.shuffle(Float32x4.XXXX) * a0 +
b3.shuffle(Float32x4.YYYY) * a1 +
b3.shuffle(Float32x4.ZZZZ) * a2 +
@@ -292,20 +296,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) {
- Float32x4 v = vector[vectorOffset];
- Float32x4 xxxx = v.shuffle(Float32x4.XXXX);
+ final Float32x4 v = vector[vectorOffset];
+ final Float32x4 xxxx = v.shuffle(Float32x4.XXXX);
Float32x4 z = new Float32x4.zero();
z += xxxx * matrix[0 + matrixOffset];
- Float32x4 yyyy = v.shuffle(Float32x4.YYYY);
+ final Float32x4 yyyy = v.shuffle(Float32x4.YYYY);
z += yyyy * matrix[1 + matrixOffset];
- Float32x4 zzzz = v.shuffle(Float32x4.ZZZZ);
+ final Float32x4 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) {
- var z = new Float32x4.zero();
+ final Float32x4 z = new Float32x4.zero();
matrix[offset++] = z;
matrix[offset++] = z;
matrix[offset++] = z;
diff --git a/lib/vector_math.dart b/lib/vector_math.dart
index c7cfaa9..a9c1a32 100644
--- a/lib/vector_math.dart
+++ b/lib/vector_math.dart
@@ -19,8 +19,8 @@
/// numbers for storage.
library vector_math;
+import 'dart:math' as math;
import 'dart:typed_data';
-import 'dart:math' as Math;
import 'hash.dart' as quiver;
part 'src/vector_math/utilities.dart';
diff --git a/lib/vector_math_64.dart b/lib/vector_math_64.dart
index 1ed52b1..16faa8f 100644
--- a/lib/vector_math_64.dart
+++ b/lib/vector_math_64.dart
@@ -19,8 +19,8 @@
/// numbers for storage.
library vector_math_64;
+import 'dart:math' as math;
import 'dart:typed_data';
-import 'dart:math' as Math;
import 'hash.dart' as quiver;
part 'src/vector_math_64/utilities.dart';
diff --git a/lib/vector_math_geometry.dart b/lib/vector_math_geometry.dart
index 353bc29..6dc17e7 100644
--- a/lib/vector_math_geometry.dart
+++ b/lib/vector_math_geometry.dart
@@ -7,8 +7,8 @@
/// [ColorFilter] and [InvertFilter]).
library vector_math_geometry;
+import 'dart:math' as math;
import 'dart:typed_data';
-import 'dart:math' as Math;
import 'package:vector_math/vector_math.dart';
import 'package:vector_math/vector_math_lists.dart';
diff --git a/lib/vector_math_lists.dart b/lib/vector_math_lists.dart
index 10d09af..0c19993 100644
--- a/lib/vector_math_lists.dart
+++ b/lib/vector_math_lists.dart
@@ -5,8 +5,8 @@
/// A library for working with lists of vectors in a memory efficient way.
library vector_math_lists;
+import 'dart:math' as math;
import 'dart:typed_data';
-import 'dart:math' as Math;
import 'package:vector_math/vector_math.dart';
part 'src/vector_math_lists/scalar_list_view.dart';
diff --git a/pubspec.yaml b/pubspec.yaml
index 07405bd..66cfa86 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -4,7 +4,7 @@
description: A Vector Math library for 2D and 3D applications.
homepage: https://github.com/google/vector_math.dart
environment:
- sdk: '>=1.0.0 <2.0.0'
+ sdk: '>=1.21.0 <2.0.0'
dev_dependencies:
benchmark_harness: any
browser: any
diff --git a/test/aabb2_test.dart b/test/aabb2_test.dart
index 799553d..a0c5191 100644
--- a/test/aabb2_test.dart
+++ b/test/aabb2_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.aabb2_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -165,30 +165,30 @@
}
void testAabb2Rotate() {
- final rotation = new Matrix3.rotationZ(Math.PI / 4);
+ final rotation = new Matrix3.rotationZ(math.PI / 4);
final input = new Aabb2.minMax($v2(1.0, 1.0), $v2(3.0, 3.0));
final result = input..rotate(rotation);
- relativeTest(result.min.x, 2 - Math.sqrt(2));
- relativeTest(result.min.y, 2 - Math.sqrt(2));
- relativeTest(result.max.x, 2 + Math.sqrt(2));
- relativeTest(result.max.y, 2 + Math.sqrt(2));
+ relativeTest(result.min.x, 2 - math.sqrt(2));
+ relativeTest(result.min.y, 2 - math.sqrt(2));
+ relativeTest(result.max.x, 2 + math.sqrt(2));
+ relativeTest(result.max.y, 2 + math.sqrt(2));
relativeTest(result.center.x, 2.0);
relativeTest(result.center.y, 2.0);
}
void testAabb2Transform() {
- final rotation = new Matrix3.rotationZ(Math.PI / 4);
+ final rotation = new Matrix3.rotationZ(math.PI / 4);
final input = new Aabb2.minMax($v2(1.0, 1.0), $v2(3.0, 3.0));
final result = input..transform(rotation);
- final newCenterY = Math.sqrt(8);
+ final newCenterY = math.sqrt(8);
- relativeTest(result.min.x, -Math.sqrt(2));
- relativeTest(result.min.y, newCenterY - Math.sqrt(2));
- relativeTest(result.max.x, Math.sqrt(2));
- relativeTest(result.max.y, newCenterY + Math.sqrt(2));
+ relativeTest(result.min.x, -math.sqrt(2));
+ relativeTest(result.min.y, newCenterY - math.sqrt(2));
+ relativeTest(result.max.x, math.sqrt(2));
+ relativeTest(result.max.y, newCenterY + math.sqrt(2));
relativeTest(result.center.x, 0.0);
relativeTest(result.center.y, newCenterY);
}
diff --git a/test/geometry_test.dart b/test/geometry_test.dart
index 93b1603..15f6990 100644
--- a/test/geometry_test.dart
+++ b/test/geometry_test.dart
@@ -80,7 +80,7 @@
MeshGeometry cube = filterUnitCube(filter);
// Check to ensure all the vertices were properly scaled
- Vector3List positions = cube.getViewForAttrib("POSITION");
+ Vector3List positions = cube.getViewForAttrib("POSITION") as Vector3List;
for (int i = 0; i < positions.length; ++i) {
Vector3 position = positions[i];
expect(position.storage[0].abs(), equals(2.0));
@@ -115,7 +115,7 @@
MeshGeometry cube = filterUnitCube(filter);
// Ensure that the same color was applied to all vertices
- Vector4List colors = cube.getViewForAttrib("COLOR");
+ Vector4List colors = cube.getViewForAttrib("COLOR") as Vector4List;
for (int i = 0; i < colors.length; ++i) {
Vector4 color = colors[i];
relativeTest(color, filterColor);
diff --git a/test/matrix2_test.dart b/test/matrix2_test.dart
index 348f9ee..2c7b194 100644
--- a/test/matrix2_test.dart
+++ b/test/matrix2_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.matrix2_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -13,17 +13,18 @@
import 'test_utils.dart';
void testMatrix2Adjoint() {
- var input = new List();
- var expectedOutput = new List();
+ var input = new List<Matrix2>();
+ var expectedOutput = new List<Matrix2>();
- input.add(parseMatrix('''0.830828627896291 0.549723608291140
- 0.585264091152724 0.917193663829810'''));
- expectedOutput.add(parseMatrix(''' 0.917193663829810 -0.549723608291140
- -0.585264091152724 0.830828627896291'''));
- input.add(parseMatrix(''' 1 0
- 0 1'''));
- expectedOutput.add(parseMatrix(''' 1 0
+ input.add(parseMatrix<Matrix2>('''0.830828627896291 0.549723608291140
+ 0.585264091152724 0.917193663829810'''));
+ expectedOutput
+ .add(parseMatrix<Matrix2>(''' 0.917193663829810 -0.549723608291140
+ -0.585264091152724 0.830828627896291'''));
+ input.add(parseMatrix<Matrix2>(''' 1 0
0 1'''));
+ expectedOutput.add(parseMatrix<Matrix2>(''' 1 0
+ 0 1'''));
assert(input.length == expectedOutput.length);
@@ -35,11 +36,11 @@
}
void testMatrix2Determinant() {
- var input = new List();
+ var input = new List<Matrix2>();
List<double> expectedOutput = new List<double>();
- input.add(parseMatrix('''0.830828627896291 0.549723608291140
- 0.585264091152724 0.917193663829810'''));
+ input.add(parseMatrix<Matrix2>('''0.830828627896291 0.549723608291140
+ 0.585264091152724 0.917193663829810'''));
expectedOutput.add(0.440297265243183);
assert(input.length == expectedOutput.length);
@@ -52,7 +53,7 @@
}
void testMatrix2Transform() {
- var rot = new Matrix2.rotation(Math.PI / 4);
+ var rot = new Matrix2.rotation(math.PI / 4);
final input = new Vector2(0.234245234259, 0.890723489233);
final expected = new Vector2(
diff --git a/test/matrix3_test.dart b/test/matrix3_test.dart
index cf7474e..5721a3b 100644
--- a/test/matrix3_test.dart
+++ b/test/matrix3_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.matrix3_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -13,47 +13,47 @@
import 'test_utils.dart';
void testMatrix3Adjoint() {
- var input = new List();
- var expectedOutput = new List();
+ var input = new List<dynamic>();
+ var expectedOutput = new List<dynamic>();
- input.add(
- parseMatrix(''' 0.285839018820374 0.380445846975357 0.053950118666607
+ input.add(parseMatrix<Matrix3>(
+ ''' 0.285839018820374 0.380445846975357 0.053950118666607
0.757200229110721 0.567821640725221 0.530797553008973
0.753729094278495 0.075854289563064 0.779167230102011'''));
- expectedOutput.add(
- parseMatrix(''' 0.402164743710542 -0.292338588868304 0.171305679728352
+ expectedOutput.add(parseMatrix<Matrix3>(
+ ''' 0.402164743710542 -0.292338588868304 0.171305679728352
-0.189908046274114 0.182052622470548 -0.110871609529434
-0.370546805539367 0.265070987960728 -0.125768101844091'''));
- input.add(parseMatrix('''1 0 0
- 0 1 0
- 0 0 1'''));
- expectedOutput.add(parseMatrix('''1 0 0
+ input.add(parseMatrix<Matrix3>('''1 0 0
0 1 0
0 0 1'''));
- input.add(parseMatrix('''1 0 0 0
- 0 1 0 0
- 0 0 1 0
- 0 0 0 1'''));
- expectedOutput.add(parseMatrix('''1 0 0 0
+ expectedOutput.add(parseMatrix<Matrix3>('''1 0 0
+ 0 1 0
+ 0 0 1'''));
+ input.add(parseMatrix<Matrix4>('''1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1'''));
+ expectedOutput.add(parseMatrix<Matrix4>('''1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ 0 0 0 1'''));
assert(input.length == expectedOutput.length);
for (int i = 0; i < input.length; i++) {
- var output = input[i].clone();
+ dynamic output = input[i].clone();
output.scaleAdjoint(1.0);
relativeTest(output, expectedOutput[i]);
}
}
void testMatrix3Determinant() {
- var input = new List();
+ var input = new List<Matrix3>();
List<double> expectedOutput = new List<double>();
- input.add(
- parseMatrix('''0.285839018820374 0.380445846975357 0.053950118666607
+ input.add(parseMatrix<Matrix3>(
+ '''0.285839018820374 0.380445846975357 0.053950118666607
0.757200229110721 0.567821640725221 0.530797553008973
0.753729094278495 0.075854289563064 0.779167230102011'''));
expectedOutput.add(0.022713604103796);
@@ -68,33 +68,33 @@
}
void testMatrix3SelfTransposeMultiply() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix3>();
+ var inputB = new List<Matrix3>();
+ var expectedOutput = new List<Matrix3>();
- inputA.add(
- parseMatrix('''0.084435845510910 0.800068480224308 0.181847028302852
+ inputA.add(parseMatrix<Matrix3>(
+ '''0.084435845510910 0.800068480224308 0.181847028302852
0.399782649098896 0.431413827463545 0.263802916521990
0.259870402850654 0.910647594429523 0.145538980384717'''));
- inputB.add(
- parseMatrix('''0.136068558708664 0.549860201836332 0.622055131485066
+ inputB.add(parseMatrix<Matrix3>(
+ '''0.136068558708664 0.549860201836332 0.622055131485066
0.869292207640089 0.144954798223727 0.350952380892271
0.579704587365570 0.853031117721894 0.513249539867053'''));
- expectedOutput.add(
- parseMatrix('''0.509665070066463 0.326055864494860 0.326206788210183
+ expectedOutput.add(parseMatrix<Matrix3>(
+ '''0.509665070066463 0.326055864494860 0.326206788210183
1.011795431418814 1.279272055656899 1.116481872383158
0.338435097301446 0.262379221330899 0.280398953455993'''));
- inputA.add(
- parseMatrix('''0.136068558708664 0.549860201836332 0.622055131485066
+ inputA.add(parseMatrix<Matrix3>(
+ '''0.136068558708664 0.549860201836332 0.622055131485066
0.869292207640089 0.144954798223727 0.350952380892271
0.579704587365570 0.853031117721894 0.513249539867053'''));
- inputB.add(
- parseMatrix('''0.084435845510910 0.800068480224308 0.181847028302852
+ inputB.add(parseMatrix<Matrix3>(
+ '''0.084435845510910 0.800068480224308 0.181847028302852
0.399782649098896 0.431413827463545 0.263802916521990
0.259870402850654 0.910647594429523 0.145538980384717'''));
- expectedOutput.add(
- parseMatrix('''0.509665070066463 1.011795431418814 0.338435097301446
+ expectedOutput.add(parseMatrix<Matrix3>(
+ '''0.509665070066463 1.011795431418814 0.338435097301446
0.326055864494860 1.279272055656899 0.262379221330899
0.326206788210183 1.116481872383158 0.280398953455993'''));
assert(inputA.length == inputB.length);
@@ -108,33 +108,33 @@
}
void testMatrix3SelfMultiply() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix3>();
+ var inputB = new List<Matrix3>();
+ var expectedOutput = new List<Matrix3>();
- inputA.add(
- parseMatrix('''0.084435845510910 0.800068480224308 0.181847028302852
+ inputA.add(parseMatrix<Matrix3>(
+ '''0.084435845510910 0.800068480224308 0.181847028302852
0.399782649098896 0.431413827463545 0.263802916521990
0.259870402850654 0.910647594429523 0.145538980384717'''));
- inputB.add(
- parseMatrix('''0.136068558708664 0.549860201836332 0.622055131485066
+ inputB.add(parseMatrix<Matrix3>(
+ '''0.136068558708664 0.549860201836332 0.622055131485066
0.869292207640089 0.144954798223727 0.350952380892271
0.579704587365570 0.853031117721894 0.513249539867053'''));
- expectedOutput.add(
- parseMatrix('''0.812399915745417 0.317522849978516 0.426642592595554
+ expectedOutput.add(parseMatrix<Matrix3>(
+ '''0.812399915745417 0.317522849978516 0.426642592595554
0.582350288210078 0.507392169174135 0.535489283769338
0.911348663480233 0.399044409575883 0.555945473748377'''));
- inputA.add(
- parseMatrix('''0.136068558708664 0.549860201836332 0.622055131485066
+ inputA.add(parseMatrix<Matrix3>(
+ '''0.136068558708664 0.549860201836332 0.622055131485066
0.869292207640089 0.144954798223727 0.350952380892271
0.579704587365570 0.853031117721894 0.513249539867053'''));
- inputB.add(
- parseMatrix('''0.084435845510910 0.800068480224308 0.181847028302852
+ inputB.add(parseMatrix<Matrix3>(
+ '''0.084435845510910 0.800068480224308 0.181847028302852
0.399782649098896 0.431413827463545 0.263802916521990
0.259870402850654 0.910647594429523 0.145538980384717'''));
- expectedOutput.add(
- parseMatrix('''0.392967349540540 0.912554468305858 0.260331657549835
+ expectedOutput.add(parseMatrix<Matrix3>(
+ '''0.392967349540540 0.912554468305858 0.260331657549835
0.222551972385485 1.077622741167203 0.247394954900102
0.523353251675581 1.299202246456530 0.405147467960185'''));
assert(inputA.length == inputB.length);
@@ -148,33 +148,33 @@
}
void testMatrix3SelfMultiplyTranspose() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix3>();
+ var inputB = new List<Matrix3>();
+ var expectedOutput = new List<Matrix3>();
- inputA.add(
- parseMatrix('''0.084435845510910 0.800068480224308 0.181847028302852
+ inputA.add(parseMatrix<Matrix3>(
+ '''0.084435845510910 0.800068480224308 0.181847028302852
0.399782649098896 0.431413827463545 0.263802916521990
0.259870402850654 0.910647594429523 0.145538980384717'''));
- inputB.add(
- parseMatrix('''0.136068558708664 0.549860201836332 0.622055131485066
+ inputB.add(parseMatrix<Matrix3>(
+ '''0.136068558708664 0.549860201836332 0.622055131485066
0.869292207640089 0.144954798223727 0.350952380892271
0.579704587365570 0.853031117721894 0.513249539867053'''));
- expectedOutput.add(
- parseMatrix('''0.564533756922142 0.253192835205285 0.824764060523193
+ expectedOutput.add(parseMatrix<Matrix3>(
+ '''0.564533756922142 0.253192835205285 0.824764060523193
0.455715101026938 0.502645707562004 0.735161980594196
0.626622330821134 0.408983306176468 1.002156614695209'''));
- inputA.add(
- parseMatrix('''0.136068558708664 0.549860201836332 0.622055131485066
+ inputA.add(parseMatrix<Matrix3>(
+ '''0.136068558708664 0.549860201836332 0.622055131485066
0.869292207640089 0.144954798223727 0.350952380892271
0.579704587365570 0.853031117721894 0.513249539867053'''));
- inputB.add(
- parseMatrix('''0.084435845510910 0.800068480224308 0.181847028302852
+ inputB.add(parseMatrix<Matrix3>(
+ '''0.084435845510910 0.800068480224308 0.181847028302852
0.399782649098896 0.431413827463545 0.263802916521990
0.259870402850654 0.910647594429523 0.145538980384717'''));
- expectedOutput.add(
- parseMatrix('''0.564533756922142 0.455715101026938 0.626622330821134
+ expectedOutput.add(parseMatrix<Matrix3>(
+ '''0.564533756922142 0.455715101026938 0.626622330821134
0.253192835205285 0.502645707562004 0.408983306176468
0.824764060523193 0.735161980594196 1.002156614695209'''));
assert(inputA.length == inputB.length);
@@ -188,20 +188,20 @@
}
void testMatrix3Transform() {
- Matrix3 rotX = new Matrix3.rotationX(Math.PI / 4);
- Matrix3 rotY = new Matrix3.rotationY(Math.PI / 4);
- Matrix3 rotZ = new Matrix3.rotationZ(Math.PI / 4);
+ Matrix3 rotX = new Matrix3.rotationX(math.PI / 4);
+ Matrix3 rotY = new Matrix3.rotationY(math.PI / 4);
+ Matrix3 rotZ = new Matrix3.rotationZ(math.PI / 4);
final input = new Vector3(1.0, 0.0, 0.0);
relativeTest(rotX.transformed(input), input);
relativeTest(rotY.transformed(input),
- new Vector3(1.0 / Math.sqrt(2.0), 0.0, 1.0 / Math.sqrt(2.0)));
+ new Vector3(1.0 / math.sqrt(2.0), 0.0, 1.0 / math.sqrt(2.0)));
relativeTest(rotZ.transformed(input),
- new Vector3(1.0 / Math.sqrt(2.0), 1.0 / Math.sqrt(2.0), 0.0));
+ new Vector3(1.0 / math.sqrt(2.0), 1.0 / math.sqrt(2.0), 0.0));
}
void testMatrix3Transform2() {
- Matrix3 rotZ = new Matrix3.rotationZ(Math.PI / 4);
+ Matrix3 rotZ = new Matrix3.rotationZ(math.PI / 4);
Matrix3 trans = new Matrix3(1.0, 0.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0);
Matrix3 transB =
new Matrix3.fromList([1.0, 0.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0]);
@@ -210,14 +210,14 @@
final input = new Vector2(1.0, 0.0);
relativeTest(rotZ.transform2(input.clone()),
- new Vector2(Math.sqrt(0.5), Math.sqrt(0.5)));
+ new Vector2(math.sqrt(0.5), math.sqrt(0.5)));
relativeTest(trans.transform2(input.clone()), new Vector2(4.0, 2.0));
}
void testMatrix3AbsoluteRotate2() {
- Matrix3 rotZ = new Matrix3.rotationZ(-Math.PI / 4);
- Matrix3 rotZcw = new Matrix3.rotationZ(Math.PI / 4);
+ Matrix3 rotZ = new Matrix3.rotationZ(-math.PI / 4);
+ Matrix3 rotZcw = new Matrix3.rotationZ(math.PI / 4);
// Add translation
rotZ.setEntry(2, 0, 3.0);
rotZ.setEntry(2, 1, 2.0);
@@ -225,10 +225,10 @@
final input = new Vector2(1.0, 0.0);
relativeTest(rotZ.absoluteRotate2(input.clone()),
- new Vector2(Math.sqrt(0.5), Math.sqrt(0.5)));
+ new Vector2(math.sqrt(0.5), math.sqrt(0.5)));
relativeTest(rotZcw.absoluteRotate2(input.clone()),
- new Vector2(Math.sqrt(0.5), Math.sqrt(0.5)));
+ new Vector2(math.sqrt(0.5), math.sqrt(0.5)));
}
void testMatrix3ConstructorCopy() {
diff --git a/test/matrix4_test.dart b/test/matrix4_test.dart
index b71ebfa..14254ea 100644
--- a/test/matrix4_test.dart
+++ b/test/matrix4_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.matrix4_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'dart:typed_data';
import 'package:test/test.dart';
@@ -118,9 +118,9 @@
}
void testMatrix4Transpose() {
- var inputA = new List();
- var expectedOutput = new List();
- inputA.add(parseMatrix(
+ var inputA = new List<Matrix4>();
+ var expectedOutput = new List<Matrix4>();
+ inputA.add(parseMatrix<Matrix4>(
'''0.337719409821377 0.780252068321138 0.096454525168389 0.575208595078466
0.900053846417662 0.389738836961253 0.131973292606335 0.059779542947156
0.369246781120215 0.241691285913833 0.942050590775485 0.234779913372406
@@ -134,93 +134,93 @@
}
void testMatrix4VectorMultiplication() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Vector4>();
+ var expectedOutput = new List<Vector4>();
- inputA.add(parseMatrix(
+ inputA.add(parseMatrix<Matrix4>(
'''0.337719409821377 0.780252068321138 0.096454525168389 0.575208595078466
0.900053846417662 0.389738836961253 0.131973292606335 0.059779542947156
0.369246781120215 0.241691285913833 0.942050590775485 0.234779913372406
0.111202755293787 0.403912145588115 0.956134540229802 0.353158571222071'''));
- inputB.add(parseVector('''0.821194040197959
- 0.015403437651555
- 0.043023801657808
- 0.168990029462704'''));
- expectedOutput.add(parseVector('''0.390706088480722
- 0.760902311900085
- 0.387152194918898
- 0.198357495624973'''));
+ inputB.add(parseVector<Vector4>('''0.821194040197959
+ 0.015403437651555
+ 0.043023801657808
+ 0.168990029462704'''));
+ expectedOutput.add(parseVector<Vector4>('''0.390706088480722
+ 0.760902311900085
+ 0.387152194918898
+ 0.198357495624973'''));
assert(inputA.length == inputB.length);
assert(expectedOutput.length == inputB.length);
for (int i = 0; i < inputA.length; i++) {
- var output = inputA[i] * inputB[i];
+ var output = inputA[i] * inputB[i] as Vector4;
relativeTest(output, expectedOutput[i]);
}
}
void testMatrix4Multiplication() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Matrix4>();
+ var expectedOutput = new List<Matrix4>();
- inputA.add(parseMatrix(
+ inputA.add(parseMatrix<Matrix4>(
'''0.587044704531417 0.230488160211558 0.170708047147859 0.923379642103244
- 0.207742292733028 0.844308792695389 0.227664297816554 0.430207391329584
- 0.301246330279491 0.194764289567049 0.435698684103899 0.184816320124136
- 0.470923348517591 0.225921780972399 0.311102286650413 0.904880968679893'''));
- inputB.add(parseMatrix(
+ 0.207742292733028 0.844308792695389 0.227664297816554 0.430207391329584
+ 0.301246330279491 0.194764289567049 0.435698684103899 0.184816320124136
+ 0.470923348517591 0.225921780972399 0.311102286650413 0.904880968679893'''));
+ inputB.add(parseMatrix<Matrix4>(
'''0.979748378356085 0.408719846112552 0.711215780433683 0.318778301925882
- 0.438869973126103 0.594896074008614 0.221746734017240 0.424166759713807
- 0.111119223440599 0.262211747780845 0.117417650855806 0.507858284661118
- 0.258064695912067 0.602843089382083 0.296675873218327 0.085515797090044'''));
- expectedOutput.add(parseMatrix(
+ 0.438869973126103 0.594896074008614 0.221746734017240 0.424166759713807
+ 0.111119223440599 0.262211747780845 0.117417650855806 0.507858284661118
+ 0.258064695912067 0.602843089382083 0.296675873218327 0.085515797090044'''));
+ expectedOutput.add(parseMatrix<Matrix4>(
'''0.933571062150012 0.978468014433530 0.762614053950618 0.450561572247979
- 0.710396171182635 0.906228190244263 0.489336274658484 0.576762187862375
- 0.476730868989407 0.464650419830879 0.363428748133464 0.415721232510293
- 0.828623949506267 0.953951612073692 0.690010785130483 0.481326146122225'''));
+ 0.710396171182635 0.906228190244263 0.489336274658484 0.576762187862375
+ 0.476730868989407 0.464650419830879 0.363428748133464 0.415721232510293
+ 0.828623949506267 0.953951612073692 0.690010785130483 0.481326146122225'''));
assert(inputA.length == inputB.length);
assert(expectedOutput.length == inputB.length);
for (int i = 0; i < inputA.length; i++) {
- var output = inputA[i] * inputB[i];
+ var output = inputA[i] * inputB[i] as Matrix4;
//print('${inputA[i].cols}x${inputA[i].rows} * ${inputB[i].cols}x${inputB[i].rows} = ${output.cols}x${output.rows}');
relativeTest(output, expectedOutput[i]);
}
}
void testMatrix4Adjoint() {
- var input = new List();
- var expectedOutput = new List();
+ var input = new List<Matrix4>();
+ var expectedOutput = new List<Matrix4>();
- input.add(parseMatrix(
+ input.add(parseMatrix<Matrix4>(
'''0.934010684229183 0.011902069501241 0.311215042044805 0.262971284540144
0.129906208473730 0.337122644398882 0.528533135506213 0.654079098476782
0.568823660872193 0.162182308193243 0.165648729499781 0.689214503140008
0.469390641058206 0.794284540683907 0.601981941401637 0.748151592823709'''));
- expectedOutput.add(parseMatrix(
+ expectedOutput.add(parseMatrix<Matrix4>(
'''0.104914550911225 -0.120218628213523 0.026180662741638 0.044107217835411
-0.081375770192194 -0.233925009984709 -0.022194776259965 0.253560794325371
0.155967414263983 0.300399085119975 -0.261648453454468 -0.076412061081351
-0.104925204524921 0.082065846290507 0.217666653572481 -0.077704028180558'''));
- input.add(parseMatrix('''1 0 0 0
- 0 1 0 0
- 0 0 1 0
- 0 0 0 1'''));
- expectedOutput.add(parseMatrix('''1 0 0 0
+ input.add(parseMatrix<Matrix4>('''1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1'''));
+ expectedOutput.add(parseMatrix<Matrix4>('''1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ 0 0 0 1'''));
- input.add(parseMatrix(
+ input.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- expectedOutput.add(parseMatrix(
+ expectedOutput.add(parseMatrix<Matrix4>(
'''-0.100386867815513 0.076681891597503 -0.049082198794982 -0.021689260610181
-0.279454715225440 -0.269081505356250 0.114433412778961 0.133858687769130
0.218879650360982 0.073892735462981 0.069073300555062 -0.132069899391626
@@ -236,23 +236,23 @@
}
void testMatrix4Determinant() {
- var input = new List();
+ var input = new List<Matrix4>();
List<double> expectedOutput = new List<double>();
- input.add(parseMatrix(
+ input.add(parseMatrix<Matrix4>(
'''0.046171390631154 0.317099480060861 0.381558457093008 0.489764395788231
0.097131781235848 0.950222048838355 0.765516788149002 0.445586200710899
0.823457828327293 0.034446080502909 0.795199901137063 0.646313010111265
0.694828622975817 0.438744359656398 0.186872604554379 0.709364830858073'''));
expectedOutput.add(-0.199908980087990);
- input.add(parseMatrix(
+ input.add(parseMatrix<Matrix4>(
''' -2.336158020850647 0.358791716162913 0.571930324052307 0.866477090273158
-1.190335868711951 1.132044609886021 -0.693048859451418 0.742195189800671
0.015919048685702 0.552417702663606 1.020805610524362 -1.288062497216858
3.020318574990609 -1.197139524685751 -0.400475005629390 0.441263145991252'''));
expectedOutput.add(-5.002276533849802);
- input.add(parseMatrix(
+ input.add(parseMatrix<Matrix4>(
'''0.934010684229183 0.011902069501241 0.311215042044805 0.262971284540144
0.129906208473730 0.337122644398882 0.528533135506213 0.654079098476782
0.568823660872193 0.162182308193243 0.165648729499781 0.689214503140008
@@ -268,21 +268,21 @@
}
void testMatrix4SelfTransposeMultiply() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Matrix4>();
+ var expectedOutput = new List<Matrix4>();
- inputA.add(parseMatrix(
+ inputA.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- inputB.add(parseMatrix(
+ inputB.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- expectedOutput.add(parseMatrix(
+ expectedOutput.add(parseMatrix<Matrix4>(
'''1.096629343508065 1.170948826011164 0.975285713492989 1.047596917860438
1.170948826011164 1.987289692246011 1.393079247172284 1.945966332001094
0.975285713492989 1.393079247172284 1.138698195167051 1.266161729169725
@@ -299,21 +299,21 @@
}
void testMatrix4SelfMultiply() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Matrix4>();
+ var expectedOutput = new List<Matrix4>();
- inputA.add(parseMatrix(
+ inputA.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- inputB.add(parseMatrix(
+ inputB.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- expectedOutput.add(parseMatrix(
+ expectedOutput.add(parseMatrix<Matrix4>(
'''0.237893273152584 0.241190507375353 0.115471053480014 0.188086069635435
0.916103942227480 1.704973929800637 1.164721763902784 1.675285658272358
0.919182849383279 1.351023203753565 1.053750106199745 1.215382950294249
@@ -330,21 +330,21 @@
}
void testMatrix4SelfMultiplyTranspose() {
- var inputA = new List();
- var inputB = new List();
- var expectedOutput = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Matrix4>();
+ var expectedOutput = new List<Matrix4>();
- inputA.add(parseMatrix(
+ inputA.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- inputB.add(parseMatrix(
+ inputB.add(parseMatrix<Matrix4>(
'''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510'''));
- expectedOutput.add(parseMatrix(
+ expectedOutput.add(parseMatrix<Matrix4>(
'''0.232339681975335 0.201799089276976 0.197320406329789 0.642508126615338
0.201799089276976 1.485449982570056 1.144315170085286 1.998154153033270
0.197320406329789 1.144315170085286 1.021602397682138 1.557970885061235
@@ -361,14 +361,14 @@
}
void testMatrix4Translation() {
- var inputA = new List();
- var inputB = new List();
- var output1 = new List();
- var output2 = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Matrix4>();
+ var output1 = new List<Matrix4>();
+ var output2 = new List<Matrix4>();
inputA.add(new Matrix4.identity());
inputB.add(new Matrix4.translationValues(1.0, 3.0, 5.7));
- output1.add(inputA[0] * inputB[0]);
+ output1.add(inputA[0] * inputB[0] as Matrix4);
output2.add((new Matrix4.identity())..translate(1.0, 3.0, 5.7));
assert(inputA.length == inputB.length);
@@ -380,14 +380,14 @@
}
void testMatrix4Scale() {
- var inputA = new List();
- var inputB = new List();
- var output1 = new List();
- var output2 = new List();
+ var inputA = new List<Matrix4>();
+ var inputB = new List<Matrix4>();
+ var output1 = new List<Matrix4>();
+ var output2 = new List<Matrix4>();
inputA.add(new Matrix4.identity());
inputB.add(new Matrix4.diagonal3Values(1.0, 3.0, 5.7));
- output1.add(inputA[0] * inputB[0]);
+ output1.add(inputA[0] * inputB[0] as Matrix4);
output2.add(new Matrix4.identity()..scale(1.0, 3.0, 5.7));
assert(inputA.length == inputB.length);
@@ -399,8 +399,8 @@
}
void testMatrix4Rotate() {
- var output1 = new List();
- var output2 = new List();
+ var output1 = new List<Matrix4>();
+ var output2 = new List<Matrix4>();
output1.add(new Matrix4.rotationX(1.57079632679));
output2.add(new Matrix4.identity()..rotateX(1.57079632679));
output1.add(new Matrix4.rotationY(1.57079632679 * 0.5));
@@ -410,7 +410,7 @@
{
var axis = new Vector3(1.1, 1.1, 1.1);
axis.normalize();
- num angle = 1.5;
+ double angle = 1.5;
Quaternion q = new Quaternion.axisAngle(axis, angle);
Matrix3 R = q.asRotationMatrix();
@@ -428,12 +428,12 @@
}
void testMatrix4GetRotation() {
- final mat4 = new Matrix4.rotationX(Math.PI) *
- new Matrix4.rotationY(-Math.PI) *
- new Matrix4.rotationZ(Math.PI);
- final mat3 = new Matrix3.rotationX(Math.PI) *
- new Matrix3.rotationY(-Math.PI) *
- new Matrix3.rotationZ(Math.PI);
+ final mat4 = new Matrix4.rotationX(math.PI) *
+ new Matrix4.rotationY(-math.PI) *
+ new Matrix4.rotationZ(math.PI) as Matrix4;
+ final mat3 = new Matrix3.rotationX(math.PI) *
+ new Matrix3.rotationY(-math.PI) *
+ new Matrix3.rotationZ(math.PI) as Matrix3;
final matRot = mat4.getRotation();
relativeTest(mat3, matRot);
@@ -489,7 +489,7 @@
}
void testMatrix4PerspectiveTransform() {
- final matrix = makePerspectiveMatrix(Math.PI, 1.0, 1.0, 100.0);
+ final matrix = makePerspectiveMatrix(math.PI, 1.0, 1.0, 100.0);
final vec = new Vector3(10.0, 20.0, 30.0);
matrix.perspectiveTransform(vec);
@@ -621,7 +621,7 @@
expect(m.entry(1, 1), equals(1.0));
expect(m.entry(2, 2), equals(1.0));
expect(m.entry(3, 3), equals(1.0));
- relativeTest(m.entry(1, 0), Math.tan(1.57));
+ relativeTest(m.entry(1, 0), math.tan(1.57));
expect(m.entry(0, 1), equals(0.0));
expect(m2, equals(m));
@@ -634,7 +634,7 @@
expect(n.entry(2, 2), equals(1.0));
expect(n.entry(3, 3), equals(1.0));
expect(n.entry(1, 0), equals(0.0));
- relativeTest(m.entry(1, 0), Math.tan(1.57));
+ relativeTest(m.entry(1, 0), math.tan(1.57));
expect(n2, equals(n));
}
diff --git a/test/obb3_test.dart b/test/obb3_test.dart
index 4a92e20..c40ef02 100644
--- a/test/obb3_test.dart
+++ b/test/obb3_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.obb3_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -164,11 +164,11 @@
a.closestPointTo(b, closestPoint);
- absoluteTest(closestPoint, new Vector3(Math.SQRT2, Math.SQRT2, 2.0));
+ absoluteTest(closestPoint, new Vector3(math.SQRT2, math.SQRT2, 2.0));
a.closestPointTo(c, closestPoint);
- absoluteTest(closestPoint, new Vector3(Math.SQRT2, Math.SQRT2, -2.0));
+ absoluteTest(closestPoint, new Vector3(math.SQRT2, math.SQRT2, -2.0));
}
void testIntersectionObb3() {
diff --git a/test/opengl_matrix_test.dart b/test/opengl_matrix_test.dart
index 18ee781..c5f904e 100644
--- a/test/opengl_matrix_test.dart
+++ b/test/opengl_matrix_test.dart
@@ -16,14 +16,14 @@
Vector3 focusPosition = new Vector3(0.0, 0.0, -1.0);
Vector3 upDirection = new Vector3(0.0, 1.0, 0.0);
Matrix4 lookat = makeViewMatrix(position, focusPosition, upDirection);
- num n = 0.1;
- num f = 1000.0;
- num l = -10.0;
- num r = 10.0;
- num b = -10.0;
- num t = 10.0;
+ double n = 0.1;
+ double f = 1000.0;
+ double l = -10.0;
+ double r = 10.0;
+ double b = -10.0;
+ double t = 10.0;
Matrix4 frustum = makeFrustumMatrix(l, r, b, t, n, f);
- Matrix4 C = frustum * lookat;
+ Matrix4 C = frustum * lookat as Matrix4;
Vector3 re = new Vector3.zero();
unproject(C, 0.0, 100.0, 0.0, 100.0, 50.0, 50.0, 1.0, re);
}
@@ -45,12 +45,12 @@
}
void testFrustumMatrix() {
- num n = 0.1;
- num f = 1000.0;
- num l = -1.0;
- num r = 1.0;
- num b = -1.0;
- num t = 1.0;
+ double n = 0.1;
+ double f = 1000.0;
+ double l = -1.0;
+ double r = 1.0;
+ double b = -1.0;
+ double t = 1.0;
Matrix4 frustum = makeFrustumMatrix(l, r, b, t, n, f);
relativeTest(
frustum.getColumn(0), new Vector4(2 * n / (r - l), 0.0, 0.0, 0.0));
@@ -92,12 +92,12 @@
}
void testOrthographicMatrix() {
- num n = 0.1;
- num f = 1000.0;
- num l = -1.0;
- num r = 1.0;
- num b = -1.0;
- num t = 1.0;
+ double n = 0.1;
+ double f = 1000.0;
+ double l = -1.0;
+ double r = 1.0;
+ double b = -1.0;
+ double t = 1.0;
Matrix4 ortho = makeOrthographicMatrix(l, r, b, t, n, f);
relativeTest(ortho.getColumn(0), new Vector4(2 / (r - l), 0.0, 0.0, 0.0));
relativeTest(ortho.getColumn(1), new Vector4(0.0, 2 / (t - b), 0.0, 0.0));
diff --git a/test/quad_test.dart b/test/quad_test.dart
index d9492bc..e68e30d 100644
--- a/test/quad_test.dart
+++ b/test/quad_test.dart
@@ -10,7 +10,7 @@
import 'test_utils.dart';
-testQuadCopyNormalInto() {
+void testQuadCopyNormalInto() {
final quad = new Quad.points(
new Vector3(1.0, 0.0, 1.0),
new Vector3(0.0, 2.0, 1.0),
@@ -24,7 +24,7 @@
normal, new Vector3(-0.8944271802902222, -0.4472135901451111, 0.0));
}
-testQuadCopyTriangles() {
+void testQuadCopyTriangles() {
final quad = new Quad.points(
new Vector3(1.0, 0.0, 1.0),
new Vector3(0.0, 2.0, 1.0),
diff --git a/test/quaternion_test.dart b/test/quaternion_test.dart
index 184567d..e98ed94 100644
--- a/test/quaternion_test.dart
+++ b/test/quaternion_test.dart
@@ -5,7 +5,7 @@
library vector_math.test.quaternion_test;
import 'dart:typed_data';
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -181,8 +181,8 @@
// Test conversion to and from axis-angle representation
{
Quaternion q =
- new Quaternion.axisAngle(new Vector3(0.0, 1.0, 0.0), 0.5 * Math.PI);
- relativeTest(q.radians, 0.5 * Math.PI);
+ new Quaternion.axisAngle(new Vector3(0.0, 1.0, 0.0), 0.5 * math.PI);
+ relativeTest(q.radians, 0.5 * math.PI);
relativeTest(q.axis, new Vector3(0.0, 1.0, 0.0));
}
@@ -199,7 +199,7 @@
Vector3 a = new Vector3(1.0, 0.0, 0.0);
Vector3 b = new Vector3(0.0, 1.0, 0.0);
Quaternion q = new Quaternion.fromTwoVectors(a, b);
- relativeTest(q.radians, 0.5 * Math.PI);
+ relativeTest(q.radians, 0.5 * math.PI);
relativeTest(q.axis, new Vector3(0.0, 0.0, 1.0));
}
{
@@ -215,7 +215,7 @@
Vector3 a = new Vector3(1.0, 0.0, 0.0);
Vector3 b = new Vector3(-1.0, 0.0, 0.0);
Quaternion q = new Quaternion.fromTwoVectors(a, b);
- relativeTest(q.radians, Math.PI);
+ relativeTest(q.radians, math.PI);
}
}
diff --git a/test/ray_test.dart b/test/ray_test.dart
index 6d3f8b3..5b63d7d 100644
--- a/test/ray_test.dart
+++ b/test/ray_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.ray_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -58,8 +58,8 @@
final outside = new Sphere.centerRadius($v3(-2.5, 1.0, 1.0), 1.0);
final behind = new Sphere.centerRadius($v3(1.0, -1.0, 1.0), 1.0);
- expect(parent.intersectsWithSphere(inside), equals(Math.sqrt(3.0)));
- expect(parent.intersectsWithSphere(hitting), equals(3.5 - Math.sqrt(1.75)));
+ expect(parent.intersectsWithSphere(inside), equals(math.sqrt(3.0)));
+ expect(parent.intersectsWithSphere(hitting), equals(3.5 - math.sqrt(1.75)));
expect(parent.intersectsWithSphere(cutting), equals(4.0));
expect(parent.intersectsWithSphere(outside), equals(null));
expect(parent.intersectsWithSphere(behind), equals(null));
diff --git a/test/scalar_list_view_test.dart b/test/scalar_list_view_test.dart
index d2466a1..fc8352d 100644
--- a/test/scalar_list_view_test.dart
+++ b/test/scalar_list_view_test.dart
@@ -21,7 +21,7 @@
expect(list.buffer[4], equals(0.0));
}
-testScalarListView() {
+void testScalarListView() {
final buffer = new Float32List(10);
final list = new ScalarListView.view(buffer, 1, 4);
expect(list.length, 2);
@@ -39,7 +39,7 @@
expect(buffer[9], equals(0.0));
}
-testScalarListViewFromList() {
+void testScalarListViewFromList() {
List<double> input = new List<double>(3);
input[0] = 1.0;
input[1] = 4.0;
diff --git a/test/test_utils.dart b/test/test_utils.dart
index bc01dc3..9ce96ee 100644
--- a/test/test_utils.dart
+++ b/test/test_utils.dart
@@ -14,21 +14,21 @@
Vector4 $v4(double x, double y, double z, double w) => new Vector4(x, y, z, w);
-void relativeTest(var output, var expectedOutput) {
+void relativeTest(dynamic output, dynamic expectedOutput) {
final num errorThreshold = 0.0005;
num error = relativeError(output, expectedOutput).abs();
expect(error >= errorThreshold, isFalse,
reason: '$output != $expectedOutput : relativeError = $error');
}
-void absoluteTest(var output, var expectedOutput) {
+void absoluteTest(dynamic output, dynamic expectedOutput) {
final num errorThreshold = 0.0005;
num error = absoluteError(output, expectedOutput).abs();
expect(error >= errorThreshold, isFalse,
reason: '$output != $expectedOutput : absoluteError = $error');
}
-makeMatrix(int rows, int cols) {
+dynamic makeMatrix(int rows, int cols) {
if (rows != cols) {
return null;
}
@@ -46,7 +46,7 @@
return null;
}
-parseMatrix(String input) {
+T parseMatrix<T>(String input) {
input = input.trim();
List<String> rows = input.split("\n");
List<double> values = new List<double>();
@@ -69,7 +69,7 @@
}
}
- var m = makeMatrix(rows.length, col_count);
+ dynamic m = makeMatrix(rows.length, col_count);
for (int j = 0; j < rows.length; j++) {
for (int i = 0; i < col_count; i++) {
m[m.index(j, i)] = values[j * col_count + i];
@@ -77,10 +77,10 @@
}
}
- return m;
+ return m as T;
}
-parseVector(String v) {
+T parseVector<T extends Vector>(String v) {
v = v.trim();
Pattern pattern = new RegExp('[\\s]+', multiLine: true, caseSensitive: false);
List<String> rows = v.split(pattern);
@@ -93,7 +93,7 @@
values.add(double.parse(rows[i]));
}
- var r;
+ Vector r;
if (values.length == 2) {
r = new Vector2(values[0], values[1]);
} else if (values.length == 3) {
@@ -102,5 +102,5 @@
r = new Vector4(values[0], values[1], values[2], values[3]);
}
- return r;
+ return r as T;
}
diff --git a/test/utilities_test.dart b/test/utilities_test.dart
index b3399d3..4f904ab 100644
--- a/test/utilities_test.dart
+++ b/test/utilities_test.dart
@@ -4,7 +4,7 @@
library vector_math.test.utilities_test;
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -13,11 +13,11 @@
import 'test_utils.dart';
void testDegrees() {
- relativeTest(degrees(Math.PI), 180.0);
+ relativeTest(degrees(math.PI), 180.0);
}
void testRadians() {
- relativeTest(radians(90.0), Math.PI / 2.0);
+ relativeTest(radians(90.0), math.PI / 2.0);
}
void testMix() {
diff --git a/test/vector2_test.dart b/test/vector2_test.dart
index c59ef5a..d5890fe 100644
--- a/test/vector2_test.dart
+++ b/test/vector2_test.dart
@@ -6,7 +6,7 @@
import 'dart:typed_data';
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -98,8 +98,8 @@
inputInv.invert();
// print("input $inputMatrix");
// print("input $inputInv");
- Vector2 resultOld = inputMatrix.transposed() * inputVector;
- Vector2 resultOldvInv = inputInv * inputVector;
+ Vector2 resultOld = inputMatrix.transposed() * inputVector as Vector2;
+ Vector2 resultOldvInv = inputInv * inputVector as Vector2;
Vector2 resultNew = inputVector..postmultiply(inputMatrix);
expect(resultNew.x, equals(resultOld.x));
expect(resultNew.y, equals(resultOld.y));
@@ -111,15 +111,15 @@
final Vector2 inputA = new Vector2(0.417267069084370, 0.049654430325742);
final Vector2 inputB = new Vector2(0.944787189721646, 0.490864092468080);
double expectedOutputCross = inputA.x * inputB.y - inputA.y * inputB.x;
- var result;
+ dynamic result;
result = cross2(inputA, inputB);
relativeTest(result, expectedOutputCross);
result = new Vector2.zero();
- cross2A(1.0, inputA, result);
+ cross2A(1.0, inputA, result as Vector2);
relativeTest(result, new Vector2(-inputA.y, inputA.x));
- cross2B(inputA, 1.0, result);
+ cross2B(inputA, 1.0, result as Vector2);
relativeTest(result, new Vector2(inputA.y, -inputA.x));
- cross2B(inputA, 1.0, result);
+ cross2B(inputA, 1.0, result as Vector2);
relativeTest(result, new Vector2(inputA.y, -inputA.x));
}
@@ -147,7 +147,7 @@
expect(v2.x, equals(2.0));
expect(v2.y, equals(2.0));
- var v3 = new Vector2.random(new Math.Random());
+ var v3 = new Vector2.random(new math.Random());
expect(v3.x, greaterThanOrEqualTo(0.0));
expect(v3.x, lessThanOrEqualTo(1.0));
expect(v3.y, greaterThanOrEqualTo(0.0));
@@ -259,7 +259,7 @@
final v1 = new Vector2(0.0, 1.0);
expect(v0.angleTo(v0), equals(0.0));
- expect(v0.angleTo(v1), equals(Math.PI / 2.0));
+ expect(v0.angleTo(v1), equals(math.PI / 2.0));
}
void testVector2AngleToSigned() {
@@ -268,9 +268,9 @@
final v2 = new Vector2(-1.0, 0.0);
expect(v0.angleToSigned(v0), equals(0.0));
- expect(v0.angleToSigned(v1), equals(Math.PI / 2.0));
- expect(v1.angleToSigned(v0), equals(-Math.PI / 2.0));
- expect(v0.angleToSigned(v2), equals(Math.PI));
+ expect(v0.angleToSigned(v1), equals(math.PI / 2.0));
+ expect(v1.angleToSigned(v0), equals(-math.PI / 2.0));
+ expect(v0.angleToSigned(v2), equals(math.PI));
}
void testVector2Clamp() {
@@ -279,13 +279,13 @@
final v1 = new Vector2(-x, -y);
final v2 = new Vector2(-2.0 * x, 2.0 * y)..clamp(v1, v0);
- expect(v2.storage, orderedEquals([-x, y]));
+ expect(v2.storage, orderedEquals(<double>[-x, y]));
}
void testVector2ClampScalar() {
final x = 2.0;
final v0 = new Vector2(-2.0 * x, 2.0 * x)..clampScalar(-x, x);
- expect(v0.storage, orderedEquals([-x, x]));
+ expect(v0.storage, orderedEquals(<double>[-x, x]));
}
void testVector2Floor() {
@@ -293,9 +293,9 @@
final v1 = new Vector2(-0.5, 0.5)..floor();
final v2 = new Vector2(-0.9, 0.9)..floor();
- expect(v0.storage, orderedEquals([-1.0, 0.0]));
- expect(v1.storage, orderedEquals([-1.0, 0.0]));
- expect(v2.storage, orderedEquals([-1.0, 0.0]));
+ expect(v0.storage, orderedEquals(<double>[-1.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[-1.0, 0.0]));
+ expect(v2.storage, orderedEquals(<double>[-1.0, 0.0]));
}
void testVector2Ceil() {
@@ -303,9 +303,9 @@
final v1 = new Vector2(-0.5, 0.5)..ceil();
final v2 = new Vector2(-0.9, 0.9)..ceil();
- expect(v0.storage, orderedEquals([0.0, 1.0]));
- expect(v1.storage, orderedEquals([0.0, 1.0]));
- expect(v2.storage, orderedEquals([0.0, 1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 1.0]));
+ expect(v1.storage, orderedEquals(<double>[0.0, 1.0]));
+ expect(v2.storage, orderedEquals(<double>[0.0, 1.0]));
}
void testVector2Round() {
@@ -313,9 +313,9 @@
final v1 = new Vector2(-0.5, 0.5)..round();
final v2 = new Vector2(-0.9, 0.9)..round();
- expect(v0.storage, orderedEquals([0.0, 0.0]));
- expect(v1.storage, orderedEquals([-1.0, 1.0]));
- expect(v2.storage, orderedEquals([-1.0, 1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[-1.0, 1.0]));
+ expect(v2.storage, orderedEquals(<double>[-1.0, 1.0]));
}
void testVector2RoundToZero() {
@@ -326,12 +326,12 @@
final v4 = new Vector2(-1.5, 1.5)..roundToZero();
final v5 = new Vector2(-1.9, 1.9)..roundToZero();
- expect(v0.storage, orderedEquals([0.0, 0.0]));
- expect(v1.storage, orderedEquals([0.0, 0.0]));
- expect(v2.storage, orderedEquals([0.0, 0.0]));
- expect(v3.storage, orderedEquals([-1.0, 1.0]));
- expect(v4.storage, orderedEquals([-1.0, 1.0]));
- expect(v5.storage, orderedEquals([-1.0, 1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[0.0, 0.0]));
+ expect(v2.storage, orderedEquals(<double>[0.0, 0.0]));
+ expect(v3.storage, orderedEquals(<double>[-1.0, 1.0]));
+ expect(v4.storage, orderedEquals(<double>[-1.0, 1.0]));
+ expect(v5.storage, orderedEquals(<double>[-1.0, 1.0]));
}
void main() {
diff --git a/test/vector3_test.dart b/test/vector3_test.dart
index fe17f0f..5e60ee8 100644
--- a/test/vector3_test.dart
+++ b/test/vector3_test.dart
@@ -5,7 +5,7 @@
library vector_math.test.vector3_test;
import 'dart:typed_data';
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -97,12 +97,12 @@
List<Vector3> inputA = new List<Vector3>();
List<Vector3> inputB = new List<Vector3>();
List<double> expectedOutput = new List<double>();
- inputA.add(parseVector('''0.417267069084370
- 0.049654430325742
- 0.902716109915281'''));
- inputB.add(parseVector('''0.944787189721646
- 0.490864092468080
- 0.489252638400019'''));
+ inputA.add(parseVector<Vector3>('''0.417267069084370
+ 0.049654430325742
+ 0.902716109915281'''));
+ inputB.add(parseVector<Vector3>('''0.944787189721646
+ 0.490864092468080
+ 0.489252638400019'''));
expectedOutput.add(0.860258396944727);
assert(inputA.length == inputB.length);
assert(inputB.length == expectedOutput.length);
@@ -116,12 +116,12 @@
void testVector3Postmultiplication() {
Matrix3 inputMatrix =
- (new Matrix3.rotationX(.4)) * (new Matrix3.rotationZ(.5));
+ (new Matrix3.rotationX(.4)) * (new Matrix3.rotationZ(.5)) as Matrix3;
Vector3 inputVector = new Vector3(1.0, 2.0, 3.0);
Matrix3 inputInv = new Matrix3.copy(inputMatrix);
inputInv.invert();
- Vector3 resultOld = inputMatrix.transposed() * inputVector;
- Vector3 resultOldvInv = inputInv * inputVector;
+ Vector3 resultOld = inputMatrix.transposed() * inputVector as Vector3;
+ Vector3 resultOldvInv = inputInv * inputVector as Vector3;
Vector3 resultNew = inputVector..postmultiply(inputMatrix);
expect(resultNew.x, equals(resultOld.x));
@@ -137,25 +137,25 @@
List<Vector3> inputB = new List<Vector3>();
List<Vector3> expectedOutput = new List<Vector3>();
- inputA.add(parseVector('''0.417267069084370
- 0.049654430325742
- 0.902716109915281'''));
- inputB.add(parseVector('''0.944787189721646
- 0.490864092468080
- 0.489252638400019'''));
- expectedOutput.add(parseVector(''' -0.418817363004761
- 0.648725602136344
- 0.157908551498227'''));
+ inputA.add(parseVector<Vector3>('''0.417267069084370
+ 0.049654430325742
+ 0.902716109915281'''));
+ inputB.add(parseVector<Vector3>('''0.944787189721646
+ 0.490864092468080
+ 0.489252638400019'''));
+ expectedOutput.add(parseVector<Vector3>(''' -0.418817363004761
+ 0.648725602136344
+ 0.157908551498227'''));
- inputA.add(parseVector('''0.944787189721646
- 0.490864092468080
- 0.489252638400019'''));
- inputB.add(parseVector('''0.417267069084370
- 0.049654430325742
- 0.902716109915281'''));
- expectedOutput.add(parseVector(''' 0.418817363004761
- -0.648725602136344
- -0.157908551498227'''));
+ inputA.add(parseVector<Vector3>('''0.944787189721646
+ 0.490864092468080
+ 0.489252638400019'''));
+ inputB.add(parseVector<Vector3>('''0.417267069084370
+ 0.049654430325742
+ 0.902716109915281'''));
+ expectedOutput.add(parseVector<Vector3>(''' 0.418817363004761
+ -0.648725602136344
+ -0.157908551498227'''));
assert(inputA.length == inputB.length);
assert(inputB.length == expectedOutput.length);
@@ -200,7 +200,7 @@
expect(v2.y, equals(2.0));
expect(v2.z, equals(2.0));
- var v3 = new Vector3.random(new Math.Random());
+ var v3 = new Vector3.random(new math.Random());
expect(v3.x, greaterThanOrEqualTo(0.0));
expect(v3.x, lessThanOrEqualTo(1.0));
expect(v3.y, greaterThanOrEqualTo(0.0));
@@ -359,7 +359,7 @@
final v1 = new Vector3(0.0, 1.0, 0.0);
expect(v0.angleTo(v0), equals(0.0));
- expect(v0.angleTo(v1), equals(Math.PI / 2.0));
+ expect(v0.angleTo(v1), equals(math.PI / 2.0));
}
void testVector3AngleToSigned() {
@@ -368,8 +368,8 @@
final n = new Vector3(0.0, 0.0, 1.0);
expect(v0.angleToSigned(v0, n), equals(0.0));
- expect(v0.angleToSigned(v1, n), equals(Math.PI / 2.0));
- expect(v1.angleToSigned(v0, n), equals(-Math.PI / 2.0));
+ expect(v0.angleToSigned(v1, n), equals(math.PI / 2.0));
+ expect(v1.angleToSigned(v0, n), equals(-math.PI / 2.0));
}
void testVector3Clamp() {
@@ -378,14 +378,14 @@
final v1 = new Vector3(-x, -y, -z);
final v2 = new Vector3(-2.0 * x, 2.0 * y, -2.0 * z)..clamp(v1, v0);
- expect(v2.storage, orderedEquals([-x, y, -z]));
+ expect(v2.storage, orderedEquals(<double>[-x, y, -z]));
}
void testVector3ClampScalar() {
final x = 2.0;
final v0 = new Vector3(-2.0 * x, 2.0 * x, -2.0 * x)..clampScalar(-x, x);
- expect(v0.storage, orderedEquals([-x, x, -x]));
+ expect(v0.storage, orderedEquals(<double>[-x, x, -x]));
}
void testVector3Floor() {
@@ -393,9 +393,9 @@
final v1 = new Vector3(-0.5, 0.5, -0.5)..floor();
final v2 = new Vector3(-0.9, 0.9, -0.5)..floor();
- expect(v0.storage, orderedEquals([-1.0, 0.0, -1.0]));
- expect(v1.storage, orderedEquals([-1.0, 0.0, -1.0]));
- expect(v2.storage, orderedEquals([-1.0, 0.0, -1.0]));
+ expect(v0.storage, orderedEquals(<double>[-1.0, 0.0, -1.0]));
+ expect(v1.storage, orderedEquals(<double>[-1.0, 0.0, -1.0]));
+ expect(v2.storage, orderedEquals(<double>[-1.0, 0.0, -1.0]));
}
void testVector3Ceil() {
@@ -403,9 +403,9 @@
final v1 = new Vector3(-0.5, 0.5, -0.5)..ceil();
final v2 = new Vector3(-0.9, 0.9, -0.9)..ceil();
- expect(v0.storage, orderedEquals([0.0, 1.0, 0.0]));
- expect(v1.storage, orderedEquals([0.0, 1.0, 0.0]));
- expect(v2.storage, orderedEquals([0.0, 1.0, 0.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 1.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[0.0, 1.0, 0.0]));
+ expect(v2.storage, orderedEquals(<double>[0.0, 1.0, 0.0]));
}
void testVector3Round() {
@@ -413,9 +413,9 @@
final v1 = new Vector3(-0.5, 0.5, -0.5)..round();
final v2 = new Vector3(-0.9, 0.9, -0.9)..round();
- expect(v0.storage, orderedEquals([0.0, 0.0, 0.0]));
- expect(v1.storage, orderedEquals([-1.0, 1.0, -1.0]));
- expect(v2.storage, orderedEquals([-1.0, 1.0, -1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 0.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[-1.0, 1.0, -1.0]));
+ expect(v2.storage, orderedEquals(<double>[-1.0, 1.0, -1.0]));
}
void testVector3RoundToZero() {
@@ -426,12 +426,12 @@
final v4 = new Vector3(-1.5, 1.5, -1.5)..roundToZero();
final v5 = new Vector3(-1.9, 1.9, -1.9)..roundToZero();
- expect(v0.storage, orderedEquals([0.0, 0.0, 0.0]));
- expect(v1.storage, orderedEquals([0.0, 0.0, 0.0]));
- expect(v2.storage, orderedEquals([0.0, 0.0, 0.0]));
- expect(v3.storage, orderedEquals([-1.0, 1.0, -1.0]));
- expect(v4.storage, orderedEquals([-1.0, 1.0, -1.0]));
- expect(v5.storage, orderedEquals([-1.0, 1.0, -1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 0.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[0.0, 0.0, 0.0]));
+ expect(v2.storage, orderedEquals(<double>[0.0, 0.0, 0.0]));
+ expect(v3.storage, orderedEquals(<double>[-1.0, 1.0, -1.0]));
+ expect(v4.storage, orderedEquals(<double>[-1.0, 1.0, -1.0]));
+ expect(v5.storage, orderedEquals(<double>[-1.0, 1.0, -1.0]));
}
void testVector3ApplyQuaternion() {
diff --git a/test/vector4_test.dart b/test/vector4_test.dart
index d4f6430..a4026e3 100644
--- a/test/vector4_test.dart
+++ b/test/vector4_test.dart
@@ -6,7 +6,7 @@
import 'dart:typed_data';
-import 'dart:math' as Math;
+import 'dart:math' as math;
import 'package:test/test.dart';
@@ -116,7 +116,7 @@
expect(v2.z, equals(2.0));
expect(v2.w, equals(2.0));
- var v3 = new Vector4.random(new Math.Random());
+ var v3 = new Vector4.random(new math.Random());
expect(v3.x, greaterThanOrEqualTo(0.0));
expect(v3.x, lessThanOrEqualTo(1.0));
expect(v3.y, greaterThanOrEqualTo(0.0));
@@ -213,7 +213,7 @@
final v1 = new Vector4(-x, -y, -z, -w);
final v2 = new Vector4(-2.0 * x, 2.0 * y, -2.0 * z, 2.0 * w)..clamp(v1, v0);
- expect(v2.storage, orderedEquals([-x, y, -z, w]));
+ expect(v2.storage, orderedEquals(<double>[-x, y, -z, w]));
}
void testVector4ClampScalar() {
@@ -221,7 +221,7 @@
final v0 = new Vector4(-2.0 * x, 2.0 * x, -2.0 * x, 2.0 * x)
..clampScalar(-x, x);
- expect(v0.storage, orderedEquals([-x, x, -x, x]));
+ expect(v0.storage, orderedEquals(<double>[-x, x, -x, x]));
}
void testVector4Floor() {
@@ -229,9 +229,9 @@
final v1 = new Vector4(-0.5, 0.5, -0.5, 0.5)..floor();
final v2 = new Vector4(-0.9, 0.9, -0.5, 0.9)..floor();
- expect(v0.storage, orderedEquals([-1.0, 0.0, -1.0, 0.0]));
- expect(v1.storage, orderedEquals([-1.0, 0.0, -1.0, 0.0]));
- expect(v2.storage, orderedEquals([-1.0, 0.0, -1.0, 0.0]));
+ expect(v0.storage, orderedEquals(<double>[-1.0, 0.0, -1.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[-1.0, 0.0, -1.0, 0.0]));
+ expect(v2.storage, orderedEquals(<double>[-1.0, 0.0, -1.0, 0.0]));
}
void testVector4Ceil() {
@@ -239,9 +239,9 @@
final v1 = new Vector4(-0.5, 0.5, -0.5, 0.5)..ceil();
final v2 = new Vector4(-0.9, 0.9, -0.9, 0.9)..ceil();
- expect(v0.storage, orderedEquals([0.0, 1.0, 0.0, 1.0]));
- expect(v1.storage, orderedEquals([0.0, 1.0, 0.0, 1.0]));
- expect(v2.storage, orderedEquals([0.0, 1.0, 0.0, 1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 1.0, 0.0, 1.0]));
+ expect(v1.storage, orderedEquals(<double>[0.0, 1.0, 0.0, 1.0]));
+ expect(v2.storage, orderedEquals(<double>[0.0, 1.0, 0.0, 1.0]));
}
void testVector4Round() {
@@ -249,9 +249,9 @@
final v1 = new Vector4(-0.5, 0.5, -0.5, 0.5)..round();
final v2 = new Vector4(-0.9, 0.9, -0.9, 0.9)..round();
- expect(v0.storage, orderedEquals([0.0, 0.0, 0.0, 0.0]));
- expect(v1.storage, orderedEquals([-1.0, 1.0, -1.0, 1.0]));
- expect(v2.storage, orderedEquals([-1.0, 1.0, -1.0, 1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 0.0, 0.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[-1.0, 1.0, -1.0, 1.0]));
+ expect(v2.storage, orderedEquals(<double>[-1.0, 1.0, -1.0, 1.0]));
}
void testVector4RoundToZero() {
@@ -262,12 +262,12 @@
final v4 = new Vector4(-1.5, 1.5, -1.5, 1.5)..roundToZero();
final v5 = new Vector4(-1.9, 1.9, -1.9, 1.9)..roundToZero();
- expect(v0.storage, orderedEquals([0.0, 0.0, 0.0, 0.0]));
- expect(v1.storage, orderedEquals([0.0, 0.0, 0.0, 0.0]));
- expect(v2.storage, orderedEquals([0.0, 0.0, 0.0, 0.0]));
- expect(v3.storage, orderedEquals([-1.0, 1.0, -1.0, 1.0]));
- expect(v4.storage, orderedEquals([-1.0, 1.0, -1.0, 1.0]));
- expect(v5.storage, orderedEquals([-1.0, 1.0, -1.0, 1.0]));
+ expect(v0.storage, orderedEquals(<double>[0.0, 0.0, 0.0, 0.0]));
+ expect(v1.storage, orderedEquals(<double>[0.0, 0.0, 0.0, 0.0]));
+ expect(v2.storage, orderedEquals(<double>[0.0, 0.0, 0.0, 0.0]));
+ expect(v3.storage, orderedEquals(<double>[-1.0, 1.0, -1.0, 1.0]));
+ expect(v4.storage, orderedEquals(<double>[-1.0, 1.0, -1.0, 1.0]));
+ expect(v5.storage, orderedEquals(<double>[-1.0, 1.0, -1.0, 1.0]));
}
void main() {
diff --git a/tool/generate_vector_math_64.dart b/tool/generate_vector_math_64.dart
index 6576ab8..56b63d8 100644
--- a/tool/generate_vector_math_64.dart
+++ b/tool/generate_vector_math_64.dart
@@ -8,28 +8,28 @@
import 'package:path/path.dart' as p;
-main() async {
+Future<Null> main() async {
await generateVectorMath64();
print('Generated vector_math_64');
}
-Future generateVectorMath64() async {
- final directory = new Directory('lib/src/vector_math_64/');
- final libraryFile = new File('lib/vector_math_64.dart');
+Future<Null> generateVectorMath64() async {
+ final Directory directory = new Directory('lib/src/vector_math_64/');
+ final File libraryFile = new File('lib/vector_math_64.dart');
if (await directory.exists()) {
await directory.delete(recursive: true);
}
- if (await libraryFile.exists()) {
+ if (libraryFile.existsSync()) {
await libraryFile.delete();
}
await directory.create(recursive: true);
await _processFile('lib/vector_math.dart');
- await for (var f
+ await for (FileSystemEntity f
in new Directory('lib/src/vector_math/').list(recursive: true)) {
if (f is File) {
await _processFile(f.path);
@@ -37,24 +37,22 @@
}
}
-Future _processFile(String inputFileName) async {
- final inputFile = new File(inputFileName);
+Future<Null> _processFile(String inputFileName) async {
+ final File inputFile = new File(inputFileName);
- final input = await inputFile.readAsString();
- final output = _convertToVectorMath64(input);
+ final String input = await inputFile.readAsString();
+ final String output = _convertToVectorMath64(input);
- final outputFileName =
+ final String outputFileName =
inputFileName.replaceAll('vector_math', 'vector_math_64');
- var dir = new Directory(p.dirname(outputFileName));
+ final Directory dir = new Directory(p.dirname(outputFileName));
await dir.create(recursive: true);
- final outputFile = new File(outputFileName);
+ final File outputFile = new File(outputFileName);
await outputFile.writeAsString(output);
}
-String _convertToVectorMath64(String input) {
- return input
- .replaceAll('vector_math', 'vector_math_64')
- .replaceAll('Float32List', 'Float64List');
-}
+String _convertToVectorMath64(String input) => input
+ .replaceAll('vector_math', 'vector_math_64')
+ .replaceAll('Float32List', 'Float64List');