Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/vector_math/lib/src/vector_math/aabb2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ 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);

/// Set the AABB by a [center] and [halfExtents].
void setCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) {
Expand Down Expand Up @@ -109,17 +108,15 @@ 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].
Expand Down
21 changes: 9 additions & 12 deletions packages/vector_math/lib/src/vector_math/aabb3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ 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);

/// Set the AABB by a [center] and [halfExtents].
void setCenterAndHalfExtents(Vector3 center, Vector3 halfExtents) {
Expand Down Expand Up @@ -266,17 +265,15 @@ 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) {
Expand Down
7 changes: 3 additions & 4 deletions packages/vector_math/lib/src/vector_math/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,9 @@ class Colors {
if (hslColor.y == 0.0) {
rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a);
} else {
final double q =
hslColor.z < 0.5
? hslColor.z * (1.0 + hslColor.y)
: hslColor.z + hslColor.y - hslColor.z * hslColor.y;
final double q = hslColor.z < 0.5
? hslColor.z * (1.0 + hslColor.y)
: hslColor.z + hslColor.y - hslColor.z * hslColor.y;
final double p = 2.0 * hslColor.z - q;

final double r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0);
Expand Down
7 changes: 3 additions & 4 deletions packages/vector_math/lib/src/vector_math/matrix2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ class Matrix2 {
Matrix2.zero() : _m2storage = Float32List(4);

/// Identity matrix.
factory Matrix2.identity() =>
Matrix2.zero()
.._m2storage[0] = 1.0
.._m2storage[3] = 1.0;
factory Matrix2.identity() => Matrix2.zero()
.._m2storage[0] = 1.0
.._m2storage[3] = 1.0;

/// Copies values from [other].
factory Matrix2.copy(Matrix2 other) => Matrix2.zero()..setFrom(other);
Expand Down
33 changes: 16 additions & 17 deletions packages/vector_math/lib/src/vector_math/matrix3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,27 @@ class Matrix3 {
..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);

/// New matrix from [values].
factory Matrix3.fromList(List<double> 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<double> 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);

/// Identity matrix.
factory Matrix3.identity() =>
Matrix3.zero()
.._m3storage[0] = 1.0
.._m3storage[4] = 1.0
.._m3storage[8] = 1.0;
factory Matrix3.identity() => Matrix3.zero()
.._m3storage[0] = 1.0
.._m3storage[4] = 1.0
.._m3storage[8] = 1.0;

/// Copes values from [other].
factory Matrix3.copy(Matrix3 other) => Matrix3.zero()..setFrom(other);
Expand Down
115 changes: 55 additions & 60 deletions packages/vector_math/lib/src/vector_math/matrix4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,56 @@ class Matrix4 {
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,
);
) => 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<double> values) =>
Matrix4.zero()..setValues(
values[0],
values[1],
values[2],
values[3],
values[4],
values[5],
values[6],
values[7],
values[8],
values[9],
values[10],
values[11],
values[12],
values[13],
values[14],
values[15],
);
factory Matrix4.fromList(List<double> values) => Matrix4.zero()
..setValues(
values[0],
values[1],
values[2],
values[3],
values[4],
values[5],
values[6],
values[7],
values[8],
values[9],
values[10],
values[11],
values[12],
values[13],
values[14],
values[15],
);

/// Zero matrix.
Matrix4.zero() : _m4storage = Float32List(16);

/// Identity matrix.
factory Matrix4.identity() =>
Matrix4.zero()
.._m4storage[0] = 1.0
.._m4storage[5] = 1.0
.._m4storage[10] = 1.0
.._m4storage[15] = 1.0;
factory Matrix4.identity() => Matrix4.zero()
.._m4storage[0] = 1.0
.._m4storage[5] = 1.0
.._m4storage[10] = 1.0
.._m4storage[15] = 1.0;

/// Copies values from [other].
factory Matrix4.copy(Matrix4 other) => Matrix4.zero()..setFrom(other);
Expand All @@ -106,28 +105,24 @@ class Matrix4 {
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) =>
Expand Down
7 changes: 3 additions & 4 deletions packages/vector_math/lib/src/vector_math/quaternion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ 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 int j = (i + 1) % 3;
final int k = (i + 2) % 3;
double s = math.sqrt(
Expand Down
14 changes: 6 additions & 8 deletions packages/vector_math/lib/src/vector_math/vector2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,12 @@ 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.
Expand Down
21 changes: 9 additions & 12 deletions packages/vector_math/lib/src/vector_math/vector3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,15 @@ 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.
Expand Down
28 changes: 12 additions & 16 deletions packages/vector_math/lib/src/vector_math/vector4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,22 +419,18 @@ 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.
Expand Down
Loading
Loading