Skip to content

Bump min SDK to 3.7, update dependencies, reformat #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.1-wip

- Require `sdk: ^3.7.0`.

## 2.2.0

- Performance of functions that take `dynamic` arguments improved.
Expand Down
25 changes: 18 additions & 7 deletions benchmark/matrix_bench.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase {

class Matrix4TranslateByDoubleGenericBenchmark extends BenchmarkBase {
Matrix4TranslateByDoubleGenericBenchmark()
: super('Matrix4.translateByDoubleGeneric');
: super('Matrix4.translateByDoubleGeneric');

final temp = Matrix4.zero()..setIdentity();

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
);
}
}

Expand Down Expand Up @@ -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()),
);
}
}

Expand Down Expand Up @@ -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(),
),
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bin/mesh_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Map<String, GenerateFunction> generators = <String, GenerateFunction>{
'sphere': generateSphere,
'circle': generateCircle,
'cylinder': generateCylinder,
'ring': generateRing
'ring': generateRing,
};

void main(List<String> args) {
Expand Down
41 changes: 22 additions & 19 deletions lib/src/vector_math/aabb2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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) {
Expand Down Expand Up @@ -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].
Expand Down
131 changes: 81 additions & 50 deletions lib/src/vector_math/aabb3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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].
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Loading