diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fddf045..14b0ed68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [3.1, dev] + sdk: [3.7, dev] steps: # These are the latest versions of the github actions; dependabot will diff --git a/CHANGELOG.md b/CHANGELOG.md index d85213dd..9282de03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.1-wip + +- Require `sdk: ^3.7.0`. + ## 2.2.0 - Performance of functions that take `dynamic` arguments improved. diff --git a/benchmark/matrix_bench.dart b/benchmark/matrix_bench.dart index 3cc7ddd6..195b0c8a 100644 --- a/benchmark/matrix_bench.dart +++ b/benchmark/matrix_bench.dart @@ -325,7 +325,7 @@ class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase { class Matrix4TranslateByDoubleGenericBenchmark extends BenchmarkBase { Matrix4TranslateByDoubleGenericBenchmark() - : super('Matrix4.translateByDoubleGeneric'); + : super('Matrix4.translateByDoubleGeneric'); final temp = Matrix4.zero()..setIdentity(); @@ -343,7 +343,7 @@ class Matrix4TranslateByDoubleGenericBenchmark extends BenchmarkBase { class Matrix4TranslateByVector3GenericBenchmark extends BenchmarkBase { Matrix4TranslateByVector3GenericBenchmark() - : super('Matrix4.translateByVector3Generic'); + : super('Matrix4.translateByVector3Generic'); final temp = Matrix4.zero()..setIdentity(); final vec = Vector3(10.0, 20.0, 30.0); @@ -362,7 +362,7 @@ class Matrix4TranslateByVector3GenericBenchmark extends BenchmarkBase { class Matrix4TranslateByVector4GenericBenchmark extends BenchmarkBase { Matrix4TranslateByVector4GenericBenchmark() - : super('Matrix4.translateByVector4Generic'); + : super('Matrix4.translateByVector4Generic'); final temp = Matrix4.zero()..setIdentity(); final vec = Vector4(10.0, 20.0, 30.0, 40.0); @@ -395,7 +395,11 @@ class Matrix4TranslateByDoubleBenchmark extends BenchmarkBase { void setup() { for (var i = 0; i < 10; i++) { temp.translateByDouble( - i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble(), 1.0); + i.toDouble(), + (i * 10).toDouble(), + (i * 5).toDouble(), + 1.0, + ); } } @@ -424,7 +428,8 @@ class Matrix4TranslateByVector3Benchmark extends BenchmarkBase { void setup() { for (var i = 0; i < 10; i++) { temp.translateByVector3( - Vector3(i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble())); + Vector3(i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble()), + ); } } @@ -452,8 +457,14 @@ class Matrix4TranslateByVector4Benchmark extends BenchmarkBase { @override void setup() { for (var i = 0; i < 10; i++) { - temp.translateByVector4(Vector4(i.toDouble(), (i * 10).toDouble(), - (i * 5).toDouble(), (i * 20).toDouble())); + temp.translateByVector4( + Vector4( + i.toDouble(), + (i * 10).toDouble(), + (i * 5).toDouble(), + (i * 20).toDouble(), + ), + ); } } diff --git a/bin/mesh_generator.dart b/bin/mesh_generator.dart index 5015bf7c..fe349c2e 100644 --- a/bin/mesh_generator.dart +++ b/bin/mesh_generator.dart @@ -62,7 +62,7 @@ Map generators = { 'sphere': generateSphere, 'circle': generateCircle, 'cylinder': generateCylinder, - 'ring': generateRing + 'ring': generateRing, }; void main(List args) { diff --git a/lib/src/vector_math/aabb2.dart b/lib/src/vector_math/aabb2.dart index 41283d11..9ca4d8fa 100644 --- a/lib/src/vector_math/aabb2.dart +++ b/lib/src/vector_math/aabb2.dart @@ -17,24 +17,23 @@ class Aabb2 { Vector2 get max => _max; /// The center of the AABB. - Vector2 get center => _min.clone() - ..add(_max) - ..scale(0.5); + Vector2 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Create a new AABB with [min] and [max] set to the origin. - Aabb2() - : _min = Vector2.zero(), - _max = Vector2.zero(); + Aabb2() : _min = Vector2.zero(), _max = Vector2.zero(); /// Create a new AABB as a copy of [other]. Aabb2.copy(Aabb2 other) - : _min = Vector2.copy(other._min), - _max = Vector2.copy(other._max); + : _min = Vector2.copy(other._min), + _max = Vector2.copy(other._max); /// Create a new AABB with a [min] and [max]. Aabb2.minMax(Vector2 min, Vector2 max) - : _min = Vector2.copy(min), - _max = Vector2.copy(max); + : _min = Vector2.copy(min), + _max = Vector2.copy(max); /// Create a new AABB with a [center] and [halfExtents]. factory Aabb2.centerAndHalfExtents(Vector2 center, Vector2 halfExtents) => @@ -44,9 +43,11 @@ class Aabb2 { /// starting at [offset]. [offset] has to be multiple of /// [Float32List.bytesPerElement]. Aabb2.fromBuffer(ByteBuffer buffer, int offset) - : _min = Vector2.fromBuffer(buffer, offset), - _max = Vector2.fromBuffer( - buffer, offset + Float32List.bytesPerElement * 2); + : _min = Vector2.fromBuffer(buffer, offset), + _max = Vector2.fromBuffer( + buffer, + offset + Float32List.bytesPerElement * 2, + ); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) { @@ -109,15 +110,17 @@ class Aabb2 { /// Create a copy of this that is transformed by the transform [t] and store /// it in [out]. - Aabb2 transformed(Matrix3 t, Aabb2 out) => out - ..copyFrom(this) - ..transform(t); + Aabb2 transformed(Matrix3 t, Aabb2 out) => + out + ..copyFrom(this) + ..transform(t); /// Create a copy of this that is rotated by the rotation matrix [t] and /// store it in [out]. - Aabb2 rotated(Matrix3 t, Aabb2 out) => out - ..copyFrom(this) - ..rotate(t); + Aabb2 rotated(Matrix3 t, Aabb2 out) => + out + ..copyFrom(this) + ..rotate(t); /// Set the min and max of this so that this is a hull of this and /// [other]. diff --git a/lib/src/vector_math/aabb3.dart b/lib/src/vector_math/aabb3.dart index f48511df..da3aff7d 100644 --- a/lib/src/vector_math/aabb3.dart +++ b/lib/src/vector_math/aabb3.dart @@ -14,24 +14,23 @@ class Aabb3 { Vector3 get max => _max; /// The center of the AABB. - Vector3 get center => _min.clone() - ..add(_max) - ..scale(0.5); + Vector3 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Create a new AABB with [min] and [max] set to the origin. - Aabb3() - : _min = Vector3.zero(), - _max = Vector3.zero(); + Aabb3() : _min = Vector3.zero(), _max = Vector3.zero(); /// Create a new AABB as a copy of [other]. Aabb3.copy(Aabb3 other) - : _min = Vector3.copy(other._min), - _max = Vector3.copy(other._max); + : _min = Vector3.copy(other._min), + _max = Vector3.copy(other._max); /// Create a new AABB with a [min] and [max]. Aabb3.minMax(Vector3 min, Vector3 max) - : _min = Vector3.copy(min), - _max = Vector3.copy(max); + : _min = Vector3.copy(min), + _max = Vector3.copy(max); /// Create a new AABB that encloses a [sphere]. factory Aabb3.fromSphere(Sphere sphere) => Aabb3()..setSphere(sphere); @@ -59,9 +58,11 @@ class Aabb3 { /// starting at [offset]. [offset] has to be multiple of /// [Float32List.bytesPerElement]. Aabb3.fromBuffer(ByteBuffer buffer, int offset) - : _min = Vector3.fromBuffer(buffer, offset), - _max = Vector3.fromBuffer( - buffer, offset + Float32List.bytesPerElement * 3); + : _min = Vector3.fromBuffer(buffer, offset), + _max = Vector3.fromBuffer( + buffer, + offset + Float32List.bytesPerElement * 3, + ); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector3 center, Vector3 halfExtents) { @@ -86,41 +87,65 @@ class Aabb3 { /// 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( - quad._point0.z, - math.min( - quad._point1.z, math.min(quad._point2.z, quad._point3.z)))); + 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)), + ), + ); _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( - quad._point0.z, - math.max( - quad._point1.z, math.max(quad._point2.z, quad._point3.z)))); + 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)), + ), + ); } /// Set the AABB to enclose a [obb]. @@ -238,15 +263,17 @@ class Aabb3 { /// Create a copy of this that is transformed by the transform [t] and store /// it in [out]. - Aabb3 transformed(Matrix4 t, Aabb3 out) => out - ..copyFrom(this) - ..transform(t); + Aabb3 transformed(Matrix4 t, Aabb3 out) => + out + ..copyFrom(this) + ..transform(t); /// Create a copy of this that is rotated by the rotation matrix [t] and /// store it in [out]. - Aabb3 rotated(Matrix4 t, Aabb3 out) => out - ..copyFrom(this) - ..rotate(t); + Aabb3 rotated(Matrix4 t, Aabb3 out) => + out + ..copyFrom(this) + ..rotate(t); void getPN(Vector3 planeNormal, Vector3 outP, Vector3 outN) { if (planeNormal.x < 0.0) { @@ -393,8 +420,11 @@ class Aabb3 { /// be used for the test. If [result] is specified and an intersection is /// found, result is modified to contain more details about the type of /// intersection. - bool intersectsWithTriangle(Triangle other, - {double epsilon = 1e-3, IntersectionResult? result}) { + bool intersectsWithTriangle( + Triangle other, { + double epsilon = 1e-3, + IntersectionResult? result, + }) { double p0, p1, p2, r, len; double a; @@ -639,7 +669,8 @@ class Aabb3 { copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents); // Compute the projection interval radius of b onto L(t) = b.c + t * p.n - final r = _aabbHalfExtents[0] * other.normal[0].abs() + + final r = + _aabbHalfExtents[0] * other.normal[0].abs() + _aabbHalfExtents[1] * other.normal[1].abs() + _aabbHalfExtents[2] * other.normal[2].abs(); // Compute distance of box center from plane diff --git a/lib/src/vector_math/colors.dart b/lib/src/vector_math/colors.dart index fed2bd6c..939daab4 100644 --- a/lib/src/vector_math/colors.dart +++ b/lib/src/vector_math/colors.dart @@ -9,11 +9,13 @@ part of '../../vector_math.dart'; /// for fast prototyping. class Colors { static final _hexStringFullRegex = RegExp( - r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?', - caseSensitive: false); + r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?', + caseSensitive: false, + ); static final _hexStringSmallRegex = RegExp( - r'\#?([0-9a-f])([0-9a-f])([0-9a-f])(?:([0-9a-f]))?', - caseSensitive: false); + r'\#?([0-9a-f])([0-9a-f])([0-9a-f])(?:([0-9a-f]))?', + caseSensitive: false, + ); /// Convert a color with [r], [g], [b] and [a] component between 0 and 255 to /// a color with values between 0.0 and 1.0 and store it in [result]. @@ -75,27 +77,33 @@ class Colors { /// the alpha channel, set [alpha] to true, it is false by default. If [short] /// is true, the resulting hex string might also be a short version, like #ff0 /// (default false). - static String toHexString(Vector4 input, - {bool alpha = false, bool short = 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 isShort = short && + final isShort = + short && ((r >> 4) == (r & 0xF)) && ((g >> 4) == (g & 0xF)) && ((b >> 4) == (b & 0xF)) && (!alpha || (a >> 4) == (a & 0xF)); if (isShort) { - final rgb = (r & 0xF).toRadixString(16) + + final rgb = + (r & 0xF).toRadixString(16) + (g & 0xF).toRadixString(16) + (b & 0xF).toRadixString(16); return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb; } else { - final rgb = r.toRadixString(16).padLeft(2, '0') + + final rgb = + r.toRadixString(16).padLeft(2, '0') + g.toRadixString(16).padLeft(2, '0') + b.toRadixString(16).padLeft(2, '0'); @@ -106,17 +114,23 @@ class Colors { /// Blend the [foreground] color over [background] color and store the color /// in [result]. static void alphaBlend( - Vector4 foreground, Vector4 background, Vector4 result) { + Vector4 foreground, + Vector4 background, + Vector4 result, + ) { final a = foreground.a + (1.0 - foreground.a) * background.a; final factor = 1.0 / a; - final r = factor * + final r = + factor * (foreground.a * foreground.r + (1.0 - foreground.a) * background.a * background.r); - final g = factor * + final g = + factor * (foreground.a * foreground.g + (1.0 - foreground.a) * background.a * background.g); - final b = factor * + final b = + factor * (foreground.a * foreground.b + (1.0 - foreground.a) * background.a * background.b); @@ -137,8 +151,11 @@ class Colors { /// Convert [linearColor] from linear space into gamma color space and store /// the result in [gammaColor]. It is possible to specify a optional [gamma], /// the default value is 2.2. - static void linearToGamma(Vector4 linearColor, Vector4 gammaColor, - [double gamma = 2.2]) { + static void linearToGamma( + Vector4 linearColor, + Vector4 gammaColor, [ + double gamma = 2.2, + ]) { final exponent = 1.0 / gamma; gammaColor @@ -151,8 +168,11 @@ class Colors { /// Convert [gammaColor] from gamma space into linear color space and store /// the result in [linearColor]. It is possible to specify a optional [gamma], /// the default value is 2.2. - static void gammaToLinear(Vector4 gammaColor, Vector4 linearColor, - [double gamma = 2.2]) { + static void gammaToLinear( + Vector4 gammaColor, + Vector4 linearColor, [ + double gamma = 2.2, + ]) { linearColor ..r = math.pow(gammaColor.r, gamma).toDouble() ..g = math.pow(gammaColor.g, gamma).toDouble() @@ -172,7 +192,8 @@ class Colors { if (max != min) { if (max == rgbColor.r) { - h = (rgbColor.g - rgbColor.b) / d + + h = + (rgbColor.g - rgbColor.b) / d + (rgbColor.g < rgbColor.b ? 6.0 : 0.0); } else if (max == rgbColor.g) { h = (rgbColor.b - rgbColor.r) / d + 2.0; @@ -232,7 +253,8 @@ class Colors { s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min); if (max == rgbColor.r) { - h = (rgbColor.g - rgbColor.b) / d + + h = + (rgbColor.g - rgbColor.b) / d + (rgbColor.g < rgbColor.b ? 6.0 : 0.0); } else if (max == rgbColor.g) { h = (rgbColor.b - rgbColor.r) / d + 2.0; @@ -252,9 +274,10 @@ class Colors { if (hslColor.y == 0.0) { rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a); } else { - final q = hslColor.z < 0.5 - ? hslColor.z * (1.0 + hslColor.y) - : hslColor.z + hslColor.y - hslColor.z * hslColor.y; + final 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 r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0); diff --git a/lib/src/vector_math/frustum.dart b/lib/src/vector_math/frustum.dart index a2381bea..f246ac76 100644 --- a/lib/src/vector_math/frustum.dart +++ b/lib/src/vector_math/frustum.dart @@ -33,12 +33,12 @@ class Frustum { /// Create a new frustum without initializing its bounds. Frustum() - : _plane0 = Plane(), - _plane1 = Plane(), - _plane2 = Plane(), - _plane3 = Plane(), - _plane4 = Plane(), - _plane5 = Plane(); + : _plane0 = Plane(), + _plane1 = Plane(), + _plane2 = Plane(), + _plane3 = Plane(), + _plane4 = Plane(), + _plane5 = Plane(); /// Create a new frustum as a copy of [other]. factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other); @@ -177,14 +177,15 @@ class Frustum { /// Calculate the corners of this and write them into [corner0] to // [corner7]. void calculateCorners( - Vector3 corner0, - Vector3 corner1, - Vector3 corner2, - Vector3 corner3, - Vector3 corner4, - Vector3 corner5, - Vector3 corner6, - Vector3 corner7) { + Vector3 corner0, + Vector3 corner1, + Vector3 corner2, + Vector3 corner3, + Vector3 corner4, + Vector3 corner5, + Vector3 corner6, + Vector3 corner7, + ) { Plane.intersection(_plane0, _plane2, _plane4, corner0); Plane.intersection(_plane0, _plane3, _plane4, corner1); Plane.intersection(_plane0, _plane3, _plane5, corner2); @@ -222,11 +223,13 @@ class Frustum { outNz = aabb.min.z; } - final d1 = plane._normal.x * outPx + + final d1 = + plane._normal.x * outPx + plane._normal.y * outPy + plane._normal.z * outPz + plane.constant; - final d2 = plane._normal.x * outNx + + final d2 = + plane._normal.x * outNx + plane._normal.y * outNy + plane._normal.z * outNz + plane.constant; diff --git a/lib/src/vector_math/matrix3.dart b/lib/src/vector_math/matrix3.dart index c61208b1..d58f539e 100644 --- a/lib/src/vector_math/matrix3.dart +++ b/lib/src/vector_math/matrix3.dart @@ -99,15 +99,33 @@ class Matrix3 { } /// New matrix with specified values. - factory Matrix3(double arg0, double arg1, double arg2, double arg3, - double arg4, double arg5, double arg6, double arg7, double arg8) => + factory Matrix3( + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + ) => Matrix3.zero() ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); /// New matrix from [values]. - factory Matrix3.fromList(List values) => 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 values) => + 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 = Float32List(9); @@ -138,8 +156,17 @@ class Matrix3 { Matrix3.zero()..setRotationZ(radians); /// Sets the matrix with specified values. - void setValues(double arg0, double arg1, double arg2, double arg3, - double arg4, double arg5, double arg6, double arg7, double arg8) { + void setValues( + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + ) { _m3storage[8] = arg8; _m3storage[7] = arg7; _m3storage[6] = arg6; @@ -413,11 +440,14 @@ class Matrix3 { /// Returns the determinant of this matrix. double determinant() { - final x = _m3storage[0] * + final x = + _m3storage[0] * ((_m3storage[4] * _m3storage[8]) - (_m3storage[5] * _m3storage[7])); - final y = _m3storage[1] * + final y = + _m3storage[1] * ((_m3storage[3] * _m3storage[8]) - (_m3storage[5] * _m3storage[6])); - final z = _m3storage[2] * + final z = + _m3storage[2] * ((_m3storage[3] * _m3storage[7]) - (_m3storage[4] * _m3storage[6])); return x - y + z; } @@ -503,23 +533,32 @@ class Matrix3 { } final invDet = 1.0 / det; final argStorage = arg._m3storage; - final ix = invDet * + final ix = + invDet * (argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]); - final iy = invDet * + final iy = + invDet * (argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]); - final iz = invDet * + final iz = + invDet * (argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]); - final jx = invDet * + final jx = + invDet * (argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]); - final jy = invDet * + final jy = + invDet * (argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]); - final jz = invDet * + final jz = + invDet * (argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]); - final kx = invDet * + final kx = + invDet * (argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]); - final ky = invDet * + final ky = + invDet * (argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]); - final kz = invDet * + final kz = + invDet * (argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]); _m3storage[0] = ix; _m3storage[1] = iy; @@ -648,10 +687,12 @@ class Matrix3 { /// Transforms [arg] with this. Vector2 transform2(Vector2 arg) { final argStorage = arg._v2storage; - final x_ = (_m3storage[0] * argStorage[0]) + + final x_ = + (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + _m3storage[6]; - final y_ = (_m3storage[1] * argStorage[0]) + + final y_ = + (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + _m3storage[7]; argStorage[0] = x_; @@ -817,13 +858,16 @@ class Matrix3 { /// this. Vector3 transform(Vector3 arg) { final argStorage = arg._v3storage; - final x_ = (_m3storage[0] * argStorage[0]) + + final x_ = + (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + (_m3storage[6] * argStorage[2]); - final y_ = (_m3storage[1] * argStorage[0]) + + final y_ = + (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + (_m3storage[7] * argStorage[2]); - final z_ = (_m3storage[2] * argStorage[0]) + + final z_ = + (_m3storage[2] * argStorage[0]) + (_m3storage[5] * argStorage[1]) + (_m3storage[8] * argStorage[2]); arg @@ -908,31 +952,37 @@ class Matrix3 { /// Is this the identity matrix? bool isIdentity() => - _m3storage[0] == 1.0 // col 1 - && + _m3storage[0] == + 1.0 // col 1 + && _m3storage[1] == 0.0 && _m3storage[2] == 0.0 && - _m3storage[3] == 0.0 // col 2 - && + _m3storage[3] == + 0.0 // col 2 + && _m3storage[4] == 1.0 && _m3storage[5] == 0.0 && - _m3storage[6] == 0.0 // col 3 - && + _m3storage[6] == + 0.0 // col 3 + && _m3storage[7] == 0.0 && _m3storage[8] == 1.0; /// Is this the zero matrix? bool isZero() => - _m3storage[0] == 0.0 // col 1 - && + _m3storage[0] == + 0.0 // col 1 + && _m3storage[1] == 0.0 && _m3storage[2] == 0.0 && - _m3storage[3] == 0.0 // col 2 - && + _m3storage[3] == + 0.0 // col 2 + && _m3storage[4] == 0.0 && _m3storage[5] == 0.0 && - _m3storage[6] == 0.0 // col 3 - && + _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 123ca940..c5ce8faf 100644 --- a/lib/src/vector_math/matrix4.dart +++ b/lib/src/vector_math/matrix4.dart @@ -126,22 +126,26 @@ class Matrix4 { } x - ..x = det * + ..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 * + ..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 * + ..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 * + ..w = + det * -((a21 * b05 - a22 * b04 + a23 * b03) * bX - (a20 * b05 - a22 * b02 + a23 * b01) * bY + (a20 * b04 - a21 * b02 + a23 * b00) * bZ - @@ -180,29 +184,45 @@ class Matrix4 { /// Constructs a new mat4. factory Matrix4( - double arg0, - double arg1, - double arg2, - double arg3, - double arg4, - double arg5, - double arg6, - double arg7, - double arg8, - double arg9, - double arg10, - double arg11, - double arg12, - double arg13, - double arg14, - double arg15) => - Matrix4.zero() - ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, - arg10, arg11, arg12, arg13, arg14, arg15); + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + double arg9, + double arg10, + double arg11, + double arg12, + double arg13, + double arg14, + double arg15, + ) => + Matrix4.zero()..setValues( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + ); /// New matrix from [values]. - factory Matrix4.fromList(List values) => Matrix4.zero() - ..setValues( + factory Matrix4.fromList(List values) => + Matrix4.zero()..setValues( values[0], values[1], values[2], @@ -218,7 +238,8 @@ class Matrix4 { values[12], values[13], values[14], - values[15]); + values[15], + ); /// Zero matrix. Matrix4.zero() : _m4storage = Float32List(16); @@ -241,31 +262,38 @@ class Matrix4 { /// Constructs a new mat4 from columns. factory Matrix4.columns( - Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) => - Matrix4.zero()..setColumns(arg0, arg1, arg2, arg3); + Vector4 arg0, + Vector4 arg1, + Vector4 arg2, + Vector4 arg3, + ) => Matrix4.zero()..setColumns(arg0, arg1, arg2, arg3); /// Outer product of [u] and [v]. factory Matrix4.outer(Vector4 u, Vector4 v) => Matrix4.zero()..setOuter(u, v); /// Rotation of [radians] around X. - factory Matrix4.rotationX(double radians) => Matrix4.zero() - .._m4storage[15] = 1.0 - ..setRotationX(radians); + factory Matrix4.rotationX(double radians) => + Matrix4.zero() + .._m4storage[15] = 1.0 + ..setRotationX(radians); /// Rotation of [radians] around Y. - factory Matrix4.rotationY(double radians) => Matrix4.zero() - .._m4storage[15] = 1.0 - ..setRotationY(radians); + factory Matrix4.rotationY(double radians) => + Matrix4.zero() + .._m4storage[15] = 1.0 + ..setRotationY(radians); /// Rotation of [radians] around Z. - factory Matrix4.rotationZ(double radians) => Matrix4.zero() - .._m4storage[15] = 1.0 - ..setRotationZ(radians); + factory Matrix4.rotationZ(double radians) => + Matrix4.zero() + .._m4storage[15] = 1.0 + ..setRotationZ(radians); /// Translation matrix. - factory Matrix4.translation(Vector3 translation) => Matrix4.zero() - ..setIdentity() - ..setTranslation(translation); + factory Matrix4.translation(Vector3 translation) => + Matrix4.zero() + ..setIdentity() + ..setTranslation(translation); /// Translation matrix. factory Matrix4.translationValues(double x, double y, double z) => @@ -321,11 +349,14 @@ class Matrix4 { /// Constructs Matrix4 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float32List.bytesPerElement]. Matrix4.fromBuffer(ByteBuffer buffer, int offset) - : _m4storage = Float32List.view(buffer, offset, 16); + : _m4storage = Float32List.view(buffer, offset, 16); /// Constructs Matrix4 from [translation], [rotation] and [scale]. factory Matrix4.compose( - Vector3 translation, Quaternion rotation, Vector3 scale) => + Vector3 translation, + Quaternion rotation, + Vector3 scale, + ) => Matrix4.zero() ..setFromTranslationRotationScale(translation, rotation, scale); @@ -339,22 +370,23 @@ class Matrix4 { /// Sets the matrix with specified values. void setValues( - double arg0, - double arg1, - double arg2, - double arg3, - double arg4, - double arg5, - double arg6, - double arg7, - double arg8, - double arg9, - double arg10, - double arg11, - double arg12, - double arg13, - double arg14, - double arg15) { + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + double arg9, + double arg10, + double arg11, + double arg12, + double arg13, + double arg14, + double arg15, + ) { _m4storage[15] = arg15; _m4storage[14] = arg14; _m4storage[13] = arg13; @@ -459,7 +491,10 @@ class Matrix4 { /// Sets the matrix from [translation], [rotation] and [scale]. void setFromTranslationRotationScale( - Vector3 translation, Quaternion rotation, Vector3 scale) { + Vector3 translation, + Quaternion rotation, + Vector3 scale, + ) { setFromTranslationRotation(translation, rotation); scaleByVector3(scale); } @@ -505,7 +540,8 @@ class Matrix4 { /// Returns a printable string @override - String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n' + String toString() => + '[0] ${getRow(0)}\n[1] ${getRow(1)}\n' '[2] ${getRow(2)}\n[3] ${getRow(3)}\n'; /// Dimension of the matrix. @@ -676,8 +712,10 @@ class Matrix4 { @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - @Deprecated('Use translateByVector3, translateByVector4, ' - 'or translateByDouble instead') + @Deprecated( + 'Use translateByVector3, translateByVector4, ' + 'or translateByDouble instead', + ) void translate(dynamic x, [double y = 0.0, double z = 0.0]) { if (x is Vector3) { translateByVector3(x); @@ -692,25 +730,29 @@ class Matrix4 { /// Translate this matrix by x, y, z, w. void translateByDouble(double tx, double ty, double tz, double tw) { - final t1 = _m4storage[0] * tx + + final t1 = + _m4storage[0] * tx + _m4storage[4] * ty + _m4storage[8] * tz + _m4storage[12] * tw; _m4storage[12] = t1; - final t2 = _m4storage[1] * tx + + final t2 = + _m4storage[1] * tx + _m4storage[5] * ty + _m4storage[9] * tz + _m4storage[13] * tw; _m4storage[13] = t2; - final t3 = _m4storage[2] * tx + + final t3 = + _m4storage[2] * tx + _m4storage[6] * ty + _m4storage[10] * tz + _m4storage[14] * tw; _m4storage[14] = t3; - final t4 = _m4storage[3] * tx + + final t4 = + _m4storage[3] * tx + _m4storage[7] * ty + _m4storage[11] * tz + _m4storage[15] * tw; @@ -742,8 +784,10 @@ class Matrix4 { @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - @Deprecated('Use leftTranslateByVector3, leftTranslateByVector4, ' - 'or leftTranslateByDouble instead') + @Deprecated( + 'Use leftTranslateByVector3, leftTranslateByVector4, ' + 'or leftTranslateByDouble instead', + ) void leftTranslate(dynamic x, [double y = 0.0, double z = 0.0]) { if (x is Vector3) { leftTranslateByVector3(x); @@ -1095,16 +1139,20 @@ class Matrix4 { _m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5]; final det2_01_23 = _m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6]; - final det3_201_012 = _m4storage[8] * det2_01_12 - + final det3_201_012 = + _m4storage[8] * det2_01_12 - _m4storage[9] * det2_01_02 + _m4storage[10] * det2_01_01; - final det3_201_013 = _m4storage[8] * det2_01_13 - + final det3_201_013 = + _m4storage[8] * det2_01_13 - _m4storage[9] * det2_01_03 + _m4storage[11] * det2_01_01; - final det3_201_023 = _m4storage[8] * det2_01_23 - + final det3_201_023 = + _m4storage[8] * det2_01_23 - _m4storage[10] * det2_01_03 + _m4storage[11] * det2_01_02; - final det3_201_123 = _m4storage[9] * det2_01_23 - + final det3_201_123 = + _m4storage[9] * det2_01_23 - _m4storage[10] * det2_01_13 + _m4storage[11] * det2_01_12; return -det3_201_123 * _m4storage[12] + @@ -1267,13 +1315,16 @@ class Matrix4 { /// Returns the max scale value of the 3 axes. double getMaxScaleOnAxis() { - final scaleXSq = _m4storage[0] * _m4storage[0] + + final scaleXSq = + _m4storage[0] * _m4storage[0] + _m4storage[1] * _m4storage[1] + _m4storage[2] * _m4storage[2]; - final scaleYSq = _m4storage[4] * _m4storage[4] + + final scaleYSq = + _m4storage[4] * _m4storage[4] + _m4storage[5] * _m4storage[5] + _m4storage[6] * _m4storage[6]; - final scaleZSq = _m4storage[8] * _m4storage[8] + + final scaleZSq = + _m4storage[8] * _m4storage[8] + _m4storage[9] * _m4storage[9] + _m4storage[10] * _m4storage[10]; return math.sqrt(math.max(scaleXSq, math.max(scaleYSq, scaleZSq))); @@ -1377,23 +1428,32 @@ class Matrix4 { double kx; double ky; double kz; - ix = invDet * + ix = + invDet * (_m4storage[5] * _m4storage[10] - _m4storage[6] * _m4storage[9]); - iy = invDet * + iy = + invDet * (_m4storage[2] * _m4storage[9] - _m4storage[1] * _m4storage[10]); - iz = invDet * + iz = + invDet * (_m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5]); - jx = invDet * + jx = + invDet * (_m4storage[6] * _m4storage[8] - _m4storage[4] * _m4storage[10]); - jy = invDet * + jy = + invDet * (_m4storage[0] * _m4storage[10] - _m4storage[2] * _m4storage[8]); - jz = invDet * + jz = + invDet * (_m4storage[2] * _m4storage[4] - _m4storage[0] * _m4storage[6]); - kx = invDet * + kx = + invDet * (_m4storage[4] * _m4storage[9] - _m4storage[5] * _m4storage[8]); - ky = invDet * + ky = + invDet * (_m4storage[1] * _m4storage[8] - _m4storage[0] * _m4storage[9]); - kz = invDet * + kz = + invDet * (_m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4]); _m4storage[0] = ix; _m4storage[1] = iy; @@ -1480,67 +1540,83 @@ class Matrix4 { final b4 = _m4storage[7]; final c4 = _m4storage[11]; final d4 = _m4storage[15]; - _m4storage[0] = (b2 * (c3 * d4 - c4 * d3) - + _m4storage[0] = + (b2 * (c3 * d4 - c4 * d3) - c2 * (b3 * d4 - b4 * d3) + d2 * (b3 * c4 - b4 * c3)) * scale; - _m4storage[1] = -(a2 * (c3 * d4 - c4 * d3) - + _m4storage[1] = + -(a2 * (c3 * d4 - c4 * d3) - c2 * (a3 * d4 - a4 * d3) + d2 * (a3 * c4 - a4 * c3)) * scale; - _m4storage[2] = (a2 * (b3 * d4 - b4 * d3) - + _m4storage[2] = + (a2 * (b3 * d4 - b4 * d3) - b2 * (a3 * d4 - a4 * d3) + d2 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[3] = -(a2 * (b3 * c4 - b4 * c3) - + _m4storage[3] = + -(a2 * (b3 * c4 - b4 * c3) - b2 * (a3 * c4 - a4 * c3) + c2 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[4] = -(b1 * (c3 * d4 - c4 * d3) - + _m4storage[4] = + -(b1 * (c3 * d4 - c4 * d3) - c1 * (b3 * d4 - b4 * d3) + d1 * (b3 * c4 - b4 * c3)) * scale; - _m4storage[5] = (a1 * (c3 * d4 - c4 * d3) - + _m4storage[5] = + (a1 * (c3 * d4 - c4 * d3) - c1 * (a3 * d4 - a4 * d3) + d1 * (a3 * c4 - a4 * c3)) * scale; - _m4storage[6] = -(a1 * (b3 * d4 - b4 * d3) - + _m4storage[6] = + -(a1 * (b3 * d4 - b4 * d3) - b1 * (a3 * d4 - a4 * d3) + d1 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[7] = (a1 * (b3 * c4 - b4 * c3) - + _m4storage[7] = + (a1 * (b3 * c4 - b4 * c3) - b1 * (a3 * c4 - a4 * c3) + c1 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[8] = (b1 * (c2 * d4 - c4 * d2) - + _m4storage[8] = + (b1 * (c2 * d4 - c4 * d2) - c1 * (b2 * d4 - b4 * d2) + d1 * (b2 * c4 - b4 * c2)) * scale; - _m4storage[9] = -(a1 * (c2 * d4 - c4 * d2) - + _m4storage[9] = + -(a1 * (c2 * d4 - c4 * d2) - c1 * (a2 * d4 - a4 * d2) + d1 * (a2 * c4 - a4 * c2)) * scale; - _m4storage[10] = (a1 * (b2 * d4 - b4 * d2) - + _m4storage[10] = + (a1 * (b2 * d4 - b4 * d2) - b1 * (a2 * d4 - a4 * d2) + d1 * (a2 * b4 - a4 * b2)) * scale; - _m4storage[11] = -(a1 * (b2 * c4 - b4 * c2) - + _m4storage[11] = + -(a1 * (b2 * c4 - b4 * c2) - b1 * (a2 * c4 - a4 * c2) + c1 * (a2 * b4 - a4 * b2)) * scale; - _m4storage[12] = -(b1 * (c2 * d3 - c3 * d2) - + _m4storage[12] = + -(b1 * (c2 * d3 - c3 * d2) - c1 * (b2 * d3 - b3 * d2) + d1 * (b2 * c3 - b3 * c2)) * scale; - _m4storage[13] = (a1 * (c2 * d3 - c3 * d2) - + _m4storage[13] = + (a1 * (c2 * d3 - c3 * d2) - c1 * (a2 * d3 - a3 * d2) + d1 * (a2 * c3 - a3 * c2)) * scale; - _m4storage[14] = -(a1 * (b2 * d3 - b3 * d2) - + _m4storage[14] = + -(a1 * (b2 * d3 - b3 * d2) - b1 * (a2 * d3 - a3 * d2) + d1 * (a2 * b3 - a3 * b2)) * scale; - _m4storage[15] = (a1 * (b2 * c3 - b3 * c2) - + _m4storage[15] = + (a1 * (b2 * c3 - b3 * c2) - b1 * (a2 * c3 - a3 * c2) + c1 * (a2 * b3 - a3 * b2)) * scale; @@ -1706,67 +1782,83 @@ class Matrix4 { final m32 = _m4storage[14]; final m33 = _m4storage[15]; final argStorage = arg._m4storage; - _m4storage[0] = (m00 * argStorage[0]) + + _m4storage[0] = + (m00 * argStorage[0]) + (m01 * argStorage[1]) + (m02 * argStorage[2]) + (m03 * argStorage[3]); - _m4storage[4] = (m00 * argStorage[4]) + + _m4storage[4] = + (m00 * argStorage[4]) + (m01 * argStorage[5]) + (m02 * argStorage[6]) + (m03 * argStorage[7]); - _m4storage[8] = (m00 * argStorage[8]) + + _m4storage[8] = + (m00 * argStorage[8]) + (m01 * argStorage[9]) + (m02 * argStorage[10]) + (m03 * argStorage[11]); - _m4storage[12] = (m00 * argStorage[12]) + + _m4storage[12] = + (m00 * argStorage[12]) + (m01 * argStorage[13]) + (m02 * argStorage[14]) + (m03 * argStorage[15]); - _m4storage[1] = (m10 * argStorage[0]) + + _m4storage[1] = + (m10 * argStorage[0]) + (m11 * argStorage[1]) + (m12 * argStorage[2]) + (m13 * argStorage[3]); - _m4storage[5] = (m10 * argStorage[4]) + + _m4storage[5] = + (m10 * argStorage[4]) + (m11 * argStorage[5]) + (m12 * argStorage[6]) + (m13 * argStorage[7]); - _m4storage[9] = (m10 * argStorage[8]) + + _m4storage[9] = + (m10 * argStorage[8]) + (m11 * argStorage[9]) + (m12 * argStorage[10]) + (m13 * argStorage[11]); - _m4storage[13] = (m10 * argStorage[12]) + + _m4storage[13] = + (m10 * argStorage[12]) + (m11 * argStorage[13]) + (m12 * argStorage[14]) + (m13 * argStorage[15]); - _m4storage[2] = (m20 * argStorage[0]) + + _m4storage[2] = + (m20 * argStorage[0]) + (m21 * argStorage[1]) + (m22 * argStorage[2]) + (m23 * argStorage[3]); - _m4storage[6] = (m20 * argStorage[4]) + + _m4storage[6] = + (m20 * argStorage[4]) + (m21 * argStorage[5]) + (m22 * argStorage[6]) + (m23 * argStorage[7]); - _m4storage[10] = (m20 * argStorage[8]) + + _m4storage[10] = + (m20 * argStorage[8]) + (m21 * argStorage[9]) + (m22 * argStorage[10]) + (m23 * argStorage[11]); - _m4storage[14] = (m20 * argStorage[12]) + + _m4storage[14] = + (m20 * argStorage[12]) + (m21 * argStorage[13]) + (m22 * argStorage[14]) + (m23 * argStorage[15]); - _m4storage[3] = (m30 * argStorage[0]) + + _m4storage[3] = + (m30 * argStorage[0]) + (m31 * argStorage[1]) + (m32 * argStorage[2]) + (m33 * argStorage[3]); - _m4storage[7] = (m30 * argStorage[4]) + + _m4storage[7] = + (m30 * argStorage[4]) + (m31 * argStorage[5]) + (m32 * argStorage[6]) + (m33 * argStorage[7]); - _m4storage[11] = (m30 * argStorage[8]) + + _m4storage[11] = + (m30 * argStorage[8]) + (m31 * argStorage[9]) + (m32 * argStorage[10]) + (m33 * argStorage[11]); - _m4storage[15] = (m30 * argStorage[12]) + + _m4storage[15] = + (m30 * argStorage[12]) + (m31 * argStorage[13]) + (m32 * argStorage[14]) + (m33 * argStorage[15]); @@ -1791,67 +1883,83 @@ class Matrix4 { final m32 = _m4storage[11]; final m33 = _m4storage[15]; final argStorage = arg._m4storage; - _m4storage[0] = (m00 * argStorage[0]) + + _m4storage[0] = + (m00 * argStorage[0]) + (m01 * argStorage[4]) + (m02 * argStorage[8]) + (m03 * argStorage[12]); - _m4storage[4] = (m00 * argStorage[1]) + + _m4storage[4] = + (m00 * argStorage[1]) + (m01 * argStorage[5]) + (m02 * argStorage[9]) + (m03 * argStorage[13]); - _m4storage[8] = (m00 * argStorage[2]) + + _m4storage[8] = + (m00 * argStorage[2]) + (m01 * argStorage[6]) + (m02 * argStorage[10]) + (m03 * argStorage[14]); - _m4storage[12] = (m00 * argStorage[3]) + + _m4storage[12] = + (m00 * argStorage[3]) + (m01 * argStorage[7]) + (m02 * argStorage[11]) + (m03 * argStorage[15]); - _m4storage[1] = (m10 * argStorage[0]) + + _m4storage[1] = + (m10 * argStorage[0]) + (m11 * argStorage[4]) + (m12 * argStorage[8]) + (m13 * argStorage[12]); - _m4storage[5] = (m10 * argStorage[1]) + + _m4storage[5] = + (m10 * argStorage[1]) + (m11 * argStorage[5]) + (m12 * argStorage[9]) + (m13 * argStorage[13]); - _m4storage[9] = (m10 * argStorage[2]) + + _m4storage[9] = + (m10 * argStorage[2]) + (m11 * argStorage[6]) + (m12 * argStorage[10]) + (m13 * argStorage[14]); - _m4storage[13] = (m10 * argStorage[3]) + + _m4storage[13] = + (m10 * argStorage[3]) + (m11 * argStorage[7]) + (m12 * argStorage[11]) + (m13 * argStorage[15]); - _m4storage[2] = (m20 * argStorage[0]) + + _m4storage[2] = + (m20 * argStorage[0]) + (m21 * argStorage[4]) + (m22 * argStorage[8]) + (m23 * argStorage[12]); - _m4storage[6] = (m20 * argStorage[1]) + + _m4storage[6] = + (m20 * argStorage[1]) + (m21 * argStorage[5]) + (m22 * argStorage[9]) + (m23 * argStorage[13]); - _m4storage[10] = (m20 * argStorage[2]) + + _m4storage[10] = + (m20 * argStorage[2]) + (m21 * argStorage[6]) + (m22 * argStorage[10]) + (m23 * argStorage[14]); - _m4storage[14] = (m20 * argStorage[3]) + + _m4storage[14] = + (m20 * argStorage[3]) + (m21 * argStorage[7]) + (m22 * argStorage[11]) + (m23 * argStorage[15]); - _m4storage[3] = (m30 * argStorage[0]) + + _m4storage[3] = + (m30 * argStorage[0]) + (m31 * argStorage[4]) + (m32 * argStorage[8]) + (m33 * argStorage[12]); - _m4storage[7] = (m30 * argStorage[1]) + + _m4storage[7] = + (m30 * argStorage[1]) + (m31 * argStorage[5]) + (m32 * argStorage[9]) + (m33 * argStorage[13]); - _m4storage[11] = (m30 * argStorage[2]) + + _m4storage[11] = + (m30 * argStorage[2]) + (m31 * argStorage[6]) + (m32 * argStorage[10]) + (m33 * argStorage[14]); - _m4storage[15] = (m30 * argStorage[3]) + + _m4storage[15] = + (m30 * argStorage[3]) + (m31 * argStorage[7]) + (m32 * argStorage[11]) + (m33 * argStorage[15]); @@ -1906,13 +2014,16 @@ class Matrix4 { /// 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 x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]); - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]); - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]); argStorage[0] = x_; @@ -1936,15 +2047,18 @@ class Matrix4 { /// this. Vector3 transform3(Vector3 arg) { final argStorage = arg._v3storage; - final x_ = (_m4storage[0] * argStorage[0]) + + final x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + _m4storage[14]; @@ -1970,19 +2084,23 @@ class Matrix4 { /// this. Vector4 transform(Vector4 arg) { final argStorage = arg._v4storage; - final x_ = (_m4storage[0] * argStorage[0]) + + final x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + (_m4storage[12] * argStorage[3]); - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + (_m4storage[13] * argStorage[3]); - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + (_m4storage[14] * argStorage[3]); - final w_ = (_m4storage[3] * argStorage[0]) + + final w_ = + (_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + (_m4storage[11] * argStorage[2]) + (_m4storage[15] * argStorage[3]); @@ -1997,19 +2115,23 @@ class Matrix4 { /// defined by this. Vector3 perspectiveTransform(Vector3 arg) { final argStorage = arg._v3storage; - final x_ = (_m4storage[0] * argStorage[0]) + + final x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + _m4storage[14]; - final w_ = 1.0 / + final w_ = + 1.0 / ((_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + (_m4storage[11] * argStorage[2]) + @@ -2109,46 +2231,54 @@ class Matrix4 { /// Is this the identity matrix? bool isIdentity() => - _m4storage[0] == 1.0 // col 1 - && + _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[4] == + 0.0 // col 2 + && _m4storage[5] == 1.0 && _m4storage[6] == 0.0 && _m4storage[7] == 0.0 && - _m4storage[8] == 0.0 // col 3 - && + _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[12] == + 0.0 // col 4 + && _m4storage[13] == 0.0 && _m4storage[14] == 0.0 && _m4storage[15] == 1.0; /// Is this the zero matrix? bool isZero() => - _m4storage[0] == 0.0 // col 1 - && + _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[4] == + 0.0 // col 2 + && _m4storage[5] == 0.0 && _m4storage[6] == 0.0 && _m4storage[7] == 0.0 && - _m4storage[8] == 0.0 // col 3 - && + _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[12] == + 0.0 // col 4 + && _m4storage[13] == 0.0 && _m4storage[14] == 0.0 && _m4storage[15] == 0.0; diff --git a/lib/src/vector_math/noise.dart b/lib/src/vector_math/noise.dart index c389bd30..11f0ab0a 100644 --- a/lib/src/vector_math/noise.dart +++ b/lib/src/vector_math/noise.dart @@ -26,8 +26,10 @@ part of '../../vector_math.dart'; * found at: http://webstaff.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java */ -@Deprecated('This API will be removed ' - '(see https:github.com/google/vector_math.dart/issues/270)') +@Deprecated( + 'This API will be removed ' + '(see https:github.com/google/vector_math.dart/issues/270)', +) class SimplexNoise { static final List> _grad3 = >[ [1.0, 1.0, 0.0], @@ -41,7 +43,7 @@ class SimplexNoise { [0.0, 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, -1.0], ]; static final List> _grad4 = >[ @@ -76,7 +78,7 @@ class SimplexNoise { [-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], ]; // To remove the need for index wrapping, double the permutation table length @@ -102,10 +104,16 @@ class SimplexNoise { SimplexNoise([math.Random? r]) { r ??= math.Random(); final p = List.generate(256, (_) => r!.nextInt(256), growable: false); - _perm = List.generate(p.length * 2, (int i) => p[i % p.length], - growable: false); - _permMod12 = List.generate(_perm.length, (int i) => _perm[i] % 12, - growable: false); + _perm = List.generate( + p.length * 2, + (int i) => p[i % p.length], + growable: false, + ); + _permMod12 = List.generate( + _perm.length, + (int i) => _perm[i] % 12, + growable: false, + ); } double noise2D(double xin, double yin) { @@ -136,7 +144,8 @@ class SimplexNoise { final x1 = x0 - i1 + _G2; // Offsets for middle corner in (x,y) unskewed coords final y1 = y0 - j1 + _G2; - final x2 = x0 - + final x2 = + x0 - 1.0 + 2.0 * _G2; // Offsets for last corner in (x,y) unskewed coords final y2 = y0 - 1.0 + 2.0 * _G2; @@ -152,7 +161,8 @@ class SimplexNoise { n0 = 0.0; } else { t0 *= t0; - n0 = t0 * + n0 = + t0 * t0 * _dot2(_grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient } diff --git a/lib/src/vector_math/obb3.dart b/lib/src/vector_math/obb3.dart index ee94b5e8..6a0e0929 100644 --- a/lib/src/vector_math/obb3.dart +++ b/lib/src/vector_math/obb3.dart @@ -29,28 +29,32 @@ class Obb3 { /// Create a new OBB with erverything set to zero. Obb3() - : _center = Vector3.zero(), - _halfExtents = Vector3.zero(), - _axis0 = Vector3(1.0, 0.0, 0.0), - _axis1 = Vector3(0.0, 1.0, 0.0), - _axis2 = Vector3(0.0, 0.0, 1.0); + : _center = Vector3.zero(), + _halfExtents = Vector3.zero(), + _axis0 = Vector3(1.0, 0.0, 0.0), + _axis1 = Vector3(0.0, 1.0, 0.0), + _axis2 = Vector3(0.0, 0.0, 1.0); /// Create a new OBB as a copy of [other]. Obb3.copy(Obb3 other) - : _center = Vector3.copy(other._center), - _halfExtents = Vector3.copy(other._halfExtents), - _axis0 = Vector3.copy(other._axis0), - _axis1 = Vector3.copy(other._axis1), - _axis2 = Vector3.copy(other._axis2); + : _center = Vector3.copy(other._center), + _halfExtents = Vector3.copy(other._halfExtents), + _axis0 = Vector3.copy(other._axis0), + _axis1 = Vector3.copy(other._axis1), + _axis2 = Vector3.copy(other._axis2); /// Create a new OBB using [center], [halfExtents] and axis. - Obb3.centerExtentsAxes(Vector3 center, Vector3 halfExtents, Vector3 axis0, - Vector3 axis1, Vector3 axis2) - : _center = Vector3.copy(center), - _halfExtents = Vector3.copy(halfExtents), - _axis0 = Vector3.copy(axis0), - _axis1 = Vector3.copy(axis1), - _axis2 = Vector3.copy(axis2); + Obb3.centerExtentsAxes( + Vector3 center, + Vector3 halfExtents, + Vector3 axis0, + Vector3 axis1, + Vector3 axis2, + ) : _center = Vector3.copy(center), + _halfExtents = Vector3.copy(halfExtents), + _axis0 = Vector3.copy(axis0), + _axis1 = Vector3.copy(axis1), + _axis2 = Vector3.copy(axis2); /// Copy from [other] into this. void copyFrom(Obb3 other) { @@ -229,7 +233,8 @@ class Obb3 { // Test axes L = A0, L = A1, L = A2 for (var i = 0; i < 3; i++) { ra = _halfExtents[i]; - rb = other._halfExtents[0] * _absR.entry(i, 0) + + rb = + other._halfExtents[0] * _absR.entry(i, 0) + other._halfExtents[1] * _absR.entry(i, 1) + other._halfExtents[2] * _absR.entry(i, 2); @@ -240,7 +245,8 @@ class Obb3 { // Test axes L = B0, L = B1, L = B2 for (var i = 0; i < 3; i++) { - ra = _halfExtents[0] * _absR.entry(0, i) + + ra = + _halfExtents[0] * _absR.entry(0, i) + _halfExtents[1] * _absR.entry(1, i) + _halfExtents[2] * _absR.entry(2, i); rb = other._halfExtents[i]; @@ -255,81 +261,99 @@ class Obb3 { } // Test axis L = A0 x B0 - ra = _halfExtents[1] * _absR.entry(2, 0) + + ra = + _halfExtents[1] * _absR.entry(2, 0) + _halfExtents[2] * _absR.entry(1, 0); - rb = other._halfExtents[1] * _absR.entry(0, 2) + + rb = + other._halfExtents[1] * _absR.entry(0, 2) + other._halfExtents[2] * _absR.entry(0, 1); if ((_t[2] * _r.entry(1, 0) - _t[1] * _r.entry(2, 0)).abs() > ra + rb) { return false; } // Test axis L = A0 x B1 - ra = _halfExtents[1] * _absR.entry(2, 1) + + ra = + _halfExtents[1] * _absR.entry(2, 1) + _halfExtents[2] * _absR.entry(1, 1); - rb = other._halfExtents[0] * _absR.entry(0, 2) + + rb = + other._halfExtents[0] * _absR.entry(0, 2) + other._halfExtents[2] * _absR.entry(0, 0); if ((_t[2] * _r.entry(1, 1) - _t[1] * _r.entry(2, 1)).abs() > ra + rb) { return false; } // Test axis L = A0 x B2 - ra = _halfExtents[1] * _absR.entry(2, 2) + + ra = + _halfExtents[1] * _absR.entry(2, 2) + _halfExtents[2] * _absR.entry(1, 2); - rb = other._halfExtents[0] * _absR.entry(0, 1) + + rb = + other._halfExtents[0] * _absR.entry(0, 1) + other._halfExtents[1] * _absR.entry(0, 0); if ((_t[2] * _r.entry(1, 2) - _t[1] * _r.entry(2, 2)).abs() > ra + rb) { return false; } // Test axis L = A1 x B0 - ra = _halfExtents[0] * _absR.entry(2, 0) + + ra = + _halfExtents[0] * _absR.entry(2, 0) + _halfExtents[2] * _absR.entry(0, 0); - rb = other._halfExtents[1] * _absR.entry(1, 2) + + rb = + other._halfExtents[1] * _absR.entry(1, 2) + other._halfExtents[2] * _absR.entry(1, 1); if ((_t[0] * _r.entry(2, 0) - _t[2] * _r.entry(0, 0)).abs() > ra + rb) { return false; } // Test axis L = A1 x B1 - ra = _halfExtents[0] * _absR.entry(2, 1) + + ra = + _halfExtents[0] * _absR.entry(2, 1) + _halfExtents[2] * _absR.entry(0, 1); - rb = other._halfExtents[0] * _absR.entry(1, 2) + + rb = + other._halfExtents[0] * _absR.entry(1, 2) + other._halfExtents[2] * _absR.entry(1, 0); if ((_t[0] * _r.entry(2, 1) - _t[2] * _r.entry(0, 1)).abs() > ra + rb) { return false; } // Test axis L = A1 x B2 - ra = _halfExtents[0] * _absR.entry(2, 2) + + ra = + _halfExtents[0] * _absR.entry(2, 2) + _halfExtents[2] * _absR.entry(0, 2); - rb = other._halfExtents[0] * _absR.entry(1, 1) + + rb = + other._halfExtents[0] * _absR.entry(1, 1) + other._halfExtents[1] * _absR.entry(1, 0); if ((_t[0] * _r.entry(2, 2) - _t[2] * _r.entry(0, 2)).abs() > ra + rb) { return false; } // Test axis L = A2 x B0 - ra = _halfExtents[0] * _absR.entry(1, 0) + + ra = + _halfExtents[0] * _absR.entry(1, 0) + _halfExtents[1] * _absR.entry(0, 0); - rb = other._halfExtents[1] * _absR.entry(2, 2) + + rb = + other._halfExtents[1] * _absR.entry(2, 2) + other._halfExtents[2] * _absR.entry(2, 1); if ((_t[1] * _r.entry(0, 0) - _t[0] * _r.entry(1, 0)).abs() > ra + rb) { return false; } // Test axis L = A2 x B1 - ra = _halfExtents[0] * _absR.entry(1, 1) + + ra = + _halfExtents[0] * _absR.entry(1, 1) + _halfExtents[1] * _absR.entry(0, 1); - rb = other._halfExtents[0] * _absR.entry(2, 2) + + rb = + other._halfExtents[0] * _absR.entry(2, 2) + other._halfExtents[2] * _absR.entry(2, 0); if ((_t[1] * _r.entry(0, 1) - _t[0] * _r.entry(1, 1)).abs() > ra + rb) { return false; } // Test axis L = A2 x B2 - ra = _halfExtents[0] * _absR.entry(1, 2) + + ra = + _halfExtents[0] * _absR.entry(1, 2) + _halfExtents[1] * _absR.entry(0, 2); - rb = other._halfExtents[0] * _absR.entry(2, 1) + + rb = + other._halfExtents[0] * _absR.entry(2, 1) + other._halfExtents[1] * _absR.entry(2, 0); if ((_t[1] * _r.entry(0, 2) - _t[0] * _r.entry(1, 2)).abs() > ra + rb) { return false; @@ -350,16 +374,25 @@ class Obb3 { _triangle.point0 ..sub(_center) - ..setValues(_triangle.point0.dot(axis0), _triangle.point0.dot(axis1), - _triangle.point0.dot(axis2)); + ..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)); + ..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)); + ..setValues( + _triangle.point2.dot(axis0), + _triangle.point2.dot(axis1), + _triangle.point2.dot(axis2), + ); _aabb3.setCenterAndHalfExtents(_zeroVector, _halfExtents); diff --git a/lib/src/vector_math/opengl.dart b/lib/src/vector_math/opengl.dart index 74475f89..215676f2 100644 --- a/lib/src/vector_math/opengl.dart +++ b/lib/src/vector_math/opengl.dart @@ -41,7 +41,10 @@ part of '../../vector_math.dart'; /// } /// } void setRotationMatrix( - Matrix4 rotationMatrix, Vector3 forwardDirection, Vector3 upDirection) { + Matrix4 rotationMatrix, + Vector3 forwardDirection, + Vector3 upDirection, +) { setModelMatrix(rotationMatrix, forwardDirection, upDirection, 0.0, 0.0, 0.0); } @@ -54,14 +57,36 @@ void setRotationMatrix( /// [forwardDirection] specifies the direction of the forward vector. /// [upDirection] specifies the direction of the up vector. /// [tx],[ty],[tz] specifies the position of the object. -void setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection, - Vector3 upDirection, double tx, double ty, double tz) { +void setModelMatrix( + Matrix4 modelMatrix, + Vector3 forwardDirection, + Vector3 upDirection, + double tx, + double ty, + double tz, +) { final right = forwardDirection.cross(upDirection)..normalize(); final c1 = right; final c2 = upDirection; final c3 = -forwardDirection; - modelMatrix.setValues(c1[0], c1[1], c1[2], 0.0, c2[0], c2[1], c2[2], 0.0, - c3[0], c3[1], c3[2], 0.0, tx, ty, tz, 1.0); + 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, + ); } /// Constructs an OpenGL view matrix in [viewMatrix]. @@ -72,8 +97,12 @@ void setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection, /// [cameraPosition] specifies the position of the camera. /// [cameraFocusPosition] specifies the position the camera is focused on. /// [upDirection] specifies the direction of the up vector (usually, +Y). -void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, - Vector3 cameraFocusPosition, Vector3 upDirection) { +void setViewMatrix( + Matrix4 viewMatrix, + Vector3 cameraPosition, + Vector3 cameraFocusPosition, + Vector3 upDirection, +) { final z = (cameraPosition - cameraFocusPosition)..normalize(); final x = upDirection.cross(z)..normalize(); final y = z.cross(x)..normalize(); @@ -82,8 +111,24 @@ void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, final rotatedEyeY = -y.dot(cameraPosition); final rotatedEyeZ = -z.dot(cameraPosition); - viewMatrix.setValues(x[0], y[0], z[0], 0.0, x[1], y[1], z[1], 0.0, x[2], y[2], - z[2], 0.0, rotatedEyeX, rotatedEyeY, rotatedEyeZ, 1.0); + 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, + ); } /// Constructs a new OpenGL view matrix. @@ -92,7 +137,10 @@ void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, /// [cameraFocusPosition] specifies the position the camera is focused on. /// [upDirection] specifies the direction of the up vector (usually, +Y). Matrix4 makeViewMatrix( - Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) { + Vector3 cameraPosition, + Vector3 cameraFocusPosition, + Vector3 upDirection, +) { final r = Matrix4.zero(); setViewMatrix(r, cameraPosition, cameraFocusPosition, upDirection); return r; @@ -108,8 +156,13 @@ Matrix4 makeViewMatrix( /// (always positive). /// [zFar] specifies the distance from the viewer to the far plane /// (always positive). -void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians, - double aspectRatio, double zNear, double zFar) { +void setPerspectiveMatrix( + Matrix4 perspectiveMatrix, + double fovYRadians, + double aspectRatio, + double zNear, + double zFar, +) { final height = math.tan(fovYRadians * 0.5); final width = height * aspectRatio; final near_minus_far = zNear - zFar; @@ -134,7 +187,11 @@ void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians, /// [zFar] specifies the distance from the viewer to the far plane /// (always positive). Matrix4 makePerspectiveMatrix( - double fovYRadians, double aspectRatio, double zNear, double zFar) { + double fovYRadians, + double aspectRatio, + double zNear, + double zFar, +) { final r = Matrix4.zero(); setPerspectiveMatrix(r, fovYRadians, aspectRatio, zNear, zFar); return r; @@ -147,8 +204,12 @@ Matrix4 makePerspectiveMatrix( /// in the x direction. The aspect ratio of x (width) to y (height). /// [zNear] specifies the distance from the viewer to the near plane /// (always positive). -void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians, - double aspectRatio, double zNear) { +void setInfiniteMatrix( + Matrix4 infiniteMatrix, + double fovYRadians, + double aspectRatio, + double zNear, +) { final height = math.tan(fovYRadians * 0.5); final width = height * aspectRatio; @@ -170,7 +231,10 @@ void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians, /// [zNear] specifies the distance from the viewer to the near plane /// (always positive). Matrix4 makeInfiniteMatrix( - double fovYRadians, double aspectRatio, double zNear) { + double fovYRadians, + double aspectRatio, + double zNear, +) { final r = Matrix4.zero(); setInfiniteMatrix(r, fovYRadians, aspectRatio, zNear); return r; @@ -184,8 +248,15 @@ Matrix4 makeInfiniteMatrix( /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right, - double bottom, double top, double near, double far) { +void setFrustumMatrix( + Matrix4 perspectiveMatrix, + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final two_near = 2.0 * near; final right_minus_left = right - left; final top_minus_bottom = top - bottom; @@ -209,8 +280,14 @@ void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right, /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top, - double near, double far) { +Matrix4 makeFrustumMatrix( + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final view = Matrix4.zero(); setFrustumMatrix(view, left, right, bottom, top, near, far); return view; @@ -224,8 +301,15 @@ Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top, /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -void setOrthographicMatrix(Matrix4 orthographicMatrix, double left, - double right, double bottom, double top, double near, double far) { +void setOrthographicMatrix( + Matrix4 orthographicMatrix, + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final rml = right - left; final rpl = right + left; final tmb = top - bottom; @@ -251,8 +335,14 @@ void setOrthographicMatrix(Matrix4 orthographicMatrix, double left, /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -Matrix4 makeOrthographicMatrix(double left, double right, double bottom, - double top, double near, double far) { +Matrix4 makeOrthographicMatrix( + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final r = Matrix4.zero(); setOrthographicMatrix(r, left, right, bottom, top, near, far); return r; @@ -261,14 +351,22 @@ Matrix4 makeOrthographicMatrix(double left, double right, double bottom, /// Returns a transformation matrix that transforms points onto /// the plane specified with [planeNormal] and [planePoint]. Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) { - final v = Vector4(planeNormal.storage[0], planeNormal.storage[1], - planeNormal.storage[2], 0.0); + final v = Vector4( + planeNormal.storage[0], + planeNormal.storage[1], + planeNormal.storage[2], + 0.0, + ); final outer = Matrix4.outer(v, v); var r = Matrix4.zero(); r = r - outer; final scaledNormal = planeNormal.scaled(dot3(planePoint, planeNormal)); - final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1], - scaledNormal.storage[2], 1.0); + final T = Vector4( + scaledNormal.storage[0], + scaledNormal.storage[1], + scaledNormal.storage[2], + 1.0, + ); r.setColumn(3, T); return r; } @@ -276,15 +374,23 @@ Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) { /// Returns a transformation matrix that transforms points by reflecting /// them through the plane specified with [planeNormal] and [planePoint]. Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) { - final v = Vector4(planeNormal.storage[0], planeNormal.storage[1], - planeNormal.storage[2], 0.0); + final v = Vector4( + planeNormal.storage[0], + planeNormal.storage[1], + planeNormal.storage[2], + 0.0, + ); final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0, 1.0); var r = Matrix4.zero(); r = r - outer; final scale = 2.0 * planePoint.dot(planeNormal); final scaledNormal = planeNormal.scaled(scale); - final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1], - scaledNormal.storage[2], 1.0); + final T = Vector4( + scaledNormal.storage[0], + scaledNormal.storage[1], + scaledNormal.storage[2], + 1.0, + ); r.setColumn(3, T); return r; } @@ -301,15 +407,16 @@ Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) { /// /// Returns false on error, for example, the mouse is not in the viewport bool unproject( - Matrix4 cameraMatrix, - num viewportX, - num viewportWidth, - num viewportY, - num viewportHeight, - num pickX, - num pickY, - num pickZ, - Vector3 pickWorld) { + Matrix4 cameraMatrix, + num viewportX, + num viewportWidth, + num viewportY, + num viewportHeight, + num pickX, + num pickY, + num pickZ, + Vector3 pickWorld, +) { viewportX = viewportX.toDouble(); viewportWidth = viewportWidth.toDouble(); viewportY = viewportY.toDouble(); @@ -362,23 +469,42 @@ bool unproject( /// /// Returns false on error, for example, the mouse is not in the viewport. bool pickRay( - Matrix4 cameraMatrix, - num viewportX, - num viewportWidth, - num viewportY, - num viewportHeight, - num pickX, - num pickY, - Vector3 rayNear, - Vector3 rayFar) { + Matrix4 cameraMatrix, + num viewportX, + num viewportWidth, + num viewportY, + num viewportHeight, + num pickX, + num pickY, + Vector3 rayNear, + Vector3 rayFar, +) { bool r; - r = unproject(cameraMatrix, viewportX, viewportWidth, viewportY, - viewportHeight, pickX, viewportHeight - pickY, 0.0, rayNear); + r = unproject( + cameraMatrix, + viewportX, + viewportWidth, + viewportY, + viewportHeight, + pickX, + viewportHeight - pickY, + 0.0, + rayNear, + ); if (!r) { return false; } - return unproject(cameraMatrix, viewportX, viewportWidth, viewportY, - viewportHeight, pickX, viewportHeight - pickY, 1.0, rayFar); + return unproject( + cameraMatrix, + viewportX, + viewportWidth, + viewportY, + viewportHeight, + pickX, + viewportHeight - pickY, + 1.0, + rayFar, + ); } diff --git a/lib/src/vector_math/plane.dart b/lib/src/vector_math/plane.dart index 55533f4c..dac6ebad 100644 --- a/lib/src/vector_math/plane.dart +++ b/lib/src/vector_math/plane.dart @@ -35,19 +35,17 @@ class Plane { Vector3 get normal => _normal; - Plane() - : _normal = Vector3.zero(), - constant = 0.0; + Plane() : _normal = Vector3.zero(), constant = 0.0; Plane.copy(Plane other) - : _normal = Vector3.copy(other._normal), - constant = other.constant; + : _normal = Vector3.copy(other._normal), + constant = other.constant; Plane.components(double x, double y, double z, this.constant) - : _normal = Vector3(x, y, z); + : _normal = Vector3(x, y, z); Plane.normalconstant(Vector3 normal_, this.constant) - : _normal = Vector3.copy(normal_); + : _normal = Vector3.copy(normal_); void copyFrom(Plane o) { _normal.setFrom(o._normal); diff --git a/lib/src/vector_math/quad.dart b/lib/src/vector_math/quad.dart index 03760407..8e1a8265 100644 --- a/lib/src/vector_math/quad.dart +++ b/lib/src/vector_math/quad.dart @@ -25,24 +25,24 @@ class Quad { /// Create a new, uninitialized quad. Quad() - : _point0 = Vector3.zero(), - _point1 = Vector3.zero(), - _point2 = Vector3.zero(), - _point3 = Vector3.zero(); + : _point0 = Vector3.zero(), + _point1 = Vector3.zero(), + _point2 = Vector3.zero(), + _point3 = Vector3.zero(); /// Create a quad as a copy of [other]. Quad.copy(Quad other) - : _point0 = Vector3.copy(other._point0), - _point1 = Vector3.copy(other._point1), - _point2 = Vector3.copy(other._point2), - _point3 = Vector3.copy(other._point3); + : _point0 = Vector3.copy(other._point0), + _point1 = Vector3.copy(other._point1), + _point2 = Vector3.copy(other._point2), + _point3 = Vector3.copy(other._point3); /// Create a quad by four points. Quad.points(Vector3 point0, Vector3 point1, Vector3 point2, Vector3 point3) - : _point0 = Vector3.copy(point0), - _point1 = Vector3.copy(point1), - _point2 = Vector3.copy(point2), - _point3 = Vector3.copy(point3); + : _point0 = Vector3.copy(point0), + _point1 = Vector3.copy(point1), + _point2 = Vector3.copy(point2), + _point3 = Vector3.copy(point3); /// Copy the quad from [other] into this. void copyFrom(Quad other) { @@ -91,7 +91,8 @@ class Quad { /// Returns a printable string @override - String toString() => '[0] $_point0\n[1] $_point1\n' + String toString() => + '[0] $_point0\n[1] $_point1\n' '[2] $_point2\n[3] $_point3\n'; /// Check if two quad are the same. diff --git a/lib/src/vector_math/quaternion.dart b/lib/src/vector_math/quaternion.dart index e0363ac6..f3430212 100644 --- a/lib/src/vector_math/quaternion.dart +++ b/lib/src/vector_math/quaternion.dart @@ -85,7 +85,7 @@ class Quaternion { /// starting at [offset]. [offset] has to be multiple of /// [Float32List.bytesPerElement]. Quaternion.fromBuffer(ByteBuffer buffer, int offset) - : _qStorage = Float32List.view(buffer, offset, 4); + : _qStorage = Float32List.view(buffer, offset, 4); /// Returns a new copy of this. Quaternion clone() => Quaternion.copy(this); @@ -133,24 +133,30 @@ class Quaternion { _qStorage[1] = (rotationMatrixStorage[6] - rotationMatrixStorage[2]) * s; _qStorage[2] = (rotationMatrixStorage[1] - rotationMatrixStorage[3]) * s; } else { - final i = rotationMatrixStorage[0] < rotationMatrixStorage[4] - ? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1) - : (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0); + final i = + rotationMatrixStorage[0] < rotationMatrixStorage[4] + ? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1) + : (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0); final j = (i + 1) % 3; final k = (i + 2) % 3; - var s = math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] - - rotationMatrixStorage[rotationMatrix.index(j, j)] - - rotationMatrixStorage[rotationMatrix.index(k, k)] + - 1.0); + var s = math.sqrt( + rotationMatrixStorage[rotationMatrix.index(i, i)] - + rotationMatrixStorage[rotationMatrix.index(j, j)] - + rotationMatrixStorage[rotationMatrix.index(k, k)] + + 1.0, + ); _qStorage[i] = s * 0.5; s = 0.5 / s; - _qStorage[3] = (rotationMatrixStorage[rotationMatrix.index(k, j)] - + _qStorage[3] = + (rotationMatrixStorage[rotationMatrix.index(k, j)] - rotationMatrixStorage[rotationMatrix.index(j, k)]) * s; - _qStorage[j] = (rotationMatrixStorage[rotationMatrix.index(j, i)] + + _qStorage[j] = + (rotationMatrixStorage[rotationMatrix.index(j, i)] + rotationMatrixStorage[rotationMatrix.index(i, j)]) * s; - _qStorage[k] = (rotationMatrixStorage[rotationMatrix.index(k, i)] + + _qStorage[k] = + (rotationMatrixStorage[rotationMatrix.index(k, i)] + rotationMatrixStorage[rotationMatrix.index(i, k)]) * s; } @@ -309,7 +315,10 @@ class Quaternion { final scale = 1.0 / math.sqrt(den); return Vector3( - _qStorage[0] * scale, _qStorage[1] * scale, _qStorage[2] * scale); + _qStorage[0] * scale, + _qStorage[1] * scale, + _qStorage[2] * scale, + ); } /// Length squared. @@ -397,10 +406,11 @@ class Quaternion { final oy = otherStorage[1]; final ox = otherStorage[0]; return Quaternion( - w * ox + x * ow + y * oz - z * oy, - w * oy + y * ow + z * ox - x * oz, - w * oz + z * ow + x * oy - y * ox, - w * ow - x * ox - y * oy - z * oz); + w * ox + x * ow + y * oz - z * oy, + w * oy + y * ow + z * ox - x * oz, + w * oz + z * ow + x * oy - y * ox, + w * ow - x * ox - y * oy - z * oz, + ); } /// Check if two quaternions are the same. @@ -478,7 +488,8 @@ class Quaternion { /// Printable string. @override - String toString() => '${_qStorage[0]}, ${_qStorage[1]},' + String toString() => + '${_qStorage[0]}, ${_qStorage[1]},' ' ${_qStorage[2]} @ ${_qStorage[3]}'; /// Relative error between this and [correct]. diff --git a/lib/src/vector_math/ray.dart b/lib/src/vector_math/ray.dart index 88326633..e5d1b9d0 100644 --- a/lib/src/vector_math/ray.dart +++ b/lib/src/vector_math/ray.dart @@ -16,19 +16,17 @@ class Ray { Vector3 get direction => _direction; /// Create a new, uninitialized ray. - Ray() - : _origin = Vector3.zero(), - _direction = Vector3.zero(); + Ray() : _origin = Vector3.zero(), _direction = Vector3.zero(); /// Create a ray as a copy of [other]. Ray.copy(Ray other) - : _origin = Vector3.copy(other._origin), - _direction = Vector3.copy(other._direction); + : _origin = Vector3.copy(other._origin), + _direction = Vector3.copy(other._direction); /// Create a ray with an [origin] and a [direction]. Ray.originDirection(Vector3 origin, Vector3 direction) - : _origin = Vector3.copy(origin), - _direction = Vector3.copy(direction); + : _origin = Vector3.copy(origin), + _direction = Vector3.copy(direction); /// Copy the [origin] and [direction] from [other] into this. void copyFrom(Ray other) { diff --git a/lib/src/vector_math/sphere.dart b/lib/src/vector_math/sphere.dart index 0a0118eb..f803acc3 100644 --- a/lib/src/vector_math/sphere.dart +++ b/lib/src/vector_math/sphere.dart @@ -15,18 +15,16 @@ class Sphere { Vector3 get center => _center; /// Create a new, uninitialized sphere. - Sphere() - : _center = Vector3.zero(), - radius = 0.0; + Sphere() : _center = Vector3.zero(), radius = 0.0; /// Create a sphere as a copy of [other]. Sphere.copy(Sphere other) - : _center = Vector3.copy(other._center), - radius = other.radius; + : _center = Vector3.copy(other._center), + radius = other.radius; /// Create a sphere from a [center] and a [radius]. Sphere.centerRadius(Vector3 center, this.radius) - : _center = Vector3.copy(center); + : _center = Vector3.copy(center); /// Copy the sphere from [other] into this. void copyFrom(Sphere other) { diff --git a/lib/src/vector_math/triangle.dart b/lib/src/vector_math/triangle.dart index f3ffdfa7..89a59859 100644 --- a/lib/src/vector_math/triangle.dart +++ b/lib/src/vector_math/triangle.dart @@ -21,21 +21,21 @@ class Triangle { /// Create a new, uninitialized triangle. Triangle() - : _point0 = Vector3.zero(), - _point1 = Vector3.zero(), - _point2 = Vector3.zero(); + : _point0 = Vector3.zero(), + _point1 = Vector3.zero(), + _point2 = Vector3.zero(); /// Create a triangle as a copy of [other]. Triangle.copy(Triangle other) - : _point0 = Vector3.copy(other._point0), - _point1 = Vector3.copy(other._point1), - _point2 = Vector3.copy(other._point2); + : _point0 = Vector3.copy(other._point0), + _point1 = Vector3.copy(other._point1), + _point2 = Vector3.copy(other._point2); /// Create a triangle by three points. Triangle.points(Vector3 point0, Vector3 point1, Vector3 point2) - : _point0 = Vector3.copy(point0), - _point1 = Vector3.copy(point1), - _point2 = Vector3.copy(point2); + : _point0 = Vector3.copy(point0), + _point1 = Vector3.copy(point1), + _point2 = Vector3.copy(point2); /// Copy the triangle from [other] into this. void copyFrom(Triangle other) { diff --git a/lib/src/vector_math/utilities.dart b/lib/src/vector_math/utilities.dart index c0aaf576..eb5db844 100644 --- a/lib/src/vector_math/utilities.dart +++ b/lib/src/vector_math/utilities.dart @@ -25,8 +25,13 @@ double smoothStep(double edge0, double edge1, double amount) { /// 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) => +double catmullRom( + double edge0, + double edge1, + double edge2, + double edge3, + double amount, +) => 0.5 * ((2.0 * edge1) + (-edge0 + edge2) * amount + diff --git a/lib/src/vector_math/vector2.dart b/lib/src/vector_math/vector2.dart index b6ba70e8..932953c0 100644 --- a/lib/src/vector_math/vector2.dart +++ b/lib/src/vector_math/vector2.dart @@ -56,7 +56,7 @@ class Vector2 implements Vector { /// Constructs Vector2 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float32List.bytesPerElement]. Vector2.fromBuffer(ByteBuffer buffer, int offset) - : _v2storage = Float32List.view(buffer, offset, 2); + : _v2storage = Float32List.view(buffer, offset, 2); /// Generate random vector in the range (0, 0) to (1, 1). You can /// optionally pass your own random number generator. @@ -365,12 +365,14 @@ class Vector2 implements Vector { /// Round entries in this towards zero. void roundToZero() { - _v2storage[1] = _v2storage[1] < 0.0 - ? _v2storage[1].ceilToDouble() - : _v2storage[1].floorToDouble(); - _v2storage[0] = _v2storage[0] < 0.0 - ? _v2storage[0].ceilToDouble() - : _v2storage[0].floorToDouble(); + _v2storage[1] = + _v2storage[1] < 0.0 + ? _v2storage[1].ceilToDouble() + : _v2storage[1].floorToDouble(); + _v2storage[0] = + _v2storage[0] < 0.0 + ? _v2storage[0].ceilToDouble() + : _v2storage[0].floorToDouble(); } /// Clone of this. diff --git a/lib/src/vector_math/vector3.dart b/lib/src/vector_math/vector3.dart index 9fc57763..575b478c 100644 --- a/lib/src/vector_math/vector3.dart +++ b/lib/src/vector_math/vector3.dart @@ -60,7 +60,7 @@ class Vector3 implements Vector { /// Constructs Vector3 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float32List.bytesPerElement]. Vector3.fromBuffer(ByteBuffer buffer, int offset) - : _v3storage = Float32List.view(buffer, offset, 3); + : _v3storage = Float32List.view(buffer, offset, 3); /// Generate random vector in the range (0, 0, 0) to (1, 1, 1). You can /// optionally pass your own random number generator. @@ -302,22 +302,26 @@ class Vector3 implements Vector { final z = _v3storage[2]; final y = _v3storage[1]; final x = _v3storage[0]; - final d = 1.0 / + final d = + 1.0 / (argStorage[15] + argStorage[11] * z + argStorage[7] * y + argStorage[3] * x); - _v3storage[0] = (argStorage[12] + + _v3storage[0] = + (argStorage[12] + argStorage[8] * z + argStorage[4] * y + argStorage[0] * x) * d; - _v3storage[1] = (argStorage[13] + + _v3storage[1] = + (argStorage[13] + argStorage[9] * z + argStorage[5] * y + argStorage[1] * x) * d; - _v3storage[2] = (argStorage[14] + + _v3storage[2] = + (argStorage[14] + argStorage[10] * z + argStorage[6] * y + argStorage[2] * x) * @@ -369,15 +373,18 @@ class Vector3 implements Vector { final v2 = _v3storage[2]; final v1 = _v3storage[1]; final v0 = _v3storage[0]; - _v3storage[2] = argStorage[2] * v0 + + _v3storage[2] = + argStorage[2] * v0 + argStorage[6] * v1 + argStorage[10] * v2 + argStorage[14]; - _v3storage[1] = argStorage[1] * v0 + + _v3storage[1] = + argStorage[1] * v0 + argStorage[5] * v1 + argStorage[9] * v2 + argStorage[13]; - _v3storage[0] = argStorage[0] * v0 + + _v3storage[0] = + argStorage[0] * v0 + argStorage[4] * v1 + argStorage[8] * v2 + argStorage[12]; @@ -511,15 +518,18 @@ class Vector3 implements Vector { /// Round entries in this towards zero. void roundToZero() { - _v3storage[2] = _v3storage[2] < 0.0 - ? _v3storage[2].ceilToDouble() - : _v3storage[2].floorToDouble(); - _v3storage[1] = _v3storage[1] < 0.0 - ? _v3storage[1].ceilToDouble() - : _v3storage[1].floorToDouble(); - _v3storage[0] = _v3storage[0] < 0.0 - ? _v3storage[0].ceilToDouble() - : _v3storage[0].floorToDouble(); + _v3storage[2] = + _v3storage[2] < 0.0 + ? _v3storage[2].ceilToDouble() + : _v3storage[2].floorToDouble(); + _v3storage[1] = + _v3storage[1] < 0.0 + ? _v3storage[1].ceilToDouble() + : _v3storage[1].floorToDouble(); + _v3storage[0] = + _v3storage[0] < 0.0 + ? _v3storage[0].ceilToDouble() + : _v3storage[0].floorToDouble(); } /// Clone of this. diff --git a/lib/src/vector_math/vector4.dart b/lib/src/vector_math/vector4.dart index e9dc95f9..2e86192e 100644 --- a/lib/src/vector_math/vector4.dart +++ b/lib/src/vector_math/vector4.dart @@ -66,14 +66,18 @@ class Vector4 implements Vector { /// Constructs Vector4 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float32List.bytesPerElement]. Vector4.fromBuffer(ByteBuffer buffer, int offset) - : _v4storage = Float32List.view(buffer, offset, 4); + : _v4storage = Float32List.view(buffer, offset, 4); /// 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 ??= math.Random(); return Vector4( - rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble()); + rng.nextDouble(), + rng.nextDouble(), + rng.nextDouble(), + rng.nextDouble(), + ); } /// Set the values of the vector. @@ -119,7 +123,8 @@ class Vector4 implements Vector { /// Returns a printable string @override - String toString() => '[${_v4storage[0]},${_v4storage[1]},' + String toString() => + '[${_v4storage[0]},${_v4storage[1]},' '${_v4storage[2]},${_v4storage[3]}]'; /// Check if two vectors are the same. @@ -244,19 +249,23 @@ class Vector4 implements Vector { final v2 = _v4storage[1]; final v1 = _v4storage[0]; final argStorage = arg._m4storage; - _v4storage[3] = argStorage[3] * v1 + + _v4storage[3] = + argStorage[3] * v1 + argStorage[7] * v2 + argStorage[11] * v3 + argStorage[15] * v4; - _v4storage[2] = argStorage[2] * v1 + + _v4storage[2] = + argStorage[2] * v1 + argStorage[6] * v2 + argStorage[10] * v3 + argStorage[14] * v4; - _v4storage[1] = argStorage[1] * v1 + + _v4storage[1] = + argStorage[1] * v1 + argStorage[5] * v2 + argStorage[9] * v3 + argStorage[13] * v4; - _v4storage[0] = argStorage[0] * v1 + + _v4storage[0] = + argStorage[0] * v1 + argStorage[4] * v2 + argStorage[8] * v3 + argStorage[12] * v4; @@ -410,18 +419,22 @@ class Vector4 implements Vector { /// Round entries in this towards zero. void roundToZero() { - _v4storage[3] = _v4storage[3] < 0.0 - ? _v4storage[3].ceilToDouble() - : _v4storage[3].floorToDouble(); - _v4storage[2] = _v4storage[2] < 0.0 - ? _v4storage[2].ceilToDouble() - : _v4storage[2].floorToDouble(); - _v4storage[1] = _v4storage[1] < 0.0 - ? _v4storage[1].ceilToDouble() - : _v4storage[1].floorToDouble(); - _v4storage[0] = _v4storage[0] < 0.0 - ? _v4storage[0].ceilToDouble() - : _v4storage[0].floorToDouble(); + _v4storage[3] = + _v4storage[3] < 0.0 + ? _v4storage[3].ceilToDouble() + : _v4storage[3].floorToDouble(); + _v4storage[2] = + _v4storage[2] < 0.0 + ? _v4storage[2].ceilToDouble() + : _v4storage[2].floorToDouble(); + _v4storage[1] = + _v4storage[1] < 0.0 + ? _v4storage[1].ceilToDouble() + : _v4storage[1].floorToDouble(); + _v4storage[0] = + _v4storage[0] < 0.0 + ? _v4storage[0].ceilToDouble() + : _v4storage[0].floorToDouble(); } /// Create a copy of this. diff --git a/lib/src/vector_math_64/aabb2.dart b/lib/src/vector_math_64/aabb2.dart index fea7535f..18a74156 100644 --- a/lib/src/vector_math_64/aabb2.dart +++ b/lib/src/vector_math_64/aabb2.dart @@ -17,24 +17,23 @@ class Aabb2 { Vector2 get max => _max; /// The center of the AABB. - Vector2 get center => _min.clone() - ..add(_max) - ..scale(0.5); + Vector2 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Create a new AABB with [min] and [max] set to the origin. - Aabb2() - : _min = Vector2.zero(), - _max = Vector2.zero(); + Aabb2() : _min = Vector2.zero(), _max = Vector2.zero(); /// Create a new AABB as a copy of [other]. Aabb2.copy(Aabb2 other) - : _min = Vector2.copy(other._min), - _max = Vector2.copy(other._max); + : _min = Vector2.copy(other._min), + _max = Vector2.copy(other._max); /// Create a new AABB with a [min] and [max]. Aabb2.minMax(Vector2 min, Vector2 max) - : _min = Vector2.copy(min), - _max = Vector2.copy(max); + : _min = Vector2.copy(min), + _max = Vector2.copy(max); /// Create a new AABB with a [center] and [halfExtents]. factory Aabb2.centerAndHalfExtents(Vector2 center, Vector2 halfExtents) => @@ -44,9 +43,11 @@ class Aabb2 { /// starting at [offset]. [offset] has to be multiple of /// [Float64List.bytesPerElement]. Aabb2.fromBuffer(ByteBuffer buffer, int offset) - : _min = Vector2.fromBuffer(buffer, offset), - _max = Vector2.fromBuffer( - buffer, offset + Float64List.bytesPerElement * 2); + : _min = Vector2.fromBuffer(buffer, offset), + _max = Vector2.fromBuffer( + buffer, + offset + Float64List.bytesPerElement * 2, + ); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) { @@ -109,15 +110,17 @@ class Aabb2 { /// Create a copy of this that is transformed by the transform [t] and store /// it in [out]. - Aabb2 transformed(Matrix3 t, Aabb2 out) => out - ..copyFrom(this) - ..transform(t); + Aabb2 transformed(Matrix3 t, Aabb2 out) => + out + ..copyFrom(this) + ..transform(t); /// Create a copy of this that is rotated by the rotation matrix [t] and /// store it in [out]. - Aabb2 rotated(Matrix3 t, Aabb2 out) => out - ..copyFrom(this) - ..rotate(t); + Aabb2 rotated(Matrix3 t, Aabb2 out) => + out + ..copyFrom(this) + ..rotate(t); /// Set the min and max of this so that this is a hull of this and /// [other]. diff --git a/lib/src/vector_math_64/aabb3.dart b/lib/src/vector_math_64/aabb3.dart index 22a62dcc..b098036e 100644 --- a/lib/src/vector_math_64/aabb3.dart +++ b/lib/src/vector_math_64/aabb3.dart @@ -14,24 +14,23 @@ class Aabb3 { Vector3 get max => _max; /// The center of the AABB. - Vector3 get center => _min.clone() - ..add(_max) - ..scale(0.5); + Vector3 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Create a new AABB with [min] and [max] set to the origin. - Aabb3() - : _min = Vector3.zero(), - _max = Vector3.zero(); + Aabb3() : _min = Vector3.zero(), _max = Vector3.zero(); /// Create a new AABB as a copy of [other]. Aabb3.copy(Aabb3 other) - : _min = Vector3.copy(other._min), - _max = Vector3.copy(other._max); + : _min = Vector3.copy(other._min), + _max = Vector3.copy(other._max); /// Create a new AABB with a [min] and [max]. Aabb3.minMax(Vector3 min, Vector3 max) - : _min = Vector3.copy(min), - _max = Vector3.copy(max); + : _min = Vector3.copy(min), + _max = Vector3.copy(max); /// Create a new AABB that encloses a [sphere]. factory Aabb3.fromSphere(Sphere sphere) => Aabb3()..setSphere(sphere); @@ -59,9 +58,11 @@ class Aabb3 { /// starting at [offset]. [offset] has to be multiple of /// [Float64List.bytesPerElement]. Aabb3.fromBuffer(ByteBuffer buffer, int offset) - : _min = Vector3.fromBuffer(buffer, offset), - _max = Vector3.fromBuffer( - buffer, offset + Float64List.bytesPerElement * 3); + : _min = Vector3.fromBuffer(buffer, offset), + _max = Vector3.fromBuffer( + buffer, + offset + Float64List.bytesPerElement * 3, + ); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector3 center, Vector3 halfExtents) { @@ -86,41 +87,65 @@ class Aabb3 { /// 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( - quad._point0.z, - math.min( - quad._point1.z, math.min(quad._point2.z, quad._point3.z)))); + 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)), + ), + ); _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( - quad._point0.z, - math.max( - quad._point1.z, math.max(quad._point2.z, quad._point3.z)))); + 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)), + ), + ); } /// Set the AABB to enclose a [obb]. @@ -238,15 +263,17 @@ class Aabb3 { /// Create a copy of this that is transformed by the transform [t] and store /// it in [out]. - Aabb3 transformed(Matrix4 t, Aabb3 out) => out - ..copyFrom(this) - ..transform(t); + Aabb3 transformed(Matrix4 t, Aabb3 out) => + out + ..copyFrom(this) + ..transform(t); /// Create a copy of this that is rotated by the rotation matrix [t] and /// store it in [out]. - Aabb3 rotated(Matrix4 t, Aabb3 out) => out - ..copyFrom(this) - ..rotate(t); + Aabb3 rotated(Matrix4 t, Aabb3 out) => + out + ..copyFrom(this) + ..rotate(t); void getPN(Vector3 planeNormal, Vector3 outP, Vector3 outN) { if (planeNormal.x < 0.0) { @@ -393,8 +420,11 @@ class Aabb3 { /// be used for the test. If [result] is specified and an intersection is /// found, result is modified to contain more details about the type of /// intersection. - bool intersectsWithTriangle(Triangle other, - {double epsilon = 1e-3, IntersectionResult? result}) { + bool intersectsWithTriangle( + Triangle other, { + double epsilon = 1e-3, + IntersectionResult? result, + }) { double p0, p1, p2, r, len; double a; @@ -639,7 +669,8 @@ class Aabb3 { copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents); // Compute the projection interval radius of b onto L(t) = b.c + t * p.n - final r = _aabbHalfExtents[0] * other.normal[0].abs() + + final r = + _aabbHalfExtents[0] * other.normal[0].abs() + _aabbHalfExtents[1] * other.normal[1].abs() + _aabbHalfExtents[2] * other.normal[2].abs(); // Compute distance of box center from plane diff --git a/lib/src/vector_math_64/colors.dart b/lib/src/vector_math_64/colors.dart index 6bb069b7..603dcc25 100644 --- a/lib/src/vector_math_64/colors.dart +++ b/lib/src/vector_math_64/colors.dart @@ -9,11 +9,13 @@ part of '../../vector_math_64.dart'; /// for fast prototyping. class Colors { static final _hexStringFullRegex = RegExp( - r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?', - caseSensitive: false); + r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?', + caseSensitive: false, + ); static final _hexStringSmallRegex = RegExp( - r'\#?([0-9a-f])([0-9a-f])([0-9a-f])(?:([0-9a-f]))?', - caseSensitive: false); + r'\#?([0-9a-f])([0-9a-f])([0-9a-f])(?:([0-9a-f]))?', + caseSensitive: false, + ); /// Convert a color with [r], [g], [b] and [a] component between 0 and 255 to /// a color with values between 0.0 and 1.0 and store it in [result]. @@ -75,27 +77,33 @@ class Colors { /// the alpha channel, set [alpha] to true, it is false by default. If [short] /// is true, the resulting hex string might also be a short version, like #ff0 /// (default false). - static String toHexString(Vector4 input, - {bool alpha = false, bool short = 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 isShort = short && + final isShort = + short && ((r >> 4) == (r & 0xF)) && ((g >> 4) == (g & 0xF)) && ((b >> 4) == (b & 0xF)) && (!alpha || (a >> 4) == (a & 0xF)); if (isShort) { - final rgb = (r & 0xF).toRadixString(16) + + final rgb = + (r & 0xF).toRadixString(16) + (g & 0xF).toRadixString(16) + (b & 0xF).toRadixString(16); return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb; } else { - final rgb = r.toRadixString(16).padLeft(2, '0') + + final rgb = + r.toRadixString(16).padLeft(2, '0') + g.toRadixString(16).padLeft(2, '0') + b.toRadixString(16).padLeft(2, '0'); @@ -106,17 +114,23 @@ class Colors { /// Blend the [foreground] color over [background] color and store the color /// in [result]. static void alphaBlend( - Vector4 foreground, Vector4 background, Vector4 result) { + Vector4 foreground, + Vector4 background, + Vector4 result, + ) { final a = foreground.a + (1.0 - foreground.a) * background.a; final factor = 1.0 / a; - final r = factor * + final r = + factor * (foreground.a * foreground.r + (1.0 - foreground.a) * background.a * background.r); - final g = factor * + final g = + factor * (foreground.a * foreground.g + (1.0 - foreground.a) * background.a * background.g); - final b = factor * + final b = + factor * (foreground.a * foreground.b + (1.0 - foreground.a) * background.a * background.b); @@ -137,8 +151,11 @@ class Colors { /// Convert [linearColor] from linear space into gamma color space and store /// the result in [gammaColor]. It is possible to specify a optional [gamma], /// the default value is 2.2. - static void linearToGamma(Vector4 linearColor, Vector4 gammaColor, - [double gamma = 2.2]) { + static void linearToGamma( + Vector4 linearColor, + Vector4 gammaColor, [ + double gamma = 2.2, + ]) { final exponent = 1.0 / gamma; gammaColor @@ -151,8 +168,11 @@ class Colors { /// Convert [gammaColor] from gamma space into linear color space and store /// the result in [linearColor]. It is possible to specify a optional [gamma], /// the default value is 2.2. - static void gammaToLinear(Vector4 gammaColor, Vector4 linearColor, - [double gamma = 2.2]) { + static void gammaToLinear( + Vector4 gammaColor, + Vector4 linearColor, [ + double gamma = 2.2, + ]) { linearColor ..r = math.pow(gammaColor.r, gamma).toDouble() ..g = math.pow(gammaColor.g, gamma).toDouble() @@ -172,7 +192,8 @@ class Colors { if (max != min) { if (max == rgbColor.r) { - h = (rgbColor.g - rgbColor.b) / d + + h = + (rgbColor.g - rgbColor.b) / d + (rgbColor.g < rgbColor.b ? 6.0 : 0.0); } else if (max == rgbColor.g) { h = (rgbColor.b - rgbColor.r) / d + 2.0; @@ -232,7 +253,8 @@ class Colors { s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min); if (max == rgbColor.r) { - h = (rgbColor.g - rgbColor.b) / d + + h = + (rgbColor.g - rgbColor.b) / d + (rgbColor.g < rgbColor.b ? 6.0 : 0.0); } else if (max == rgbColor.g) { h = (rgbColor.b - rgbColor.r) / d + 2.0; @@ -252,9 +274,10 @@ class Colors { if (hslColor.y == 0.0) { rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a); } else { - final q = hslColor.z < 0.5 - ? hslColor.z * (1.0 + hslColor.y) - : hslColor.z + hslColor.y - hslColor.z * hslColor.y; + final 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 r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0); diff --git a/lib/src/vector_math_64/frustum.dart b/lib/src/vector_math_64/frustum.dart index 8b2c94bc..bfa49e38 100644 --- a/lib/src/vector_math_64/frustum.dart +++ b/lib/src/vector_math_64/frustum.dart @@ -33,12 +33,12 @@ class Frustum { /// Create a new frustum without initializing its bounds. Frustum() - : _plane0 = Plane(), - _plane1 = Plane(), - _plane2 = Plane(), - _plane3 = Plane(), - _plane4 = Plane(), - _plane5 = Plane(); + : _plane0 = Plane(), + _plane1 = Plane(), + _plane2 = Plane(), + _plane3 = Plane(), + _plane4 = Plane(), + _plane5 = Plane(); /// Create a new frustum as a copy of [other]. factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other); @@ -177,14 +177,15 @@ class Frustum { /// Calculate the corners of this and write them into [corner0] to // [corner7]. void calculateCorners( - Vector3 corner0, - Vector3 corner1, - Vector3 corner2, - Vector3 corner3, - Vector3 corner4, - Vector3 corner5, - Vector3 corner6, - Vector3 corner7) { + Vector3 corner0, + Vector3 corner1, + Vector3 corner2, + Vector3 corner3, + Vector3 corner4, + Vector3 corner5, + Vector3 corner6, + Vector3 corner7, + ) { Plane.intersection(_plane0, _plane2, _plane4, corner0); Plane.intersection(_plane0, _plane3, _plane4, corner1); Plane.intersection(_plane0, _plane3, _plane5, corner2); @@ -222,11 +223,13 @@ class Frustum { outNz = aabb.min.z; } - final d1 = plane._normal.x * outPx + + final d1 = + plane._normal.x * outPx + plane._normal.y * outPy + plane._normal.z * outPz + plane.constant; - final d2 = plane._normal.x * outNx + + final d2 = + plane._normal.x * outNx + plane._normal.y * outNy + plane._normal.z * outNz + plane.constant; diff --git a/lib/src/vector_math_64/matrix3.dart b/lib/src/vector_math_64/matrix3.dart index e5638f9d..ffc5a22b 100644 --- a/lib/src/vector_math_64/matrix3.dart +++ b/lib/src/vector_math_64/matrix3.dart @@ -99,15 +99,33 @@ class Matrix3 { } /// New matrix with specified values. - factory Matrix3(double arg0, double arg1, double arg2, double arg3, - double arg4, double arg5, double arg6, double arg7, double arg8) => + factory Matrix3( + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + ) => Matrix3.zero() ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); /// New matrix from [values]. - factory Matrix3.fromList(List values) => 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 values) => + 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 = Float64List(9); @@ -138,8 +156,17 @@ class Matrix3 { Matrix3.zero()..setRotationZ(radians); /// Sets the matrix with specified values. - void setValues(double arg0, double arg1, double arg2, double arg3, - double arg4, double arg5, double arg6, double arg7, double arg8) { + void setValues( + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + ) { _m3storage[8] = arg8; _m3storage[7] = arg7; _m3storage[6] = arg6; @@ -413,11 +440,14 @@ class Matrix3 { /// Returns the determinant of this matrix. double determinant() { - final x = _m3storage[0] * + final x = + _m3storage[0] * ((_m3storage[4] * _m3storage[8]) - (_m3storage[5] * _m3storage[7])); - final y = _m3storage[1] * + final y = + _m3storage[1] * ((_m3storage[3] * _m3storage[8]) - (_m3storage[5] * _m3storage[6])); - final z = _m3storage[2] * + final z = + _m3storage[2] * ((_m3storage[3] * _m3storage[7]) - (_m3storage[4] * _m3storage[6])); return x - y + z; } @@ -503,23 +533,32 @@ class Matrix3 { } final invDet = 1.0 / det; final argStorage = arg._m3storage; - final ix = invDet * + final ix = + invDet * (argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]); - final iy = invDet * + final iy = + invDet * (argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]); - final iz = invDet * + final iz = + invDet * (argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]); - final jx = invDet * + final jx = + invDet * (argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]); - final jy = invDet * + final jy = + invDet * (argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]); - final jz = invDet * + final jz = + invDet * (argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]); - final kx = invDet * + final kx = + invDet * (argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]); - final ky = invDet * + final ky = + invDet * (argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]); - final kz = invDet * + final kz = + invDet * (argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]); _m3storage[0] = ix; _m3storage[1] = iy; @@ -648,10 +687,12 @@ class Matrix3 { /// Transforms [arg] with this. Vector2 transform2(Vector2 arg) { final argStorage = arg._v2storage; - final x_ = (_m3storage[0] * argStorage[0]) + + final x_ = + (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + _m3storage[6]; - final y_ = (_m3storage[1] * argStorage[0]) + + final y_ = + (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + _m3storage[7]; argStorage[0] = x_; @@ -817,13 +858,16 @@ class Matrix3 { /// this. Vector3 transform(Vector3 arg) { final argStorage = arg._v3storage; - final x_ = (_m3storage[0] * argStorage[0]) + + final x_ = + (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + (_m3storage[6] * argStorage[2]); - final y_ = (_m3storage[1] * argStorage[0]) + + final y_ = + (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + (_m3storage[7] * argStorage[2]); - final z_ = (_m3storage[2] * argStorage[0]) + + final z_ = + (_m3storage[2] * argStorage[0]) + (_m3storage[5] * argStorage[1]) + (_m3storage[8] * argStorage[2]); arg @@ -908,31 +952,37 @@ class Matrix3 { /// Is this the identity matrix? bool isIdentity() => - _m3storage[0] == 1.0 // col 1 - && + _m3storage[0] == + 1.0 // col 1 + && _m3storage[1] == 0.0 && _m3storage[2] == 0.0 && - _m3storage[3] == 0.0 // col 2 - && + _m3storage[3] == + 0.0 // col 2 + && _m3storage[4] == 1.0 && _m3storage[5] == 0.0 && - _m3storage[6] == 0.0 // col 3 - && + _m3storage[6] == + 0.0 // col 3 + && _m3storage[7] == 0.0 && _m3storage[8] == 1.0; /// Is this the zero matrix? bool isZero() => - _m3storage[0] == 0.0 // col 1 - && + _m3storage[0] == + 0.0 // col 1 + && _m3storage[1] == 0.0 && _m3storage[2] == 0.0 && - _m3storage[3] == 0.0 // col 2 - && + _m3storage[3] == + 0.0 // col 2 + && _m3storage[4] == 0.0 && _m3storage[5] == 0.0 && - _m3storage[6] == 0.0 // col 3 - && + _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 c5e8981c..5ded1cea 100644 --- a/lib/src/vector_math_64/matrix4.dart +++ b/lib/src/vector_math_64/matrix4.dart @@ -126,22 +126,26 @@ class Matrix4 { } x - ..x = det * + ..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 * + ..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 * + ..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 * + ..w = + det * -((a21 * b05 - a22 * b04 + a23 * b03) * bX - (a20 * b05 - a22 * b02 + a23 * b01) * bY + (a20 * b04 - a21 * b02 + a23 * b00) * bZ - @@ -180,29 +184,45 @@ class Matrix4 { /// Constructs a new mat4. factory Matrix4( - double arg0, - double arg1, - double arg2, - double arg3, - double arg4, - double arg5, - double arg6, - double arg7, - double arg8, - double arg9, - double arg10, - double arg11, - double arg12, - double arg13, - double arg14, - double arg15) => - Matrix4.zero() - ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, - arg10, arg11, arg12, arg13, arg14, arg15); + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + double arg9, + double arg10, + double arg11, + double arg12, + double arg13, + double arg14, + double arg15, + ) => + Matrix4.zero()..setValues( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8, + arg9, + arg10, + arg11, + arg12, + arg13, + arg14, + arg15, + ); /// New matrix from [values]. - factory Matrix4.fromList(List values) => Matrix4.zero() - ..setValues( + factory Matrix4.fromList(List values) => + Matrix4.zero()..setValues( values[0], values[1], values[2], @@ -218,7 +238,8 @@ class Matrix4 { values[12], values[13], values[14], - values[15]); + values[15], + ); /// Zero matrix. Matrix4.zero() : _m4storage = Float64List(16); @@ -241,31 +262,38 @@ class Matrix4 { /// Constructs a new mat4 from columns. factory Matrix4.columns( - Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) => - Matrix4.zero()..setColumns(arg0, arg1, arg2, arg3); + Vector4 arg0, + Vector4 arg1, + Vector4 arg2, + Vector4 arg3, + ) => Matrix4.zero()..setColumns(arg0, arg1, arg2, arg3); /// Outer product of [u] and [v]. factory Matrix4.outer(Vector4 u, Vector4 v) => Matrix4.zero()..setOuter(u, v); /// Rotation of [radians] around X. - factory Matrix4.rotationX(double radians) => Matrix4.zero() - .._m4storage[15] = 1.0 - ..setRotationX(radians); + factory Matrix4.rotationX(double radians) => + Matrix4.zero() + .._m4storage[15] = 1.0 + ..setRotationX(radians); /// Rotation of [radians] around Y. - factory Matrix4.rotationY(double radians) => Matrix4.zero() - .._m4storage[15] = 1.0 - ..setRotationY(radians); + factory Matrix4.rotationY(double radians) => + Matrix4.zero() + .._m4storage[15] = 1.0 + ..setRotationY(radians); /// Rotation of [radians] around Z. - factory Matrix4.rotationZ(double radians) => Matrix4.zero() - .._m4storage[15] = 1.0 - ..setRotationZ(radians); + factory Matrix4.rotationZ(double radians) => + Matrix4.zero() + .._m4storage[15] = 1.0 + ..setRotationZ(radians); /// Translation matrix. - factory Matrix4.translation(Vector3 translation) => Matrix4.zero() - ..setIdentity() - ..setTranslation(translation); + factory Matrix4.translation(Vector3 translation) => + Matrix4.zero() + ..setIdentity() + ..setTranslation(translation); /// Translation matrix. factory Matrix4.translationValues(double x, double y, double z) => @@ -321,11 +349,14 @@ class Matrix4 { /// Constructs Matrix4 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float64List.bytesPerElement]. Matrix4.fromBuffer(ByteBuffer buffer, int offset) - : _m4storage = Float64List.view(buffer, offset, 16); + : _m4storage = Float64List.view(buffer, offset, 16); /// Constructs Matrix4 from [translation], [rotation] and [scale]. factory Matrix4.compose( - Vector3 translation, Quaternion rotation, Vector3 scale) => + Vector3 translation, + Quaternion rotation, + Vector3 scale, + ) => Matrix4.zero() ..setFromTranslationRotationScale(translation, rotation, scale); @@ -339,22 +370,23 @@ class Matrix4 { /// Sets the matrix with specified values. void setValues( - double arg0, - double arg1, - double arg2, - double arg3, - double arg4, - double arg5, - double arg6, - double arg7, - double arg8, - double arg9, - double arg10, - double arg11, - double arg12, - double arg13, - double arg14, - double arg15) { + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + double arg9, + double arg10, + double arg11, + double arg12, + double arg13, + double arg14, + double arg15, + ) { _m4storage[15] = arg15; _m4storage[14] = arg14; _m4storage[13] = arg13; @@ -459,7 +491,10 @@ class Matrix4 { /// Sets the matrix from [translation], [rotation] and [scale]. void setFromTranslationRotationScale( - Vector3 translation, Quaternion rotation, Vector3 scale) { + Vector3 translation, + Quaternion rotation, + Vector3 scale, + ) { setFromTranslationRotation(translation, rotation); scaleByVector3(scale); } @@ -505,7 +540,8 @@ class Matrix4 { /// Returns a printable string @override - String toString() => '[0] ${getRow(0)}\n[1] ${getRow(1)}\n' + String toString() => + '[0] ${getRow(0)}\n[1] ${getRow(1)}\n' '[2] ${getRow(2)}\n[3] ${getRow(3)}\n'; /// Dimension of the matrix. @@ -676,8 +712,10 @@ class Matrix4 { @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - @Deprecated('Use translateByVector3, translateByVector4, ' - 'or translateByDouble instead') + @Deprecated( + 'Use translateByVector3, translateByVector4, ' + 'or translateByDouble instead', + ) void translate(dynamic x, [double y = 0.0, double z = 0.0]) { if (x is Vector3) { translateByVector3(x); @@ -692,25 +730,29 @@ class Matrix4 { /// Translate this matrix by x, y, z, w. void translateByDouble(double tx, double ty, double tz, double tw) { - final t1 = _m4storage[0] * tx + + final t1 = + _m4storage[0] * tx + _m4storage[4] * ty + _m4storage[8] * tz + _m4storage[12] * tw; _m4storage[12] = t1; - final t2 = _m4storage[1] * tx + + final t2 = + _m4storage[1] * tx + _m4storage[5] * ty + _m4storage[9] * tz + _m4storage[13] * tw; _m4storage[13] = t2; - final t3 = _m4storage[2] * tx + + final t3 = + _m4storage[2] * tx + _m4storage[6] * ty + _m4storage[10] * tz + _m4storage[14] * tw; _m4storage[14] = t3; - final t4 = _m4storage[3] * tx + + final t4 = + _m4storage[3] * tx + _m4storage[7] * ty + _m4storage[11] * tz + _m4storage[15] * tw; @@ -742,8 +784,10 @@ class Matrix4 { @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - @Deprecated('Use leftTranslateByVector3, leftTranslateByVector4, ' - 'or leftTranslateByDouble instead') + @Deprecated( + 'Use leftTranslateByVector3, leftTranslateByVector4, ' + 'or leftTranslateByDouble instead', + ) void leftTranslate(dynamic x, [double y = 0.0, double z = 0.0]) { if (x is Vector3) { leftTranslateByVector3(x); @@ -1095,16 +1139,20 @@ class Matrix4 { _m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5]; final det2_01_23 = _m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6]; - final det3_201_012 = _m4storage[8] * det2_01_12 - + final det3_201_012 = + _m4storage[8] * det2_01_12 - _m4storage[9] * det2_01_02 + _m4storage[10] * det2_01_01; - final det3_201_013 = _m4storage[8] * det2_01_13 - + final det3_201_013 = + _m4storage[8] * det2_01_13 - _m4storage[9] * det2_01_03 + _m4storage[11] * det2_01_01; - final det3_201_023 = _m4storage[8] * det2_01_23 - + final det3_201_023 = + _m4storage[8] * det2_01_23 - _m4storage[10] * det2_01_03 + _m4storage[11] * det2_01_02; - final det3_201_123 = _m4storage[9] * det2_01_23 - + final det3_201_123 = + _m4storage[9] * det2_01_23 - _m4storage[10] * det2_01_13 + _m4storage[11] * det2_01_12; return -det3_201_123 * _m4storage[12] + @@ -1267,13 +1315,16 @@ class Matrix4 { /// Returns the max scale value of the 3 axes. double getMaxScaleOnAxis() { - final scaleXSq = _m4storage[0] * _m4storage[0] + + final scaleXSq = + _m4storage[0] * _m4storage[0] + _m4storage[1] * _m4storage[1] + _m4storage[2] * _m4storage[2]; - final scaleYSq = _m4storage[4] * _m4storage[4] + + final scaleYSq = + _m4storage[4] * _m4storage[4] + _m4storage[5] * _m4storage[5] + _m4storage[6] * _m4storage[6]; - final scaleZSq = _m4storage[8] * _m4storage[8] + + final scaleZSq = + _m4storage[8] * _m4storage[8] + _m4storage[9] * _m4storage[9] + _m4storage[10] * _m4storage[10]; return math.sqrt(math.max(scaleXSq, math.max(scaleYSq, scaleZSq))); @@ -1377,23 +1428,32 @@ class Matrix4 { double kx; double ky; double kz; - ix = invDet * + ix = + invDet * (_m4storage[5] * _m4storage[10] - _m4storage[6] * _m4storage[9]); - iy = invDet * + iy = + invDet * (_m4storage[2] * _m4storage[9] - _m4storage[1] * _m4storage[10]); - iz = invDet * + iz = + invDet * (_m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5]); - jx = invDet * + jx = + invDet * (_m4storage[6] * _m4storage[8] - _m4storage[4] * _m4storage[10]); - jy = invDet * + jy = + invDet * (_m4storage[0] * _m4storage[10] - _m4storage[2] * _m4storage[8]); - jz = invDet * + jz = + invDet * (_m4storage[2] * _m4storage[4] - _m4storage[0] * _m4storage[6]); - kx = invDet * + kx = + invDet * (_m4storage[4] * _m4storage[9] - _m4storage[5] * _m4storage[8]); - ky = invDet * + ky = + invDet * (_m4storage[1] * _m4storage[8] - _m4storage[0] * _m4storage[9]); - kz = invDet * + kz = + invDet * (_m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4]); _m4storage[0] = ix; _m4storage[1] = iy; @@ -1480,67 +1540,83 @@ class Matrix4 { final b4 = _m4storage[7]; final c4 = _m4storage[11]; final d4 = _m4storage[15]; - _m4storage[0] = (b2 * (c3 * d4 - c4 * d3) - + _m4storage[0] = + (b2 * (c3 * d4 - c4 * d3) - c2 * (b3 * d4 - b4 * d3) + d2 * (b3 * c4 - b4 * c3)) * scale; - _m4storage[1] = -(a2 * (c3 * d4 - c4 * d3) - + _m4storage[1] = + -(a2 * (c3 * d4 - c4 * d3) - c2 * (a3 * d4 - a4 * d3) + d2 * (a3 * c4 - a4 * c3)) * scale; - _m4storage[2] = (a2 * (b3 * d4 - b4 * d3) - + _m4storage[2] = + (a2 * (b3 * d4 - b4 * d3) - b2 * (a3 * d4 - a4 * d3) + d2 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[3] = -(a2 * (b3 * c4 - b4 * c3) - + _m4storage[3] = + -(a2 * (b3 * c4 - b4 * c3) - b2 * (a3 * c4 - a4 * c3) + c2 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[4] = -(b1 * (c3 * d4 - c4 * d3) - + _m4storage[4] = + -(b1 * (c3 * d4 - c4 * d3) - c1 * (b3 * d4 - b4 * d3) + d1 * (b3 * c4 - b4 * c3)) * scale; - _m4storage[5] = (a1 * (c3 * d4 - c4 * d3) - + _m4storage[5] = + (a1 * (c3 * d4 - c4 * d3) - c1 * (a3 * d4 - a4 * d3) + d1 * (a3 * c4 - a4 * c3)) * scale; - _m4storage[6] = -(a1 * (b3 * d4 - b4 * d3) - + _m4storage[6] = + -(a1 * (b3 * d4 - b4 * d3) - b1 * (a3 * d4 - a4 * d3) + d1 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[7] = (a1 * (b3 * c4 - b4 * c3) - + _m4storage[7] = + (a1 * (b3 * c4 - b4 * c3) - b1 * (a3 * c4 - a4 * c3) + c1 * (a3 * b4 - a4 * b3)) * scale; - _m4storage[8] = (b1 * (c2 * d4 - c4 * d2) - + _m4storage[8] = + (b1 * (c2 * d4 - c4 * d2) - c1 * (b2 * d4 - b4 * d2) + d1 * (b2 * c4 - b4 * c2)) * scale; - _m4storage[9] = -(a1 * (c2 * d4 - c4 * d2) - + _m4storage[9] = + -(a1 * (c2 * d4 - c4 * d2) - c1 * (a2 * d4 - a4 * d2) + d1 * (a2 * c4 - a4 * c2)) * scale; - _m4storage[10] = (a1 * (b2 * d4 - b4 * d2) - + _m4storage[10] = + (a1 * (b2 * d4 - b4 * d2) - b1 * (a2 * d4 - a4 * d2) + d1 * (a2 * b4 - a4 * b2)) * scale; - _m4storage[11] = -(a1 * (b2 * c4 - b4 * c2) - + _m4storage[11] = + -(a1 * (b2 * c4 - b4 * c2) - b1 * (a2 * c4 - a4 * c2) + c1 * (a2 * b4 - a4 * b2)) * scale; - _m4storage[12] = -(b1 * (c2 * d3 - c3 * d2) - + _m4storage[12] = + -(b1 * (c2 * d3 - c3 * d2) - c1 * (b2 * d3 - b3 * d2) + d1 * (b2 * c3 - b3 * c2)) * scale; - _m4storage[13] = (a1 * (c2 * d3 - c3 * d2) - + _m4storage[13] = + (a1 * (c2 * d3 - c3 * d2) - c1 * (a2 * d3 - a3 * d2) + d1 * (a2 * c3 - a3 * c2)) * scale; - _m4storage[14] = -(a1 * (b2 * d3 - b3 * d2) - + _m4storage[14] = + -(a1 * (b2 * d3 - b3 * d2) - b1 * (a2 * d3 - a3 * d2) + d1 * (a2 * b3 - a3 * b2)) * scale; - _m4storage[15] = (a1 * (b2 * c3 - b3 * c2) - + _m4storage[15] = + (a1 * (b2 * c3 - b3 * c2) - b1 * (a2 * c3 - a3 * c2) + c1 * (a2 * b3 - a3 * b2)) * scale; @@ -1706,67 +1782,83 @@ class Matrix4 { final m32 = _m4storage[14]; final m33 = _m4storage[15]; final argStorage = arg._m4storage; - _m4storage[0] = (m00 * argStorage[0]) + + _m4storage[0] = + (m00 * argStorage[0]) + (m01 * argStorage[1]) + (m02 * argStorage[2]) + (m03 * argStorage[3]); - _m4storage[4] = (m00 * argStorage[4]) + + _m4storage[4] = + (m00 * argStorage[4]) + (m01 * argStorage[5]) + (m02 * argStorage[6]) + (m03 * argStorage[7]); - _m4storage[8] = (m00 * argStorage[8]) + + _m4storage[8] = + (m00 * argStorage[8]) + (m01 * argStorage[9]) + (m02 * argStorage[10]) + (m03 * argStorage[11]); - _m4storage[12] = (m00 * argStorage[12]) + + _m4storage[12] = + (m00 * argStorage[12]) + (m01 * argStorage[13]) + (m02 * argStorage[14]) + (m03 * argStorage[15]); - _m4storage[1] = (m10 * argStorage[0]) + + _m4storage[1] = + (m10 * argStorage[0]) + (m11 * argStorage[1]) + (m12 * argStorage[2]) + (m13 * argStorage[3]); - _m4storage[5] = (m10 * argStorage[4]) + + _m4storage[5] = + (m10 * argStorage[4]) + (m11 * argStorage[5]) + (m12 * argStorage[6]) + (m13 * argStorage[7]); - _m4storage[9] = (m10 * argStorage[8]) + + _m4storage[9] = + (m10 * argStorage[8]) + (m11 * argStorage[9]) + (m12 * argStorage[10]) + (m13 * argStorage[11]); - _m4storage[13] = (m10 * argStorage[12]) + + _m4storage[13] = + (m10 * argStorage[12]) + (m11 * argStorage[13]) + (m12 * argStorage[14]) + (m13 * argStorage[15]); - _m4storage[2] = (m20 * argStorage[0]) + + _m4storage[2] = + (m20 * argStorage[0]) + (m21 * argStorage[1]) + (m22 * argStorage[2]) + (m23 * argStorage[3]); - _m4storage[6] = (m20 * argStorage[4]) + + _m4storage[6] = + (m20 * argStorage[4]) + (m21 * argStorage[5]) + (m22 * argStorage[6]) + (m23 * argStorage[7]); - _m4storage[10] = (m20 * argStorage[8]) + + _m4storage[10] = + (m20 * argStorage[8]) + (m21 * argStorage[9]) + (m22 * argStorage[10]) + (m23 * argStorage[11]); - _m4storage[14] = (m20 * argStorage[12]) + + _m4storage[14] = + (m20 * argStorage[12]) + (m21 * argStorage[13]) + (m22 * argStorage[14]) + (m23 * argStorage[15]); - _m4storage[3] = (m30 * argStorage[0]) + + _m4storage[3] = + (m30 * argStorage[0]) + (m31 * argStorage[1]) + (m32 * argStorage[2]) + (m33 * argStorage[3]); - _m4storage[7] = (m30 * argStorage[4]) + + _m4storage[7] = + (m30 * argStorage[4]) + (m31 * argStorage[5]) + (m32 * argStorage[6]) + (m33 * argStorage[7]); - _m4storage[11] = (m30 * argStorage[8]) + + _m4storage[11] = + (m30 * argStorage[8]) + (m31 * argStorage[9]) + (m32 * argStorage[10]) + (m33 * argStorage[11]); - _m4storage[15] = (m30 * argStorage[12]) + + _m4storage[15] = + (m30 * argStorage[12]) + (m31 * argStorage[13]) + (m32 * argStorage[14]) + (m33 * argStorage[15]); @@ -1791,67 +1883,83 @@ class Matrix4 { final m32 = _m4storage[11]; final m33 = _m4storage[15]; final argStorage = arg._m4storage; - _m4storage[0] = (m00 * argStorage[0]) + + _m4storage[0] = + (m00 * argStorage[0]) + (m01 * argStorage[4]) + (m02 * argStorage[8]) + (m03 * argStorage[12]); - _m4storage[4] = (m00 * argStorage[1]) + + _m4storage[4] = + (m00 * argStorage[1]) + (m01 * argStorage[5]) + (m02 * argStorage[9]) + (m03 * argStorage[13]); - _m4storage[8] = (m00 * argStorage[2]) + + _m4storage[8] = + (m00 * argStorage[2]) + (m01 * argStorage[6]) + (m02 * argStorage[10]) + (m03 * argStorage[14]); - _m4storage[12] = (m00 * argStorage[3]) + + _m4storage[12] = + (m00 * argStorage[3]) + (m01 * argStorage[7]) + (m02 * argStorage[11]) + (m03 * argStorage[15]); - _m4storage[1] = (m10 * argStorage[0]) + + _m4storage[1] = + (m10 * argStorage[0]) + (m11 * argStorage[4]) + (m12 * argStorage[8]) + (m13 * argStorage[12]); - _m4storage[5] = (m10 * argStorage[1]) + + _m4storage[5] = + (m10 * argStorage[1]) + (m11 * argStorage[5]) + (m12 * argStorage[9]) + (m13 * argStorage[13]); - _m4storage[9] = (m10 * argStorage[2]) + + _m4storage[9] = + (m10 * argStorage[2]) + (m11 * argStorage[6]) + (m12 * argStorage[10]) + (m13 * argStorage[14]); - _m4storage[13] = (m10 * argStorage[3]) + + _m4storage[13] = + (m10 * argStorage[3]) + (m11 * argStorage[7]) + (m12 * argStorage[11]) + (m13 * argStorage[15]); - _m4storage[2] = (m20 * argStorage[0]) + + _m4storage[2] = + (m20 * argStorage[0]) + (m21 * argStorage[4]) + (m22 * argStorage[8]) + (m23 * argStorage[12]); - _m4storage[6] = (m20 * argStorage[1]) + + _m4storage[6] = + (m20 * argStorage[1]) + (m21 * argStorage[5]) + (m22 * argStorage[9]) + (m23 * argStorage[13]); - _m4storage[10] = (m20 * argStorage[2]) + + _m4storage[10] = + (m20 * argStorage[2]) + (m21 * argStorage[6]) + (m22 * argStorage[10]) + (m23 * argStorage[14]); - _m4storage[14] = (m20 * argStorage[3]) + + _m4storage[14] = + (m20 * argStorage[3]) + (m21 * argStorage[7]) + (m22 * argStorage[11]) + (m23 * argStorage[15]); - _m4storage[3] = (m30 * argStorage[0]) + + _m4storage[3] = + (m30 * argStorage[0]) + (m31 * argStorage[4]) + (m32 * argStorage[8]) + (m33 * argStorage[12]); - _m4storage[7] = (m30 * argStorage[1]) + + _m4storage[7] = + (m30 * argStorage[1]) + (m31 * argStorage[5]) + (m32 * argStorage[9]) + (m33 * argStorage[13]); - _m4storage[11] = (m30 * argStorage[2]) + + _m4storage[11] = + (m30 * argStorage[2]) + (m31 * argStorage[6]) + (m32 * argStorage[10]) + (m33 * argStorage[14]); - _m4storage[15] = (m30 * argStorage[3]) + + _m4storage[15] = + (m30 * argStorage[3]) + (m31 * argStorage[7]) + (m32 * argStorage[11]) + (m33 * argStorage[15]); @@ -1906,13 +2014,16 @@ class Matrix4 { /// 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 x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]); - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]); - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]); argStorage[0] = x_; @@ -1936,15 +2047,18 @@ class Matrix4 { /// this. Vector3 transform3(Vector3 arg) { final argStorage = arg._v3storage; - final x_ = (_m4storage[0] * argStorage[0]) + + final x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + _m4storage[14]; @@ -1970,19 +2084,23 @@ class Matrix4 { /// this. Vector4 transform(Vector4 arg) { final argStorage = arg._v4storage; - final x_ = (_m4storage[0] * argStorage[0]) + + final x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + (_m4storage[12] * argStorage[3]); - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + (_m4storage[13] * argStorage[3]); - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + (_m4storage[14] * argStorage[3]); - final w_ = (_m4storage[3] * argStorage[0]) + + final w_ = + (_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + (_m4storage[11] * argStorage[2]) + (_m4storage[15] * argStorage[3]); @@ -1997,19 +2115,23 @@ class Matrix4 { /// defined by this. Vector3 perspectiveTransform(Vector3 arg) { final argStorage = arg._v3storage; - final x_ = (_m4storage[0] * argStorage[0]) + + final x_ = + (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = (_m4storage[1] * argStorage[0]) + + final y_ = + (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = (_m4storage[2] * argStorage[0]) + + final z_ = + (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + _m4storage[14]; - final w_ = 1.0 / + final w_ = + 1.0 / ((_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + (_m4storage[11] * argStorage[2]) + @@ -2109,46 +2231,54 @@ class Matrix4 { /// Is this the identity matrix? bool isIdentity() => - _m4storage[0] == 1.0 // col 1 - && + _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[4] == + 0.0 // col 2 + && _m4storage[5] == 1.0 && _m4storage[6] == 0.0 && _m4storage[7] == 0.0 && - _m4storage[8] == 0.0 // col 3 - && + _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[12] == + 0.0 // col 4 + && _m4storage[13] == 0.0 && _m4storage[14] == 0.0 && _m4storage[15] == 1.0; /// Is this the zero matrix? bool isZero() => - _m4storage[0] == 0.0 // col 1 - && + _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[4] == + 0.0 // col 2 + && _m4storage[5] == 0.0 && _m4storage[6] == 0.0 && _m4storage[7] == 0.0 && - _m4storage[8] == 0.0 // col 3 - && + _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[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/noise.dart b/lib/src/vector_math_64/noise.dart index 701ba4a4..6ecc1b34 100644 --- a/lib/src/vector_math_64/noise.dart +++ b/lib/src/vector_math_64/noise.dart @@ -25,8 +25,10 @@ part of '../../vector_math_64.dart'; * This is based on the implementation of Simplex Noise by Stefan Gustavson * found at: http://webstaff.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java */ -@Deprecated('This API will be removed ' - '(see https:github.com/google/vector_math.dart/issues/270)') +@Deprecated( + 'This API will be removed ' + '(see https:github.com/google/vector_math.dart/issues/270)', +) class SimplexNoise { static final List> _grad3 = >[ [1.0, 1.0, 0.0], @@ -40,7 +42,7 @@ class SimplexNoise { [0.0, 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, -1.0], ]; static final List> _grad4 = >[ @@ -75,7 +77,7 @@ class SimplexNoise { [-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], ]; // To remove the need for index wrapping, double the permutation table length @@ -101,10 +103,16 @@ class SimplexNoise { SimplexNoise([math.Random? r]) { r ??= math.Random(); final p = List.generate(256, (_) => r!.nextInt(256), growable: false); - _perm = List.generate(p.length * 2, (int i) => p[i % p.length], - growable: false); - _permMod12 = List.generate(_perm.length, (int i) => _perm[i] % 12, - growable: false); + _perm = List.generate( + p.length * 2, + (int i) => p[i % p.length], + growable: false, + ); + _permMod12 = List.generate( + _perm.length, + (int i) => _perm[i] % 12, + growable: false, + ); } double noise2D(double xin, double yin) { @@ -135,7 +143,8 @@ class SimplexNoise { final x1 = x0 - i1 + _G2; // Offsets for middle corner in (x,y) unskewed coords final y1 = y0 - j1 + _G2; - final x2 = x0 - + final x2 = + x0 - 1.0 + 2.0 * _G2; // Offsets for last corner in (x,y) unskewed coords final y2 = y0 - 1.0 + 2.0 * _G2; @@ -151,7 +160,8 @@ class SimplexNoise { n0 = 0.0; } else { t0 *= t0; - n0 = t0 * + n0 = + t0 * t0 * _dot2(_grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient } diff --git a/lib/src/vector_math_64/obb3.dart b/lib/src/vector_math_64/obb3.dart index 409f5200..5b787492 100644 --- a/lib/src/vector_math_64/obb3.dart +++ b/lib/src/vector_math_64/obb3.dart @@ -29,28 +29,32 @@ class Obb3 { /// Create a new OBB with erverything set to zero. Obb3() - : _center = Vector3.zero(), - _halfExtents = Vector3.zero(), - _axis0 = Vector3(1.0, 0.0, 0.0), - _axis1 = Vector3(0.0, 1.0, 0.0), - _axis2 = Vector3(0.0, 0.0, 1.0); + : _center = Vector3.zero(), + _halfExtents = Vector3.zero(), + _axis0 = Vector3(1.0, 0.0, 0.0), + _axis1 = Vector3(0.0, 1.0, 0.0), + _axis2 = Vector3(0.0, 0.0, 1.0); /// Create a new OBB as a copy of [other]. Obb3.copy(Obb3 other) - : _center = Vector3.copy(other._center), - _halfExtents = Vector3.copy(other._halfExtents), - _axis0 = Vector3.copy(other._axis0), - _axis1 = Vector3.copy(other._axis1), - _axis2 = Vector3.copy(other._axis2); + : _center = Vector3.copy(other._center), + _halfExtents = Vector3.copy(other._halfExtents), + _axis0 = Vector3.copy(other._axis0), + _axis1 = Vector3.copy(other._axis1), + _axis2 = Vector3.copy(other._axis2); /// Create a new OBB using [center], [halfExtents] and axis. - Obb3.centerExtentsAxes(Vector3 center, Vector3 halfExtents, Vector3 axis0, - Vector3 axis1, Vector3 axis2) - : _center = Vector3.copy(center), - _halfExtents = Vector3.copy(halfExtents), - _axis0 = Vector3.copy(axis0), - _axis1 = Vector3.copy(axis1), - _axis2 = Vector3.copy(axis2); + Obb3.centerExtentsAxes( + Vector3 center, + Vector3 halfExtents, + Vector3 axis0, + Vector3 axis1, + Vector3 axis2, + ) : _center = Vector3.copy(center), + _halfExtents = Vector3.copy(halfExtents), + _axis0 = Vector3.copy(axis0), + _axis1 = Vector3.copy(axis1), + _axis2 = Vector3.copy(axis2); /// Copy from [other] into this. void copyFrom(Obb3 other) { @@ -229,7 +233,8 @@ class Obb3 { // Test axes L = A0, L = A1, L = A2 for (var i = 0; i < 3; i++) { ra = _halfExtents[i]; - rb = other._halfExtents[0] * _absR.entry(i, 0) + + rb = + other._halfExtents[0] * _absR.entry(i, 0) + other._halfExtents[1] * _absR.entry(i, 1) + other._halfExtents[2] * _absR.entry(i, 2); @@ -240,7 +245,8 @@ class Obb3 { // Test axes L = B0, L = B1, L = B2 for (var i = 0; i < 3; i++) { - ra = _halfExtents[0] * _absR.entry(0, i) + + ra = + _halfExtents[0] * _absR.entry(0, i) + _halfExtents[1] * _absR.entry(1, i) + _halfExtents[2] * _absR.entry(2, i); rb = other._halfExtents[i]; @@ -255,81 +261,99 @@ class Obb3 { } // Test axis L = A0 x B0 - ra = _halfExtents[1] * _absR.entry(2, 0) + + ra = + _halfExtents[1] * _absR.entry(2, 0) + _halfExtents[2] * _absR.entry(1, 0); - rb = other._halfExtents[1] * _absR.entry(0, 2) + + rb = + other._halfExtents[1] * _absR.entry(0, 2) + other._halfExtents[2] * _absR.entry(0, 1); if ((_t[2] * _r.entry(1, 0) - _t[1] * _r.entry(2, 0)).abs() > ra + rb) { return false; } // Test axis L = A0 x B1 - ra = _halfExtents[1] * _absR.entry(2, 1) + + ra = + _halfExtents[1] * _absR.entry(2, 1) + _halfExtents[2] * _absR.entry(1, 1); - rb = other._halfExtents[0] * _absR.entry(0, 2) + + rb = + other._halfExtents[0] * _absR.entry(0, 2) + other._halfExtents[2] * _absR.entry(0, 0); if ((_t[2] * _r.entry(1, 1) - _t[1] * _r.entry(2, 1)).abs() > ra + rb) { return false; } // Test axis L = A0 x B2 - ra = _halfExtents[1] * _absR.entry(2, 2) + + ra = + _halfExtents[1] * _absR.entry(2, 2) + _halfExtents[2] * _absR.entry(1, 2); - rb = other._halfExtents[0] * _absR.entry(0, 1) + + rb = + other._halfExtents[0] * _absR.entry(0, 1) + other._halfExtents[1] * _absR.entry(0, 0); if ((_t[2] * _r.entry(1, 2) - _t[1] * _r.entry(2, 2)).abs() > ra + rb) { return false; } // Test axis L = A1 x B0 - ra = _halfExtents[0] * _absR.entry(2, 0) + + ra = + _halfExtents[0] * _absR.entry(2, 0) + _halfExtents[2] * _absR.entry(0, 0); - rb = other._halfExtents[1] * _absR.entry(1, 2) + + rb = + other._halfExtents[1] * _absR.entry(1, 2) + other._halfExtents[2] * _absR.entry(1, 1); if ((_t[0] * _r.entry(2, 0) - _t[2] * _r.entry(0, 0)).abs() > ra + rb) { return false; } // Test axis L = A1 x B1 - ra = _halfExtents[0] * _absR.entry(2, 1) + + ra = + _halfExtents[0] * _absR.entry(2, 1) + _halfExtents[2] * _absR.entry(0, 1); - rb = other._halfExtents[0] * _absR.entry(1, 2) + + rb = + other._halfExtents[0] * _absR.entry(1, 2) + other._halfExtents[2] * _absR.entry(1, 0); if ((_t[0] * _r.entry(2, 1) - _t[2] * _r.entry(0, 1)).abs() > ra + rb) { return false; } // Test axis L = A1 x B2 - ra = _halfExtents[0] * _absR.entry(2, 2) + + ra = + _halfExtents[0] * _absR.entry(2, 2) + _halfExtents[2] * _absR.entry(0, 2); - rb = other._halfExtents[0] * _absR.entry(1, 1) + + rb = + other._halfExtents[0] * _absR.entry(1, 1) + other._halfExtents[1] * _absR.entry(1, 0); if ((_t[0] * _r.entry(2, 2) - _t[2] * _r.entry(0, 2)).abs() > ra + rb) { return false; } // Test axis L = A2 x B0 - ra = _halfExtents[0] * _absR.entry(1, 0) + + ra = + _halfExtents[0] * _absR.entry(1, 0) + _halfExtents[1] * _absR.entry(0, 0); - rb = other._halfExtents[1] * _absR.entry(2, 2) + + rb = + other._halfExtents[1] * _absR.entry(2, 2) + other._halfExtents[2] * _absR.entry(2, 1); if ((_t[1] * _r.entry(0, 0) - _t[0] * _r.entry(1, 0)).abs() > ra + rb) { return false; } // Test axis L = A2 x B1 - ra = _halfExtents[0] * _absR.entry(1, 1) + + ra = + _halfExtents[0] * _absR.entry(1, 1) + _halfExtents[1] * _absR.entry(0, 1); - rb = other._halfExtents[0] * _absR.entry(2, 2) + + rb = + other._halfExtents[0] * _absR.entry(2, 2) + other._halfExtents[2] * _absR.entry(2, 0); if ((_t[1] * _r.entry(0, 1) - _t[0] * _r.entry(1, 1)).abs() > ra + rb) { return false; } // Test axis L = A2 x B2 - ra = _halfExtents[0] * _absR.entry(1, 2) + + ra = + _halfExtents[0] * _absR.entry(1, 2) + _halfExtents[1] * _absR.entry(0, 2); - rb = other._halfExtents[0] * _absR.entry(2, 1) + + rb = + other._halfExtents[0] * _absR.entry(2, 1) + other._halfExtents[1] * _absR.entry(2, 0); if ((_t[1] * _r.entry(0, 2) - _t[0] * _r.entry(1, 2)).abs() > ra + rb) { return false; @@ -350,16 +374,25 @@ class Obb3 { _triangle.point0 ..sub(_center) - ..setValues(_triangle.point0.dot(axis0), _triangle.point0.dot(axis1), - _triangle.point0.dot(axis2)); + ..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)); + ..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)); + ..setValues( + _triangle.point2.dot(axis0), + _triangle.point2.dot(axis1), + _triangle.point2.dot(axis2), + ); _aabb3.setCenterAndHalfExtents(_zeroVector, _halfExtents); diff --git a/lib/src/vector_math_64/opengl.dart b/lib/src/vector_math_64/opengl.dart index 6d25d363..8ab277a4 100644 --- a/lib/src/vector_math_64/opengl.dart +++ b/lib/src/vector_math_64/opengl.dart @@ -41,7 +41,10 @@ part of '../../vector_math_64.dart'; /// } /// } void setRotationMatrix( - Matrix4 rotationMatrix, Vector3 forwardDirection, Vector3 upDirection) { + Matrix4 rotationMatrix, + Vector3 forwardDirection, + Vector3 upDirection, +) { setModelMatrix(rotationMatrix, forwardDirection, upDirection, 0.0, 0.0, 0.0); } @@ -54,14 +57,36 @@ void setRotationMatrix( /// [forwardDirection] specifies the direction of the forward vector. /// [upDirection] specifies the direction of the up vector. /// [tx],[ty],[tz] specifies the position of the object. -void setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection, - Vector3 upDirection, double tx, double ty, double tz) { +void setModelMatrix( + Matrix4 modelMatrix, + Vector3 forwardDirection, + Vector3 upDirection, + double tx, + double ty, + double tz, +) { final right = forwardDirection.cross(upDirection)..normalize(); final c1 = right; final c2 = upDirection; final c3 = -forwardDirection; - modelMatrix.setValues(c1[0], c1[1], c1[2], 0.0, c2[0], c2[1], c2[2], 0.0, - c3[0], c3[1], c3[2], 0.0, tx, ty, tz, 1.0); + 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, + ); } /// Constructs an OpenGL view matrix in [viewMatrix]. @@ -72,8 +97,12 @@ void setModelMatrix(Matrix4 modelMatrix, Vector3 forwardDirection, /// [cameraPosition] specifies the position of the camera. /// [cameraFocusPosition] specifies the position the camera is focused on. /// [upDirection] specifies the direction of the up vector (usually, +Y). -void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, - Vector3 cameraFocusPosition, Vector3 upDirection) { +void setViewMatrix( + Matrix4 viewMatrix, + Vector3 cameraPosition, + Vector3 cameraFocusPosition, + Vector3 upDirection, +) { final z = (cameraPosition - cameraFocusPosition)..normalize(); final x = upDirection.cross(z)..normalize(); final y = z.cross(x)..normalize(); @@ -82,8 +111,24 @@ void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, final rotatedEyeY = -y.dot(cameraPosition); final rotatedEyeZ = -z.dot(cameraPosition); - viewMatrix.setValues(x[0], y[0], z[0], 0.0, x[1], y[1], z[1], 0.0, x[2], y[2], - z[2], 0.0, rotatedEyeX, rotatedEyeY, rotatedEyeZ, 1.0); + 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, + ); } /// Constructs a new OpenGL view matrix. @@ -92,7 +137,10 @@ void setViewMatrix(Matrix4 viewMatrix, Vector3 cameraPosition, /// [cameraFocusPosition] specifies the position the camera is focused on. /// [upDirection] specifies the direction of the up vector (usually, +Y). Matrix4 makeViewMatrix( - Vector3 cameraPosition, Vector3 cameraFocusPosition, Vector3 upDirection) { + Vector3 cameraPosition, + Vector3 cameraFocusPosition, + Vector3 upDirection, +) { final r = Matrix4.zero(); setViewMatrix(r, cameraPosition, cameraFocusPosition, upDirection); return r; @@ -108,8 +156,13 @@ Matrix4 makeViewMatrix( /// (always positive). /// [zFar] specifies the distance from the viewer to the far plane /// (always positive). -void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians, - double aspectRatio, double zNear, double zFar) { +void setPerspectiveMatrix( + Matrix4 perspectiveMatrix, + double fovYRadians, + double aspectRatio, + double zNear, + double zFar, +) { final height = math.tan(fovYRadians * 0.5); final width = height * aspectRatio; final near_minus_far = zNear - zFar; @@ -134,7 +187,11 @@ void setPerspectiveMatrix(Matrix4 perspectiveMatrix, double fovYRadians, /// [zFar] specifies the distance from the viewer to the far plane /// (always positive). Matrix4 makePerspectiveMatrix( - double fovYRadians, double aspectRatio, double zNear, double zFar) { + double fovYRadians, + double aspectRatio, + double zNear, + double zFar, +) { final r = Matrix4.zero(); setPerspectiveMatrix(r, fovYRadians, aspectRatio, zNear, zFar); return r; @@ -147,8 +204,12 @@ Matrix4 makePerspectiveMatrix( /// in the x direction. The aspect ratio of x (width) to y (height). /// [zNear] specifies the distance from the viewer to the near plane /// (always positive). -void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians, - double aspectRatio, double zNear) { +void setInfiniteMatrix( + Matrix4 infiniteMatrix, + double fovYRadians, + double aspectRatio, + double zNear, +) { final height = math.tan(fovYRadians * 0.5); final width = height * aspectRatio; @@ -170,7 +231,10 @@ void setInfiniteMatrix(Matrix4 infiniteMatrix, double fovYRadians, /// [zNear] specifies the distance from the viewer to the near plane /// (always positive). Matrix4 makeInfiniteMatrix( - double fovYRadians, double aspectRatio, double zNear) { + double fovYRadians, + double aspectRatio, + double zNear, +) { final r = Matrix4.zero(); setInfiniteMatrix(r, fovYRadians, aspectRatio, zNear); return r; @@ -184,8 +248,15 @@ Matrix4 makeInfiniteMatrix( /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right, - double bottom, double top, double near, double far) { +void setFrustumMatrix( + Matrix4 perspectiveMatrix, + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final two_near = 2.0 * near; final right_minus_left = right - left; final top_minus_bottom = top - bottom; @@ -209,8 +280,14 @@ void setFrustumMatrix(Matrix4 perspectiveMatrix, double left, double right, /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top, - double near, double far) { +Matrix4 makeFrustumMatrix( + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final view = Matrix4.zero(); setFrustumMatrix(view, left, right, bottom, top, near, far); return view; @@ -224,8 +301,15 @@ Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top, /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -void setOrthographicMatrix(Matrix4 orthographicMatrix, double left, - double right, double bottom, double top, double near, double far) { +void setOrthographicMatrix( + Matrix4 orthographicMatrix, + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final rml = right - left; final rpl = right + left; final tmb = top - bottom; @@ -251,8 +335,14 @@ void setOrthographicMatrix(Matrix4 orthographicMatrix, double left, /// clipping planes. /// [near], [far] specify the coordinates to the near and far depth clipping /// planes. -Matrix4 makeOrthographicMatrix(double left, double right, double bottom, - double top, double near, double far) { +Matrix4 makeOrthographicMatrix( + double left, + double right, + double bottom, + double top, + double near, + double far, +) { final r = Matrix4.zero(); setOrthographicMatrix(r, left, right, bottom, top, near, far); return r; @@ -261,14 +351,22 @@ Matrix4 makeOrthographicMatrix(double left, double right, double bottom, /// Returns a transformation matrix that transforms points onto /// the plane specified with [planeNormal] and [planePoint]. Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) { - final v = Vector4(planeNormal.storage[0], planeNormal.storage[1], - planeNormal.storage[2], 0.0); + final v = Vector4( + planeNormal.storage[0], + planeNormal.storage[1], + planeNormal.storage[2], + 0.0, + ); final outer = Matrix4.outer(v, v); var r = Matrix4.zero(); r = r - outer; final scaledNormal = planeNormal.scaled(dot3(planePoint, planeNormal)); - final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1], - scaledNormal.storage[2], 1.0); + final T = Vector4( + scaledNormal.storage[0], + scaledNormal.storage[1], + scaledNormal.storage[2], + 1.0, + ); r.setColumn(3, T); return r; } @@ -276,15 +374,23 @@ Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) { /// Returns a transformation matrix that transforms points by reflecting /// them through the plane specified with [planeNormal] and [planePoint]. Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) { - final v = Vector4(planeNormal.storage[0], planeNormal.storage[1], - planeNormal.storage[2], 0.0); + final v = Vector4( + planeNormal.storage[0], + planeNormal.storage[1], + planeNormal.storage[2], + 0.0, + ); final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0, 1.0); var r = Matrix4.zero(); r = r - outer; final scale = 2.0 * planePoint.dot(planeNormal); final scaledNormal = planeNormal.scaled(scale); - final T = Vector4(scaledNormal.storage[0], scaledNormal.storage[1], - scaledNormal.storage[2], 1.0); + final T = Vector4( + scaledNormal.storage[0], + scaledNormal.storage[1], + scaledNormal.storage[2], + 1.0, + ); r.setColumn(3, T); return r; } @@ -301,15 +407,16 @@ Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) { /// /// Returns false on error, for example, the mouse is not in the viewport bool unproject( - Matrix4 cameraMatrix, - num viewportX, - num viewportWidth, - num viewportY, - num viewportHeight, - num pickX, - num pickY, - num pickZ, - Vector3 pickWorld) { + Matrix4 cameraMatrix, + num viewportX, + num viewportWidth, + num viewportY, + num viewportHeight, + num pickX, + num pickY, + num pickZ, + Vector3 pickWorld, +) { viewportX = viewportX.toDouble(); viewportWidth = viewportWidth.toDouble(); viewportY = viewportY.toDouble(); @@ -362,23 +469,42 @@ bool unproject( /// /// Returns false on error, for example, the mouse is not in the viewport. bool pickRay( - Matrix4 cameraMatrix, - num viewportX, - num viewportWidth, - num viewportY, - num viewportHeight, - num pickX, - num pickY, - Vector3 rayNear, - Vector3 rayFar) { + Matrix4 cameraMatrix, + num viewportX, + num viewportWidth, + num viewportY, + num viewportHeight, + num pickX, + num pickY, + Vector3 rayNear, + Vector3 rayFar, +) { bool r; - r = unproject(cameraMatrix, viewportX, viewportWidth, viewportY, - viewportHeight, pickX, viewportHeight - pickY, 0.0, rayNear); + r = unproject( + cameraMatrix, + viewportX, + viewportWidth, + viewportY, + viewportHeight, + pickX, + viewportHeight - pickY, + 0.0, + rayNear, + ); if (!r) { return false; } - return unproject(cameraMatrix, viewportX, viewportWidth, viewportY, - viewportHeight, pickX, viewportHeight - pickY, 1.0, rayFar); + return unproject( + cameraMatrix, + viewportX, + viewportWidth, + viewportY, + viewportHeight, + pickX, + viewportHeight - pickY, + 1.0, + rayFar, + ); } diff --git a/lib/src/vector_math_64/plane.dart b/lib/src/vector_math_64/plane.dart index 3436c178..70fece85 100644 --- a/lib/src/vector_math_64/plane.dart +++ b/lib/src/vector_math_64/plane.dart @@ -35,19 +35,17 @@ class Plane { Vector3 get normal => _normal; - Plane() - : _normal = Vector3.zero(), - constant = 0.0; + Plane() : _normal = Vector3.zero(), constant = 0.0; Plane.copy(Plane other) - : _normal = Vector3.copy(other._normal), - constant = other.constant; + : _normal = Vector3.copy(other._normal), + constant = other.constant; Plane.components(double x, double y, double z, this.constant) - : _normal = Vector3(x, y, z); + : _normal = Vector3(x, y, z); Plane.normalconstant(Vector3 normal_, this.constant) - : _normal = Vector3.copy(normal_); + : _normal = Vector3.copy(normal_); void copyFrom(Plane o) { _normal.setFrom(o._normal); diff --git a/lib/src/vector_math_64/quad.dart b/lib/src/vector_math_64/quad.dart index 94c4ab13..48d15a0e 100644 --- a/lib/src/vector_math_64/quad.dart +++ b/lib/src/vector_math_64/quad.dart @@ -25,24 +25,24 @@ class Quad { /// Create a new, uninitialized quad. Quad() - : _point0 = Vector3.zero(), - _point1 = Vector3.zero(), - _point2 = Vector3.zero(), - _point3 = Vector3.zero(); + : _point0 = Vector3.zero(), + _point1 = Vector3.zero(), + _point2 = Vector3.zero(), + _point3 = Vector3.zero(); /// Create a quad as a copy of [other]. Quad.copy(Quad other) - : _point0 = Vector3.copy(other._point0), - _point1 = Vector3.copy(other._point1), - _point2 = Vector3.copy(other._point2), - _point3 = Vector3.copy(other._point3); + : _point0 = Vector3.copy(other._point0), + _point1 = Vector3.copy(other._point1), + _point2 = Vector3.copy(other._point2), + _point3 = Vector3.copy(other._point3); /// Create a quad by four points. Quad.points(Vector3 point0, Vector3 point1, Vector3 point2, Vector3 point3) - : _point0 = Vector3.copy(point0), - _point1 = Vector3.copy(point1), - _point2 = Vector3.copy(point2), - _point3 = Vector3.copy(point3); + : _point0 = Vector3.copy(point0), + _point1 = Vector3.copy(point1), + _point2 = Vector3.copy(point2), + _point3 = Vector3.copy(point3); /// Copy the quad from [other] into this. void copyFrom(Quad other) { @@ -91,7 +91,8 @@ class Quad { /// Returns a printable string @override - String toString() => '[0] $_point0\n[1] $_point1\n' + String toString() => + '[0] $_point0\n[1] $_point1\n' '[2] $_point2\n[3] $_point3\n'; /// Check if two quad are the same. diff --git a/lib/src/vector_math_64/quaternion.dart b/lib/src/vector_math_64/quaternion.dart index ebb52523..4425aa8e 100644 --- a/lib/src/vector_math_64/quaternion.dart +++ b/lib/src/vector_math_64/quaternion.dart @@ -85,7 +85,7 @@ class Quaternion { /// starting at [offset]. [offset] has to be multiple of /// [Float64List.bytesPerElement]. Quaternion.fromBuffer(ByteBuffer buffer, int offset) - : _qStorage = Float64List.view(buffer, offset, 4); + : _qStorage = Float64List.view(buffer, offset, 4); /// Returns a new copy of this. Quaternion clone() => Quaternion.copy(this); @@ -133,24 +133,30 @@ class Quaternion { _qStorage[1] = (rotationMatrixStorage[6] - rotationMatrixStorage[2]) * s; _qStorage[2] = (rotationMatrixStorage[1] - rotationMatrixStorage[3]) * s; } else { - final i = rotationMatrixStorage[0] < rotationMatrixStorage[4] - ? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1) - : (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0); + final i = + rotationMatrixStorage[0] < rotationMatrixStorage[4] + ? (rotationMatrixStorage[4] < rotationMatrixStorage[8] ? 2 : 1) + : (rotationMatrixStorage[0] < rotationMatrixStorage[8] ? 2 : 0); final j = (i + 1) % 3; final k = (i + 2) % 3; - var s = math.sqrt(rotationMatrixStorage[rotationMatrix.index(i, i)] - - rotationMatrixStorage[rotationMatrix.index(j, j)] - - rotationMatrixStorage[rotationMatrix.index(k, k)] + - 1.0); + var s = math.sqrt( + rotationMatrixStorage[rotationMatrix.index(i, i)] - + rotationMatrixStorage[rotationMatrix.index(j, j)] - + rotationMatrixStorage[rotationMatrix.index(k, k)] + + 1.0, + ); _qStorage[i] = s * 0.5; s = 0.5 / s; - _qStorage[3] = (rotationMatrixStorage[rotationMatrix.index(k, j)] - + _qStorage[3] = + (rotationMatrixStorage[rotationMatrix.index(k, j)] - rotationMatrixStorage[rotationMatrix.index(j, k)]) * s; - _qStorage[j] = (rotationMatrixStorage[rotationMatrix.index(j, i)] + + _qStorage[j] = + (rotationMatrixStorage[rotationMatrix.index(j, i)] + rotationMatrixStorage[rotationMatrix.index(i, j)]) * s; - _qStorage[k] = (rotationMatrixStorage[rotationMatrix.index(k, i)] + + _qStorage[k] = + (rotationMatrixStorage[rotationMatrix.index(k, i)] + rotationMatrixStorage[rotationMatrix.index(i, k)]) * s; } @@ -309,7 +315,10 @@ class Quaternion { final scale = 1.0 / math.sqrt(den); return Vector3( - _qStorage[0] * scale, _qStorage[1] * scale, _qStorage[2] * scale); + _qStorage[0] * scale, + _qStorage[1] * scale, + _qStorage[2] * scale, + ); } /// Length squared. @@ -397,10 +406,11 @@ class Quaternion { final oy = otherStorage[1]; final ox = otherStorage[0]; return Quaternion( - w * ox + x * ow + y * oz - z * oy, - w * oy + y * ow + z * ox - x * oz, - w * oz + z * ow + x * oy - y * ox, - w * ow - x * ox - y * oy - z * oz); + w * ox + x * ow + y * oz - z * oy, + w * oy + y * ow + z * ox - x * oz, + w * oz + z * ow + x * oy - y * ox, + w * ow - x * ox - y * oy - z * oz, + ); } /// Check if two quaternions are the same. @@ -478,7 +488,8 @@ class Quaternion { /// Printable string. @override - String toString() => '${_qStorage[0]}, ${_qStorage[1]},' + String toString() => + '${_qStorage[0]}, ${_qStorage[1]},' ' ${_qStorage[2]} @ ${_qStorage[3]}'; /// Relative error between this and [correct]. diff --git a/lib/src/vector_math_64/ray.dart b/lib/src/vector_math_64/ray.dart index 2aedd318..052e8488 100644 --- a/lib/src/vector_math_64/ray.dart +++ b/lib/src/vector_math_64/ray.dart @@ -16,19 +16,17 @@ class Ray { Vector3 get direction => _direction; /// Create a new, uninitialized ray. - Ray() - : _origin = Vector3.zero(), - _direction = Vector3.zero(); + Ray() : _origin = Vector3.zero(), _direction = Vector3.zero(); /// Create a ray as a copy of [other]. Ray.copy(Ray other) - : _origin = Vector3.copy(other._origin), - _direction = Vector3.copy(other._direction); + : _origin = Vector3.copy(other._origin), + _direction = Vector3.copy(other._direction); /// Create a ray with an [origin] and a [direction]. Ray.originDirection(Vector3 origin, Vector3 direction) - : _origin = Vector3.copy(origin), - _direction = Vector3.copy(direction); + : _origin = Vector3.copy(origin), + _direction = Vector3.copy(direction); /// Copy the [origin] and [direction] from [other] into this. void copyFrom(Ray other) { diff --git a/lib/src/vector_math_64/sphere.dart b/lib/src/vector_math_64/sphere.dart index fad7a108..b9b11417 100644 --- a/lib/src/vector_math_64/sphere.dart +++ b/lib/src/vector_math_64/sphere.dart @@ -15,18 +15,16 @@ class Sphere { Vector3 get center => _center; /// Create a new, uninitialized sphere. - Sphere() - : _center = Vector3.zero(), - radius = 0.0; + Sphere() : _center = Vector3.zero(), radius = 0.0; /// Create a sphere as a copy of [other]. Sphere.copy(Sphere other) - : _center = Vector3.copy(other._center), - radius = other.radius; + : _center = Vector3.copy(other._center), + radius = other.radius; /// Create a sphere from a [center] and a [radius]. Sphere.centerRadius(Vector3 center, this.radius) - : _center = Vector3.copy(center); + : _center = Vector3.copy(center); /// Copy the sphere from [other] into this. void copyFrom(Sphere other) { diff --git a/lib/src/vector_math_64/triangle.dart b/lib/src/vector_math_64/triangle.dart index f77ad04d..3b0ee00c 100644 --- a/lib/src/vector_math_64/triangle.dart +++ b/lib/src/vector_math_64/triangle.dart @@ -21,21 +21,21 @@ class Triangle { /// Create a new, uninitialized triangle. Triangle() - : _point0 = Vector3.zero(), - _point1 = Vector3.zero(), - _point2 = Vector3.zero(); + : _point0 = Vector3.zero(), + _point1 = Vector3.zero(), + _point2 = Vector3.zero(); /// Create a triangle as a copy of [other]. Triangle.copy(Triangle other) - : _point0 = Vector3.copy(other._point0), - _point1 = Vector3.copy(other._point1), - _point2 = Vector3.copy(other._point2); + : _point0 = Vector3.copy(other._point0), + _point1 = Vector3.copy(other._point1), + _point2 = Vector3.copy(other._point2); /// Create a triangle by three points. Triangle.points(Vector3 point0, Vector3 point1, Vector3 point2) - : _point0 = Vector3.copy(point0), - _point1 = Vector3.copy(point1), - _point2 = Vector3.copy(point2); + : _point0 = Vector3.copy(point0), + _point1 = Vector3.copy(point1), + _point2 = Vector3.copy(point2); /// Copy the triangle from [other] into this. void copyFrom(Triangle other) { diff --git a/lib/src/vector_math_64/utilities.dart b/lib/src/vector_math_64/utilities.dart index 9c3cf7b2..3c4f2a48 100644 --- a/lib/src/vector_math_64/utilities.dart +++ b/lib/src/vector_math_64/utilities.dart @@ -25,8 +25,13 @@ double smoothStep(double edge0, double edge1, double amount) { /// 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) => +double catmullRom( + double edge0, + double edge1, + double edge2, + double edge3, + double amount, +) => 0.5 * ((2.0 * edge1) + (-edge0 + edge2) * amount + diff --git a/lib/src/vector_math_64/vector2.dart b/lib/src/vector_math_64/vector2.dart index 3fd7837d..60f39267 100644 --- a/lib/src/vector_math_64/vector2.dart +++ b/lib/src/vector_math_64/vector2.dart @@ -56,7 +56,7 @@ class Vector2 implements Vector { /// Constructs Vector2 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float64List.bytesPerElement]. Vector2.fromBuffer(ByteBuffer buffer, int offset) - : _v2storage = Float64List.view(buffer, offset, 2); + : _v2storage = Float64List.view(buffer, offset, 2); /// Generate random vector in the range (0, 0) to (1, 1). You can /// optionally pass your own random number generator. @@ -365,12 +365,14 @@ class Vector2 implements Vector { /// Round entries in this towards zero. void roundToZero() { - _v2storage[1] = _v2storage[1] < 0.0 - ? _v2storage[1].ceilToDouble() - : _v2storage[1].floorToDouble(); - _v2storage[0] = _v2storage[0] < 0.0 - ? _v2storage[0].ceilToDouble() - : _v2storage[0].floorToDouble(); + _v2storage[1] = + _v2storage[1] < 0.0 + ? _v2storage[1].ceilToDouble() + : _v2storage[1].floorToDouble(); + _v2storage[0] = + _v2storage[0] < 0.0 + ? _v2storage[0].ceilToDouble() + : _v2storage[0].floorToDouble(); } /// Clone of this. diff --git a/lib/src/vector_math_64/vector3.dart b/lib/src/vector_math_64/vector3.dart index 8eddaf97..f72ea346 100644 --- a/lib/src/vector_math_64/vector3.dart +++ b/lib/src/vector_math_64/vector3.dart @@ -60,7 +60,7 @@ class Vector3 implements Vector { /// Constructs Vector3 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float64List.bytesPerElement]. Vector3.fromBuffer(ByteBuffer buffer, int offset) - : _v3storage = Float64List.view(buffer, offset, 3); + : _v3storage = Float64List.view(buffer, offset, 3); /// Generate random vector in the range (0, 0, 0) to (1, 1, 1). You can /// optionally pass your own random number generator. @@ -302,22 +302,26 @@ class Vector3 implements Vector { final z = _v3storage[2]; final y = _v3storage[1]; final x = _v3storage[0]; - final d = 1.0 / + final d = + 1.0 / (argStorage[15] + argStorage[11] * z + argStorage[7] * y + argStorage[3] * x); - _v3storage[0] = (argStorage[12] + + _v3storage[0] = + (argStorage[12] + argStorage[8] * z + argStorage[4] * y + argStorage[0] * x) * d; - _v3storage[1] = (argStorage[13] + + _v3storage[1] = + (argStorage[13] + argStorage[9] * z + argStorage[5] * y + argStorage[1] * x) * d; - _v3storage[2] = (argStorage[14] + + _v3storage[2] = + (argStorage[14] + argStorage[10] * z + argStorage[6] * y + argStorage[2] * x) * @@ -369,15 +373,18 @@ class Vector3 implements Vector { final v2 = _v3storage[2]; final v1 = _v3storage[1]; final v0 = _v3storage[0]; - _v3storage[2] = argStorage[2] * v0 + + _v3storage[2] = + argStorage[2] * v0 + argStorage[6] * v1 + argStorage[10] * v2 + argStorage[14]; - _v3storage[1] = argStorage[1] * v0 + + _v3storage[1] = + argStorage[1] * v0 + argStorage[5] * v1 + argStorage[9] * v2 + argStorage[13]; - _v3storage[0] = argStorage[0] * v0 + + _v3storage[0] = + argStorage[0] * v0 + argStorage[4] * v1 + argStorage[8] * v2 + argStorage[12]; @@ -511,15 +518,18 @@ class Vector3 implements Vector { /// Round entries in this towards zero. void roundToZero() { - _v3storage[2] = _v3storage[2] < 0.0 - ? _v3storage[2].ceilToDouble() - : _v3storage[2].floorToDouble(); - _v3storage[1] = _v3storage[1] < 0.0 - ? _v3storage[1].ceilToDouble() - : _v3storage[1].floorToDouble(); - _v3storage[0] = _v3storage[0] < 0.0 - ? _v3storage[0].ceilToDouble() - : _v3storage[0].floorToDouble(); + _v3storage[2] = + _v3storage[2] < 0.0 + ? _v3storage[2].ceilToDouble() + : _v3storage[2].floorToDouble(); + _v3storage[1] = + _v3storage[1] < 0.0 + ? _v3storage[1].ceilToDouble() + : _v3storage[1].floorToDouble(); + _v3storage[0] = + _v3storage[0] < 0.0 + ? _v3storage[0].ceilToDouble() + : _v3storage[0].floorToDouble(); } /// Clone of this. diff --git a/lib/src/vector_math_64/vector4.dart b/lib/src/vector_math_64/vector4.dart index 5157b03b..2dc2c780 100644 --- a/lib/src/vector_math_64/vector4.dart +++ b/lib/src/vector_math_64/vector4.dart @@ -66,14 +66,18 @@ class Vector4 implements Vector { /// Constructs Vector4 with a [storage] that views given [buffer] starting at /// [offset]. [offset] has to be multiple of [Float64List.bytesPerElement]. Vector4.fromBuffer(ByteBuffer buffer, int offset) - : _v4storage = Float64List.view(buffer, offset, 4); + : _v4storage = Float64List.view(buffer, offset, 4); /// 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 ??= math.Random(); return Vector4( - rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble()); + rng.nextDouble(), + rng.nextDouble(), + rng.nextDouble(), + rng.nextDouble(), + ); } /// Set the values of the vector. @@ -119,7 +123,8 @@ class Vector4 implements Vector { /// Returns a printable string @override - String toString() => '[${_v4storage[0]},${_v4storage[1]},' + String toString() => + '[${_v4storage[0]},${_v4storage[1]},' '${_v4storage[2]},${_v4storage[3]}]'; /// Check if two vectors are the same. @@ -244,19 +249,23 @@ class Vector4 implements Vector { final v2 = _v4storage[1]; final v1 = _v4storage[0]; final argStorage = arg._m4storage; - _v4storage[3] = argStorage[3] * v1 + + _v4storage[3] = + argStorage[3] * v1 + argStorage[7] * v2 + argStorage[11] * v3 + argStorage[15] * v4; - _v4storage[2] = argStorage[2] * v1 + + _v4storage[2] = + argStorage[2] * v1 + argStorage[6] * v2 + argStorage[10] * v3 + argStorage[14] * v4; - _v4storage[1] = argStorage[1] * v1 + + _v4storage[1] = + argStorage[1] * v1 + argStorage[5] * v2 + argStorage[9] * v3 + argStorage[13] * v4; - _v4storage[0] = argStorage[0] * v1 + + _v4storage[0] = + argStorage[0] * v1 + argStorage[4] * v2 + argStorage[8] * v3 + argStorage[12] * v4; @@ -410,18 +419,22 @@ class Vector4 implements Vector { /// Round entries in this towards zero. void roundToZero() { - _v4storage[3] = _v4storage[3] < 0.0 - ? _v4storage[3].ceilToDouble() - : _v4storage[3].floorToDouble(); - _v4storage[2] = _v4storage[2] < 0.0 - ? _v4storage[2].ceilToDouble() - : _v4storage[2].floorToDouble(); - _v4storage[1] = _v4storage[1] < 0.0 - ? _v4storage[1].ceilToDouble() - : _v4storage[1].floorToDouble(); - _v4storage[0] = _v4storage[0] < 0.0 - ? _v4storage[0].ceilToDouble() - : _v4storage[0].floorToDouble(); + _v4storage[3] = + _v4storage[3] < 0.0 + ? _v4storage[3].ceilToDouble() + : _v4storage[3].floorToDouble(); + _v4storage[2] = + _v4storage[2] < 0.0 + ? _v4storage[2].ceilToDouble() + : _v4storage[2].floorToDouble(); + _v4storage[1] = + _v4storage[1] < 0.0 + ? _v4storage[1].ceilToDouble() + : _v4storage[1].floorToDouble(); + _v4storage[0] = + _v4storage[0] < 0.0 + ? _v4storage[0].ceilToDouble() + : _v4storage[0].floorToDouble(); } /// Create a copy of this. diff --git a/lib/src/vector_math_geometry/filters/barycentric_filter.dart b/lib/src/vector_math_geometry/filters/barycentric_filter.dart index 76529510..34845f22 100644 --- a/lib/src/vector_math_geometry/filters/barycentric_filter.dart +++ b/lib/src/vector_math_geometry/filters/barycentric_filter.dart @@ -6,8 +6,9 @@ part of '../../../vector_math_geometry.dart'; class BarycentricFilter extends GeometryFilter { @override - List get generates => - [VertexAttrib('BARYCENTRIC', 3, 'float')]; + List get generates => [ + VertexAttrib('BARYCENTRIC', 3, 'float'), + ]; @override MeshGeometry filter(MeshGeometry mesh) { diff --git a/lib/src/vector_math_geometry/filters/color_filter.dart b/lib/src/vector_math_geometry/filters/color_filter.dart index ffd351e6..cecd6f02 100644 --- a/lib/src/vector_math_geometry/filters/color_filter.dart +++ b/lib/src/vector_math_geometry/filters/color_filter.dart @@ -10,8 +10,9 @@ class ColorFilter extends GeometryFilter { ColorFilter(this.color); @override - List get generates => - [VertexAttrib('COLOR', 4, 'float')]; + List get generates => [ + VertexAttrib('COLOR', 4, 'float'), + ]; @override MeshGeometry filter(MeshGeometry mesh) { 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 2bcc2dcc..290fbce7 100644 --- a/lib/src/vector_math_geometry/filters/flat_shade_filter.dart +++ b/lib/src/vector_math_geometry/filters/flat_shade_filter.dart @@ -6,12 +6,14 @@ part of '../../../vector_math_geometry.dart'; class FlatShadeFilter extends GeometryFilter { @override - List get requires => - [VertexAttrib('POSITION', 3, 'float')]; + List get requires => [ + VertexAttrib('POSITION', 3, 'float'), + ]; @override - List get generates => - [VertexAttrib('NORMAL', 3, 'float')]; + List get generates => [ + VertexAttrib('NORMAL', 3, 'float'), + ]; @override MeshGeometry filter(MeshGeometry mesh) { diff --git a/lib/src/vector_math_geometry/filters/transform_filter.dart b/lib/src/vector_math_geometry/filters/transform_filter.dart index 97cc8a4e..ac3c6448 100644 --- a/lib/src/vector_math_geometry/filters/transform_filter.dart +++ b/lib/src/vector_math_geometry/filters/transform_filter.dart @@ -10,8 +10,9 @@ class TransformFilter extends InplaceGeometryFilter { TransformFilter(this.transform); @override - List get requires => - [VertexAttrib('POSITION', 3, 'float')]; + List get requires => [ + VertexAttrib('POSITION', 3, 'float'), + ]; @override void filterInplace(MeshGeometry mesh) { diff --git a/lib/src/vector_math_geometry/generators/attribute_generators.dart b/lib/src/vector_math_geometry/generators/attribute_generators.dart index 6c76ac40..dde0e6f7 100644 --- a/lib/src/vector_math_geometry/generators/attribute_generators.dart +++ b/lib/src/vector_math_geometry/generators/attribute_generators.dart @@ -8,7 +8,10 @@ part of '../../../vector_math_geometry.dart'; /// [normals] is assumed to be zeroed out, and much match [positions] in length. /// [indices] is assumed to represent a triangle list. void generateNormals( - Vector3List normals, Vector3List positions, Uint16List indices) { + Vector3List normals, + Vector3List positions, + Uint16List indices, +) { final p0 = Vector3.zero(), p1 = Vector3.zero(), p2 = Vector3.zero(), @@ -58,8 +61,13 @@ void generateNormals( /// vec4 bitangent = cross(normal, tangent.xyz) * tangent.w; /// Derived from the granddaddy of all tangent generation functions: /// http://www.terathon.com/code/tangent.html -void generateTangents(Vector4List tangents, Vector3List positions, - Vector3List normals, Vector2List texCoords, Uint16List indices) { +void generateTangents( + Vector4List tangents, + Vector3List positions, + Vector3List normals, + Vector2List texCoords, + Uint16List indices, +) { final p0 = Vector3.zero(), p1 = Vector3.zero(), p2 = Vector3.zero(), @@ -95,10 +103,16 @@ void generateTangents(Vector4List tangents, Vector3List positions, final r = 1.0 / (uv1.x * uv2.y - uv2.x * uv1.y); - udir.setValues((uv2.y * p1.x - uv1.y * p2.x) * r, - (uv2.y * p1.y - uv1.y * p2.y) * r, (uv2.y * p1.z - uv1.y * p2.z) * r); - vdir.setValues((uv1.x * p2.x - uv2.x * p1.x) * r, - (uv1.x * p2.y - uv2.x * p1.y) * r, (uv1.x * p2.z - uv2.x * p1.z) * r); + 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, + ); + vdir.setValues( + (uv1.x * p2.x - uv2.x * p1.x) * r, + (uv1.x * p2.y - uv2.x * p1.y) * r, + (uv1.x * p2.z - uv2.x * p1.z) * r, + ); tan0.load(i0, p0); tan0[i0] = p0..add(udir); diff --git a/lib/src/vector_math_geometry/generators/circle_generator.dart b/lib/src/vector_math_geometry/generators/circle_generator.dart index 63d55bf5..b8abdd3c 100644 --- a/lib/src/vector_math_geometry/generators/circle_generator.dart +++ b/lib/src/vector_math_geometry/generators/circle_generator.dart @@ -16,12 +16,14 @@ class CircleGenerator extends GeometryGenerator { @override int get indexCount => _segments * 3; - MeshGeometry createCircle(double radius, - {GeometryGeneratorFlags? flags, - List? filters, - int segments = 64, - double thetaStart = 0.0, - double thetaLength = math.pi * 2.0}) { + MeshGeometry createCircle( + double radius, { + GeometryGeneratorFlags? flags, + List? filters, + int segments = 64, + double thetaStart = 0.0, + double thetaLength = math.pi * 2.0, + }) { _radius = radius; _segments = segments; _thetaStart = thetaStart; @@ -47,7 +49,10 @@ class CircleGenerator extends GeometryGenerator { @override void generateVertexTexCoords( - Vector2List texCoords, Vector3List positions, Uint16List indices) { + Vector2List texCoords, + Vector3List positions, + Uint16List indices, + ) { final v = Vector2(0.5, 0.5); texCoords[0] = v; var index = 1; diff --git a/lib/src/vector_math_geometry/generators/cube_generator.dart b/lib/src/vector_math_geometry/generators/cube_generator.dart index dcbbc637..9059c6cf 100644 --- a/lib/src/vector_math_geometry/generators/cube_generator.dart +++ b/lib/src/vector_math_geometry/generators/cube_generator.dart @@ -15,8 +15,13 @@ class CubeGenerator extends GeometryGenerator { @override int get indexCount => 36; - MeshGeometry createCube(num width, num height, num depth, - {GeometryGeneratorFlags? flags, List? filters}) { + MeshGeometry createCube( + num width, + num height, + num depth, { + GeometryGeneratorFlags? flags, + List? filters, + }) { _width = width.toDouble(); _height = height.toDouble(); _depth = depth.toDouble(); @@ -62,7 +67,7 @@ class CubeGenerator extends GeometryGenerator { 22, 20, 22, - 23 + 23, ]); } @@ -107,7 +112,10 @@ class CubeGenerator extends GeometryGenerator { @override void generateVertexTexCoords( - Vector2List texCoords, Vector3List positions, Uint16List indices) { + Vector2List texCoords, + Vector3List positions, + Uint16List indices, + ) { // Front texCoords[0] = Vector2(1.0, 0.0); texCoords[1] = Vector2(0.0, 0.0); diff --git a/lib/src/vector_math_geometry/generators/cylinder_generator.dart b/lib/src/vector_math_geometry/generators/cylinder_generator.dart index bdcfdbf8..2667ca42 100644 --- a/lib/src/vector_math_geometry/generators/cylinder_generator.dart +++ b/lib/src/vector_math_geometry/generators/cylinder_generator.dart @@ -16,10 +16,14 @@ class CylinderGenerator extends GeometryGenerator { @override int get indexCount => (_segments * 6) + ((_segments - 2) * 6); - MeshGeometry createCylinder(num topRadius, num bottomRadius, num height, - {int segments = 16, - GeometryGeneratorFlags? flags, - List? filters}) { + MeshGeometry createCylinder( + num topRadius, + num bottomRadius, + num height, { + int segments = 16, + GeometryGeneratorFlags? flags, + List? filters, + }) { _topRadius = topRadius.toDouble(); _bottomRadius = bottomRadius.toDouble(); _height = height.toDouble(); @@ -70,38 +74,53 @@ class CylinderGenerator extends GeometryGenerator { for (var x = 0; x <= _segments; ++x) { final u = x / _segments; - positions[i++] = Vector3(_topRadius * math.cos(u * math.pi * 2.0), - _height * 0.5, _topRadius * math.sin(u * math.pi * 2.0)); + positions[i++] = Vector3( + _topRadius * math.cos(u * math.pi * 2.0), + _height * 0.5, + _topRadius * math.sin(u * math.pi * 2.0), + ); } // Bottom for (var x = 0; x <= _segments; ++x) { final u = x / _segments; - positions[i++] = Vector3(_bottomRadius * math.cos(u * math.pi * 2.0), - _height * -0.5, _bottomRadius * math.sin(u * math.pi * 2.0)); + positions[i++] = Vector3( + _bottomRadius * math.cos(u * math.pi * 2.0), + _height * -0.5, + _bottomRadius * math.sin(u * math.pi * 2.0), + ); } // Top cap for (var x = 0; x < _segments; ++x) { final u = x / _segments; - positions[i++] = Vector3(_topRadius * math.cos(u * math.pi * 2.0), - _height * 0.5, _topRadius * math.sin(u * math.pi * 2.0)); + positions[i++] = Vector3( + _topRadius * math.cos(u * math.pi * 2.0), + _height * 0.5, + _topRadius * math.sin(u * math.pi * 2.0), + ); } // Bottom cap for (var x = 0; x < _segments; ++x) { final u = x / _segments; - positions[i++] = Vector3(_bottomRadius * math.cos(u * math.pi * 2.0), - _height * -0.5, _bottomRadius * math.sin(u * math.pi * 2.0)); + positions[i++] = 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) { + Vector2List texCoords, + Vector3List positions, + Uint16List indices, + ) { var i = 0; // Cylinder top @@ -119,15 +138,19 @@ class CylinderGenerator extends GeometryGenerator { // Top cap for (var x = 0; x < _segments; ++x) { final r = (x / _segments) * math.pi * 2.0; - texCoords[i++] = - Vector2(math.cos(r) * 0.5 + 0.5, math.sin(r) * 0.5 + 0.5); + texCoords[i++] = Vector2( + math.cos(r) * 0.5 + 0.5, + math.sin(r) * 0.5 + 0.5, + ); } // Bottom cap for (var x = 0; x < _segments; ++x) { final r = (x / _segments) * math.pi * 2.0; - texCoords[i++] = - Vector2(math.cos(r) * 0.5 + 0.5, math.sin(r) * 0.5 + 0.5); + texCoords[i++] = Vector2( + math.cos(r) * 0.5 + 0.5, + math.sin(r) * 0.5 + 0.5, + ); } } } diff --git a/lib/src/vector_math_geometry/generators/geometry_generator.dart b/lib/src/vector_math_geometry/generators/geometry_generator.dart index 3bc5dd85..43908927 100644 --- a/lib/src/vector_math_geometry/generators/geometry_generator.dart +++ b/lib/src/vector_math_geometry/generators/geometry_generator.dart @@ -9,16 +9,21 @@ class GeometryGeneratorFlags { final bool normals; final bool tangents; - GeometryGeneratorFlags( - {this.texCoords = true, this.normals = true, this.tangents = true}); + GeometryGeneratorFlags({ + this.texCoords = true, + this.normals = true, + this.tangents = true, + }); } abstract class GeometryGenerator { int get vertexCount; int get indexCount; - MeshGeometry createGeometry( - {GeometryGeneratorFlags? flags, List? filters}) { + MeshGeometry createGeometry({ + GeometryGeneratorFlags? flags, + List? filters, + }) { flags ??= GeometryGeneratorFlags(); VertexAttrib positionAttrib; @@ -81,8 +86,13 @@ abstract class GeometryGenerator { view = mesh.getViewForAttrib('TANGENT'); if (view is Vector4List) { tangentView = view; - generateVertexTangents(tangentView, positionView!, normalView!, - texCoordView!, mesh.indices!); + generateVertexTangents( + tangentView, + positionView!, + normalView!, + texCoordView!, + mesh.indices!, + ); } } @@ -104,7 +114,10 @@ abstract class GeometryGenerator { void generateVertexPositions(Vector3List positions, Uint16List indices); void generateVertexTexCoords( - Vector2List texCoords, Vector3List positions, Uint16List indices) { + Vector2List texCoords, + Vector3List positions, + Uint16List indices, + ) { for (var i = 0; i < positions.length; ++i) { final p = positions[i]; @@ -115,12 +128,20 @@ abstract class GeometryGenerator { } void generateVertexNormals( - Vector3List normals, Vector3List positions, Uint16List indices) { + Vector3List normals, + Vector3List positions, + Uint16List indices, + ) { generateNormals(normals, positions, indices); } - void generateVertexTangents(Vector4List tangents, Vector3List positions, - Vector3List normals, Vector2List texCoords, Uint16List indices) { + void generateVertexTangents( + Vector4List tangents, + Vector3List positions, + Vector3List normals, + Vector2List texCoords, + Uint16List indices, + ) { generateTangents(tangents, positions, normals, texCoords, indices); } } diff --git a/lib/src/vector_math_geometry/generators/ring_generator.dart b/lib/src/vector_math_geometry/generators/ring_generator.dart index 7976962e..b287c919 100644 --- a/lib/src/vector_math_geometry/generators/ring_generator.dart +++ b/lib/src/vector_math_geometry/generators/ring_generator.dart @@ -18,13 +18,16 @@ class RingGenerator extends GeometryGenerator { @override int get indexCount => _segments * 3 * 2; - MeshGeometry createRing(double innerRadius, double outerRadius, - {GeometryGeneratorFlags? flags, - List? filters, - int segments = 64, - double thetaStart = 0.0, - double thetaLength = math.pi * 2.0, - bool stripTextureCoordinates = true}) { + MeshGeometry createRing( + double innerRadius, + double outerRadius, { + GeometryGeneratorFlags? flags, + List? filters, + int segments = 64, + double thetaStart = 0.0, + double thetaLength = math.pi * 2.0, + bool stripTextureCoordinates = true, + }) { _innerRadius = innerRadius; _outerRadius = outerRadius; _segments = segments; @@ -56,7 +59,10 @@ class RingGenerator extends GeometryGenerator { @override void generateVertexTexCoords( - Vector2List texCoords, Vector3List positions, Uint16List indices) { + Vector2List texCoords, + Vector3List positions, + Uint16List indices, + ) { if (_stripTextureCoordinates) { final v = Vector2.zero(); var index = 0; diff --git a/lib/src/vector_math_geometry/generators/sphere_generator.dart b/lib/src/vector_math_geometry/generators/sphere_generator.dart index 6e9fe381..fe4e61a9 100644 --- a/lib/src/vector_math_geometry/generators/sphere_generator.dart +++ b/lib/src/vector_math_geometry/generators/sphere_generator.dart @@ -15,11 +15,13 @@ class SphereGenerator extends GeometryGenerator { @override int get indexCount => 6 * _lonSegments * _latSegments; - MeshGeometry createSphere(num radius, - {int latSegments = 16, - int lonSegments = 16, - GeometryGeneratorFlags? flags, - List? filters}) { + MeshGeometry createSphere( + num radius, { + int latSegments = 16, + int lonSegments = 16, + GeometryGeneratorFlags? flags, + List? filters, + }) { _radius = radius.toDouble(); _latSegments = latSegments; _lonSegments = lonSegments; @@ -57,15 +59,21 @@ class SphereGenerator extends GeometryGenerator { for (var x = 0; x <= _lonSegments; ++x) { final u = x / _lonSegments; - positions[i++] = Vector3(_radius * math.cos(u * math.pi * 2.0) * sv, - _radius * cv, _radius * math.sin(u * math.pi * 2.0) * sv); + positions[i++] = 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) { + Vector2List texCoords, + Vector3List positions, + Uint16List indices, + ) { var i = 0; for (var y = 0; y <= _latSegments; ++y) { final v = y / _latSegments; @@ -79,7 +87,10 @@ class SphereGenerator extends GeometryGenerator { @override void generateVertexNormals( - Vector3List normals, Vector3List positions, Uint16List indices) { + Vector3List normals, + Vector3List positions, + Uint16List indices, + ) { var i = 0; for (var y = 0; y <= _latSegments; ++y) { final v = y / _latSegments; @@ -89,8 +100,11 @@ class SphereGenerator extends GeometryGenerator { for (var x = 0; x <= _lonSegments; ++x) { final u = x / _lonSegments; - normals[i++] = Vector3(math.cos(u * math.pi * 2.0) * sv, cv, - math.sin(u * math.pi * 2.0) * sv); + normals[i++] = Vector3( + math.cos(u * math.pi * 2.0) * sv, + cv, + math.sin(u * math.pi * 2.0) * sv, + ); } } } diff --git a/lib/src/vector_math_geometry/mesh_geometry.dart b/lib/src/vector_math_geometry/mesh_geometry.dart index 6893e0f3..d76c727a 100644 --- a/lib/src/vector_math_geometry/mesh_geometry.dart +++ b/lib/src/vector_math_geometry/mesh_geometry.dart @@ -11,24 +11,27 @@ class VertexAttrib { final int stride; final int offset; - VertexAttrib(this.name, this.size, this.type) - : stride = 0, - offset = 0; + VertexAttrib(this.name, this.size, this.type) : stride = 0, offset = 0; VertexAttrib.copy(VertexAttrib attrib) - : name = attrib.name, - size = attrib.size, - type = attrib.type, - stride = attrib.stride, - offset = attrib.offset; + : name = attrib.name, + size = attrib.size, + type = attrib.type, + stride = attrib.stride, + offset = attrib.offset; VertexAttrib._internal( - this.name, this.size, this.type, this.stride, this.offset); + this.name, + this.size, + this.type, + this.stride, + this.offset, + ); VertexAttrib._resetStrideOffset(VertexAttrib attrib, this.stride, this.offset) - : name = attrib.name, - size = attrib.size, - type = attrib.type; + : name = attrib.name, + size = attrib.size, + type = attrib.type; VectorList getView(Float32List buffer) { final viewOffset = offset ~/ buffer.elementSizeInBytes; @@ -62,13 +65,13 @@ class VertexAttrib { } Map toJson() => { - 'format': format, - 'name': name, - 'offset': offset, - 'stride': stride, - 'size': size, - 'type': type - }; + 'format': format, + 'name': name, + 'offset': offset, + 'stride': stride, + 'size': size, + 'type': type, + }; } class MeshGeometry { @@ -93,16 +96,21 @@ class MeshGeometry { return MeshGeometry._internal(length, stride, attribs); } - MeshGeometry._internal(this.length, this.stride, this.attribs, - [Float32List? externBuffer]) { - buffer = externBuffer ?? + MeshGeometry._internal( + this.length, + this.stride, + this.attribs, [ + Float32List? externBuffer, + ]) { + buffer = + externBuffer ?? Float32List((length * stride) ~/ Float32List.bytesPerElement); } MeshGeometry.copy(MeshGeometry mesh) - : stride = mesh.stride, - length = mesh.length, - attribs = mesh.attribs { + : stride = mesh.stride, + length = mesh.length, + attribs = mesh.attribs { // Copy the buffer buffer = Float32List(mesh.buffer.length); buffer.setAll(0, mesh.buffer); @@ -120,7 +128,10 @@ class MeshGeometry { buffer = Float32List.fromList(jsonBuffer); } else { throw ArgumentError.value( - jsonBuffer, 'json["buffer"]', 'Value type must be List'); + jsonBuffer, + 'json["buffer"]', + 'Value type must be List', + ); } final jsonAttribs = json['attribs']; @@ -128,8 +139,11 @@ class MeshGeometry { if (jsonAttribs is Map) { jsonAttribsMap = jsonAttribs; } else { - throw ArgumentError.value(jsonBuffer, 'json["attribs"]', - 'Value type must be Map'); + throw ArgumentError.value( + jsonBuffer, + 'json["attribs"]', + 'Value type must be Map', + ); } final attribs = []; var stride = 0; @@ -146,7 +160,11 @@ class MeshGeometry { } final mesh = MeshGeometry._internal( - buffer.lengthInBytes ~/ stride, stride, attribs, buffer); + buffer.lengthInBytes ~/ stride, + stride, + attribs, + buffer, + ); final jsonIndices = json['indices']; if (jsonIndices is List) { @@ -157,7 +175,9 @@ class MeshGeometry { } factory MeshGeometry.resetAttribs( - MeshGeometry inputMesh, List attributes) { + MeshGeometry inputMesh, + List attributes, + ) { final mesh = MeshGeometry(inputMesh.length, attributes) ..indices = inputMesh.indices; @@ -168,7 +188,8 @@ class MeshGeometry { if (inputAttrib.size != attrib.size || inputAttrib.type != attrib.type) { throw Exception( - 'Attributes size or type is mismatched: ${attrib.name}'); + 'Attributes size or type is mismatched: ${attrib.name}', + ); } final inputView = inputAttrib.getView(inputMesh.buffer); @@ -184,7 +205,8 @@ class MeshGeometry { factory MeshGeometry.combine(List meshes) { if (meshes.length < 2) { throw Exception( - 'Must provide at least two MeshGeometry instances to combine.'); + 'Must provide at least two MeshGeometry instances to combine.', + ); } // When combining meshes they must all have a matching set of VertexAttribs @@ -196,14 +218,18 @@ class MeshGeometry { final srcMesh = meshes[i]; if (!firstMesh.attribsAreCompatible(srcMesh)) { throw Exception( - 'All meshes must have identical attributes to combine.'); + 'All meshes must have identical attributes to combine.', + ); } totalVerts += srcMesh.length; totalIndices += srcMesh.indices != null ? srcMesh.indices!.length : 0; } - final mesh = - MeshGeometry._internal(totalVerts, firstMesh.stride, firstMesh.attribs); + final mesh = MeshGeometry._internal( + totalVerts, + firstMesh.stride, + firstMesh.attribs, + ); if (totalIndices > 0) { mesh.indices = Uint16List(totalIndices); @@ -251,7 +277,12 @@ class MeshGeometry { jsonStride is int && jsonOffset is int) { return VertexAttrib._internal( - name, jsonSize, jsonType, jsonStride, jsonOffset); + name, + jsonSize, + jsonType, + jsonStride, + jsonOffset, + ); } else { throw UnimplementedError(); } diff --git a/lib/src/vector_math_lists/scalar_list_view.dart b/lib/src/vector_math_lists/scalar_list_view.dart index 44062a49..f00321c9 100644 --- a/lib/src/vector_math_lists/scalar_list_view.dart +++ b/lib/src/vector_math_lists/scalar_list_view.dart @@ -28,21 +28,20 @@ class ScalarListView { /// Optionally it is possible to specify an [offset] in the /// [buffer] and a [stride] between each vector. ScalarListView(int length, [int offset = 0, int stride = 0]) - : _offset = offset, - _stride = stride == 0 ? 1 : stride, - _length = length, - _buffer = Float32List(_listLength(offset, stride, length)); + : _offset = offset, + _stride = stride == 0 ? 1 : stride, + _length = length, + _buffer = Float32List(_listLength(offset, stride, length)); /// Create a new vector list from a list of vectors. /// /// Optionally it is possible to specify an [offset] in the /// [buffer] and a [stride] between each vector. ScalarListView.fromList(List list, [int offset = 0, int stride = 0]) - : _offset = offset, - _stride = stride == 0 ? 1 : stride, - _length = list.length, - _buffer = - Float32List(offset + list.length * (stride == 0 ? 1 : stride)) { + : _offset = offset, + _stride = stride == 0 ? 1 : stride, + _length = list.length, + _buffer = Float32List(offset + list.length * (stride == 0 ? 1 : stride)) { for (var i = 0; i < _length; i++) { this[i] = list[i]; } @@ -51,11 +50,12 @@ class ScalarListView { /// Create a new stride list as a view of [buffer]. Optionally it is possible /// to specify a [offset] in the [buffer] and a [stride] between each vector. 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)) ~/ - (stride == 0 ? 1 : stride), - _buffer = buffer; + : _offset = offset, + _stride = stride == 0 ? 1 : stride, + _length = + (buffer.length - math.max(0, offset - stride)) ~/ + (stride == 0 ? 1 : stride), + _buffer = buffer; int _elementIndexToBufferIndex(int index) => _offset + _stride * index; diff --git a/lib/src/vector_math_lists/vector2_list.dart b/lib/src/vector_math_lists/vector2_list.dart index 3984d6df..ec3045dd 100644 --- a/lib/src/vector_math_lists/vector2_list.dart +++ b/lib/src/vector_math_lists/vector2_list.dart @@ -9,17 +9,17 @@ class Vector2List extends VectorList { /// Create a new vector list with [length] elements. Optionally it is possible /// to specify an [offset] in the [buffer] and a [stride] between each vector. Vector2List(int length, [int offset = 0, int stride = 0]) - : super(length, 2, offset, stride); + : super(length, 2, offset, stride); /// Create a new vector list from a list of vectors. Optionally it is possible /// to specify an [offset] in the [buffer] and a [stride] between each vector. Vector2List.fromList(List list, [int offset = 0, int stride = 0]) - : super.fromList(list, 2, offset, stride); + : super.fromList(list, 2, offset, stride); /// Create a new vector list as a view of [buffer]. Optionally it is possible /// to specify a [offset] in the [buffer] and a [stride] between each vector. Vector2List.view(Float32List buffer, [int offset = 0, int stride = 0]) - : super.view(buffer, 2, offset, stride); + : super.view(buffer, 2, offset, stride); @override Vector2 newVector() => Vector2.zero(); diff --git a/lib/src/vector_math_lists/vector3_list.dart b/lib/src/vector_math_lists/vector3_list.dart index df8d9d69..527681bf 100644 --- a/lib/src/vector_math_lists/vector3_list.dart +++ b/lib/src/vector_math_lists/vector3_list.dart @@ -9,17 +9,17 @@ class Vector3List extends VectorList { /// Create a new vector list with [length] elements. Optionally it is possible /// to specify an [offset] in the [buffer] and a [stride] between each vector. Vector3List(int length, [int offset = 0, int stride = 0]) - : super(length, 3, offset, stride); + : super(length, 3, offset, stride); /// Create a new vector list from a list of vectors. Optionally it is possible /// to specify an [offset] in the [buffer] and a [stride] between each vector. Vector3List.fromList(List list, [int offset = 0, int stride = 0]) - : super.fromList(list, 3, offset, stride); + : super.fromList(list, 3, offset, stride); /// Create a new vector list as a view of [buffer]. Optionally it is possible /// to specify a [offset] in the [buffer] and a [stride] between each vector. Vector3List.view(Float32List buffer, [int offset = 0, int stride = 0]) - : super.view(buffer, 3, offset, stride); + : super.view(buffer, 3, offset, stride); @override Vector3 newVector() => Vector3.zero(); diff --git a/lib/src/vector_math_lists/vector4_list.dart b/lib/src/vector_math_lists/vector4_list.dart index 1e6453ca..f724ca72 100644 --- a/lib/src/vector_math_lists/vector4_list.dart +++ b/lib/src/vector_math_lists/vector4_list.dart @@ -9,17 +9,17 @@ class Vector4List extends VectorList { /// Create a new vector list with [length] elements. Optionally it is possible /// to specify an [offset] in the [buffer] and a [stride] between each vector. Vector4List(int length, [int offset = 0, int stride = 0]) - : super(length, 4, offset, stride); + : super(length, 4, offset, stride); /// Create a new vector list from a list of vectors. Optionally it is possible /// to specify an [offset] in the [buffer] and a [stride] between each vector. Vector4List.fromList(List list, [int offset = 0, int stride = 0]) - : super.fromList(list, 4, offset, stride); + : super.fromList(list, 4, offset, stride); /// Create a new vector list as a view of [buffer]. Optionally it is possible /// to specify a [offset] in the [buffer] and a [stride] between each vector. Vector4List.view(Float32List buffer, [int offset = 0, int stride = 0]) - : super.view(buffer, 4, offset, stride); + : super.view(buffer, 4, offset, stride); @override Vector4 newVector() => Vector4.zero(); diff --git a/lib/src/vector_math_lists/vector_list.dart b/lib/src/vector_math_lists/vector_list.dart index 2628c0ff..f6635521 100644 --- a/lib/src/vector_math_lists/vector_list.dart +++ b/lib/src/vector_math_lists/vector_list.dart @@ -28,12 +28,13 @@ abstract class VectorList { /// [vectorLength]. Optionally it is possible to specify an [offset] in the /// [buffer] and a [stride] between each vector. VectorList(int length, int vectorLength, [int offset = 0, int stride = 0]) - : _vectorLength = vectorLength, - _offset = offset, - _stride = stride == 0 ? vectorLength : stride, - _length = length, - _buffer = Float32List( - VectorList._listLength(offset, stride, vectorLength, length)) { + : _vectorLength = vectorLength, + _offset = offset, + _stride = stride == 0 ? vectorLength : stride, + _length = length, + _buffer = Float32List( + VectorList._listLength(offset, stride, vectorLength, length), + ) { if (_stride < _vectorLength) { throw ArgumentError('Stride cannot be smaller than the vector size.'); } @@ -42,14 +43,18 @@ abstract class VectorList { /// 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, - [int offset = 0, int stride = 0]) - : _vectorLength = vectorLength, - _offset = offset, - _stride = stride == 0 ? vectorLength : stride, - _length = list.length, - _buffer = Float32List( - offset + list.length * (stride == 0 ? vectorLength : stride)) { + VectorList.fromList( + List list, + int vectorLength, [ + int offset = 0, + int stride = 0, + ]) : _vectorLength = vectorLength, + _offset = offset, + _stride = stride == 0 ? vectorLength : stride, + _length = list.length, + _buffer = Float32List( + offset + list.length * (stride == 0 ? vectorLength : stride), + ) { if (_stride < _vectorLength) { throw ArgumentError('Stride cannot be smaller than the vector size.'); } @@ -61,14 +66,18 @@ abstract class VectorList { /// Create a new vector list as a view of [buffer] for 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.view(Float32List buffer, int vectorLength, - [int offset = 0, int stride = 0]) - : _vectorLength = vectorLength, - _offset = offset, - _stride = stride == 0 ? vectorLength : stride, - _length = (buffer.length - math.max(0, offset - stride)) ~/ - (stride == 0 ? vectorLength : stride), - _buffer = buffer { + VectorList.view( + Float32List buffer, + int vectorLength, [ + int offset = 0, + int stride = 0, + ]) : _vectorLength = vectorLength, + _offset = offset, + _stride = stride == 0 ? vectorLength : stride, + _length = + (buffer.length - math.max(0, offset - stride)) ~/ + (stride == 0 ? vectorLength : stride), + _buffer = buffer { if (_stride < _vectorLength) { throw ArgumentError('Stride cannot be smaller than the vector size.'); } @@ -87,8 +96,12 @@ abstract class VectorList { /// 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 src, { + int srcOffset = 0, + int offset = 0, + int count = 0, + }) { if (count == 0) { count = math.min(length - offset, src.length - srcOffset); } diff --git a/lib/src/vector_math_operations/matrix.dart b/lib/src/vector_math_operations/matrix.dart index 2fd75515..946a5ce8 100644 --- a/lib/src/vector_math_operations/matrix.dart +++ b/lib/src/vector_math_operations/matrix.dart @@ -130,8 +130,14 @@ class Matrix44Operations { throw UnimplementedError(); /// [out] = [a] * [b]; Starting at [outOffset], [aOffset], and [bOffset]. - static void multiply(Float32List out, int outOffset, Float32List a, - int aOffset, Float32List b, int bOffset) { + static void multiply( + Float32List out, + int outOffset, + Float32List a, + int aOffset, + Float32List b, + int bOffset, + ) { final a00 = a[aOffset++]; final a01 = a[aOffset++]; final a02 = a[aOffset++]; @@ -195,8 +201,14 @@ class Matrix44Operations { /// Transform the 4D [vector] starting at [vectorOffset] by the 4x4 [matrix] /// 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) { + static void transform4( + Float32List out, + int outOffset, + Float32List matrix, + int matrixOffset, + Float32List vector, + int vectorOffset, + ) { final x = vector[vectorOffset++]; final y = vector[vectorOffset++]; final z = vector[vectorOffset++]; @@ -225,8 +237,14 @@ class Matrix44Operations { /// Transform the 3D [vector] starting at [vectorOffset] by the 4x4 [matrix] /// starting at [matrixOffset]. Store result in [out] starting at [outOffset]. - static void transform3(Float32List out, int outOffset, Float32List matrix, - int matrixOffset, Float32List vector, int vectorOffset) {} + static void transform3( + Float32List out, + int outOffset, + Float32List matrix, + int matrixOffset, + Float32List vector, + int vectorOffset, + ) {} /// Transpose the 4x4 [matrix] starting at [offset]. static void transpose(Float32List matrix, int offset) {} @@ -262,29 +280,39 @@ class Matrix44Operations { /// Float32x4List. class Matrix44SIMDOperations { /// [out] = [A] * [B]; Starting at [outOffset], [aOffset], and [bOffset]. - static void multiply(Float32x4List out, int outOffset, Float32x4List A, - int aOffset, Float32x4List B, int bOffset) { + static void multiply( + Float32x4List out, + int outOffset, + Float32x4List A, + int aOffset, + Float32x4List B, + int bOffset, + ) { final a0 = A[aOffset++]; final a1 = A[aOffset++]; final a2 = A[aOffset++]; final a3 = A[aOffset++]; final b0 = B[bOffset++]; - out[outOffset++] = b0.shuffle(Float32x4.xxxx) * a0 + + out[outOffset++] = + b0.shuffle(Float32x4.xxxx) * a0 + b0.shuffle(Float32x4.yyyy) * a1 + b0.shuffle(Float32x4.zzzz) * a2 + b0.shuffle(Float32x4.wwww) * a3; final b1 = B[bOffset++]; - out[outOffset++] = b1.shuffle(Float32x4.xxxx) * a0 + + out[outOffset++] = + b1.shuffle(Float32x4.xxxx) * a0 + b1.shuffle(Float32x4.yyyy) * a1 + b1.shuffle(Float32x4.zzzz) * a2 + b1.shuffle(Float32x4.wwww) * a3; final b2 = B[bOffset++]; - out[outOffset++] = b2.shuffle(Float32x4.xxxx) * a0 + + out[outOffset++] = + b2.shuffle(Float32x4.xxxx) * a0 + b2.shuffle(Float32x4.yyyy) * a1 + b2.shuffle(Float32x4.zzzz) * a2 + b2.shuffle(Float32x4.wwww) * a3; final b3 = B[bOffset++]; - out[outOffset++] = b3.shuffle(Float32x4.xxxx) * a0 + + out[outOffset++] = + b3.shuffle(Float32x4.xxxx) * a0 + b3.shuffle(Float32x4.yyyy) * a1 + b3.shuffle(Float32x4.zzzz) * a2 + b3.shuffle(Float32x4.wwww) * a3; @@ -292,8 +320,14 @@ class Matrix44SIMDOperations { /// Transform the 4D [vector] starting at [vectorOffset] by the 4x4 [matrix] /// 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) { + static void transform4( + Float32x4List out, + int outOffset, + Float32x4List matrix, + int matrixOffset, + Float32x4List vector, + int vectorOffset, + ) { final v = vector[vectorOffset]; final xxxx = v.shuffle(Float32x4.xxxx); var z = Float32x4.zero(); diff --git a/pubspec.yaml b/pubspec.yaml index 22b2ebd2..833ea249 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,16 +1,16 @@ name: vector_math -version: 2.2.0 +version: 2.2.1-wip description: A Vector Math library for 2D and 3D applications. repository: https://github.com/google/vector_math.dart environment: - sdk: ^3.1.0 + sdk: ^3.7.0 dev_dependencies: benchmark_harness: ^2.0.0 - build_runner: ^2.2.1 - build_test: ^2.1.2 - build_web_compilers: ^4.0.3 + build_runner: ^2.5.0 + build_test: ^3.0.0 + build_web_compilers: ^4.1.1 dart_flutter_team_lints: ^3.0.0 - path: ^1.8.0 - test: ^1.21.6 + path: ^1.9.0 + test: ^1.25.9 diff --git a/test/aabb2_test.dart b/test/aabb2_test.dart index 7bb4cbb7..a4d60446 100644 --- a/test/aabb2_test.dart +++ b/test/aabb2_test.dart @@ -112,10 +112,16 @@ void testAabb2IntersectionAabb2() { expect(parent.intersectsWithAabb2(grandParent), isTrue); expect(grandParent.intersectsWithAabb2(parent), isTrue); - expect(siblingOne.intersectsWithAabb2(siblingTwo), isTrue, - reason: 'Touching edges are counted as intersection.'); - expect(siblingOne.intersectsWithAabb2(siblingThree), isTrue, - reason: 'Touching corners are counted as intersection.'); + expect( + siblingOne.intersectsWithAabb2(siblingTwo), + isTrue, + reason: 'Touching edges are counted as intersection.', + ); + expect( + siblingOne.intersectsWithAabb2(siblingThree), + isTrue, + reason: 'Touching corners are counted as intersection.', + ); } void testAabb2IntersectionVector2() { diff --git a/test/aabb3_test.dart b/test/aabb3_test.dart index a331bc1a..f61b7d4b 100644 --- a/test/aabb3_test.dart +++ b/test/aabb3_test.dart @@ -59,10 +59,14 @@ void testAabb3CopyCenterAndHalfExtents() { } void testAabb3setCenterAndHalfExtents() { - final a1 = - Aabb3.centerAndHalfExtents($v3(0.0, 0.0, 0.0), $v3(10.0, 20.0, 30.0)); + final a1 = Aabb3.centerAndHalfExtents( + $v3(0.0, 0.0, 0.0), + $v3(10.0, 20.0, 30.0), + ); final a2 = Aabb3.centerAndHalfExtents( - $v3(-10.0, -20.0, -30.0), $v3(10.0, 20.0, 30.0)); + $v3(-10.0, -20.0, -30.0), + $v3(10.0, 20.0, 30.0), + ); relativeTest(a1.min, $v3(-10.0, -20.0, -30.0)); relativeTest(a1.max, $v3(10.0, 20.0, 30.0)); @@ -80,8 +84,10 @@ void testAabb3setSphere() { } void testAabb3setRay() { - final r = - Ray.originDirection($v3(1.0, 2.0, 3.0), $v3(1.0, 5.0, -1.0)..normalize()); + final r = Ray.originDirection( + $v3(1.0, 2.0, 3.0), + $v3(1.0, 5.0, -1.0)..normalize(), + ); final a = Aabb3.fromRay(r, 0.0, 10.0); expect(a.intersectsWithVector3(r.at(0.0)), isTrue); @@ -90,7 +96,10 @@ void testAabb3setRay() { void testAabb3setTriangle() { final t = Triangle.points( - $v3(2.0, 0.0, 0.0), $v3(0.0, 2.0, 0.0), $v3(0.0, 0.0, 2.0)); + $v3(2.0, 0.0, 0.0), + $v3(0.0, 2.0, 0.0), + $v3(0.0, 0.0, 2.0), + ); final a = Aabb3.fromTriangle(t); expect(a.intersectsWithVector3(t.point0), isTrue); @@ -99,8 +108,12 @@ void testAabb3setTriangle() { } void testAabb3setQuad() { - final q = Quad.points($v3(2.0, 0.0, 0.0), $v3(0.0, 2.0, 0.0), - $v3(0.0, 0.0, 2.0), $v3(0.0, 0.0, -2.0)); + final q = Quad.points( + $v3(2.0, 0.0, 0.0), + $v3(0.0, 2.0, 0.0), + $v3(0.0, 0.0, 2.0), + $v3(0.0, 0.0, -2.0), + ); final a = Aabb3.fromQuad(q); expect(a.intersectsWithVector3(q.point0), isTrue); @@ -148,13 +161,25 @@ void testAabb3ContainsVector3() { void testAabb3ContainsTriangle() { final parent = Aabb3.minMax($v3(1.0, 1.0, 1.0), $v3(8.0, 8.0, 8.0)); final child = Triangle.points( - $v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0)); + $v3(2.0, 2.0, 2.0), + $v3(3.0, 3.0, 3.0), + $v3(4.0, 4.0, 4.0), + ); final edge = Triangle.points( - $v3(1.0, 1.0, 1.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0)); + $v3(1.0, 1.0, 1.0), + $v3(3.0, 3.0, 3.0), + $v3(4.0, 4.0, 4.0), + ); final cutting = Triangle.points( - $v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(14.0, 14.0, 14.0)); + $v3(2.0, 2.0, 2.0), + $v3(3.0, 3.0, 3.0), + $v3(14.0, 14.0, 14.0), + ); final outside = Triangle.points( - $v3(0.0, 0.0, 0.0), $v3(-3.0, -3.0, -3.0), $v3(-4.0, -4.0, -4.0)); + $v3(0.0, 0.0, 0.0), + $v3(-3.0, -3.0, -3.0), + $v3(-4.0, -4.0, -4.0), + ); expect(parent.containsTriangle(child), isTrue); expect(parent.containsTriangle(edge), isFalse); @@ -187,10 +212,16 @@ void testAabb3IntersectionAabb3() { expect(parent.intersectsWithAabb3(grandParent), isTrue); expect(grandParent.intersectsWithAabb3(parent), isTrue); - expect(siblingOne.intersectsWithAabb3(siblingTwo), isTrue, - reason: 'Touching edges are counted as intersection.'); - expect(siblingOne.intersectsWithAabb3(siblingThree), isTrue, - reason: 'Touching corners are counted as intersection.'); + expect( + siblingOne.intersectsWithAabb3(siblingTwo), + isTrue, + reason: 'Touching edges are counted as intersection.', + ); + expect( + siblingOne.intersectsWithAabb3(siblingThree), + isTrue, + reason: 'Touching corners are counted as intersection.', + ); } void testAabb3IntersectionSphere() { @@ -207,13 +238,25 @@ void testAabb3IntersectionSphere() { void testIntersectionTriangle() { final parent = Aabb3.minMax($v3(1.0, 1.0, 1.0), $v3(8.0, 8.0, 8.0)); final child = Triangle.points( - $v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0)); + $v3(2.0, 2.0, 2.0), + $v3(3.0, 3.0, 3.0), + $v3(4.0, 4.0, 4.0), + ); final edge = Triangle.points( - $v3(1.0, 1.0, 1.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0)); + $v3(1.0, 1.0, 1.0), + $v3(3.0, 3.0, 3.0), + $v3(4.0, 4.0, 4.0), + ); final cutting = Triangle.points( - $v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(14.0, 14.0, 14.0)); + $v3(2.0, 2.0, 2.0), + $v3(3.0, 3.0, 3.0), + $v3(14.0, 14.0, 14.0), + ); final outside = Triangle.points( - $v3(0.0, 0.0, 0.0), $v3(-3.0, -3.0, -3.0), $v3(-4.0, -4.0, -4.0)); + $v3(0.0, 0.0, 0.0), + $v3(-3.0, -3.0, -3.0), + $v3(-4.0, -4.0, -4.0), + ); expect(parent.intersectsWithTriangle(child), isTrue); expect(parent.intersectsWithTriangle(edge), isTrue); @@ -222,23 +265,40 @@ void testIntersectionTriangle() { // Special tests final testAabb = Aabb3.minMax( - $v3(20.458911895751953, -36.607460021972656, 2.549999952316284), - $v3(21.017810821533203, -36.192543029785156, 3.049999952316284)); + $v3(20.458911895751953, -36.607460021972656, 2.549999952316284), + $v3(21.017810821533203, -36.192543029785156, 3.049999952316284), + ); final testTriangle = Triangle.points( - $v3(20.5, -36.5, 3.5), $v3(21.5, -36.5, 2.5), $v3(20.5, -36.5, 2.5)); + $v3(20.5, -36.5, 3.5), + $v3(21.5, -36.5, 2.5), + $v3(20.5, -36.5, 2.5), + ); expect(testAabb.intersectsWithTriangle(testTriangle), isTrue); final aabb = Aabb3.minMax( - $v3(19.07674217224121, -39.46818161010742, 2.299999952316284), - $v3(19.40754508972168, -38.9503288269043, 2.799999952316284)); + $v3(19.07674217224121, -39.46818161010742, 2.299999952316284), + $v3(19.40754508972168, -38.9503288269043, 2.799999952316284), + ); final triangle4 = Triangle.points( - $v3(18.5, -39.5, 2.5), $v3(19.5, -39.5, 2.5), $v3(19.5, -38.5, 2.5)); + $v3(18.5, -39.5, 2.5), + $v3(19.5, -39.5, 2.5), + $v3(19.5, -38.5, 2.5), + ); final triangle4_1 = Triangle.points( - $v3(19.5, -38.5, 2.5), $v3(19.5, -39.5, 2.5), $v3(18.5, -39.5, 2.5)); + $v3(19.5, -38.5, 2.5), + $v3(19.5, -39.5, 2.5), + $v3(18.5, -39.5, 2.5), + ); final triangle4_2 = Triangle.points( - $v3(18.5, -39.5, 2.5), $v3(19.5, -38.5, 2.5), $v3(18.5, -38.5, 2.5)); + $v3(18.5, -39.5, 2.5), + $v3(19.5, -38.5, 2.5), + $v3(18.5, -38.5, 2.5), + ); final triangle4_3 = Triangle.points( - $v3(18.5, -38.5, 2.5), $v3(19.5, -38.5, 2.5), $v3(18.5, -39.5, 2.5)); + $v3(18.5, -38.5, 2.5), + $v3(19.5, -38.5, 2.5), + $v3(18.5, -39.5, 2.5), + ); expect(aabb.intersectsWithTriangle(triangle4), isTrue); expect(aabb.intersectsWithTriangle(triangle4_1), isTrue); diff --git a/test/colors_test.dart b/test/colors_test.dart index 15c5ee9b..b6e14397 100644 --- a/test/colors_test.dart +++ b/test/colors_test.dart @@ -122,8 +122,10 @@ void testHexString() { expect(Colors.toHexString(color, alpha: true), equals('00000000')); - expect(() => Colors.fromHexString('vector_math rules!', color), - throwsA(isA())); + expect( + () => Colors.fromHexString('vector_math rules!', color), + throwsA(isA()), + ); } void testFromRgba() { diff --git a/test/frustum_test.dart b/test/frustum_test.dart index 656603e0..43f63174 100644 --- a/test/frustum_test.dart +++ b/test/frustum_test.dart @@ -9,8 +9,9 @@ import 'package:vector_math/vector_math.dart'; import 'test_utils.dart'; void testFrustumContainsVector3() { - final frustum = - Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0)); + final frustum = Frustum.matrix( + makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0), + ); expect(frustum.containsVector3($v3(0.0, 0.0, 0.0)), isFalse); expect(frustum.containsVector3($v3(0.0, 0.0, -50.0)), isTrue); @@ -28,140 +29,197 @@ void testFrustumContainsVector3() { } void testFrustumIntersectsWithSphere() { - final frustum = - Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0)); + final frustum = Frustum.matrix( + makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0), + ); expect( - frustum - .intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, 0.0), 0.0)), - isFalse); + frustum.intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, 0.0), 0.0)), + isFalse, + ); expect( - frustum - .intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, 0.0), 0.9)), - isFalse); + frustum.intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, 0.0), 0.9)), + isFalse, + ); expect( - frustum - .intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, 0.0), 1.1)), - isTrue); + frustum.intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, 0.0), 1.1)), + isTrue, + ); expect( - frustum - .intersectsWithSphere(Sphere.centerRadius($v3(0.0, 0.0, -50.0), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(0.0, 0.0, -50.0), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(0.0, 0.0, -1.001), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(0.0, 0.0, -1.001), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(-1.0, -1.0, -1.001), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(-1.0, -1.0, -1.001), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(-1.1, -1.1, -1.001), 0.0)), - isFalse); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(-1.1, -1.1, -1.001), 0.0), + ), + isFalse, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(-1.1, -1.1, -1.001), 0.5)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(-1.1, -1.1, -1.001), 0.5), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(1.0, 1.0, -1.001), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(1.0, 1.0, -1.001), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(1.1, 1.1, -1.001), 0.0)), - isFalse); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(1.1, 1.1, -1.001), 0.0), + ), + isFalse, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(1.1, 1.1, -1.001), 0.5)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(1.1, 1.1, -1.001), 0.5), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(0.0, 0.0, -99.999), 0.5)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(0.0, 0.0, -99.999), 0.5), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(0.0, 0.0, -99.999), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(0.0, 0.0, -99.999), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(-99.999, -99.999, -99.999), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(-99.999, -99.999, -99.999), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(-100.1, -100.1, -100.1), 0.0)), - isFalse); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(-100.1, -100.1, -100.1), 0.0), + ), + isFalse, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(-100.1, -100.1, -100.1), 0.5)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(-100.1, -100.1, -100.1), 0.5), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(99.999, 99.999, -99.999), 0.0)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(99.999, 99.999, -99.999), 0.0), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(100.1, 100.1, -100.1), 0.0)), - isFalse); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(100.1, 100.1, -100.1), 0.0), + ), + isFalse, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(100.1, 100.1, -100.1), 0.2)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(100.1, 100.1, -100.1), 0.2), + ), + isTrue, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(0.0, 0.0, -101.0), 0.0)), - isFalse); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(0.0, 0.0, -101.0), 0.0), + ), + isFalse, + ); expect( - frustum.intersectsWithSphere( - Sphere.centerRadius($v3(0.0, 0.0, -101.0), 1.1)), - isTrue); + frustum.intersectsWithSphere( + Sphere.centerRadius($v3(0.0, 0.0, -101.0), 1.1), + ), + isTrue, + ); } void testFrustumIntersectsWithAabb3() { - final frustum = - Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0)); + final frustum = Frustum.matrix( + makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0), + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(500.0, 500.0, 500.0), $v3(1000.0, 1000.0, 1000.0))), - isFalse); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(500.0, 500.0, 500.0), $v3(1000.0, 1000.0, 1000.0)), + ), + isFalse, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(-150.0, -150.0, -150.0), $v3(150.0, 150.0, 150.0))), - isTrue); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(-150.0, -150.0, -150.0), $v3(150.0, 150.0, 150.0)), + ), + isTrue, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(-1.5, -1.5, -1.5), $v3(1.5, 1.5, 1.5))), - isTrue); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(-1.5, -1.5, -1.5), $v3(1.5, 1.5, 1.5)), + ), + isTrue, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(0.0, 0.0, -50.0), $v3(1.0, 1.0, -49.0))), - isTrue); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(0.0, 0.0, -50.0), $v3(1.0, 1.0, -49.0)), + ), + isTrue, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(0.0, 0.0, 50.0), $v3(1.0, 1.0, 51.0))), - isFalse); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(0.0, 0.0, 50.0), $v3(1.0, 1.0, 51.0)), + ), + isFalse, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(0.0, 0.0, -0.99), $v3(1.0, 1.0, 1.0))), - isFalse); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(0.0, 0.0, -0.99), $v3(1.0, 1.0, 1.0)), + ), + isFalse, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(0.0, 0.0, -1.0), $v3(1.0, 1.0, 1.0))), - isTrue); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(0.0, 0.0, -1.0), $v3(1.0, 1.0, 1.0)), + ), + isTrue, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(0.0, 1.0, -10.0), $v3(1.0, 2.0, 15.0))), - isTrue); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(0.0, 1.0, -10.0), $v3(1.0, 2.0, 15.0)), + ), + isTrue, + ); expect( - frustum.intersectsWithAabb3( - Aabb3.minMax($v3(1.1, 1.1, -1.0), $v3(2.0, 2.0, 0.0))), - isFalse); + frustum.intersectsWithAabb3( + Aabb3.minMax($v3(1.1, 1.1, -1.0), $v3(2.0, 2.0, 0.0)), + ), + isFalse, + ); } void testFrustumCalculateCorners() { - final frustum = - Frustum.matrix(makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0)); + final frustum = Frustum.matrix( + makeFrustumMatrix(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0), + ); final c0 = Vector3.zero(); final c1 = Vector3.zero(); diff --git a/test/geometry_test.dart b/test/geometry_test.dart index 6c81de58..e2803dd1 100644 --- a/test/geometry_test.dart +++ b/test/geometry_test.dart @@ -125,10 +125,16 @@ void testCombineIndices() { // Combining two meshes should generate indices that are not out of range. final sphereGenerator = SphereGenerator(); - final sphere0 = - sphereGenerator.createSphere(10.0, latSegments: 8, lonSegments: 8); - final sphere1 = - sphereGenerator.createSphere(10.0, latSegments: 8, lonSegments: 8); + final sphere0 = sphereGenerator.createSphere( + 10.0, + latSegments: 8, + lonSegments: 8, + ); + final sphere1 = sphereGenerator.createSphere( + 10.0, + latSegments: 8, + lonSegments: 8, + ); final combined = MeshGeometry.combine([sphere0, sphere1]); expect(combined.indices, everyElement(lessThan(combined.length))); diff --git a/test/matrix2_test.dart b/test/matrix2_test.dart index 9ca9f7e8..b48b87d1 100644 --- a/test/matrix2_test.dart +++ b/test/matrix2_test.dart @@ -14,15 +14,22 @@ void testMatrix2Adjoint() { final input = []; final expectedOutput = []; - 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 - 0 1''')); + 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 + 0 1'''), + ); assert(input.length == expectedOutput.length); @@ -37,8 +44,10 @@ void testMatrix2Determinant() { final input = []; final expectedOutput = []; - input.add(parseMatrix('''0.830828627896291 0.549723608291140 - 0.585264091152724 0.917193663829810''')); + input.add( + parseMatrix('''0.830828627896291 0.549723608291140 + 0.585264091152724 0.917193663829810'''), + ); expectedOutput.add(0.440297265243183); assert(input.length == expectedOutput.length); @@ -55,12 +64,14 @@ void testMatrix2Transform() { final input = Vector2(0.234245234259, 0.890723489233); final expected = Vector2( - rot.entry(0, 0) * input.x + rot.entry(0, 1) * input.y, - rot.entry(1, 0) * input.x + rot.entry(1, 1) * input.y); + rot.entry(0, 0) * input.x + rot.entry(0, 1) * input.y, + rot.entry(1, 0) * input.x + rot.entry(1, 1) * input.y, + ); final transExpected = Vector2( - rot.entry(0, 0) * input.x + rot.entry(1, 0) * input.y, - rot.entry(0, 1) * input.x + rot.entry(1, 1) * input.y); + rot.entry(0, 0) * input.x + rot.entry(1, 0) * input.y, + rot.entry(0, 1) * input.x + rot.entry(1, 1) * input.y, + ); relativeTest(rot.transformed(input), expected); relativeTest(rot.transposed().transformed(input), transExpected); diff --git a/test/matrix3_test.dart b/test/matrix3_test.dart index 4e0c3c9e..47f878ac 100644 --- a/test/matrix3_test.dart +++ b/test/matrix3_test.dart @@ -13,28 +13,42 @@ void testMatrix3Adjoint() { final input = []; final expectedOutput = []; - input.add(parseMatrix( + input.add( + parseMatrix( ''' 0.285839018820374 0.380445846975357 0.053950118666607 0.757200229110721 0.567821640725221 0.530797553008973 - 0.753729094278495 0.075854289563064 0.779167230102011''')); - expectedOutput.add(parseMatrix( + 0.753729094278495 0.075854289563064 0.779167230102011''', + ), + ); + expectedOutput.add( + parseMatrix( ''' 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.370546805539367 0.265070987960728 -0.125768101844091''', + ), + ); + input.add( + parseMatrix('''1 0 0 0 1 0 - 0 0 1''')); - expectedOutput.add(parseMatrix('''1 0 0 + 0 0 1'''), + ); + expectedOutput.add( + parseMatrix('''1 0 0 0 1 0 - 0 0 1''')); - input.add(parseMatrix('''1 0 0 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 + 0 0 0 1'''), + ); + expectedOutput.add( + parseMatrix('''1 0 0 0 0 1 0 0 0 0 1 0 - 0 0 0 1''')); + 0 0 0 1'''), + ); assert(input.length == expectedOutput.length); @@ -51,10 +65,13 @@ void testMatrix3Determinant() { final input = []; final expectedOutput = []; - input.add(parseMatrix( + input.add( + parseMatrix( '''0.285839018820374 0.380445846975357 0.053950118666607 0.757200229110721 0.567821640725221 0.530797553008973 - 0.753729094278495 0.075854289563064 0.779167230102011''')); + 0.753729094278495 0.075854289563064 0.779167230102011''', + ), + ); expectedOutput.add(0.022713604103796); assert(input.length == expectedOutput.length); @@ -71,31 +88,49 @@ void testMatrix3SelfTransposeMultiply() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''')); - inputB.add(parseMatrix( + 0.259870402850654 0.910647594429523 0.145538980384717''', + ), + ); + inputB.add( + parseMatrix( '''0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''')); - expectedOutput.add(parseMatrix( + 0.579704587365570 0.853031117721894 0.513249539867053''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.509665070066463 0.326055864494860 0.326206788210183 1.011795431418814 1.279272055656899 1.116481872383158 - 0.338435097301446 0.262379221330899 0.280398953455993''')); + 0.338435097301446 0.262379221330899 0.280398953455993''', + ), + ); - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''')); - inputB.add(parseMatrix( + 0.579704587365570 0.853031117721894 0.513249539867053''', + ), + ); + inputB.add( + parseMatrix( '''0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''')); - expectedOutput.add(parseMatrix( + 0.259870402850654 0.910647594429523 0.145538980384717''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.509665070066463 1.011795431418814 0.338435097301446 0.326055864494860 1.279272055656899 0.262379221330899 - 0.326206788210183 1.116481872383158 0.280398953455993''')); + 0.326206788210183 1.116481872383158 0.280398953455993''', + ), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -111,31 +146,49 @@ void testMatrix3SelfMultiply() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''')); - inputB.add(parseMatrix( + 0.259870402850654 0.910647594429523 0.145538980384717''', + ), + ); + inputB.add( + parseMatrix( '''0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''')); - expectedOutput.add(parseMatrix( + 0.579704587365570 0.853031117721894 0.513249539867053''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.812399915745417 0.317522849978516 0.426642592595554 0.582350288210078 0.507392169174135 0.535489283769338 - 0.911348663480233 0.399044409575883 0.555945473748377''')); + 0.911348663480233 0.399044409575883 0.555945473748377''', + ), + ); - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''')); - inputB.add(parseMatrix( + 0.579704587365570 0.853031117721894 0.513249539867053''', + ), + ); + inputB.add( + parseMatrix( '''0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''')); - expectedOutput.add(parseMatrix( + 0.259870402850654 0.910647594429523 0.145538980384717''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.392967349540540 0.912554468305858 0.260331657549835 0.222551972385485 1.077622741167203 0.247394954900102 - 0.523353251675581 1.299202246456530 0.405147467960185''')); + 0.523353251675581 1.299202246456530 0.405147467960185''', + ), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -151,31 +204,49 @@ void testMatrix3SelfMultiplyTranspose() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''')); - inputB.add(parseMatrix( + 0.259870402850654 0.910647594429523 0.145538980384717''', + ), + ); + inputB.add( + parseMatrix( '''0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''')); - expectedOutput.add(parseMatrix( + 0.579704587365570 0.853031117721894 0.513249539867053''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.564533756922142 0.253192835205285 0.824764060523193 0.455715101026938 0.502645707562004 0.735161980594196 - 0.626622330821134 0.408983306176468 1.002156614695209''')); + 0.626622330821134 0.408983306176468 1.002156614695209''', + ), + ); - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''')); - inputB.add(parseMatrix( + 0.579704587365570 0.853031117721894 0.513249539867053''', + ), + ); + inputB.add( + parseMatrix( '''0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''')); - expectedOutput.add(parseMatrix( + 0.259870402850654 0.910647594429523 0.145538980384717''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.564533756922142 0.455715101026938 0.626622330821134 0.253192835205285 0.502645707562004 0.408983306176468 - 0.824764060523193 0.735161980594196 1.002156614695209''')); + 0.824764060523193 0.735161980594196 1.002156614695209''', + ), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -193,10 +264,14 @@ void testMatrix3Transform() { final input = Vector3(1.0, 0.0, 0.0); relativeTest(rotX.transformed(input), input); - relativeTest(rotY.transformed(input), - Vector3(1.0 / math.sqrt(2.0), 0.0, -1.0 / math.sqrt(2.0))); - relativeTest(rotZ.transformed(input), - Vector3(1.0 / math.sqrt(2.0), 1.0 / math.sqrt(2.0), 0.0)); + relativeTest( + rotY.transformed(input), + Vector3(1.0 / math.sqrt(2.0), 0.0, -1.0 / math.sqrt(2.0)), + ); + relativeTest( + rotZ.transformed(input), + Vector3(1.0 / math.sqrt(2.0), 1.0 / math.sqrt(2.0), 0.0), + ); } void testMatrix3RotationX() { @@ -223,14 +298,25 @@ void testMatrix3RotationZ() { void testMatrix3Transform2() { final rotZ = Matrix3.rotationZ(math.pi / 4); final trans = Matrix3(1.0, 0.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0); - final transB = - Matrix3.fromList([1.0, 0.0, 3.0, 0.0, 1.0, 2.0, 3.0, 2.0, 1.0]); + final transB = Matrix3.fromList([ + 1.0, + 0.0, + 3.0, + 0.0, + 1.0, + 2.0, + 3.0, + 2.0, + 1.0, + ]); expect(trans, equals(transB)); final input = Vector2(1.0, 0.0); relativeTest( - rotZ.transform2(input.clone()), Vector2(math.sqrt(0.5), math.sqrt(0.5))); + rotZ.transform2(input.clone()), + Vector2(math.sqrt(0.5), math.sqrt(0.5)), + ); relativeTest(trans.transform2(input.clone()), Vector2(4.0, 2.0)); } @@ -244,11 +330,15 @@ void testMatrix3AbsoluteRotate2() { final input = Vector2(1.0, 0.0); - relativeTest(rotZ.absoluteRotate2(input.clone()), - Vector2(math.sqrt(0.5), math.sqrt(0.5))); + relativeTest( + rotZ.absoluteRotate2(input.clone()), + Vector2(math.sqrt(0.5), math.sqrt(0.5)), + ); - relativeTest(rotZcw.absoluteRotate2(input.clone()), - Vector2(math.sqrt(0.5), math.sqrt(0.5))); + relativeTest( + rotZcw.absoluteRotate2(input.clone()), + Vector2(math.sqrt(0.5), math.sqrt(0.5)), + ); } void testMatrix3ConstructorCopy() { diff --git a/test/matrix4_test.dart b/test/matrix4_test.dart index 6900e5ca..e780c9bc 100644 --- a/test/matrix4_test.dart +++ b/test/matrix4_test.dart @@ -29,7 +29,7 @@ void testMatrix4InstacingFromFloat32List() { 13.0, 14.0, 15.0, - 16.0 + 16.0, ]); final input = Matrix4.fromFloat32List(float32List); final inputB = Matrix4.fromList(float32List); @@ -74,7 +74,7 @@ void testMatrix4InstacingFromByteBuffer() { 14.0, 15.0, 16.0, - 17.0 + 17.0, ]); final buffer = float32List.buffer; final zeroOffset = Matrix4.fromBuffer(buffer, 0); @@ -118,11 +118,14 @@ void testMatrix4InstacingFromByteBuffer() { void testMatrix4Transpose() { final inputA = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''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''')); + 0.111202755293787 0.403912145588115 0.956134540229802 0.353158571222071''', + ), + ); expectedOutput.add(inputA[0].transposed()); for (var i = 0; i < inputA.length; i++) { @@ -136,19 +139,26 @@ void testMatrix4VectorMultiplication() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''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.111202755293787 0.403912145588115 0.956134540229802 0.353158571222071''', + ), + ); + inputB.add( + parseVector('''0.821194040197959 0.015403437651555 0.043023801657808 - 0.168990029462704''')); - expectedOutput.add(parseVector('''0.390706088480722 + 0.168990029462704'''), + ); + expectedOutput.add( + parseVector('''0.390706088480722 0.760902311900085 0.387152194918898 - 0.198357495624973''')); + 0.198357495624973'''), + ); assert(inputA.length == inputB.length); assert(expectedOutput.length == inputB.length); @@ -164,21 +174,30 @@ void testMatrix4Multiplication() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''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.470923348517591 0.225921780972399 0.311102286650413 0.904880968679893''', + ), + ); + inputB.add( + parseMatrix( '''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.258064695912067 0.602843089382083 0.296675873218327 0.085515797090044''', + ), + ); + expectedOutput.add( + parseMatrix( '''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.828623949506267 0.953951612073692 0.690010785130483 0.481326146122225''', + ), + ); assert(inputA.length == inputB.length); assert(expectedOutput.length == inputB.length); @@ -193,35 +212,51 @@ void testMatrix4Adjoint() { final input = []; final expectedOutput = []; - input.add(parseMatrix( + input.add( + parseMatrix( '''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( + 0.469390641058206 0.794284540683907 0.601981941401637 0.748151592823709''', + ), + ); + expectedOutput.add( + parseMatrix( '''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.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 + 0 0 0 1'''), + ); + expectedOutput.add( + parseMatrix('''1 0 0 0 0 1 0 0 0 0 1 0 - 0 0 0 1''')); + 0 0 0 1'''), + ); - input.add(parseMatrix( + input.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + expectedOutput.add( + parseMatrix( '''-0.100386867815513 0.076681891597503 -0.049082198794982 -0.021689260610181 -0.279454715225440 -0.269081505356250 0.114433412778961 0.133858687769130 0.218879650360982 0.073892735462981 0.069073300555062 -0.132069899391626 - 0.183633794399577 0.146113141160308 -0.156100829983306 -0.064859465665816''')); + 0.183633794399577 0.146113141160308 -0.156100829983306 -0.064859465665816''', + ), + ); assert(input.length == expectedOutput.length); @@ -235,25 +270,34 @@ void testMatrix4Adjoint() { void testMatrix4Determinant() { final input = []; final expectedOutput = []; - input.add(parseMatrix( + input.add( + parseMatrix( '''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''')); + 0.694828622975817 0.438744359656398 0.186872604554379 0.709364830858073''', + ), + ); expectedOutput.add(-0.199908980087990); - input.add(parseMatrix( + input.add( + parseMatrix( ''' -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''')); + 3.020318574990609 -1.197139524685751 -0.400475005629390 0.441263145991252''', + ), + ); expectedOutput.add(-5.002276533849802); - input.add(parseMatrix( + input.add( + parseMatrix( '''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''')); + 0.469390641058206 0.794284540683907 0.601981941401637 0.748151592823709''', + ), + ); expectedOutput.add(0.117969860982876); assert(input.length == expectedOutput.length); @@ -269,21 +313,30 @@ void testMatrix4SelfTransposeMultiply() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + inputB.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + expectedOutput.add( + parseMatrix( '''1.096629343508065 1.170948826011164 0.975285713492989 1.047596917860438 1.170948826011164 1.987289692246011 1.393079247172284 1.945966332001094 0.975285713492989 1.393079247172284 1.138698195167051 1.266161729169725 - 1.047596917860438 1.945966332001094 1.266161729169725 2.023122749969790''')); + 1.047596917860438 1.945966332001094 1.266161729169725 2.023122749969790''', + ), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -300,21 +353,30 @@ void testMatrix4SelfMultiply() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + inputB.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.237893273152584 0.241190507375353 0.115471053480014 0.188086069635435 0.916103942227480 1.704973929800637 1.164721763902784 1.675285658272358 0.919182849383279 1.351023203753565 1.053750106199745 1.215382950294249 - 1.508657696357159 2.344965008135463 1.450552688877760 2.316940716769603''')); + 1.508657696357159 2.344965008135463 1.450552688877760 2.316940716769603''', + ), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -331,21 +393,30 @@ void testMatrix4SelfMultiplyTranspose() { final inputB = []; final expectedOutput = []; - inputA.add(parseMatrix( + inputA.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + inputB.add( + parseMatrix( '''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( + 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', + ), + ); + expectedOutput.add( + parseMatrix( '''0.232339681975335 0.201799089276976 0.197320406329789 0.642508126615338 0.201799089276976 1.485449982570056 1.144315170085286 1.998154153033270 0.197320406329789 1.144315170085286 1.021602397682138 1.557970885061235 - 0.642508126615338 1.998154153033270 1.557970885061235 3.506347918663387''')); + 0.642508126615338 1.998154153033270 1.557970885061235 3.506347918663387''', + ), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -386,10 +457,7 @@ void testMatrix4Translation() { output3[13] = input.dotRow(1, Vector4(4, 8, 12, 1)); output3[14] = input.dotRow(2, Vector4(4, 8, 12, 1)); output3[15] = input.dotRow(3, Vector4(4, 8, 12, 1)); - relativeTest( - input.clone()..translateByDouble(4.0, 8.0, 12.0, 1.0), - output3, - ); + relativeTest(input.clone()..translateByDouble(4.0, 8.0, 12.0, 1.0), output3); relativeTest( input.clone()..translateByVector3(Vector3(4.0, 8.0, 12.0)), output3, @@ -457,10 +525,12 @@ void testMatrix4Rotate() { void testMatrix4GetRotation() { final mat4 = (Matrix4.rotationX(math.pi) * Matrix4.rotationY(-math.pi) as Matrix4) * - Matrix4.rotationZ(math.pi) as Matrix4; + Matrix4.rotationZ(math.pi) + as Matrix4; final mat3 = (Matrix3.rotationX(math.pi) * Matrix3.rotationY(-math.pi) as Matrix3) * - Matrix3.rotationZ(math.pi) as Matrix3; + Matrix3.rotationZ(math.pi) + as Matrix3; final matRot = mat4.getRotation(); relativeTest(mat3, matRot); @@ -478,8 +548,24 @@ void testMatrix4Column() { } void testMatrix4Inversion() { - final m = Matrix4(1.0, 0.0, 2.0, 2.0, 0.0, 2.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, - 1.0, 2.0, 1.0, 4.0); + final m = Matrix4( + 1.0, + 0.0, + 2.0, + 2.0, + 0.0, + 2.0, + 1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 1.0, + 1.0, + 2.0, + 1.0, + 4.0, + ); final result = Matrix4.zero(); final det = result.copyInverse(m); expect(det, 2.0); @@ -502,8 +588,24 @@ void testMatrix4Inversion() { } void testMatrix4Dot() { - final matrix = Matrix4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, - 11.0, 12.0, 13.0, 14.0, 15.0, 16.0); + final matrix = Matrix4( + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0, + 8.0, + 9.0, + 10.0, + 11.0, + 12.0, + 13.0, + 14.0, + 15.0, + 16.0, + ); final v = Vector4(1.0, 2.0, 3.0, 4.0); @@ -525,8 +627,24 @@ void testMatrix4PerspectiveTransform() { } void testMatrix4Solving() { - final A = Matrix4(2.0, 12.0, 8.0, 8.0, 20.0, 24.0, 26.0, 4.0, 8.0, 4.0, 60.0, - 12.0, 16.0, 16.0, 14.0, 64.0); + final A = Matrix4( + 2.0, + 12.0, + 8.0, + 8.0, + 20.0, + 24.0, + 26.0, + 4.0, + 8.0, + 4.0, + 60.0, + 12.0, + 16.0, + 16.0, + 14.0, + 64.0, + ); final A_small = Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0); @@ -570,7 +688,7 @@ void testMatrix4Compose() { Vector3(0.0, -7.0, 0.0), Vector3(0.0, 0.0, -8.0), Vector3(-2.0, 5.0, -9.0), - Vector3(-2.0, -5.0, -9.0) + Vector3(-2.0, -5.0, -9.0), ]; final sValues = [ @@ -582,16 +700,24 @@ void testMatrix4Compose() { Vector3(2.0, -2.0, 1.0), Vector3(-1.0, 2.0, -2.0), Vector3(-1.0, -1.0, -1.0), - Vector3(-2.0, -2.0, -2.0) + Vector3(-2.0, -2.0, -2.0), ]; final rValues = [ Quaternion.identity(), - Quaternion(0.42073549240394825, 0.42073549240394825, 0.22984884706593015, - 0.7701511529340699), - Quaternion(0.16751879124639693, -0.5709414713577319, 0.16751879124639693, - 0.7860666291368439), - Quaternion(0.0, 0.9238795292366128, 0.0, 0.38268342717215614) + Quaternion( + 0.42073549240394825, + 0.42073549240394825, + 0.22984884706593015, + 0.7701511529340699, + ), + Quaternion( + 0.16751879124639693, + -0.5709414713577319, + 0.16751879124639693, + 0.7860666291368439, + ), + Quaternion(0.0, 0.9238795292366128, 0.0, 0.38268342717215614), ]; for (var ti = 0; ti < tValues.length; ti++) { diff --git a/test/noise_test.dart b/test/noise_test.dart index 63681137..a8da0421 100644 --- a/test/noise_test.dart +++ b/test/noise_test.dart @@ -23,8 +23,10 @@ void testSimplexNoise() { // Ensure that querying those same coordinates repeats the cached value for (var i = 0; i < values2D.length; ++i) { expect(values2D[i], equals(noise.noise2D(i.toDouble(), i.toDouble()))); - expect(values3D[i], - equals(noise.noise3D(i.toDouble(), i.toDouble(), i.toDouble()))); + expect( + values3D[i], + equals(noise.noise3D(i.toDouble(), i.toDouble(), i.toDouble())), + ); } } diff --git a/test/obb3_test.dart b/test/obb3_test.dart index 43339caa..628d9d09 100644 --- a/test/obb3_test.dart +++ b/test/obb3_test.dart @@ -11,9 +11,10 @@ import 'package:vector_math/vector_math.dart'; import 'test_utils.dart'; void testCorners() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); a.copyCorner(0, corner); @@ -42,9 +43,10 @@ void testCorners() { } void testTranslate() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); a.translate(Vector3(-1.0, 2.0, 3.0)); @@ -75,9 +77,10 @@ void testTranslate() { } void testRotate() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); final matrix = Matrix3.rotationY(radians(-45.0)); @@ -109,9 +112,10 @@ void testRotate() { } void testTransform() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); final matrix = Matrix4.diagonal3Values(3.0, 3.0, 3.0); @@ -143,9 +147,10 @@ void testTransform() { } void testClosestPointTo() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(2.0, 2.0, 2.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(2.0, 2.0, 2.0); final b = Vector3(3.0, 3.0, 3.0); final c = Vector3(3.0, 3.0, -3.0); final closestPoint = Vector3.zero(); @@ -170,45 +175,55 @@ void testClosestPointTo() { } void testIntersectionObb3() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(2.0, 2.0, 2.0); - - final b = Obb3() - ..center.setValues(3.0, 0.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final c = Obb3() - ..center.setValues(0.0, 3.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final d = Obb3() - ..center.setValues(0.0, 0.0, 3.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final e = Obb3() - ..center.setValues(-3.0, 0.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final f = Obb3() - ..center.setValues(0.0, -3.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final g = Obb3() - ..center.setValues(0.0, 0.0, -3.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final u = Obb3() - ..center.setValues(1.0, 1.0, 1.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final v = Obb3() - ..center.setValues(10.0, 10.0, -10.0) - ..halfExtents.setValues(2.0, 2.0, 2.0); - - final w = Obb3() - ..center.setValues(10.0, 0.0, 0.0) - ..halfExtents.setValues(1.0, 1.0, 1.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(2.0, 2.0, 2.0); + + final b = + Obb3() + ..center.setValues(3.0, 0.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final c = + Obb3() + ..center.setValues(0.0, 3.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final d = + Obb3() + ..center.setValues(0.0, 0.0, 3.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final e = + Obb3() + ..center.setValues(-3.0, 0.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final f = + Obb3() + ..center.setValues(0.0, -3.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final g = + Obb3() + ..center.setValues(0.0, 0.0, -3.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final u = + Obb3() + ..center.setValues(1.0, 1.0, 1.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final v = + Obb3() + ..center.setValues(10.0, 10.0, -10.0) + ..halfExtents.setValues(2.0, 2.0, 2.0); + + final w = + Obb3() + ..center.setValues(10.0, 0.0, 0.0) + ..halfExtents.setValues(1.0, 1.0, 1.0); // a - b expect(a.intersectsWithObb3(b), isFalse); @@ -302,9 +317,10 @@ void testIntersectionObb3() { void testIntersectionVector3() { //final parent = new Aabb3.minMax(_v(1.0,1.0,1.0), _v(8.0,8.0,8.0)); - final parent = Obb3() - ..center.setValues(4.5, 4.5, 4.5) - ..halfExtents.setValues(3.5, 3.5, 3.5); + final parent = + Obb3() + ..center.setValues(4.5, 4.5, 4.5) + ..halfExtents.setValues(3.5, 3.5, 3.5); final child = $v3(7.0, 7.0, 7.0); final cutting = $v3(1.0, 2.0, 1.0); final outside1 = $v3(-10.0, 10.0, 10.0); @@ -329,19 +345,40 @@ void testIntersectionTriangle() { parent.center.setValues(4.5, 4.5, 4.5); parent.halfExtents.setValues(3.5, 3.5, 3.5); final child = Triangle.points( - $v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0)); + $v3(2.0, 2.0, 2.0), + $v3(3.0, 3.0, 3.0), + $v3(4.0, 4.0, 4.0), + ); final edge = Triangle.points( - $v3(1.0, 1.0, 1.0), $v3(3.0, 3.0, 3.0), $v3(4.0, 4.0, 4.0)); + $v3(1.0, 1.0, 1.0), + $v3(3.0, 3.0, 3.0), + $v3(4.0, 4.0, 4.0), + ); final cutting = Triangle.points( - $v3(2.0, 2.0, 2.0), $v3(3.0, 3.0, 3.0), $v3(14.0, 14.0, 14.0)); + $v3(2.0, 2.0, 2.0), + $v3(3.0, 3.0, 3.0), + $v3(14.0, 14.0, 14.0), + ); final outside = Triangle.points( - $v3(0.0, 0.0, 0.0), $v3(-3.0, -3.0, -3.0), $v3(-4.0, -4.0, -4.0)); + $v3(0.0, 0.0, 0.0), + $v3(-3.0, -3.0, -3.0), + $v3(-4.0, -4.0, -4.0), + ); final parallel0 = Triangle.points( - $v3(1.0, 0.0, 1.0), $v3(1.0, 10.0, 1.0), $v3(1.0, 0.0, 10.0)); + $v3(1.0, 0.0, 1.0), + $v3(1.0, 10.0, 1.0), + $v3(1.0, 0.0, 10.0), + ); final parallel1 = Triangle.points( - $v3(1.0, 4.5, 0.0), $v3(1.0, -1.0, 9.0), $v3(1.0, 10.0, 9.0)); + $v3(1.0, 4.5, 0.0), + $v3(1.0, -1.0, 9.0), + $v3(1.0, 10.0, 9.0), + ); final parallel2 = Triangle.points( - $v3(1.0, 10.0, 9.0), $v3(1.0, -1.0, 9.0), $v3(1.0, 4.5, 0.0)); + $v3(1.0, 10.0, 9.0), + $v3(1.0, -1.0, 9.0), + $v3(1.0, 4.5, 0.0), + ); expect(parent.intersectsWithTriangle(child), isTrue); expect(parent.intersectsWithTriangle(edge), isTrue); @@ -385,58 +422,89 @@ void testIntersectionTriangle() { expect(parent.intersectsWithTriangle(parallel2), isTrue); final obb = Obb3.centerExtentsAxes( - $v3(21.0, -36.400001525878906, 2.799999952316284), - $v3(0.25, 0.15000000596046448, 0.25), - $v3(0.0, 1.0, 0.0), - $v3(-1.0, 0.0, 0.0), - $v3(0.0, 0.0, 1.0)); + $v3(21.0, -36.400001525878906, 2.799999952316284), + $v3(0.25, 0.15000000596046448, 0.25), + $v3(0.0, 1.0, 0.0), + $v3(-1.0, 0.0, 0.0), + $v3(0.0, 0.0, 1.0), + ); final triangle = Triangle.points( - $v3(20.5, -36.5, 3.5), $v3(21.5, -36.5, 2.5), $v3(20.5, -36.5, 2.5)); + $v3(20.5, -36.5, 3.5), + $v3(21.5, -36.5, 2.5), + $v3(20.5, -36.5, 2.5), + ); expect(obb.intersectsWithTriangle(triangle), isTrue); final obb2 = Obb3.centerExtentsAxes( - $v3(25.15829086303711, -36.27009201049805, 3.0299079418182373), - $v3(0.25, 0.15000000596046448, 0.25), - $v3(-0.7071067690849304, 0.7071067690849304, 0.0), - $v3(-0.7071067690849304, -0.7071067690849304, 0.0), - $v3(0.0, 0.0, 1.0)); + $v3(25.15829086303711, -36.27009201049805, 3.0299079418182373), + $v3(0.25, 0.15000000596046448, 0.25), + $v3(-0.7071067690849304, 0.7071067690849304, 0.0), + $v3(-0.7071067690849304, -0.7071067690849304, 0.0), + $v3(0.0, 0.0, 1.0), + ); final triangle2 = Triangle.points( - $v3(25.5, -36.5, 2.5), $v3(25.5, -35.5, 3.5), $v3(24.5, -36.5, 2.5)); - final triangle2_1 = Triangle.points($v3(24.5, -36.5, 2.5), - $v3(25.5, -35.5, 3.5), $v3(25.5, -36.5, 2.5)); // reverse normal direction + $v3(25.5, -36.5, 2.5), + $v3(25.5, -35.5, 3.5), + $v3(24.5, -36.5, 2.5), + ); + final triangle2_1 = Triangle.points( + $v3(24.5, -36.5, 2.5), + $v3(25.5, -35.5, 3.5), + $v3(25.5, -36.5, 2.5), + ); // reverse normal direction expect(obb2.intersectsWithTriangle(triangle2), isTrue); expect(obb2.intersectsWithTriangle(triangle2_1), isTrue); final obb3 = Obb3.centerExtentsAxes( - $v3(20.937196731567383, -37.599998474121094, 2.799999952316284), - $v3(0.25, 0.15000000596046448, 0.25), - $v3(0.0, -1.0, 0.0), - $v3(1.0, 0.0, 0.0), - $v3(0.0, 0.0, 1.0)); + $v3(20.937196731567383, -37.599998474121094, 2.799999952316284), + $v3(0.25, 0.15000000596046448, 0.25), + $v3(0.0, -1.0, 0.0), + $v3(1.0, 0.0, 0.0), + $v3(0.0, 0.0, 1.0), + ); final triangle3 = Triangle.points( - $v3(20.5, -37.5, 3.5), $v3(20.5, -37.5, 2.5), $v3(21.5, -37.5, 2.5)); - final triangle3_1 = Triangle.points($v3(21.5, -37.5, 2.5), - $v3(20.5, -37.5, 2.5), $v3(20.5, -37.5, 3.5)); // reverse normal direction + $v3(20.5, -37.5, 3.5), + $v3(20.5, -37.5, 2.5), + $v3(21.5, -37.5, 2.5), + ); + final triangle3_1 = Triangle.points( + $v3(21.5, -37.5, 2.5), + $v3(20.5, -37.5, 2.5), + $v3(20.5, -37.5, 3.5), + ); // reverse normal direction expect(obb3.intersectsWithTriangle(triangle3), isTrue); expect(obb3.intersectsWithTriangle(triangle3_1), isTrue); final obb4 = Obb3.centerExtentsAxes( - $v3(19.242143630981445, -39.20925521850586, 2.549999952316284), - $v3(0.25, 0.15000000596046448, 0.25), - $v3(0.0, 1.0, 0.0), - $v3(-1.0, 0.0, 0.0), - $v3(0.0, 0.0, 1.0)); + $v3(19.242143630981445, -39.20925521850586, 2.549999952316284), + $v3(0.25, 0.15000000596046448, 0.25), + $v3(0.0, 1.0, 0.0), + $v3(-1.0, 0.0, 0.0), + $v3(0.0, 0.0, 1.0), + ); final triangle4 = Triangle.points( - $v3(18.5, -39.5, 2.5), $v3(19.5, -39.5, 2.5), $v3(19.5, -38.5, 2.5)); - final triangle4_1 = Triangle.points($v3(19.5, -38.5, 2.5), - $v3(19.5, -39.5, 2.5), $v3(18.5, -39.5, 2.5)); // reverse normal direction + $v3(18.5, -39.5, 2.5), + $v3(19.5, -39.5, 2.5), + $v3(19.5, -38.5, 2.5), + ); + final triangle4_1 = Triangle.points( + $v3(19.5, -38.5, 2.5), + $v3(19.5, -39.5, 2.5), + $v3(18.5, -39.5, 2.5), + ); // reverse normal direction final triangle4_2 = Triangle.points( - $v3(18.5, -39.5, 2.5), $v3(19.5, -38.5, 2.5), $v3(18.5, -38.5, 2.5)); - final triangle4_3 = Triangle.points($v3(18.5, -38.5, 2.5), - $v3(19.5, -38.5, 2.5), $v3(18.5, -39.5, 2.5)); // reverse normal direction + $v3(18.5, -39.5, 2.5), + $v3(19.5, -38.5, 2.5), + $v3(18.5, -38.5, 2.5), + ); + final triangle4_3 = Triangle.points( + $v3(18.5, -38.5, 2.5), + $v3(19.5, -38.5, 2.5), + $v3(18.5, -39.5, 2.5), + ); // reverse normal direction expect(obb4.intersectsWithTriangle(triangle4), isTrue); expect(obb4.intersectsWithTriangle(triangle4_1), isTrue); diff --git a/test/opengl_matrix_test.dart b/test/opengl_matrix_test.dart index e2bedd0a..e9b48e3a 100644 --- a/test/opengl_matrix_test.dart +++ b/test/opengl_matrix_test.dart @@ -52,10 +52,14 @@ void testFrustumMatrix() { final frustum = makeFrustumMatrix(l, r, b, t, n, f); relativeTest(frustum.getColumn(0), Vector4(2 * n / (r - l), 0.0, 0.0, 0.0)); relativeTest(frustum.getColumn(1), Vector4(0.0, 2 * n / (t - b), 0.0, 0.0)); - relativeTest(frustum.getColumn(2), - Vector4((r + l) / (r - l), (t + b) / (t - b), -(f + n) / (f - n), -1.0)); relativeTest( - frustum.getColumn(3), Vector4(0.0, 0.0, -2.0 * f * n / (f - n), 0.0)); + frustum.getColumn(2), + Vector4((r + l) / (r - l), (t + b) / (t - b), -(f + n) / (f - n), -1.0), + ); + relativeTest( + frustum.getColumn(3), + Vector4(0.0, 0.0, -2.0 * f * n / (f - n), 0.0), + ); } void testPerspectiveMatrix() { @@ -68,7 +72,9 @@ void testPerspectiveMatrix() { relativeTest(perspective.getColumn(0), Vector4(0.5, 0.0, 0.0, 0.0)); relativeTest(perspective.getColumn(1), Vector4(0.0, 1.0, 0.0, 0.0)); relativeTest( - perspective.getColumn(2), Vector4(0.0, 0.0, -101.0 / 99.0, -1.0)); + perspective.getColumn(2), + Vector4(0.0, 0.0, -101.0 / 99.0, -1.0), + ); relativeTest(perspective.getColumn(3), Vector4(0.0, 0.0, -200.0 / 99.0, 0.0)); } @@ -95,8 +101,10 @@ void testOrthographicMatrix() { relativeTest(ortho.getColumn(0), Vector4(2 / (r - l), 0.0, 0.0, 0.0)); relativeTest(ortho.getColumn(1), Vector4(0.0, 2 / (t - b), 0.0, 0.0)); relativeTest(ortho.getColumn(2), Vector4(0.0, 0.0, -2 / (f - n), 0.0)); - relativeTest(ortho.getColumn(3), - Vector4(-(r + l) / (r - l), -(t + b) / (t - b), -(f + n) / (f - n), 1.0)); + relativeTest( + ortho.getColumn(3), + Vector4(-(r + l) / (r - l), -(t + b) / (t - b), -(f + n) / (f - n), 1.0), + ); } void testModelMatrix() { diff --git a/test/quad_test.dart b/test/quad_test.dart index b97e0dbe..939d8d9e 100644 --- a/test/quad_test.dart +++ b/test/quad_test.dart @@ -9,8 +9,12 @@ import 'package:vector_math/vector_math.dart'; import 'test_utils.dart'; void testQuadCopy() { - final quad = Quad.points(Vector3(1.0, 0.0, 1.0), Vector3(0.0, 2.0, 1.0), - Vector3(1.0, 0.0, 0.0), Vector3(0.0, 2.0, 0.0)); + final quad = Quad.points( + Vector3(1.0, 0.0, 1.0), + Vector3(0.0, 2.0, 1.0), + Vector3(1.0, 0.0, 0.0), + Vector3(0.0, 2.0, 0.0), + ); final quadCopy = Quad.copy(quad); relativeTest(quadCopy.point0, quad.point0); @@ -20,8 +24,12 @@ void testQuadCopy() { } void testQuadCopyNormalInto() { - final quad = Quad.points(Vector3(1.0, 0.0, 1.0), Vector3(0.0, 2.0, 1.0), - Vector3(1.0, 0.0, 0.0), Vector3(0.0, 2.0, 0.0)); + final quad = Quad.points( + Vector3(1.0, 0.0, 1.0), + Vector3(0.0, 2.0, 1.0), + Vector3(1.0, 0.0, 0.0), + Vector3(0.0, 2.0, 0.0), + ); final normal = Vector3.zero(); quad.copyNormalInto(normal); @@ -30,8 +38,12 @@ void testQuadCopyNormalInto() { } void testQuadCopyTriangles() { - final quad = Quad.points(Vector3(1.0, 0.0, 1.0), Vector3(0.0, 2.0, 1.0), - Vector3(1.0, 0.0, 0.0), Vector3(0.0, 2.0, 0.0)); + final quad = Quad.points( + Vector3(1.0, 0.0, 1.0), + Vector3(0.0, 2.0, 1.0), + Vector3(1.0, 0.0, 0.0), + Vector3(0.0, 2.0, 0.0), + ); final t1 = Triangle(); final t2 = Triangle(); final normal = Vector3.zero(); @@ -62,8 +74,10 @@ void testQuadEquals() { expect(quad, isNot(Quad.points(v1, v2, Vector3.zero(), v4))); expect(quad, isNot(Quad.points(v1, v2, v3, Vector3.zero()))); - expect(Quad.points(v1, v2, v3, v4).hashCode, - equals(Quad.points(v1, v2, v3, v4).hashCode)); + expect( + Quad.points(v1, v2, v3, v4).hashCode, + equals(Quad.points(v1, v2, v3, v4).hashCode), + ); } void main() { diff --git a/test/quaternion_test.dart b/test/quaternion_test.dart index af1fab46..189e76e3 100644 --- a/test/quaternion_test.dart +++ b/test/quaternion_test.dart @@ -25,8 +25,10 @@ void testQuaternionInstacingFromByteBuffer() { final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0]); final buffer = float32List.buffer; final zeroOffset = Quaternion.fromBuffer(buffer, 0); - final offsetVector = - Quaternion.fromBuffer(buffer, Float32List.bytesPerElement); + final offsetVector = Quaternion.fromBuffer( + buffer, + Float32List.bytesPerElement, + ); expect(zeroOffset.x, equals(1.0)); expect(zeroOffset.y, equals(2.0)); @@ -65,18 +67,26 @@ void testQuaternionMatrixRoundTrip(List input) { } } -void testQuaternionMultiply(List inputA, List inputB, - List expectedOutput) { +void testQuaternionMultiply( + List inputA, + List inputB, + List expectedOutput, +) { for (var i = 0; i < inputA.length; i++) { final output = inputA[i] * inputB[i]; relativeTest(output, expectedOutput[i]); } } -void testQuaternionVectorRotate(List inputA, List inputB, - List expectedOutput) { - assert((inputA.length == inputB.length) && - (inputB.length == expectedOutput.length)); +void testQuaternionVectorRotate( + List inputA, + List inputB, + List expectedOutput, +) { + assert( + (inputA.length == inputB.length) && + (inputB.length == expectedOutput.length), + ); for (var i = 0; i < inputA.length; i++) { final output = inputA[i].rotate(inputB[i]); relativeTest(output, expectedOutput[i]); @@ -236,14 +246,20 @@ void testFromTwoVectors() { } void testSmallAngleQuaternionAxis() { - final quaternion32 = - Quaternion.axisAngle(Vector3(0.0, 0.0, 1.0), 0.6 * degrees2Radians); + final quaternion32 = Quaternion.axisAngle( + Vector3(0.0, 0.0, 1.0), + 0.6 * degrees2Radians, + ); relativeTest(quaternion32.axis, Vector3(0.0, 0.0, 1.0)); relativeTest(quaternion32.radians, 0.6 * degrees2Radians); - final quaternion64 = - v64.Quaternion.axisAngle(v64.Vector3(0, 0, 1), 0.01 * degrees2Radians); + final quaternion64 = v64.Quaternion.axisAngle( + v64.Vector3(0, 0, 1), + 0.01 * degrees2Radians, + ); expect( - quaternion64.axis.relativeError(v64.Vector3(0, 0, 1)), closeTo(0, 1e-5)); + quaternion64.axis.relativeError(v64.Vector3(0, 0, 1)), + closeTo(0, 1e-5), + ); expect(quaternion64.radians, closeTo(0.01 * degrees2Radians, 1e-5)); } @@ -253,8 +269,10 @@ void main() { test('ByteBuffer instacing', testQuaternionInstacingFromByteBuffer); test('Negate', testQuaternionNegate); test('Conjugate', testQuaternionConjugate); - test('Matrix Quaternion Round Trip', - testQuaternionMatrixQuaternionRoundTrip); + test( + 'Matrix Quaternion Round Trip', + testQuaternionMatrixQuaternionRoundTrip, + ); test('Multiply', testQuaternionMultiplying); test('Normalize', testQuaternionNormalize); test('Axis-Angle', testQuaternionAxisAngle); diff --git a/test/ray_test.dart b/test/ray_test.dart index f560ee75..d2184725 100644 --- a/test/ray_test.dart +++ b/test/ray_test.dart @@ -64,13 +64,25 @@ void testRayIntersectionSphere() { void testRayIntersectionTriangle() { final parent = Ray.originDirection($v3(1.0, 1.0, 1.0), $v3(0.0, 1.0, 0.0)); final hitting = Triangle.points( - $v3(2.0, 2.0, 0.0), $v3(0.0, 4.0, -1.0), $v3(0.0, 4.0, 3.0)); + $v3(2.0, 2.0, 0.0), + $v3(0.0, 4.0, -1.0), + $v3(0.0, 4.0, 3.0), + ); final cutting = Triangle.points( - $v3(0.0, 1.5, 1.0), $v3(2.0, 1.5, 1.0), $v3(1.0, 1.5, 3.0)); + $v3(0.0, 1.5, 1.0), + $v3(2.0, 1.5, 1.0), + $v3(1.0, 1.5, 3.0), + ); final outside = Triangle.points( - $v3(2.0, 2.0, 0.0), $v3(2.0, 6.0, 0.0), $v3(2.0, 2.0, 3.0)); + $v3(2.0, 2.0, 0.0), + $v3(2.0, 6.0, 0.0), + $v3(2.0, 2.0, 3.0), + ); final behind = Triangle.points( - $v3(0.0, 0.0, 0.0), $v3(0.0, 3.0, 0.0), $v3(0.0, 3.0, 4.0)); + $v3(0.0, 0.0, 0.0), + $v3(0.0, 3.0, 0.0), + $v3(0.0, 3.0, 4.0), + ); absoluteTest(parent.intersectsWithTriangle(hitting), 2.0); absoluteTest(parent.intersectsWithTriangle(cutting), 0.5); @@ -80,21 +92,25 @@ void testRayIntersectionTriangle() { // Test cases from real-world failures: // Just barely intersects, but gets rounded out final p2 = Ray.originDirection( - $v3(0.0, -0.16833500564098358, 0.7677000164985657), - $v3(-0.0, -0.8124330043792725, -0.5829949975013733)); + $v3(0.0, -0.16833500564098358, 0.7677000164985657), + $v3(-0.0, -0.8124330043792725, -0.5829949975013733), + ); final t2 = Triangle.points( - $v3(0.03430179879069328, -0.7268069982528687, 0.3532710075378418), - $v3(0.0, -0.7817990183830261, 0.3641969859600067), - $v3(0.0, -0.7293699979782104, 0.3516849875450134)); + $v3(0.03430179879069328, -0.7268069982528687, 0.3532710075378418), + $v3(0.0, -0.7817990183830261, 0.3641969859600067), + $v3(0.0, -0.7293699979782104, 0.3516849875450134), + ); expect(p2.intersectsWithTriangle(t2), closeTo(0.7078371874391822, 1e-10)); // Ray is not quite perpendicular to triangle, but gets rounded out final p3 = Ray.originDirection( - $v3(0.023712199181318283, -0.15045200288295746, 0.7751160264015198), - $v3(0.6024960279464722, -0.739005982875824, -0.3013699948787689)); + $v3(0.023712199181318283, -0.15045200288295746, 0.7751160264015198), + $v3(0.6024960279464722, -0.739005982875824, -0.3013699948787689), + ); final t3 = Triangle.points( - $v3(0.16174300014972687, -0.3446039855480194, 0.7121580243110657), - $v3(0.1857299953699112, -0.3468630015850067, 0.6926270127296448), - $v3(0.18045000731945038, -0.3193660080432892, 0.6921690106391907)); + $v3(0.16174300014972687, -0.3446039855480194, 0.7121580243110657), + $v3(0.1857299953699112, -0.3468630015850067, 0.6926270127296448), + $v3(0.18045000731945038, -0.3193660080432892, 0.6921690106391907), + ); expect(p3.intersectsWithTriangle(t3), closeTo(0.2538471189773835, 1e-10)); } diff --git a/test/scalar_list_view_test.dart b/test/scalar_list_view_test.dart index 111e750c..ffbe6cd6 100644 --- a/test/scalar_list_view_test.dart +++ b/test/scalar_list_view_test.dart @@ -38,11 +38,7 @@ void testScalarListView() { } void testScalarListViewFromList() { - final input = [ - 1.0, - 4.0, - 7.0, - ]; + final input = [1.0, 4.0, 7.0]; final list = ScalarListView.fromList(input, 2, 3); expect(list.buffer.length, 11); expect(list.buffer[0], 0.0); diff --git a/test/test_utils.dart b/test/test_utils.dart index 974f1f83..51d5debe 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -14,15 +14,21 @@ Vector4 $v4(double x, double y, double z, double w) => Vector4(x, y, z, w); void relativeTest(dynamic output, dynamic expectedOutput) { final errorThreshold = 0.0005; final num error = relativeError(output, expectedOutput).abs(); - expect(error >= errorThreshold, isFalse, - reason: '$output != $expectedOutput : relativeError = $error'); + expect( + error >= errorThreshold, + isFalse, + reason: '$output != $expectedOutput : relativeError = $error', + ); } void absoluteTest(dynamic output, dynamic expectedOutput) { final errorThreshold = 0.0005; final num error = absoluteError(output, expectedOutput).abs(); - expect(error >= errorThreshold, isFalse, - reason: '$output != $expectedOutput : absoluteError = $error'); + expect( + error >= errorThreshold, + isFalse, + reason: '$output != $expectedOutput : absoluteError = $error', + ); } dynamic makeMatrix(int rows, int cols) { @@ -79,8 +85,11 @@ T parseMatrix(String input) { T parseVector(String v) { v = v.trim(); - final Pattern pattern = - RegExp('[\\s]+', multiLine: true, caseSensitive: false); + final Pattern pattern = RegExp( + '[\\s]+', + multiLine: true, + caseSensitive: false, + ); final rows = v.split(pattern); final values = []; for (var i = 0; i < rows.length; i++) { diff --git a/test/triangle_test.dart b/test/triangle_test.dart index 8d2da250..e243d31d 100644 --- a/test/triangle_test.dart +++ b/test/triangle_test.dart @@ -10,7 +10,10 @@ import 'test_utils.dart'; void testCopyNormalInto() { final triangle = Triangle.points( - Vector3(1.0, 0.0, 1.0), Vector3(0.0, 2.0, 1.0), Vector3(1.0, 2.0, 0.0)); + Vector3(1.0, 0.0, 1.0), + Vector3(0.0, 2.0, 1.0), + Vector3(1.0, 2.0, 0.0), + ); final normal = Vector3.zero(); triangle.copyNormalInto(normal); diff --git a/test/vector2_list_test.dart b/test/vector2_list_test.dart index 8b344c6f..e81326cf 100644 --- a/test/vector2_list_test.dart +++ b/test/vector2_list_test.dart @@ -58,11 +58,7 @@ void testVector2ListViewTightFit() { } void testVector2ListFromList() { - final input = [ - Vector2(1.0, 2.0), - Vector2(3.0, 4.0), - Vector2(5.0, 6.0), - ]; + final input = [Vector2(1.0, 2.0), Vector2(3.0, 4.0), Vector2(5.0, 6.0)]; final list = Vector2List.fromList(input, 2, 5); expect(list.buffer.length, 17); expect(list.buffer[0], 0.0); diff --git a/test/vector3_list_test.dart b/test/vector3_list_test.dart index eb3216d7..531a0724 100644 --- a/test/vector3_list_test.dart +++ b/test/vector3_list_test.dart @@ -104,8 +104,9 @@ void testVector3ListSetValue() { } void testVector3ListSetZero() { - final list = - Vector3List.view(Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); + final list = Vector3List.view( + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), + ); list.setZero(1); @@ -118,8 +119,9 @@ void testVector3ListSetZero() { } void testVector3ListAdd() { - final list = - Vector3List.view(Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); + final list = Vector3List.view( + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), + ); list.add(1, $v3(2.0, 2.0, 2.0)); @@ -132,8 +134,9 @@ void testVector3ListAdd() { } void testVector3ListAddScaled() { - final list = - Vector3List.view(Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); + final list = Vector3List.view( + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), + ); list.addScaled(1, $v3(2.0, 2.0, 2.0), 2.0); @@ -146,8 +149,9 @@ void testVector3ListAddScaled() { } void testVector3ListSub() { - final list = - Vector3List.view(Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); + final list = Vector3List.view( + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), + ); list.sub(1, $v3(2.0, 2.0, 2.0)); @@ -160,8 +164,9 @@ void testVector3ListSub() { } void testVector3ListMultiply() { - final list = - Vector3List.view(Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); + final list = Vector3List.view( + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), + ); list.multiply(1, $v3(2.0, 3.0, 4.0)); @@ -174,8 +179,9 @@ void testVector3ListMultiply() { } void testVector3ListScale() { - final list = - Vector3List.view(Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); + final list = Vector3List.view( + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]), + ); list.scale(1, 2.0); diff --git a/test/vector3_test.dart b/test/vector3_test.dart index 567976ae..74f1069c 100644 --- a/test/vector3_test.dart +++ b/test/vector3_test.dart @@ -92,12 +92,16 @@ void testVector3DotProduct() { final inputA = []; final inputB = []; final expectedOutput = []; - inputA.add(parseVector('''0.417267069084370 + inputA.add( + parseVector('''0.417267069084370 0.049654430325742 - 0.902716109915281''')); - inputB.add(parseVector('''0.944787189721646 + 0.902716109915281'''), + ); + inputB.add( + parseVector('''0.944787189721646 0.490864092468080 - 0.489252638400019''')); + 0.489252638400019'''), + ); expectedOutput.add(0.860258396944727); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -132,25 +136,37 @@ void testVector3CrossProduct() { final inputB = []; final expectedOutput = []; - inputA.add(parseVector('''0.417267069084370 + inputA.add( + parseVector('''0.417267069084370 0.049654430325742 - 0.902716109915281''')); - inputB.add(parseVector('''0.944787189721646 + 0.902716109915281'''), + ); + inputB.add( + parseVector('''0.944787189721646 0.490864092468080 - 0.489252638400019''')); - expectedOutput.add(parseVector(''' -0.418817363004761 + 0.489252638400019'''), + ); + expectedOutput.add( + parseVector(''' -0.418817363004761 0.648725602136344 - 0.157908551498227''')); + 0.157908551498227'''), + ); - inputA.add(parseVector('''0.944787189721646 + inputA.add( + parseVector('''0.944787189721646 0.490864092468080 - 0.489252638400019''')); - inputB.add(parseVector('''0.417267069084370 + 0.489252638400019'''), + ); + inputB.add( + parseVector('''0.417267069084370 0.049654430325742 - 0.902716109915281''')); - expectedOutput.add(parseVector(''' 0.418817363004761 + 0.902716109915281'''), + ); + expectedOutput.add( + parseVector(''' 0.418817363004761 -0.648725602136344 - -0.157908551498227''')); + -0.157908551498227'''), + ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); @@ -228,12 +244,16 @@ void testVector3SetLength() { v1.length = 2.0; relativeTest( - v1, Vector3(1.4552137851715088, -0.9701424837112427, 0.9701424837112427)); + v1, + Vector3(1.4552137851715088, -0.9701424837112427, 0.9701424837112427), + ); relativeTest(v1.length, 2.0); v2.length = 0.5; - relativeTest(v2, - Vector3(-0.1666666716337204, 0.3333333432674408, -0.3333333432674408)); + relativeTest( + v2, + Vector3(-0.1666666716337204, 0.3333333432674408, -0.3333333432674408), + ); relativeTest(v2.length, 0.5); v3.length = -1.0; @@ -257,7 +277,9 @@ void testVector3Equals() { expect(v3 == Vector3(1.0, 0.0, 3.0), isFalse); expect(v3 == Vector3(1.0, 2.0, 0.0), isFalse); expect( - Vector3(1.0, 2.0, 3.0).hashCode, equals(Vector3(1.0, 2.0, 3.0).hashCode)); + Vector3(1.0, 2.0, 3.0).hashCode, + equals(Vector3(1.0, 2.0, 3.0).hashCode), + ); } void testVector3Reflect() { @@ -320,8 +342,24 @@ void testVector3Projection() { final v = Vector3(1.0, 1.0, 1.0); final a = 2.0 / 3.0; final b = 1.0 / 3.0; - final m = - Matrix4(a, b, -b, 0.0, b, a, b, 0.0, -b, b, a, 0.0, 0.0, 0.0, 0.0, 1.0); + final m = Matrix4( + a, + b, + -b, + 0.0, + b, + a, + b, + 0.0, + -b, + b, + a, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + ); v.applyProjection(m); relativeTest(v.x, a); @@ -437,8 +475,10 @@ void testVector3ApplyQuaternion() { final v = Vector3(0.417267069084370, 0.049654430325742, 0.753423475845592) ..applyQuaternion(q); - relativeTest(v, - Vector3(0.23769846558570862, 0.04965442791581154, -0.8278031349182129)); + relativeTest( + v, + Vector3(0.23769846558570862, 0.04965442791581154, -0.8278031349182129), + ); } void main() { diff --git a/test/vector4_list_test.dart b/test/vector4_list_test.dart index 9195f34a..7110cde8 100644 --- a/test/vector4_list_test.dart +++ b/test/vector4_list_test.dart @@ -113,7 +113,8 @@ void testVector4ListSetValue() { void testVector4ListSetZero() { final list = Vector4List.view( - Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])); + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + ); list.setZero(1); @@ -129,7 +130,8 @@ void testVector4ListSetZero() { void testVector4ListAdd() { final list = Vector4List.view( - Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])); + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + ); list.add(1, $v4(2.0, 2.0, 2.0, 2.0)); @@ -145,7 +147,8 @@ void testVector4ListAdd() { void testVector4ListAddScaled() { final list = Vector4List.view( - Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])); + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + ); list.addScaled(1, $v4(2.0, 2.0, 2.0, 2.0), 2.0); @@ -161,7 +164,8 @@ void testVector4ListAddScaled() { void testVector4ListSub() { final list = Vector4List.view( - Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])); + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + ); list.sub(1, $v4(2.0, 2.0, 2.0, 2.0)); @@ -177,7 +181,8 @@ void testVector4ListSub() { void testVector4ListMultiply() { final list = Vector4List.view( - Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])); + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + ); list.multiply(1, $v4(2.0, 3.0, 4.0, 5.0)); @@ -193,7 +198,8 @@ void testVector4ListMultiply() { void testVector4ListScale() { final list = Vector4List.view( - Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])); + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + ); list.scale(1, 2.0); diff --git a/test/vector4_test.dart b/test/vector4_test.dart index b39aa38d..fb987848 100644 --- a/test/vector4_test.dart +++ b/test/vector4_test.dart @@ -147,16 +147,26 @@ void testVector4SetLength() { v1.length = 2.0; relativeTest( - v1, - Vector4(1.4142135381698608, -0.9428090453147888, 0.9428090453147888, - 0.4714045226573944)); + v1, + Vector4( + 1.4142135381698608, + -0.9428090453147888, + 0.9428090453147888, + 0.4714045226573944, + ), + ); relativeTest(v1.length, 2.0); v2.length = 0.5; relativeTest( - v2, - Vector4(-0.1178511306643486, 0.2357022613286972, -0.2357022613286972, - -0.3535533845424652)); + v2, + Vector4( + -0.1178511306643486, + 0.2357022613286972, + -0.2357022613286972, + -0.3535533845424652, + ), + ); relativeTest(v2.length, 0.5); v3.length = -1.0; @@ -180,8 +190,10 @@ void testVector4Equals() { expect(v4 == Vector4(1.0, 0.0, 3.0, 4.0), isFalse); expect(v4 == Vector4(1.0, 2.0, 0.0, 4.0), isFalse); expect(v4 == Vector4(1.0, 2.0, 3.0, 0.0), isFalse); - expect(Vector4(1.0, 2.0, 3.0, 4.0).hashCode, - equals(Vector4(1.0, 2.0, 3.0, 4.0).hashCode)); + expect( + Vector4(1.0, 2.0, 3.0, 4.0).hashCode, + equals(Vector4(1.0, 2.0, 3.0, 4.0).hashCode), + ); } void testVector4DistanceTo() { diff --git a/tool/generate_vector_math_64.dart b/tool/generate_vector_math_64.dart index 8d6280ba..2022b9e4 100644 --- a/tool/generate_vector_math_64.dart +++ b/tool/generate_vector_math_64.dart @@ -28,8 +28,9 @@ Future generateVectorMath64() async { await directory.create(recursive: true); await _processFile('lib/vector_math.dart'); - await for (FileSystemEntity f - in Directory('lib/src/vector_math/').list(recursive: true)) { + await for (FileSystemEntity f in Directory( + 'lib/src/vector_math/', + ).list(recursive: true)) { if (f is File) { await _processFile(f.path); } @@ -42,8 +43,10 @@ Future _processFile(String inputFileName) async { final input = await inputFile.readAsString(); final output = _convertToVectorMath64(input); - final outputFileName = - inputFileName.replaceAll('vector_math', 'vector_math_64'); + final outputFileName = inputFileName.replaceAll( + 'vector_math', + 'vector_math_64', + ); final dir = Directory(p.dirname(outputFileName)); await dir.create(recursive: true);