diff --git a/lib/src/vector_math/matrix2.dart b/lib/src/vector_math/matrix2.dart index cd102bdc..0ed51195 100644 --- a/lib/src/vector_math/matrix2.dart +++ b/lib/src/vector_math/matrix2.dart @@ -218,19 +218,12 @@ class Matrix2 { @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 c61208b1..1b261d86 100644 --- a/lib/src/vector_math/matrix3.dart +++ b/lib/src/vector_math/matrix3.dart @@ -329,19 +329,12 @@ class Matrix3 { @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 8c82523c..f2d35fc2 100644 --- a/lib/src/vector_math/matrix4.dart +++ b/lib/src/vector_math/matrix4.dart @@ -647,21 +647,13 @@ class Matrix4 { @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 a35be282..f8424843 100644 --- a/lib/src/vector_math_64/matrix2.dart +++ b/lib/src/vector_math_64/matrix2.dart @@ -218,19 +218,12 @@ class Matrix2 { @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 e5638f9d..3b179365 100644 --- a/lib/src/vector_math_64/matrix3.dart +++ b/lib/src/vector_math_64/matrix3.dart @@ -329,19 +329,12 @@ class Matrix3 { @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 f1ed9f00..13f280d1 100644 --- a/lib/src/vector_math_64/matrix4.dart +++ b/lib/src/vector_math_64/matrix4.dart @@ -647,21 +647,13 @@ class Matrix4 { @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);