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
35 changes: 26 additions & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Specify analysis options.
#
# This file is a copy of analysis_options.yaml from flutter/packages
# as of 2026-05-20. The file is expected to be kept in sync with the
# as of 2026-06-03. The file is expected to be kept in sync with the
# flutter/packages copy (which is in turn mostly synchronized with
# flutter/flutter).

Expand All @@ -24,33 +24,40 @@ analyzer:
- '**/*.ffi.dart'
- '**/*.mocks.dart' # Mockito @GenerateMocks

formatter:
page_width: 100

linter:
rules:
# This list is derived from the list of all available lints located at
# https://github.com/dart-lang/linter/blob/main/example/all.yaml
# https://github.com/dart-lang/sdk/blob/main/pkg/linter/example/all.yaml
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
# - always_specify_types # conflicts with omit_obvious_local_variable_types
# - always_use_package_imports # we do this commonly
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
- annotate_redeclares
# - avoid_annotating_with_dynamic # conflicts with type_annotate_public_apis
- avoid_bool_literals_in_conditional_expressions
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/4998
# - avoid_classes_with_only_static_members # we do this commonly for `abstract final class`es
- avoid_double_and_int_checks
- avoid_dynamic_calls
- avoid_empty_else
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_escaping_inner_quotes
- avoid_field_initializers_in_const_classes
# - avoid_final_parameters # incompatible with prefer_final_parameters
# TODO(kallentu): Remove this lint once the Dart SDK in Flutter is on version 3.13.
- avoid_final_parameters
- avoid_function_literals_in_foreach_calls
# - avoid_futureor_void # not yet tested
# - avoid_implementing_value_types # see https://github.com/dart-lang/linter/issues/4558
- avoid_init_to_null
- avoid_js_rounded_ints
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
- avoid_null_checks_in_equality_operators
# - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
- avoid_print
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
Expand All @@ -66,7 +73,7 @@ linter:
- avoid_slow_async_io
- avoid_type_to_string
- avoid_types_as_parameter_names
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
# - avoid_types_on_closure_parameters # not yet tested
- avoid_unnecessary_containers
- avoid_unused_constructor_parameters
- avoid_void_async
Expand All @@ -93,6 +100,7 @@ linter:
- directives_ordering
# - discarded_futures # too many false positives, similar to unawaited_futures
# - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
# - document_ignores # not yet tested
- empty_catches
- empty_constructor_bodies
- empty_statements
Expand All @@ -105,6 +113,7 @@ linter:
- implicit_call_tearoffs
- implicit_reopen
- invalid_case_patterns
- invalid_runtime_check_with_js_interop_types
# - join_return_with_assignment # not required by flutter style
- leading_newlines_in_multiline_strings
- library_annotations
Expand All @@ -116,7 +125,7 @@ linter:
# - matching_super_parameters # blocked on https://github.com/dart-lang/language/issues/2509
- missing_code_block_language_in_doc_comment
- missing_whitespace_between_adjacent_strings
# - no_adjacent_strings_in_list # conflicts with prefer_adjacent_string_concatenation
- no_adjacent_strings_in_list
- no_default_cases
- no_duplicate_case_values
- no_leading_underscores_for_library_prefixes
Expand All @@ -130,12 +139,12 @@ linter:
- noop_primitive_operations
- null_check_on_nullable_type_parameter
- null_closures
# - omit_local_variable_types # conflicts with specify_nonobvious_local_variable_types
# - omit_local_variable_types # superset of omit_obvious_local_variable_types
- omit_obvious_local_variable_types
# - omit_obvious_property_types # conflicts with type_annotate_public_apis
# - one_member_abstracts # too many false positives
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
- overridden_fields
# - package_api_docs # Deprecated (https://github.com/dart-lang/linter/issues/5107)
- package_names
- package_prefixed_library_names
# - parameter_assignments # we do this commonly
Expand Down Expand Up @@ -192,6 +201,7 @@ linter:
- sort_unnamed_constructors_first
- specify_nonobvious_local_variable_types
- specify_nonobvious_property_types
- strict_top_level_inference
- test_types_in_equals
- throw_in_finally
- tighten_type_of_initializing_formals
Expand All @@ -207,9 +217,11 @@ linter:
- unnecessary_constructor_name
# - unnecessary_final # conflicts with prefer_final_locals
- unnecessary_getters_setters
# - unnecessary_ignore # Disabled by default to simplify migrations; should be periodically enabled locally to clean up offenders
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
- unnecessary_late
- unnecessary_library_directive
# - unnecessary_library_name # blocked on https://github.com/dart-lang/dartdoc/issues/3882
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_aware_operator_on_extension_on_nullable
Expand All @@ -224,8 +236,10 @@ linter:
- unnecessary_string_interpolations
- unnecessary_this
- unnecessary_to_list_in_spreads
- unnecessary_underscores
- unreachable_from_main
- unrelated_type_equality_checks
# - unsafe_variance # not yet tested
- use_build_context_synchronously
- use_colored_box
# - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
Expand All @@ -245,5 +259,8 @@ linter:
- use_super_parameters
- use_test_throws_matchers
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
- use_truncating_division
- valid_regexps
# TODO(kallentu): Remove this lint once the Dart SDK in Flutter is on version 3.13.
- var_with_no_type_annotation
- void_checks
15 changes: 7 additions & 8 deletions packages/vector_math/benchmark/matrix4_tween_bench.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ class Matrix4TweenBenchmark1 extends BenchmarkBase with Setup {
final endScale = Vector3.zero();
begin.decompose(beginTranslation, beginRotation, beginScale);
end.decompose(endTranslation, endRotation, endScale);
final Vector3 lerpTranslation =
beginTranslation * (1.0 - t) + endTranslation * t;
final Quaternion lerpRotation =
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
final Vector3 lerpTranslation = beginTranslation * (1.0 - t) + endTranslation * t;
final Quaternion lerpRotation = (beginRotation.scaled(1.0 - t) + endRotation.scaled(t))
.normalized();
final Vector3 lerpScale = beginScale * (1.0 - t) + endScale * t;
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
}
Expand All @@ -66,8 +65,8 @@ class Matrix4TweenBenchmark2 extends BenchmarkBase with Setup {
begin.decompose(beginTranslation, beginRotation, beginScale);
end.decompose(endTranslation, endRotation, endScale);
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
final Quaternion lerpRotation =
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
final Quaternion lerpRotation = (beginRotation.scaled(1.0 - t) + endRotation.scaled(t))
.normalized();
Vector3.mix(beginScale, endScale, t, lerpScale);
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
}
Expand All @@ -91,8 +90,8 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup {
begin.decompose(beginTranslation, beginRotation, beginScale);
end.decompose(endTranslation, endRotation, endScale);
Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation);
final Quaternion lerpRotation =
(beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized();
final Quaternion lerpRotation = (beginRotation.scaled(1.0 - t) + endRotation.scaled(t))
.normalized();
Vector3.mix(beginScale, endScale, t, lerpScale);
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale);
}
Expand Down
27 changes: 6 additions & 21 deletions packages/vector_math/benchmark/matrix_bench.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase {
}

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

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

