Migrate matrix* dynamic operators to switch expressions
diff --git a/lib/src/vector_math/matrix2.dart b/lib/src/vector_math/matrix2.dart index cd102bd..0ed5119 100644 --- a/lib/src/vector_math/matrix2.dart +++ b/lib/src/vector_math/matrix2.dart
@@ -218,19 +218,12 @@ @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - dynamic operator *(dynamic arg) { - final Object result; - if (arg is double) { - result = scaled(arg); - } else if (arg is Vector2) { - result = transformed(arg); - } else if (arg is Matrix2) { - result = multiplied(arg); - } else { - throw ArgumentError(arg); - } - return result; - } + dynamic operator *(dynamic arg) => switch (arg) { + double() => scaled(arg), + Vector2() => transformed(arg), + Matrix2() => multiplied(arg), + _ => throw ArgumentError(arg) + }; /// Returns new matrix after component wise this + [arg] Matrix2 operator +(Matrix2 arg) => clone()..add(arg);
diff --git a/lib/src/vector_math/matrix3.dart b/lib/src/vector_math/matrix3.dart index c61208b..1b261d8 100644 --- a/lib/src/vector_math/matrix3.dart +++ b/lib/src/vector_math/matrix3.dart
@@ -329,19 +329,12 @@ @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - dynamic operator *(dynamic arg) { - final Object result; - if (arg is double) { - result = scaled(arg); - } else if (arg is Vector3) { - result = transformed(arg); - } else if (arg is Matrix3) { - result = multiplied(arg); - } else { - throw ArgumentError(arg); - } - return result; - } + dynamic operator *(dynamic arg) => switch (arg) { + double() => scaled(arg), + Vector3() => transformed(arg), + Matrix3() => multiplied(arg), + _ => throw ArgumentError(arg) + }; /// Returns new matrix after component wise this + [arg] Matrix3 operator +(Matrix3 arg) => clone()..add(arg);
diff --git a/lib/src/vector_math/matrix4.dart b/lib/src/vector_math/matrix4.dart index 8c82523..f2d35fc 100644 --- a/lib/src/vector_math/matrix4.dart +++ b/lib/src/vector_math/matrix4.dart
@@ -647,21 +647,13 @@ @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - dynamic operator *(dynamic arg) { - final Object result; - if (arg is double) { - result = scaledByDouble(arg, arg, arg, 1.0); - } else if (arg is Vector4) { - result = transformed(arg); - } else if (arg is Vector3) { - result = transformed3(arg); - } else if (arg is Matrix4) { - result = multiplied(arg); - } else { - throw ArgumentError(arg); - } - return result; - } + dynamic operator *(dynamic arg) => switch (arg) { + double() => scaledByDouble(arg, arg, arg, 1.0), + Vector4() => transformed(arg), + Vector3() => transformed3(arg), + Matrix4() => multiplied(arg), + _ => throw ArgumentError(arg) + }; /// Returns new matrix after component wise this + [arg] Matrix4 operator +(Matrix4 arg) => clone()..add(arg);
diff --git a/lib/src/vector_math_64/matrix2.dart b/lib/src/vector_math_64/matrix2.dart index a35be28..f842484 100644 --- a/lib/src/vector_math_64/matrix2.dart +++ b/lib/src/vector_math_64/matrix2.dart
@@ -218,19 +218,12 @@ @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - dynamic operator *(dynamic arg) { - final Object result; - if (arg is double) { - result = scaled(arg); - } else if (arg is Vector2) { - result = transformed(arg); - } else if (arg is Matrix2) { - result = multiplied(arg); - } else { - throw ArgumentError(arg); - } - return result; - } + dynamic operator *(dynamic arg) => switch (arg) { + double() => scaled(arg), + Vector2() => transformed(arg), + Matrix2() => multiplied(arg), + _ => throw ArgumentError(arg) + }; /// Returns new matrix after component wise this + [arg] Matrix2 operator +(Matrix2 arg) => clone()..add(arg);
diff --git a/lib/src/vector_math_64/matrix3.dart b/lib/src/vector_math_64/matrix3.dart index e5638f9..3b17936 100644 --- a/lib/src/vector_math_64/matrix3.dart +++ b/lib/src/vector_math_64/matrix3.dart
@@ -329,19 +329,12 @@ @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - dynamic operator *(dynamic arg) { - final Object result; - if (arg is double) { - result = scaled(arg); - } else if (arg is Vector3) { - result = transformed(arg); - } else if (arg is Matrix3) { - result = multiplied(arg); - } else { - throw ArgumentError(arg); - } - return result; - } + dynamic operator *(dynamic arg) => switch (arg) { + double() => scaled(arg), + Vector3() => transformed(arg), + Matrix3() => multiplied(arg), + _ => throw ArgumentError(arg) + }; /// Returns new matrix after component wise this + [arg] Matrix3 operator +(Matrix3 arg) => clone()..add(arg);
diff --git a/lib/src/vector_math_64/matrix4.dart b/lib/src/vector_math_64/matrix4.dart index f1ed9f0..13f280d 100644 --- a/lib/src/vector_math_64/matrix4.dart +++ b/lib/src/vector_math_64/matrix4.dart
@@ -647,21 +647,13 @@ @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') @pragma('dart2js:prefer-inline') - dynamic operator *(dynamic arg) { - final Object result; - if (arg is double) { - result = scaledByDouble(arg, arg, arg, 1.0); - } else if (arg is Vector4) { - result = transformed(arg); - } else if (arg is Vector3) { - result = transformed3(arg); - } else if (arg is Matrix4) { - result = multiplied(arg); - } else { - throw ArgumentError(arg); - } - return result; - } + dynamic operator *(dynamic arg) => switch (arg) { + double() => scaledByDouble(arg, arg, arg, 1.0), + Vector4() => transformed(arg), + Vector3() => transformed3(arg), + Matrix4() => multiplied(arg), + _ => throw ArgumentError(arg) + }; /// Returns new matrix after component wise this + [arg] Matrix4 operator +(Matrix4 arg) => clone()..add(arg);