Expand All @@ -340,8 +339,7 @@ class Matrix4TranslateByDoubleGenericBenchmark extends BenchmarkBase {
}

class Matrix4TranslateByVector3GenericBenchmark extends BenchmarkBase {
Matrix4TranslateByVector3GenericBenchmark()
: super('Matrix4.translateByVector3Generic');
Matrix4TranslateByVector3GenericBenchmark() : super('Matrix4.translateByVector3Generic');

final temp = Matrix4.zero()..setIdentity();
final vec = Vector3(10.0, 20.0, 30.0);
Expand All @@ -359,8 +357,7 @@ class Matrix4TranslateByVector3GenericBenchmark extends BenchmarkBase {
}

class Matrix4TranslateByVector4GenericBenchmark extends BenchmarkBase {
Matrix4TranslateByVector4GenericBenchmark()
: super('Matrix4.translateByVector4Generic');
Matrix4TranslateByVector4GenericBenchmark() : super('Matrix4.translateByVector4Generic');

final temp = Matrix4.zero()..setIdentity();
final vec = Vector4(10.0, 20.0, 30.0, 40.0);
Expand Down Expand Up @@ -392,12 +389,7 @@ class Matrix4TranslateByDoubleBenchmark extends BenchmarkBase {
@override
void setup() {
for (var i = 0; i < 10; i++) {
temp.translateByDouble(
i.toDouble(),
(i * 10).toDouble(),
(i * 5).toDouble(),
1.0,
);
temp.translateByDouble(i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble(), 1.0);
}
}

Expand Down Expand Up @@ -425,9 +417,7 @@ class Matrix4TranslateByVector3Benchmark extends BenchmarkBase {
@override
void setup() {
for (var i = 0; i < 10; i++) {
temp.translateByVector3(
Vector3(i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble()),
);
temp.translateByVector3(Vector3(i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble()));
}
}

Expand Down Expand Up @@ -456,12 +446,7 @@ class Matrix4TranslateByVector4Benchmark extends BenchmarkBase {
void setup() {
for (var i = 0; i < 10; i++) {
temp.translateByVector4(
Vector4(
i.toDouble(),
(i * 10).toDouble(),
(i * 5).toDouble(),
(i * 20).toDouble(),
),
Vector4(i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble(), (i * 20).toDouble()),
);
}
}
Expand Down
26 changes: 6 additions & 20 deletions packages/vector_math/lib/src/vector_math/aabb2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ class Aabb2 {
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);
Aabb2.copy(Aabb2 other) : _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);
Aabb2.minMax(Vector2 min, Vector2 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 @@ -29,10 +25,7 @@ class Aabb2 {
/// [Float32List.bytesPerElement].
Aabb2.fromBuffer(ByteBuffer buffer, int offset)
: _min = Vector2.fromBuffer(buffer, offset),
_max = Vector2.fromBuffer(
buffer,
offset + Float32List.bytesPerElement * 2,
);
_max = Vector2.fromBuffer(buffer, offset + Float32List.bytesPerElement * 2);
final Vector2 _min;
final Vector2 _max;

Expand Down Expand Up @@ -77,8 +70,7 @@ class Aabb2 {

static final _center = Vector2.zero();
static final _halfExtents = Vector2.zero();
void _updateCenterAndHalfExtents() =>
copyCenterAndHalfExtents(_center, _halfExtents);
void _updateCenterAndHalfExtents() => copyCenterAndHalfExtents(_center, _halfExtents);

/// Transform this by the transform [t].
void transform(Matrix3 t) {
Expand Down Expand Up @@ -144,10 +136,7 @@ class Aabb2 {

/// Return if this contains [other].
bool containsVector2(Vector2 other) =>
(_min.x < other.x) &&
(_min.y < other.y) &&
(_max.x > other.x) &&
(_max.y > other.y);
(_min.x < other.x) && (_min.y < other.y) && (_max.x > other.x) && (_max.y > other.y);

/// Return if this intersects with [other].
bool intersectsWithAabb2(Aabb2 other) {
Expand All @@ -162,8 +151,5 @@ class Aabb2 {

/// Return if this intersects with [other].
bool intersectsWithVector2(Vector2 other) =>
(_min.x <= other.x) &&
(_min.y <= other.y) &&
(_max.x >= other.x) &&
(_max.y >= other.y);
(_min.x <= other.x) && (_min.y <= other.y) && (_max.x >= other.x) && (_max.y >= other.y);
}
Loading
Loading