diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..ac92509 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,249 @@ +# 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 +# flutter/packages copy (which is in turn mostly synchronized with +# flutter/flutter). + +analyzer: + language: + strict-casts: true + strict-inference: true + strict-raw-types: true + errors: + # allow deprecated members (we do this because otherwise we have to annotate + # every member in every test, assert, etc, when we or the Dart SDK deprecates + # something (https://github.com/flutter/flutter/issues/143312) + deprecated_member_use: ignore + deprecated_member_use_from_same_package: ignore + exclude: # DIFFERENT FROM FLUTTER/FLUTTER + # Ignore generated files + - '**/*.pb.dart' + - '**/*.g.dart' + - '**/*.jni.dart' + - '**/*.ffi.dart' + - '**/*.mocks.dart' # Mockito @GenerateMocks + +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 + - 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 + - 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_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 + - avoid_function_literals_in_foreach_calls + # - 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_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) + - avoid_redundant_argument_values + - avoid_relative_lib_imports + - avoid_renaming_method_parameters + - avoid_return_types_on_setters + - avoid_returning_null_for_void + # - avoid_returning_this # there are enough valid reasons to return `this` that this lint ends up with too many false positives + - avoid_setters_without_getters + - avoid_shadowing_type_parameters + - avoid_single_cascade_in_expression_statements + - avoid_slow_async_io + - avoid_type_to_string + - avoid_types_as_parameter_names + # - avoid_types_on_closure_parameters # conflicts with always_specify_types + - avoid_unnecessary_containers + - avoid_unused_constructor_parameters + - avoid_void_async + # - avoid_web_libraries_in_flutter # we use web libraries in web-specific code, and our tests prevent us from using them elsewhere + - await_only_futures + - camel_case_extensions + - camel_case_types + - cancel_subscriptions + # - cascade_invocations # doesn't match the typical style of this repo + - cast_nullable_to_non_nullable + # - close_sinks # not reliable enough + - collection_methods_unrelated_type + - combinators_ordering + # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142 + - conditional_uri_does_not_exist + # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 + - control_flow_in_finally + - curly_braces_in_flow_control_structures + - dangling_library_doc_comments + - depend_on_referenced_packages + - deprecated_consistency + # - deprecated_member_use_from_same_package # we allow self-references to deprecated members + # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib) + - 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 + - empty_catches + - empty_constructor_bodies + - empty_statements + - eol_at_end_of_file + - exhaustive_cases + - file_names + - flutter_style_todos + - hash_and_equals + - implementation_imports + - implicit_call_tearoffs + - implicit_reopen + - invalid_case_patterns + # - join_return_with_assignment # not required by flutter style + - leading_newlines_in_multiline_strings + - library_annotations + - library_names + - library_prefixes + - library_private_types_in_public_api + # - lines_longer_than_80_chars # not required by flutter style + - literal_only_boolean_expressions + # - 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_default_cases + - no_duplicate_case_values + - no_leading_underscores_for_library_prefixes + - no_leading_underscores_for_local_identifiers + - no_literal_bool_comparisons + - no_logic_in_create_state + - no_runtimeType_toString # DIFFERENT FROM FLUTTER/FLUTTER + - no_self_assignments + - no_wildcard_variable_uses + - non_constant_identifier_names + - noop_primitive_operations + - null_check_on_nullable_type_parameter + - null_closures + # - omit_local_variable_types # conflicts with specify_nonobvious_local_variable_types + - omit_obvious_local_variable_types + # - 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 + - prefer_adjacent_string_concatenation + - prefer_asserts_in_initializer_lists + # - prefer_asserts_with_message # not required by flutter style + - prefer_collection_literals + - prefer_conditional_assignment + - prefer_const_constructors + - prefer_const_constructors_in_immutables + - prefer_const_declarations + - prefer_const_literals_to_create_immutables + # - prefer_constructors_over_static_methods # far too many false positives + - prefer_contains + # - prefer_double_quotes # opposite of prefer_single_quotes + # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#consider-using--for-short-functions-and-methods + - prefer_final_fields + - prefer_final_in_for_each + - prefer_final_locals + # - prefer_final_parameters # adds too much verbosity + - prefer_for_elements_to_map_fromIterable + - prefer_foreach + - prefer_function_declarations_over_variables + - prefer_generic_function_type_aliases + - prefer_if_elements_to_conditional_expressions + - prefer_if_null_operators + - prefer_initializing_formals + - prefer_inlined_adds + # - prefer_int_literals # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#use-double-literals-for-double-constants + - prefer_interpolation_to_compose_strings + - prefer_is_empty + - prefer_is_not_empty + - prefer_is_not_operator + - prefer_iterable_whereType + - prefer_mixin + # - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere + - prefer_null_aware_operators + - prefer_relative_imports + - prefer_single_quotes + - prefer_spread_collections + - prefer_typing_uninitialized_variables + - prefer_void_to_null + - provide_deprecation_message + - public_member_api_docs # DIFFERENT FROM FLUTTER/FLUTTER + - recursive_getters + # - require_trailing_commas # would be nice, but requires a lot of manual work: 10,000+ code locations would need to be reformatted by hand after bulk fix is applied + - secure_pubspec_urls + - sized_box_for_whitespace + - sized_box_shrink_expand + - slash_for_doc_comments + - sort_child_properties_last + - sort_constructors_first + - sort_pub_dependencies # DIFFERENT FROM FLUTTER/FLUTTER: Flutter's use case for not sorting does not apply to this repository. + - sort_unnamed_constructors_first + - specify_nonobvious_local_variable_types + - specify_nonobvious_property_types + - test_types_in_equals + - throw_in_finally + - tighten_type_of_initializing_formals + - type_annotate_public_apis + - type_init_formals + - type_literal_in_constant_pattern + - unintended_html_in_doc_comment # DIFFERENT FROM FLUTTER/FLUTTER: Disabled due to an issue that has been fixed, so just hasn't been adopted there yet. + - unawaited_futures # DIFFERENT FROM FLUTTER/FLUTTER: It's disabled there for "too many false positives"; that's not an issue here, and missing awaits have caused production issues in plugins. + - unnecessary_await_in_return + - unnecessary_brace_in_string_interps + - unnecessary_breaks + - unnecessary_const + - unnecessary_constructor_name + # - unnecessary_final # conflicts with prefer_final_locals + - unnecessary_getters_setters + # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498 + - unnecessary_late + - unnecessary_library_directive + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_null_aware_operator_on_extension_on_nullable + - unnecessary_null_checks + - unnecessary_null_in_if_null_operators + - unnecessary_nullable_for_final_variable_declarations + - unnecessary_overrides + - unnecessary_parenthesis + # - unnecessary_raw_strings # what's "necessary" is a matter of opinion; consistency across strings can help readability more than this lint + - unnecessary_statements + - unnecessary_string_escapes + - unnecessary_string_interpolations + - unnecessary_this + - unnecessary_to_list_in_spreads + - unreachable_from_main + - unrelated_type_equality_checks + - use_build_context_synchronously + - use_colored_box + # - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding) + - use_enums + - use_full_hex_values_for_flutter_colors + - use_function_type_syntax_for_parameters + - use_if_null_to_convert_nulls_to_bools + - use_is_even_rather_than_modulo + - use_key_in_widget_constructors + - use_late_for_private_fields_and_variables + - use_named_constants + - use_raw_strings + - use_rethrow_when_possible + - use_setters_to_change_properties + # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182 + - use_string_in_part_of_directives + - 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 + - valid_regexps + - void_checks diff --git a/packages/vector_math/analysis_options.yaml b/packages/vector_math/analysis_options.yaml deleted file mode 100644 index 707d45d..0000000 --- a/packages/vector_math/analysis_options.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2013 The Flutter Authors -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. -include: package:dart_flutter_team_lints/analysis_options.yaml - -analyzer: - errors: - non_constant_identifier_names: ignore - - language: - strict-casts: true - strict-inference: true - -linter: - rules: - - avoid_bool_literals_in_conditional_expressions - - avoid_classes_with_only_static_members - - avoid_private_typedef_functions - - avoid_redundant_argument_values - - avoid_returning_this - - avoid_unused_constructor_parameters - - avoid_void_async - - cancel_subscriptions - - join_return_with_assignment - - literal_only_boolean_expressions - - missing_whitespace_between_adjacent_strings - - no_adjacent_strings_in_list - - no_runtimeType_toString - - prefer_expression_function_bodies - - prefer_final_locals - - unnecessary_await_in_return - - unnecessary_ignore - - use_string_buffers diff --git a/packages/vector_math/benchmark/matrix4_tween_bench.dart b/packages/vector_math/benchmark/matrix4_tween_bench.dart index cbb84e5..e8bed60 100644 --- a/packages/vector_math/benchmark/matrix4_tween_bench.dart +++ b/packages/vector_math/benchmark/matrix4_tween_bench.dart @@ -20,16 +20,16 @@ mixin Setup on BenchmarkBase { @override void run() { - var sum_traces = 0.0; + var sumTraces = 0.0; for (var i = 0; i <= 1024; i++) { - final t = i / 1024.0; - final m1 = lerp(beginTransform, endTransform, t); - final m2 = lerp(endTransform, beginTransform, t); - sum_traces += m1.trace(); - sum_traces += m2.trace(); + final double t = i / 1024.0; + final Matrix4 m1 = lerp(beginTransform, endTransform, t); + final Matrix4 m2 = lerp(endTransform, beginTransform, t); + sumTraces += m1.trace(); + sumTraces += m2.trace(); } - if (sum_traces < 6320 || sum_traces > 6321) { - throw StateError('Bad result: $sum_traces'); + if (sumTraces < 6320 || sumTraces > 6321) { + throw StateError('Bad result: $sumTraces'); } } @@ -49,10 +49,11 @@ class Matrix4TweenBenchmark1 extends BenchmarkBase with Setup { final endScale = Vector3.zero(); begin.decompose(beginTranslation, beginRotation, beginScale); end.decompose(endTranslation, endRotation, endScale); - final lerpTranslation = beginTranslation * (1.0 - t) + endTranslation * t; - final lerpRotation = + final Vector3 lerpTranslation = + beginTranslation * (1.0 - t) + endTranslation * t; + final Quaternion lerpRotation = (beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized(); - final lerpScale = beginScale * (1.0 - t) + endScale * t; + final Vector3 lerpScale = beginScale * (1.0 - t) + endScale * t; return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale); } } @@ -65,7 +66,7 @@ class Matrix4TweenBenchmark2 extends BenchmarkBase with Setup { begin.decompose(beginTranslation, beginRotation, beginScale); end.decompose(endTranslation, endRotation, endScale); Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation); - final lerpRotation = + final Quaternion lerpRotation = (beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized(); Vector3.mix(beginScale, endScale, t, lerpScale); return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale); @@ -90,7 +91,7 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup { begin.decompose(beginTranslation, beginRotation, beginScale); end.decompose(endTranslation, endRotation, endScale); Vector3.mix(beginTranslation, endTranslation, t, lerpTranslation); - final lerpRotation = + final Quaternion lerpRotation = (beginRotation.scaled(1.0 - t) + endRotation.scaled(t)).normalized(); Vector3.mix(beginScale, endScale, t, lerpScale); return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale); @@ -107,19 +108,19 @@ class Matrix4TweenBenchmark3 extends BenchmarkBase with Setup { } void main() { - final benchmarks = [ + final List benchmarks = [ Matrix4TweenBenchmark1(), Matrix4TweenBenchmark2(), Matrix4TweenBenchmark3(), ]; // Warmup all bencmarks. - for (var b in benchmarks) { + for (final b in benchmarks) { b.run(); } - for (var b in benchmarks) { + for (final b in benchmarks) { b.exercise(); } - for (var b in benchmarks) { + for (final b in benchmarks) { b.report(); } } diff --git a/packages/vector_math/benchmark/matrix_bench.dart b/packages/vector_math/benchmark/matrix_bench.dart index daaa5cc..5015db5 100644 --- a/packages/vector_math/benchmark/matrix_bench.dart +++ b/packages/vector_math/benchmark/matrix_bench.dart @@ -104,13 +104,13 @@ class ViewMatrixBenchmark extends BenchmarkBase { class Aabb2TransformBenchmark extends BenchmarkBase { Aabb2TransformBenchmark() : super('aabb2Transform'); - static final M = Matrix3.rotationZ(math.pi / 4); - static final P1 = Vector2(10.0, 10.0); - static final P2 = Vector2(20.0, 30.0); - static final P3 = Vector2(100.0, 50.0); - static final B1 = Aabb2.minMax(P1, P2); - static final B2 = Aabb2.minMax(P1, P3); - static final B3 = Aabb2.minMax(P2, P3); + static final m = Matrix3.rotationZ(math.pi / 4); + static final p1 = Vector2(10.0, 10.0); + static final p2 = Vector2(20.0, 30.0); + static final p3 = Vector2(100.0, 50.0); + static final b1 = Aabb2.minMax(p1, p2); + static final b2 = Aabb2.minMax(p1, p3); + static final b3 = Aabb2.minMax(p2, p3); static final temp = Aabb2(); static void main() { @@ -120,12 +120,12 @@ class Aabb2TransformBenchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 100; i++) { - temp.copyFrom(B1); - temp.transform(M); - temp.copyFrom(B2); - temp.transform(M); - temp.copyFrom(B3); - temp.transform(M); + temp.copyFrom(b1); + temp.transform(m); + temp.copyFrom(b2); + temp.transform(m); + temp.copyFrom(b3); + temp.transform(m); } } } @@ -133,13 +133,13 @@ class Aabb2TransformBenchmark extends BenchmarkBase { class Aabb2RotateBenchmark extends BenchmarkBase { Aabb2RotateBenchmark() : super('aabb2Rotate'); - static final M = Matrix3.rotationZ(math.pi / 4); - static final P1 = Vector2(10.0, 10.0); - static final P2 = Vector2(20.0, 30.0); - static final P3 = Vector2(100.0, 50.0); - static final B1 = Aabb2.minMax(P1, P2); - static final B2 = Aabb2.minMax(P1, P3); - static final B3 = Aabb2.minMax(P2, P3); + static final m = Matrix3.rotationZ(math.pi / 4); + static final p1 = Vector2(10.0, 10.0); + static final p2 = Vector2(20.0, 30.0); + static final p3 = Vector2(100.0, 50.0); + static final b1 = Aabb2.minMax(p1, p2); + static final b2 = Aabb2.minMax(p1, p3); + static final b3 = Aabb2.minMax(p2, p3); static final temp = Aabb2(); static void main() { @@ -149,12 +149,12 @@ class Aabb2RotateBenchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 100; i++) { - temp.copyFrom(B1); - temp.rotate(M); - temp.copyFrom(B2); - temp.rotate(M); - temp.copyFrom(B3); - temp.rotate(M); + temp.copyFrom(b1); + temp.rotate(m); + temp.copyFrom(b2); + temp.rotate(m); + temp.copyFrom(b3); + temp.rotate(m); } } } @@ -162,13 +162,13 @@ class Aabb2RotateBenchmark extends BenchmarkBase { class Aabb3TransformBenchmark extends BenchmarkBase { Aabb3TransformBenchmark() : super('aabb3Transform'); - static final M = Matrix4.rotationZ(math.pi / 4); - static final P1 = Vector3(10.0, 10.0, 0.0); - static final P2 = Vector3(20.0, 30.0, 1.0); - static final P3 = Vector3(100.0, 50.0, 10.0); - static final B1 = Aabb3.minMax(P1, P2); - static final B2 = Aabb3.minMax(P1, P3); - static final B3 = Aabb3.minMax(P2, P3); + static final m = Matrix4.rotationZ(math.pi / 4); + static final p1 = Vector3(10.0, 10.0, 0.0); + static final p2 = Vector3(20.0, 30.0, 1.0); + static final p3 = Vector3(100.0, 50.0, 10.0); + static final b1 = Aabb3.minMax(p1, p2); + static final b2 = Aabb3.minMax(p1, p3); + static final b3 = Aabb3.minMax(p2, p3); static final temp = Aabb3(); static void main() { @@ -178,12 +178,12 @@ class Aabb3TransformBenchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 100; i++) { - temp.copyFrom(B1); - temp.transform(M); - temp.copyFrom(B2); - temp.transform(M); - temp.copyFrom(B3); - temp.transform(M); + temp.copyFrom(b1); + temp.transform(m); + temp.copyFrom(b2); + temp.transform(m); + temp.copyFrom(b3); + temp.transform(m); } } } @@ -191,13 +191,13 @@ class Aabb3TransformBenchmark extends BenchmarkBase { class Aabb3RotateBenchmark extends BenchmarkBase { Aabb3RotateBenchmark() : super('aabb3Rotate'); - static final M = Matrix4.rotationZ(math.pi / 4); - static final P1 = Vector3(10.0, 10.0, 0.0); - static final P2 = Vector3(20.0, 30.0, 1.0); - static final P3 = Vector3(100.0, 50.0, 10.0); - static final B1 = Aabb3.minMax(P1, P2); - static final B2 = Aabb3.minMax(P1, P3); - static final B3 = Aabb3.minMax(P2, P3); + static final m = Matrix4.rotationZ(math.pi / 4); + static final p1 = Vector3(10.0, 10.0, 0.0); + static final p2 = Vector3(20.0, 30.0, 1.0); + static final p3 = Vector3(100.0, 50.0, 10.0); + static final b1 = Aabb3.minMax(p1, p2); + static final b2 = Aabb3.minMax(p1, p3); + static final b3 = Aabb3.minMax(p2, p3); static final temp = Aabb3(); static void main() { @@ -207,12 +207,12 @@ class Aabb3RotateBenchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 100; i++) { - temp.copyFrom(B1); - temp.rotate(M); - temp.copyFrom(B2); - temp.rotate(M); - temp.copyFrom(B3); - temp.rotate(M); + temp.copyFrom(b1); + temp.rotate(m); + temp.copyFrom(b2); + temp.rotate(m); + temp.copyFrom(b3); + temp.rotate(m); } } } @@ -220,9 +220,9 @@ class Aabb3RotateBenchmark extends BenchmarkBase { class Matrix3DeterminantBenchmark extends BenchmarkBase { Matrix3DeterminantBenchmark() : super('Matrix3.determinant'); - final MX = Matrix3.rotationX(math.pi / 4); - final MY = Matrix3.rotationY(math.pi / 4); - final MZ = Matrix3.rotationZ(math.pi / 4); + final mx = Matrix3.rotationX(math.pi / 4); + final my = Matrix3.rotationY(math.pi / 4); + final mz = Matrix3.rotationZ(math.pi / 4); static void main() { Matrix3DeterminantBenchmark().report(); @@ -231,9 +231,9 @@ class Matrix3DeterminantBenchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 800; i++) { - MX.determinant(); - MY.determinant(); - MZ.determinant(); + mx.determinant(); + my.determinant(); + mz.determinant(); } } } @@ -241,12 +241,12 @@ class Matrix3DeterminantBenchmark extends BenchmarkBase { class Matrix3TransformVector3Benchmark extends BenchmarkBase { Matrix3TransformVector3Benchmark() : super('Matrix3.transform(Vector3)'); - final MX = Matrix3.rotationX(math.pi / 4); - final MY = Matrix3.rotationY(math.pi / 4); - final MZ = Matrix3.rotationZ(math.pi / 4); - final V1 = Vector3(10.0, 20.0, 1.0); - final V2 = Vector3(-10.0, 20.0, 1.0); - final V3 = Vector3(10.0, -20.0, 1.0); + final mx = Matrix3.rotationX(math.pi / 4); + final my = Matrix3.rotationY(math.pi / 4); + final mz = Matrix3.rotationZ(math.pi / 4); + final v1 = Vector3(10.0, 20.0, 1.0); + final v2 = Vector3(-10.0, 20.0, 1.0); + final v3 = Vector3(10.0, -20.0, 1.0); static void main() { Matrix3TransformVector3Benchmark().report(); @@ -255,15 +255,15 @@ class Matrix3TransformVector3Benchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 800; i++) { - MX.transform(V1); - MX.transform(V2); - MX.transform(V3); - MY.transform(V1); - MY.transform(V2); - MY.transform(V3); - MZ.transform(V1); - MZ.transform(V2); - MZ.transform(V3); + mx.transform(v1); + mx.transform(v2); + mx.transform(v3); + my.transform(v1); + my.transform(v2); + my.transform(v3); + mz.transform(v1); + mz.transform(v2); + mz.transform(v3); } } } @@ -271,12 +271,12 @@ class Matrix3TransformVector3Benchmark extends BenchmarkBase { class Matrix3TransformVector2Benchmark extends BenchmarkBase { Matrix3TransformVector2Benchmark() : super('Matrix3.transform(Vector2)'); - final MX = Matrix3.rotationX(math.pi / 4); - final MY = Matrix3.rotationY(math.pi / 4); - final MZ = Matrix3.rotationZ(math.pi / 4); - final V1 = Vector2(10.0, 20.0); - final V2 = Vector2(-10.0, 20.0); - final V3 = Vector2(10.0, -20.0); + final mx = Matrix3.rotationX(math.pi / 4); + final my = Matrix3.rotationY(math.pi / 4); + final mz = Matrix3.rotationZ(math.pi / 4); + final v1 = Vector2(10.0, 20.0); + final v2 = Vector2(-10.0, 20.0); + final v3 = Vector2(10.0, -20.0); static void main() { Matrix3TransformVector2Benchmark().report(); @@ -285,15 +285,15 @@ class Matrix3TransformVector2Benchmark extends BenchmarkBase { @override void run() { for (var i = 0; i < 800; i++) { - MX.transform2(V1); - MX.transform2(V2); - MX.transform2(V3); - MY.transform2(V1); - MY.transform2(V2); - MY.transform2(V3); - MZ.transform2(V1); - MZ.transform2(V2); - MZ.transform2(V3); + mx.transform2(v1); + mx.transform2(v2); + mx.transform2(v3); + my.transform2(v1); + my.transform2(v2); + my.transform2(v3); + mz.transform2(v1); + mz.transform2(v2); + mz.transform2(v3); } } } @@ -301,9 +301,9 @@ class Matrix3TransformVector2Benchmark extends BenchmarkBase { class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase { Matrix3TransposeMultiplyBenchmark() : super('Matrix3.transposeMultiply'); - final MX = Matrix3.rotationX(math.pi / 4); - final MY = Matrix3.rotationY(math.pi / 4); - final MZ = Matrix3.rotationZ(math.pi / 4); + final mx = Matrix3.rotationX(math.pi / 4); + final my = Matrix3.rotationY(math.pi / 4); + final mz = Matrix3.rotationZ(math.pi / 4); final temp = Matrix3.zero(); static void main() { @@ -314,9 +314,9 @@ class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase { void run() { for (var i = 0; i < 100; i++) { temp.setIdentity(); - temp.transposeMultiply(MX); - temp.transposeMultiply(MY); - temp.transposeMultiply(MZ); + temp.transposeMultiply(mx); + temp.transposeMultiply(my); + temp.transposeMultiply(mz); } } } diff --git a/packages/vector_math/benchmark/vector2_bench.dart b/packages/vector_math/benchmark/vector2_bench.dart index 05e2049..c4d4f83 100644 --- a/packages/vector_math/benchmark/vector2_bench.dart +++ b/packages/vector_math/benchmark/vector2_bench.dart @@ -19,7 +19,9 @@ class ConstructorBenchmark extends BenchmarkBase { for (var i = 0; i < 100000; i++) { v = Vector2(100, 100); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -32,7 +34,9 @@ class ConstructorZeroBenchmark extends BenchmarkBase { for (var i = 0; i < 100000; i++) { v = Vector2.zero(); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -45,7 +49,9 @@ class ConstructorArrayBenchmark extends BenchmarkBase { for (var i = 0.0; i < 100000; i++) { v = Vector2.array([i, i]); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -58,7 +64,9 @@ class ConstructorAllBenchmark extends BenchmarkBase { for (var i = 0.0; i < 100000; i++) { v = Vector2.all(i); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -72,7 +80,9 @@ class ConstructorCopyBenchmark extends BenchmarkBase { for (var i = 0.0; i < 100000; i++) { v = Vector2.copy(copyFrom); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -86,7 +96,9 @@ class ConstructorFromFloat32ListBenchmark extends BenchmarkBase { for (var i = 0.0; i < 100000; i++) { v = Vector2.fromFloat32List(list); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -96,11 +108,13 @@ class ConstructorFromBufferBenchmark extends BenchmarkBase { @override void run() { Vector2? v; - final buffer = Uint32List(2).buffer; + final ByteBuffer buffer = Uint32List(2).buffer; for (var i = 0.0; i < 100000; i++) { v = Vector2.fromBuffer(buffer, 0); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -114,7 +128,9 @@ class ConstructorRandomBenchmark extends BenchmarkBase { for (var i = 0.0; i < 100000; i++) { v = Vector2.random(random); } - if (v == null) _unreachableAssertionError(); + if (v == null) { + _unreachableAssertionError(); + } } } @@ -128,7 +144,9 @@ class SetFromBenchmark extends BenchmarkBase { for (var i = 0; i < 100000; i++) { v = v..setFrom(source); } - if (v.x != 100 || v.y != 100) _unreachableAssertionError(); + if (v.x != 100 || v.y != 100) { + _unreachableAssertionError(); + } } } @@ -143,7 +161,9 @@ class DotProductBenchmark extends BenchmarkBase { for (var i = 0; i < 100000; i++) { r += v1.dot(v2); } - if (r != 30000 * 100000) _unreachableAssertionError(); + if (r != 30000 * 100000) { + _unreachableAssertionError(); + } } } diff --git a/packages/vector_math/bin/mesh_generator.dart b/packages/vector_math/bin/mesh_generator.dart index bae9fc4..6830308 100644 --- a/packages/vector_math/bin/mesh_generator.dart +++ b/packages/vector_math/bin/mesh_generator.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: avoid_print + import 'dart:convert'; import 'package:vector_math/vector_math_geometry.dart'; @@ -11,9 +13,9 @@ MeshGeometry? generateCube(List args) { if (args.length != 3) { return null; } - final width = double.parse(args[0]); - final height = double.parse(args[1]); - final depth = double.parse(args[2]); + final double width = double.parse(args[0]); + final double height = double.parse(args[1]); + final double depth = double.parse(args[2]); final generator = CubeGenerator(); return generator.createCube(width, height, depth); } @@ -22,7 +24,7 @@ MeshGeometry? generateSphere(List args) { if (args.length != 1) { return null; } - final radius = double.parse(args[0]); + final double radius = double.parse(args[0]); final generator = SphereGenerator(); return generator.createSphere(radius); } @@ -31,7 +33,7 @@ MeshGeometry? generateCircle(List args) { if (args.length != 1) { return null; } - final radius = double.parse(args[0]); + final double radius = double.parse(args[0]); final generator = CircleGenerator(); return generator.createCircle(radius); } @@ -40,9 +42,9 @@ MeshGeometry? generateCylinder(List args) { if (args.length != 3) { return null; } - final topRadius = double.parse(args[0]); - final bottomRadius = double.parse(args[1]); - final height = double.parse(args[2]); + final double topRadius = double.parse(args[0]); + final double bottomRadius = double.parse(args[1]); + final double height = double.parse(args[2]); final generator = CylinderGenerator(); return generator.createCylinder(topRadius, bottomRadius, height); } @@ -51,8 +53,8 @@ MeshGeometry? generateRing(List args) { if (args.length != 2) { return null; } - final innerRadius = double.parse(args[0]); - final outerRadius = double.parse(args[1]); + final double innerRadius = double.parse(args[0]); + final double outerRadius = double.parse(args[1]); final generator = RingGenerator(); return generator.createRing(innerRadius, outerRadius); } @@ -80,13 +82,13 @@ void main(List args) { print(''); return; } - final type = fixedArgs.removeAt(0); - final generator = generators[type]; + final String type = fixedArgs.removeAt(0); + final GenerateFunction? generator = generators[type]; if (generator == null) { print('Could not find generator for $type'); return; } - final geometry = generator(fixedArgs); + final MeshGeometry? geometry = generator(fixedArgs); if (geometry == null) { print('Error generating geometry for $type'); return; diff --git a/packages/vector_math/lib/src/vector_math/aabb2.dart b/packages/vector_math/lib/src/vector_math/aabb2.dart index b9e34d3..bef9e02 100644 --- a/packages/vector_math/lib/src/vector_math/aabb2.dart +++ b/packages/vector_math/lib/src/vector_math/aabb2.dart @@ -7,20 +7,6 @@ part of '../../vector_math.dart'; /// Defines a 2-dimensional axis-aligned bounding box between a [min] and a /// [max] position. class Aabb2 { - final Vector2 _min; - final Vector2 _max; - - /// The minimum point defining the AABB. - Vector2 get min => _min; - - /// The maximum point defining the AABB. - Vector2 get max => _max; - - /// The center of the AABB. - 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(); @@ -47,6 +33,20 @@ class Aabb2 { buffer, offset + Float32List.bytesPerElement * 2, ); + final Vector2 _min; + final Vector2 _max; + + /// The minimum point defining the AABB. + Vector2 get min => _min; + + /// The maximum point defining the AABB. + Vector2 get max => _max; + + /// The center of the AABB. + Vector2 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) { @@ -109,15 +109,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]. @@ -134,8 +136,8 @@ class Aabb2 { /// Return if this contains [other]. bool containsAabb2(Aabb2 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector2 otherMax = other._max; + final Vector2 otherMin = other._min; return (_min.x < otherMin.x) && (_min.y < otherMin.y) && @@ -152,8 +154,8 @@ class Aabb2 { /// Return if this intersects with [other]. bool intersectsWithAabb2(Aabb2 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector2 otherMax = other._max; + final Vector2 otherMin = other._min; return (_min.x <= otherMax.x) && (_min.y <= otherMax.y) && diff --git a/packages/vector_math/lib/src/vector_math/aabb3.dart b/packages/vector_math/lib/src/vector_math/aabb3.dart index 96855ba..12176d1 100644 --- a/packages/vector_math/lib/src/vector_math/aabb3.dart +++ b/packages/vector_math/lib/src/vector_math/aabb3.dart @@ -2,22 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; /// Defines a 3-dimensional axis-aligned bounding box between a [min] and a /// [max] position. class Aabb3 { - final Vector3 _min; - final Vector3 _max; - - Vector3 get min => _min; - Vector3 get max => _max; - - /// The center of the AABB. - 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(); @@ -62,6 +55,17 @@ class Aabb3 { buffer, offset + Float32List.bytesPerElement * 3, ); + final Vector3 _min; + final Vector3 _max; + + Vector3 get min => _min; + Vector3 get max => _max; + + /// The center of the AABB. + Vector3 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector3 center, Vector3 halfExtents) { @@ -185,19 +189,19 @@ class Aabb3 { ..copyAt(_max, limitMax); if (_max.x < _min.x) { - final temp = _max.x; + final double temp = _max.x; _max.x = _min.x; _min.x = temp; } if (_max.y < _min.y) { - final temp = _max.y; + final double temp = _max.y; _max.y = _min.y; _min.y = temp; } if (_max.z < _min.z) { - final temp = _max.z; + final double temp = _max.z; _max.z = _min.z; _min.z = temp; } @@ -262,15 +266,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) { @@ -313,8 +319,8 @@ class Aabb3 { /// Return if this contains [other]. bool containsAabb3(Aabb3 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector3 otherMax = other._max; + final Vector3 otherMin = other._min; return (_min.x < otherMin.x) && (_min.y < otherMin.y) && @@ -349,8 +355,8 @@ class Aabb3 { /// Return if this intersects with [other]. bool intersectsWithAabb3(Aabb3 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector3 otherMax = other._max; + final Vector3 otherMin = other._min; return (_min.x <= otherMax.x) && (_min.y <= otherMax.y) && @@ -362,8 +368,8 @@ class Aabb3 { /// Return if this intersects with [other]. bool intersectsWithSphere(Sphere other) { - final center = other._center; - final radius = other.radius; + final Vector3 center = other._center; + final double radius = other.radius; var d = 0.0; var e = 0.0; @@ -666,15 +672,15 @@ class Aabb3 { copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents); // Compute the projection interval radius of b onto L(t) = b.c + t * p.n - final r = + final double 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 - final s = other.normal.dot(_aabbCenter) - other.constant; + final double s = other.normal.dot(_aabbCenter) - other.constant; // Intersection occurs when distance s falls within [-r,+r] interval if (s.abs() <= r) { - final a = s - r; + final double a = s - r; if (result != null && (result._depth == null || (result._depth!) < a)) { result._depth = a; result.axis.setFrom(other.normal); diff --git a/packages/vector_math/lib/src/vector_math/colors.dart b/packages/vector_math/lib/src/vector_math/colors.dart index c7fba7e..90a3d06 100644 --- a/packages/vector_math/lib/src/vector_math/colors.dart +++ b/packages/vector_math/lib/src/vector_math/colors.dart @@ -8,6 +8,7 @@ part of '../../vector_math.dart'; /// manipulating colors. In addition to that, some known colors can be accessed /// for fast prototyping. class Colors { + Colors._(); static final _hexStringFullRegex = RegExp( r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?', caseSensitive: false, @@ -28,42 +29,42 @@ class Colors { /// corresponding color value and store it in [result]. The first group is /// treated as the alpha channel if a [value] with four groups is passed. static void fromHexString(String value, Vector4 result) { - final fullMatch = _hexStringFullRegex.matchAsPrefix(value); + final Match? fullMatch = _hexStringFullRegex.matchAsPrefix(value); if (fullMatch != null) { if (fullMatch[4] == null) { - final r = int.parse(fullMatch[1]!, radix: 16); - final g = int.parse(fullMatch[2]!, radix: 16); - final b = int.parse(fullMatch[3]!, radix: 16); + final int r = int.parse(fullMatch[1]!, radix: 16); + final int g = int.parse(fullMatch[2]!, radix: 16); + final int b = int.parse(fullMatch[3]!, radix: 16); fromRgba(r, g, b, 255, result); return; } else { - final a = int.parse(fullMatch[1]!, radix: 16); - final r = int.parse(fullMatch[2]!, radix: 16); - final g = int.parse(fullMatch[3]!, radix: 16); - final b = int.parse(fullMatch[4]!, radix: 16); + final int a = int.parse(fullMatch[1]!, radix: 16); + final int r = int.parse(fullMatch[2]!, radix: 16); + final int g = int.parse(fullMatch[3]!, radix: 16); + final int b = int.parse(fullMatch[4]!, radix: 16); fromRgba(r, g, b, a, result); return; } } - final smallMatch = _hexStringSmallRegex.matchAsPrefix(value); + final Match? smallMatch = _hexStringSmallRegex.matchAsPrefix(value); if (smallMatch != null) { if (smallMatch[4] == null) { - final r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); - final g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); - final b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); + final int r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); + final int g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); + final int b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); fromRgba(r, g, b, 255, result); return; } else { - final a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); - final r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); - final g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); - final b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16); + final int a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); + final int r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); + final int g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); + final int b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16); fromRgba(r, g, b, a, result); return; @@ -82,12 +83,12 @@ class Colors { bool alpha = false, bool short = false, }) { - final r = (input.r * 0xFF).floor() & 0xFF; - final g = (input.g * 0xFF).floor() & 0xFF; - final b = (input.b * 0xFF).floor() & 0xFF; - final a = (input.a * 0xFF).floor() & 0xFF; + final int r = (input.r * 0xFF).floor() & 0xFF; + final int g = (input.g * 0xFF).floor() & 0xFF; + final int b = (input.b * 0xFF).floor() & 0xFF; + final int a = (input.a * 0xFF).floor() & 0xFF; - final isShort = + final bool isShort = short && ((r >> 4) == (r & 0xF)) && ((g >> 4) == (g & 0xF)) && @@ -95,14 +96,14 @@ class Colors { (!alpha || (a >> 4) == (a & 0xF)); if (isShort) { - final rgb = + final String rgb = (r & 0xF).toRadixString(16) + (g & 0xF).toRadixString(16) + (b & 0xF).toRadixString(16); return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb; } else { - final rgb = + final String rgb = r.toRadixString(16).padLeft(2, '0') + g.toRadixString(16).padLeft(2, '0') + b.toRadixString(16).padLeft(2, '0'); @@ -118,18 +119,18 @@ class Colors { Vector4 background, Vector4 result, ) { - final a = foreground.a + (1.0 - foreground.a) * background.a; - final factor = 1.0 / a; + final double a = foreground.a + (1.0 - foreground.a) * background.a; + final double factor = 1.0 / a; - final r = + final double r = factor * (foreground.a * foreground.r + (1.0 - foreground.a) * background.a * background.r); - final g = + final double g = factor * (foreground.a * foreground.g + (1.0 - foreground.a) * background.a * background.g); - final b = + final double b = factor * (foreground.a * foreground.b + (1.0 - foreground.a) * background.a * background.b); @@ -139,7 +140,7 @@ class Colors { /// Convert a [input] color to a gray scaled color and store it in [result]. static void toGrayscale(Vector4 input, Vector4 result) { - final value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b; + final double value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b; result ..r = value @@ -156,7 +157,7 @@ class Colors { Vector4 gammaColor, [ double gamma = 2.2, ]) { - final exponent = 1.0 / gamma; + final double exponent = 1.0 / gamma; gammaColor ..r = math.pow(linearColor.r, exponent).toDouble() @@ -183,11 +184,11 @@ class Colors { /// Convert [rgbColor] from rgb color model to the hue, saturation, and value /// (HSV) color model and store it in [hsvColor]. static void rgbToHsv(Vector4 rgbColor, Vector4 hsvColor) { - final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); - final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); - final d = max - min; + final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); + final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); + final double d = max - min; final v = max; - final s = max == 0.0 ? 0.0 : d / max; + final double s = max == 0.0 ? 0.0 : d / max; var h = 0.0; if (max != min) { @@ -210,45 +211,39 @@ class Colors { /// Convert [hsvColor] from hue, saturation, and value (HSV) color model to /// the RGB color model and store it in [rgbColor]. static void hsvToRgb(Vector4 hsvColor, Vector4 rgbColor) { - final i = (hsvColor.x * 6.0).floor(); - final f = hsvColor.x * 6.0 - i.toDouble(); - final p = hsvColor.z * (1.0 - hsvColor.y); - final q = hsvColor.z * (1.0 - f * hsvColor.y); - final t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y); + final int i = (hsvColor.x * 6.0).floor(); + final double f = hsvColor.x * 6.0 - i.toDouble(); + final double p = hsvColor.z * (1.0 - hsvColor.y); + final double q = hsvColor.z * (1.0 - f * hsvColor.y); + final double t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y); switch (i % 6) { case 0: rgbColor.setValues(hsvColor.z, t, p, hsvColor.a); - break; case 1: rgbColor.setValues(q, hsvColor.z, p, hsvColor.a); - break; case 2: rgbColor.setValues(p, hsvColor.z, t, hsvColor.a); - break; case 3: rgbColor.setValues(p, q, hsvColor.z, hsvColor.a); - break; case 4: rgbColor.setValues(t, p, hsvColor.z, hsvColor.a); - break; case 5: rgbColor.setValues(hsvColor.z, p, q, hsvColor.a); - break; } } /// Convert [rgbColor] from rgb color model to the hue, saturation, and /// lightness (HSL) color model and store it in [hslColor]. static void rgbToHsl(Vector4 rgbColor, Vector4 hslColor) { - final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); - final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); - final l = (max + min) / 2.0; + final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); + final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); + final double l = (max + min) / 2.0; var h = 0.0; var s = 0.0; if (max != min) { - final d = max - min; + final double d = max - min; s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min); @@ -274,14 +269,15 @@ class Colors { if (hslColor.y == 0.0) { rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a); } else { - final q = hslColor.z < 0.5 - ? hslColor.z * (1.0 + hslColor.y) - : hslColor.z + hslColor.y - hslColor.z * hslColor.y; - final p = 2.0 * hslColor.z - q; + 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 r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0); - final g = _hueToRgb(p, q, hslColor.x); - final b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0); + final double r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0); + final double g = _hueToRgb(p, q, hslColor.x); + final double b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0); rgbColor.setValues(r, g, b, hslColor.a); } @@ -305,288 +301,567 @@ class Colors { } } + /// RGBA values for the named CSS color 'transparent'. static Vector4 get transparent => Vector4(255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0); + + /// RGBA values for the named CSS color 'aliceblue'. static Vector4 get aliceBlue => Vector4(240.0 / 255.0, 248.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'antiquewhite'. static Vector4 get antiqueWhite => Vector4(250.0 / 255.0, 235.0 / 255.0, 215.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'aqua'. static Vector4 get aqua => Vector4(0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'aquamarine'. static Vector4 get aquamarine => Vector4(127.0 / 255.0, 255.0 / 255.0, 212.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'azure'. static Vector4 get azure => Vector4(240.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'beige'. static Vector4 get beige => Vector4(245.0 / 255.0, 245.0 / 255.0, 220.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'bisque'. static Vector4 get bisque => Vector4(255.0 / 255.0, 228.0 / 255.0, 196.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'black'. static Vector4 get black => Vector4(0.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'blanchedalmond'. static Vector4 get blanchedAlmond => Vector4(255.0 / 255.0, 235.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'blue'. static Vector4 get blue => Vector4(0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'blueviolet'. static Vector4 get blueViolet => Vector4(138.0 / 255.0, 43.0 / 255.0, 226.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'brown'. static Vector4 get brown => Vector4(165.0 / 255.0, 42.0 / 255.0, 42.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'burlywood'. static Vector4 get burlyWood => Vector4(222.0 / 255.0, 184.0 / 255.0, 135.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cadetblue'. static Vector4 get cadetBlue => Vector4(95.0 / 255.0, 158.0 / 255.0, 160.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'chartreuse'. static Vector4 get chartreuse => Vector4(127.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'chocolate'. static Vector4 get chocolate => Vector4(210.0 / 255.0, 105.0 / 255.0, 30.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'coral'. static Vector4 get coral => Vector4(255.0 / 255.0, 127.0 / 255.0, 80.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cornflowerblue'. static Vector4 get cornflowerBlue => Vector4(100.0 / 255.0, 149.0 / 255.0, 237.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cornsilk'. static Vector4 get cornsilk => Vector4(255.0 / 255.0, 248.0 / 255.0, 220.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'crimson'. static Vector4 get crimson => Vector4(220.0 / 255.0, 20.0 / 255.0, 60.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cyan'. static Vector4 get cyan => Vector4(0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkblue'. static Vector4 get darkBlue => Vector4(0.0 / 255.0, 0.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkcyan'. static Vector4 get darkCyan => Vector4(0.0 / 255.0, 139.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkgoldenrod'. static Vector4 get darkGoldenrod => Vector4(184.0 / 255.0, 134.0 / 255.0, 11.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkgray'. static Vector4 get darkGray => Vector4(169.0 / 255.0, 169.0 / 255.0, 169.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkgreen'. static Vector4 get darkGreen => Vector4(0.0 / 255.0, 100.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkkhaki'. static Vector4 get darkKhaki => Vector4(189.0 / 255.0, 183.0 / 255.0, 107.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkmagenta'. static Vector4 get darkMagenta => Vector4(139.0 / 255.0, 0.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkolivegreen'. static Vector4 get darkOliveGreen => Vector4(85.0 / 255.0, 107.0 / 255.0, 47.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkorange'. static Vector4 get darkOrange => Vector4(255.0 / 255.0, 140.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkorchid'. static Vector4 get darkOrchid => Vector4(153.0 / 255.0, 50.0 / 255.0, 204.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkred'. static Vector4 get darkRed => Vector4(139.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darksalmon'. static Vector4 get darkSalmon => Vector4(233.0 / 255.0, 150.0 / 255.0, 122.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkseagreen'. static Vector4 get darkSeaGreen => Vector4(143.0 / 255.0, 188.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkslateblue'. static Vector4 get darkSlateBlue => Vector4(72.0 / 255.0, 61.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkslategray'. static Vector4 get darkSlateGray => Vector4(47.0 / 255.0, 79.0 / 255.0, 79.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkturquoise'. static Vector4 get darkTurquoise => Vector4(0.0 / 255.0, 206.0 / 255.0, 209.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkviolet'. static Vector4 get darkViolet => Vector4(148.0 / 255.0, 0.0 / 255.0, 211.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'deeppink'. static Vector4 get deepPink => Vector4(255.0 / 255.0, 20.0 / 255.0, 147.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'deepskyblue'. static Vector4 get deepSkyBlue => Vector4(0.0 / 255.0, 191.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'dimgray'. static Vector4 get dimGray => Vector4(105.0 / 255.0, 105.0 / 255.0, 105.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'dodgerblue'. static Vector4 get dodgerBlue => Vector4(30.0 / 255.0, 144.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'firebrick'. static Vector4 get firebrick => Vector4(178.0 / 255.0, 34.0 / 255.0, 34.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'floralwhite'. static Vector4 get floralWhite => Vector4(255.0 / 255.0, 250.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'forestgreen'. static Vector4 get forestGreen => Vector4(34.0 / 255.0, 139.0 / 255.0, 34.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'fuchsia'. static Vector4 get fuchsia => Vector4(255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'gainsboro'. static Vector4 get gainsboro => Vector4(220.0 / 255.0, 220.0 / 255.0, 220.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'ghostwhite'. static Vector4 get ghostWhite => Vector4(248.0 / 255.0, 248.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'gold'. static Vector4 get gold => Vector4(255.0 / 255.0, 215.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'goldenrod'. static Vector4 get goldenrod => Vector4(218.0 / 255.0, 165.0 / 255.0, 32.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'gray'. static Vector4 get gray => Vector4(128.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'green'. static Vector4 get green => Vector4(0.0 / 255.0, 128.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'greenyellow'. static Vector4 get greenYellow => Vector4(173.0 / 255.0, 255.0 / 255.0, 47.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'honeydew'. static Vector4 get honeydew => Vector4(240.0 / 255.0, 255.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'hotpink'. static Vector4 get hotPink => Vector4(255.0 / 255.0, 105.0 / 255.0, 180.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'indianred'. static Vector4 get indianRed => Vector4(205.0 / 255.0, 92.0 / 255.0, 92.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'indigo'. static Vector4 get indigo => Vector4(75.0 / 255.0, 0.0 / 255.0, 130.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'ivory'. static Vector4 get ivory => Vector4(255.0 / 255.0, 255.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'khaki'. static Vector4 get khaki => Vector4(240.0 / 255.0, 230.0 / 255.0, 140.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lavender'. static Vector4 get lavender => Vector4(230.0 / 255.0, 230.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lavenderblush'. static Vector4 get lavenderBlush => Vector4(255.0 / 255.0, 240.0 / 255.0, 245.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lawngreen'. static Vector4 get lawnGreen => Vector4(124.0 / 255.0, 252.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lemonchiffon'. static Vector4 get lemonChiffon => Vector4(255.0 / 255.0, 250.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightblue'. static Vector4 get lightBlue => Vector4(173.0 / 255.0, 216.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightcoral'. static Vector4 get lightCoral => Vector4(240.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightcyan'. static Vector4 get lightCyan => Vector4(224.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightgoldenrodyellow'. static Vector4 get lightGoldenrodYellow => Vector4(250.0 / 255.0, 250.0 / 255.0, 210.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightgreen'. static Vector4 get lightGreen => Vector4(144.0 / 255.0, 238.0 / 255.0, 144.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightgray'. static Vector4 get lightGray => Vector4(211.0 / 255.0, 211.0 / 255.0, 211.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightpink'. static Vector4 get lightPink => Vector4(255.0 / 255.0, 182.0 / 255.0, 193.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightsalmon'. static Vector4 get lightSalmon => Vector4(255.0 / 255.0, 160.0 / 255.0, 122.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightseagreen'. static Vector4 get lightSeaGreen => Vector4(32.0 / 255.0, 178.0 / 255.0, 170.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightskyblue'. static Vector4 get lightSkyBlue => Vector4(135.0 / 255.0, 206.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightslategray'. static Vector4 get lightSlateGray => Vector4(119.0 / 255.0, 136.0 / 255.0, 153.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightsteelblue'. static Vector4 get lightSteelBlue => Vector4(176.0 / 255.0, 196.0 / 255.0, 222.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightyellow'. static Vector4 get lightYellow => Vector4(255.0 / 255.0, 255.0 / 255.0, 224.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lime'. static Vector4 get lime => Vector4(0.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'limegreen'. static Vector4 get limeGreen => Vector4(50.0 / 255.0, 205.0 / 255.0, 50.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'linen'. static Vector4 get linen => Vector4(250.0 / 255.0, 240.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'magenta'. static Vector4 get magenta => Vector4(255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'maroon'. static Vector4 get maroon => Vector4(128.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumaquamarine'. static Vector4 get mediumAquamarine => Vector4(102.0 / 255.0, 205.0 / 255.0, 170.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumblue'. static Vector4 get mediumBlue => Vector4(0.0 / 255.0, 0.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumorchid'. static Vector4 get mediumOrchid => Vector4(186.0 / 255.0, 85.0 / 255.0, 211.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumpurple'. static Vector4 get mediumPurple => Vector4(147.0 / 255.0, 112.0 / 255.0, 219.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumseagreen'. static Vector4 get mediumSeaGreen => Vector4(60.0 / 255.0, 179.0 / 255.0, 113.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumslateblue'. static Vector4 get mediumSlateBlue => Vector4(123.0 / 255.0, 104.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumspringgreen'. static Vector4 get mediumSpringGreen => Vector4(0.0 / 255.0, 250.0 / 255.0, 154.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumturquoise'. static Vector4 get mediumTurquoise => Vector4(72.0 / 255.0, 209.0 / 255.0, 204.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumvioletred'. static Vector4 get mediumVioletRed => Vector4(199.0 / 255.0, 21.0 / 255.0, 133.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'midnightblue'. static Vector4 get midnightBlue => Vector4(25.0 / 255.0, 25.0 / 255.0, 112.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mintcream'. static Vector4 get mintCream => Vector4(245.0 / 255.0, 255.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mistyrose'. static Vector4 get mistyRose => Vector4(255.0 / 255.0, 228.0 / 255.0, 225.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'moccasin'. static Vector4 get moccasin => Vector4(255.0 / 255.0, 228.0 / 255.0, 181.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'navajowhite'. static Vector4 get navajoWhite => Vector4(255.0 / 255.0, 222.0 / 255.0, 173.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'navy'. static Vector4 get navy => Vector4(0.0 / 255.0, 0.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'oldlace'. static Vector4 get oldLace => Vector4(253.0 / 255.0, 245.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'olive'. static Vector4 get olive => Vector4(128.0 / 255.0, 128.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'olivedrab'. static Vector4 get oliveDrab => Vector4(107.0 / 255.0, 142.0 / 255.0, 35.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'orange'. static Vector4 get orange => Vector4(255.0 / 255.0, 165.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'orangered'. static Vector4 get orangeRed => Vector4(255.0 / 255.0, 69.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'orchid'. static Vector4 get orchid => Vector4(218.0 / 255.0, 112.0 / 255.0, 214.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'palegoldenrod'. static Vector4 get paleGoldenrod => Vector4(238.0 / 255.0, 232.0 / 255.0, 170.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'palegreen'. static Vector4 get paleGreen => Vector4(152.0 / 255.0, 251.0 / 255.0, 152.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'paleturquoise'. static Vector4 get paleTurquoise => Vector4(175.0 / 255.0, 238.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'palevioletred'. static Vector4 get paleVioletRed => Vector4(219.0 / 255.0, 112.0 / 255.0, 147.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'papayawhip'. static Vector4 get papayaWhip => Vector4(255.0 / 255.0, 239.0 / 255.0, 213.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'peachpuff'. static Vector4 get peachPuff => Vector4(255.0 / 255.0, 218.0 / 255.0, 185.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'peru'. static Vector4 get peru => Vector4(205.0 / 255.0, 133.0 / 255.0, 63.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'pink'. static Vector4 get pink => Vector4(255.0 / 255.0, 192.0 / 255.0, 203.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'plum'. static Vector4 get plum => Vector4(221.0 / 255.0, 160.0 / 255.0, 221.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'powderblue'. static Vector4 get powderBlue => Vector4(176.0 / 255.0, 224.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'purple'. static Vector4 get purple => Vector4(128.0 / 255.0, 0.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'red'. static Vector4 get red => Vector4(255.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'rosybrown'. static Vector4 get rosyBrown => Vector4(188.0 / 255.0, 143.0 / 255.0, 143.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'royalblue'. static Vector4 get royalBlue => Vector4(65.0 / 255.0, 105.0 / 255.0, 225.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'saddlebrown'. static Vector4 get saddleBrown => Vector4(139.0 / 255.0, 69.0 / 255.0, 19.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'salmon'. static Vector4 get salmon => Vector4(250.0 / 255.0, 128.0 / 255.0, 114.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'sandybrown'. static Vector4 get sandyBrown => Vector4(244.0 / 255.0, 164.0 / 255.0, 96.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'seagreen'. static Vector4 get seaGreen => Vector4(46.0 / 255.0, 139.0 / 255.0, 87.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'seashell'. static Vector4 get seaShell => Vector4(255.0 / 255.0, 245.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'sienna'. static Vector4 get sienna => Vector4(160.0 / 255.0, 82.0 / 255.0, 45.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'silver'. static Vector4 get silver => Vector4(192.0 / 255.0, 192.0 / 255.0, 192.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'skyblue'. static Vector4 get skyBlue => Vector4(135.0 / 255.0, 206.0 / 255.0, 235.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'slateblue'. static Vector4 get slateBlue => Vector4(106.0 / 255.0, 90.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'slategray'. static Vector4 get slateGray => Vector4(112.0 / 255.0, 128.0 / 255.0, 144.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'snow'. static Vector4 get snow => Vector4(255.0 / 255.0, 250.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'springgreen'. static Vector4 get springGreen => Vector4(0.0 / 255.0, 255.0 / 255.0, 127.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'steelblue'. static Vector4 get steelBlue => Vector4(70.0 / 255.0, 130.0 / 255.0, 180.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'tan'. static Vector4 get tan => Vector4(210.0 / 255.0, 180.0 / 255.0, 140.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'teal'. static Vector4 get teal => Vector4(0.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'thistle'. static Vector4 get thistle => Vector4(216.0 / 255.0, 191.0 / 255.0, 216.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'tomato'. static Vector4 get tomato => Vector4(255.0 / 255.0, 99.0 / 255.0, 71.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'turquoise'. static Vector4 get turquoise => Vector4(64.0 / 255.0, 224.0 / 255.0, 208.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'violet'. static Vector4 get violet => Vector4(238.0 / 255.0, 130.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'wheat'. static Vector4 get wheat => Vector4(245.0 / 255.0, 222.0 / 255.0, 179.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'white'. static Vector4 get white => Vector4(255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'whitesmoke'. static Vector4 get whiteSmoke => Vector4(245.0 / 255.0, 245.0 / 255.0, 245.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'yellow'. static Vector4 get yellow => Vector4(255.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'yellowgreen'. static Vector4 get yellowGreen => Vector4(154.0 / 255.0, 205.0 / 255.0, 50.0 / 255.0, 255.0 / 255.0); - - Colors._(); } diff --git a/packages/vector_math/lib/src/vector_math/error_helpers.dart b/packages/vector_math/lib/src/vector_math/error_helpers.dart index ae47b0d..254a7b5 100644 --- a/packages/vector_math/lib/src/vector_math/error_helpers.dart +++ b/packages/vector_math/lib/src/vector_math/error_helpers.dart @@ -9,7 +9,7 @@ part of '../../vector_math.dart'; /// be any vector, matrix, or quaternion. double relativeError(dynamic calculated, dynamic correct) { if (calculated is num && correct is num) { - final diff = (calculated - correct).abs().toDouble(); + final double diff = (calculated - correct).abs().toDouble(); return diff / correct; } // avoiding an `as double` cast here to maximize speed on dart2js @@ -22,7 +22,7 @@ double relativeError(dynamic calculated, dynamic correct) { /// be any vector, matrix, or quaternion. double absoluteError(dynamic calculated, dynamic correct) { if (calculated is num && correct is num) { - final diff = (calculated - correct).abs().toDouble(); + final double diff = (calculated - correct).abs().toDouble(); return diff; } // avoiding an `as double` cast here to maximize speed on dart2js diff --git a/packages/vector_math/lib/src/vector_math/frustum.dart b/packages/vector_math/lib/src/vector_math/frustum.dart index ebc2ca3..922f7d6 100644 --- a/packages/vector_math/lib/src/vector_math/frustum.dart +++ b/packages/vector_math/lib/src/vector_math/frustum.dart @@ -6,6 +6,20 @@ part of '../../vector_math.dart'; /// Defines a frustum constructed out of six [Plane]s. class Frustum { + /// Create a new frustum without initializing its bounds. + Frustum() + : _plane0 = Plane(), + _plane1 = Plane(), + _plane2 = Plane(), + _plane3 = Plane(), + _plane4 = Plane(), + _plane5 = Plane(); + + /// Create a new frustum as a copy of [other]. + factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other); + + /// Create a new furstum from a [matrix]. + factory Frustum.matrix(Matrix4 matrix) => Frustum()..setFromMatrix(matrix); final Plane _plane0; final Plane _plane1; final Plane _plane2; @@ -31,21 +45,6 @@ class Frustum { /// The sixed plane that defines the bounds of this frustum. Plane get plane5 => _plane5; - /// Create a new frustum without initializing its bounds. - Frustum() - : _plane0 = Plane(), - _plane1 = Plane(), - _plane2 = Plane(), - _plane3 = Plane(), - _plane4 = Plane(), - _plane5 = Plane(); - - /// Create a new frustum as a copy of [other]. - factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other); - - /// Create a new furstum from a [matrix]. - factory Frustum.matrix(Matrix4 matrix) => Frustum()..setFromMatrix(matrix); - /// Copy the [other] frustum into this. void copyFrom(Frustum other) { _plane0.copyFrom(other._plane0); @@ -58,11 +57,11 @@ class Frustum { /// Set this from [matrix]. void setFromMatrix(Matrix4 matrix) { - final me = matrix.storage; - final me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; - final me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; - final me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; - final me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; + final Float32List me = matrix.storage; + final double me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; + final double me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; + final double me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; + final double me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; _plane0 ..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12) @@ -144,8 +143,8 @@ class Frustum { /// Check if this intersects with [sphere]. bool intersectsWithSphere(Sphere sphere) { - final negativeRadius = -sphere.radius; - final center = sphere.center; + final double negativeRadius = -sphere.radius; + final Vector3 center = sphere.center; if (_plane0.distanceToVector3(center) < negativeRadius) { return false; @@ -223,12 +222,12 @@ class Frustum { outNz = aabb.min.z; } - final d1 = + final double d1 = plane._normal.x * outPx + plane._normal.y * outPy + plane._normal.z * outPz + plane.constant; - final d2 = + final double d2 = plane._normal.x * outNx + plane._normal.y * outNy + plane._normal.z * outNz + diff --git a/packages/vector_math/lib/src/vector_math/intersection_result.dart b/packages/vector_math/lib/src/vector_math/intersection_result.dart index 64152cd..062cc0e 100644 --- a/packages/vector_math/lib/src/vector_math/intersection_result.dart +++ b/packages/vector_math/lib/src/vector_math/intersection_result.dart @@ -1,10 +1,13 @@ // Copyright 2013 The Flutter Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. + part of '../../vector_math.dart'; /// Defines a result of an intersection test. class IntersectionResult { + /// Creates a new mutable result instance, with no initial values. + IntersectionResult(); double? _depth; /// The penetration depth of the intersection. @@ -12,6 +15,4 @@ class IntersectionResult { /// The [axis] of the intersection. final axis = Vector3.zero(); - - IntersectionResult(); } diff --git a/packages/vector_math/lib/src/vector_math/matrix2.dart b/packages/vector_math/lib/src/vector_math/matrix2.dart index 472af54..143e1d7 100644 --- a/packages/vector_math/lib/src/vector_math/matrix2.dart +++ b/packages/vector_math/lib/src/vector_math/matrix2.dart @@ -7,6 +7,36 @@ part of '../../vector_math.dart'; /// 2D Matrix. /// Values are stored in column major order. class Matrix2 { + /// New matrix with specified values. + factory Matrix2(double arg0, double arg1, double arg2, double arg3) => + Matrix2.zero()..setValues(arg0, arg1, arg2, arg3); + + /// New matrix from [values]. + factory Matrix2.fromList(List values) => + Matrix2.zero()..setValues(values[0], values[1], values[2], values[3]); + + /// Zero matrix. + Matrix2.zero() : _m2storage = Float32List(4); + + /// Identity matrix. + 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); + + /// Matrix with values from column arguments. + factory Matrix2.columns(Vector2 arg0, Vector2 arg1) => + Matrix2.zero()..setColumns(arg0, arg1); + + /// Outer product of [u] and [v]. + factory Matrix2.outer(Vector2 u, Vector2 v) => Matrix2.zero()..setOuter(u, v); + + /// Rotation of [radians]. + factory Matrix2.rotation(double radians) => + Matrix2.zero()..setRotation(radians); final Float32List _m2storage; /// The components of the matrix. @@ -14,13 +44,13 @@ class Matrix2 { /// Solve [A] * [x] = [b]. static void solve(Matrix2 A, Vector2 x, Vector2 b) { - final a11 = A.entry(0, 0); - final a12 = A.entry(0, 1); - final a21 = A.entry(1, 0); - final a22 = A.entry(1, 1); - final bx = b.x; - final by = b.y; - var det = a11 * a22 - a12 * a21; + final double a11 = A.entry(0, 0); + final double a12 = A.entry(0, 1); + final double a21 = A.entry(1, 0); + final double a22 = A.entry(1, 1); + final double bx = b.x; + final double by = b.y; + double det = a11 * a22 - a12 * a21; if (det != 0.0) { det = 1.0 / det; @@ -50,36 +80,6 @@ class Matrix2 { _m2storage[index(row, col)] = v; } - /// New matrix with specified values. - factory Matrix2(double arg0, double arg1, double arg2, double arg3) => - Matrix2.zero()..setValues(arg0, arg1, arg2, arg3); - - /// New matrix from [values]. - factory Matrix2.fromList(List values) => - Matrix2.zero()..setValues(values[0], values[1], values[2], values[3]); - - /// Zero matrix. - Matrix2.zero() : _m2storage = Float32List(4); - - /// Identity matrix. - 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); - - /// Matrix with values from column arguments. - factory Matrix2.columns(Vector2 arg0, Vector2 arg1) => - Matrix2.zero()..setColumns(arg0, arg1); - - /// Outer product of [u] and [v]. - factory Matrix2.outer(Vector2 u, Vector2 v) => Matrix2.zero()..setOuter(u, v); - - /// Rotation of [radians]. - factory Matrix2.rotation(double radians) => - Matrix2.zero()..setRotation(radians); - /// Sets the matrix with specified values. void setValues(double arg0, double arg1, double arg2, double arg3) { _m2storage[3] = arg3; @@ -90,8 +90,8 @@ class Matrix2 { /// Sets the entire matrix to the column values. void setColumns(Vector2 arg0, Vector2 arg1) { - final arg0Storage = arg0._v2storage; - final arg1Storage = arg1._v2storage; + final Float32List arg0Storage = arg0._v2storage; + final Float32List arg1Storage = arg1._v2storage; _m2storage[0] = arg0Storage[0]; _m2storage[1] = arg0Storage[1]; _m2storage[2] = arg1Storage[0]; @@ -100,7 +100,7 @@ class Matrix2 { /// Sets the entire matrix to the matrix in [arg]. void setFrom(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float32List argStorage = arg._m2storage; _m2storage[3] = argStorage[3]; _m2storage[2] = argStorage[2]; _m2storage[1] = argStorage[1]; @@ -109,8 +109,8 @@ class Matrix2 { /// Set this to the outer product of [u] and [v]. void setOuter(Vector2 u, Vector2 v) { - final uStorage = u._v2storage; - final vStorage = v._v2storage; + final Float32List uStorage = u._v2storage; + final Float32List vStorage = v._v2storage; _m2storage[0] = uStorage[0] * vStorage[0]; _m2storage[1] = uStorage[0] * vStorage[1]; _m2storage[2] = uStorage[1] * vStorage[0]; @@ -125,7 +125,7 @@ class Matrix2 { /// Sets the diagonal of the matrix to be [arg]. void setDiagonal(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _m2storage[0] = argStorage[0]; _m2storage[3] = argStorage[1]; } @@ -147,6 +147,7 @@ class Matrix2 { /// Check if two matrices are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Matrix2) && (_m2storage[0] == other._m2storage[0]) && @@ -155,6 +156,7 @@ class Matrix2 { (_m2storage[3] == other._m2storage[3]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_m2storage); /// Returns row 0 @@ -171,7 +173,7 @@ class Matrix2 { /// Sets [row] of the matrix to values in [arg] void setRow(int row, Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _m2storage[index(row, 0)] = argStorage[0]; _m2storage[index(row, 1)] = argStorage[1]; } @@ -179,7 +181,7 @@ class Matrix2 { /// Gets the [row] of the matrix Vector2 getRow(int row) { final r = Vector2.zero(); - final rStorage = r._v2storage; + final Float32List rStorage = r._v2storage; rStorage[0] = _m2storage[index(row, 0)]; rStorage[1] = _m2storage[index(row, 1)]; return r; @@ -187,8 +189,8 @@ class Matrix2 { /// Assigns the [column] of the matrix [arg] void setColumn(int column, Vector2 arg) { - final argStorage = arg._v2storage; - final entry = column * 2; + final Float32List argStorage = arg._v2storage; + final int entry = column * 2; _m2storage[entry + 1] = argStorage[1]; _m2storage[entry + 0] = argStorage[0]; } @@ -196,8 +198,8 @@ class Matrix2 { /// Gets the [column] of the matrix Vector2 getColumn(int column) { final r = Vector2.zero(); - final entry = column * 2; - final rStorage = r._v2storage; + final int entry = column * 2; + final Float32List rStorage = r._v2storage; rStorage[1] = _m2storage[entry + 1]; rStorage[0] = _m2storage[entry + 0]; return r; @@ -208,7 +210,7 @@ class Matrix2 { /// Copy this into [arg]. Matrix2 copyInto(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float32List argStorage = arg._m2storage; argStorage[0] = _m2storage[0]; argStorage[1] = _m2storage[1]; argStorage[2] = _m2storage[2]; @@ -262,8 +264,9 @@ class Matrix2 { /// Returns the tranpose of this. Matrix2 transposed() => clone()..transpose(); + /// Transposes this matrix in place. void transpose() { - final temp = _m2storage[2]; + final double temp = _m2storage[2]; _m2storage[2] = _m2storage[1]; _m2storage[1] = temp; } @@ -271,7 +274,7 @@ class Matrix2 { /// Returns the component wise absolute value of this. Matrix2 absolute() { final r = Matrix2.zero(); - final rStorage = r._m2storage; + final Float32List rStorage = r._m2storage; rStorage[0] = _m2storage[0].abs(); rStorage[1] = _m2storage[1].abs(); rStorage[2] = _m2storage[2].abs(); @@ -285,13 +288,13 @@ class Matrix2 { /// Returns the dot product of row [i] and [v]. double dotRow(int i, Vector2 v) { - final vStorage = v._v2storage; + final Float32List vStorage = v._v2storage; return _m2storage[i] * vStorage[0] + _m2storage[2 + i] * vStorage[1]; } /// Returns the dot product of column [j] and [v]. double dotColumn(int j, Vector2 v) { - final vStorage = v._v2storage; + final Float32List vStorage = v._v2storage; return _m2storage[j * 2] * vStorage[0] + _m2storage[(j * 2) + 1] * vStorage[1]; } @@ -324,28 +327,28 @@ class Matrix2 { /// Returns relative error between this and [correct] double relativeError(Matrix2 correct) { - final diff = correct - this; - final correctNorm = correct.infinityNorm(); - final diff_norm = diff.infinityNorm(); - return diff_norm / correctNorm; + final Matrix2 diff = correct - this; + final double correctNorm = correct.infinityNorm(); + final double diffNorm = diff.infinityNorm(); + return diffNorm / correctNorm; } /// Returns absolute error between this and [correct] double absoluteError(Matrix2 correct) { - final this_norm = infinityNorm(); - final correct_norm = correct.infinityNorm(); - final diff_norm = (this_norm - correct_norm).abs(); - return diff_norm; + final double thisNorm = infinityNorm(); + final double correctNorm = correct.infinityNorm(); + final double diffNorm = (thisNorm - correctNorm).abs(); + return diffNorm; } /// Invert the matrix. Returns the determinant. double invert() { - final det = determinant(); + final double det = determinant(); if (det == 0.0) { return 0.0; } - final invDet = 1.0 / det; - final temp = _m2storage[0]; + final double invDet = 1.0 / det; + final double temp = _m2storage[0]; _m2storage[0] = _m2storage[3] * invDet; _m2storage[1] = -_m2storage[1] * invDet; _m2storage[2] = -_m2storage[2] * invDet; @@ -355,13 +358,13 @@ class Matrix2 { /// Set this matrix to be the inverse of [arg] double copyInverse(Matrix2 arg) { - final det = arg.determinant(); + final double det = arg.determinant(); if (det == 0.0) { setFrom(arg); return 0.0; } - final invDet = 1.0 / det; - final argStorage = arg._m2storage; + final double invDet = 1.0 / det; + final Float32List argStorage = arg._m2storage; _m2storage[0] = argStorage[3] * invDet; _m2storage[1] = -argStorage[1] * invDet; _m2storage[2] = -argStorage[2] * invDet; @@ -371,8 +374,8 @@ class Matrix2 { /// Turns the matrix into a rotation of [radians] void setRotation(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m2storage[0] = c; _m2storage[1] = s; _m2storage[2] = -s; @@ -381,7 +384,7 @@ class Matrix2 { /// Converts into Adjugate matrix and scales by [scale] void scaleAdjoint(double scale) { - final temp = _m2storage[0]; + final double temp = _m2storage[0]; _m2storage[0] = _m2storage[3] * scale; _m2storage[2] = -_m2storage[2] * scale; _m2storage[1] = -_m2storage[1] * scale; @@ -401,7 +404,7 @@ class Matrix2 { /// Add [o] to this. void add(Matrix2 o) { - final oStorage = o._m2storage; + final Float32List oStorage = o._m2storage; _m2storage[0] = _m2storage[0] + oStorage[0]; _m2storage[1] = _m2storage[1] + oStorage[1]; _m2storage[2] = _m2storage[2] + oStorage[2]; @@ -410,7 +413,7 @@ class Matrix2 { /// Subtract [o] from this. void sub(Matrix2 o) { - final oStorage = o._m2storage; + final Float32List oStorage = o._m2storage; _m2storage[0] = _m2storage[0] - oStorage[0]; _m2storage[1] = _m2storage[1] - oStorage[1]; _m2storage[2] = _m2storage[2] - oStorage[2]; @@ -427,15 +430,15 @@ class Matrix2 { /// Multiply this with [arg] and store it in this. void multiply(Matrix2 arg) { - final m00 = _m2storage[0]; - final m01 = _m2storage[2]; - final m10 = _m2storage[1]; - final m11 = _m2storage[3]; - final argStorage = arg._m2storage; - final n00 = argStorage[0]; - final n01 = argStorage[2]; - final n10 = argStorage[1]; - final n11 = argStorage[3]; + final double m00 = _m2storage[0]; + final double m01 = _m2storage[2]; + final double m10 = _m2storage[1]; + final double m11 = _m2storage[3]; + final Float32List argStorage = arg._m2storage; + final double n00 = argStorage[0]; + final double n01 = argStorage[2]; + final double n10 = argStorage[1]; + final double n11 = argStorage[3]; _m2storage[0] = (m00 * n00) + (m01 * n10); _m2storage[2] = (m00 * n01) + (m01 * n11); _m2storage[1] = (m10 * n00) + (m11 * n10); @@ -447,11 +450,11 @@ class Matrix2 { /// Multiply a transposed this with [arg]. void transposeMultiply(Matrix2 arg) { - final m00 = _m2storage[0]; - final m01 = _m2storage[1]; - final m10 = _m2storage[2]; - final m11 = _m2storage[3]; - final argStorage = arg._m2storage; + final double m00 = _m2storage[0]; + final double m01 = _m2storage[1]; + final double m10 = _m2storage[2]; + final double m11 = _m2storage[3]; + final Float32List argStorage = arg._m2storage; _m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]); _m2storage[2] = (m00 * argStorage[2]) + (m01 * argStorage[3]); _m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[1]); @@ -460,11 +463,11 @@ class Matrix2 { /// Multiply this with a transposed [arg]. void multiplyTranspose(Matrix2 arg) { - final m00 = _m2storage[0]; - final m01 = _m2storage[2]; - final m10 = _m2storage[1]; - final m11 = _m2storage[3]; - final argStorage = arg._m2storage; + final double m00 = _m2storage[0]; + final double m01 = _m2storage[2]; + final double m10 = _m2storage[1]; + final double m11 = _m2storage[3]; + final Float32List argStorage = arg._m2storage; _m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[2]); _m2storage[2] = (m00 * argStorage[1]) + (m01 * argStorage[3]); _m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[2]); @@ -474,9 +477,11 @@ class Matrix2 { /// Transform [arg] of type [Vector2] using the transformation defined by /// this. Vector2 transform(Vector2 arg) { - final argStorage = arg._v2storage; - final x = (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]); - final y = (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]); + final Float32List argStorage = arg._v2storage; + final double x = + (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]); + final double y = + (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]); argStorage[0] = x; argStorage[1] = y; return arg; diff --git a/packages/vector_math/lib/src/vector_math/matrix3.dart b/packages/vector_math/lib/src/vector_math/matrix3.dart index 79d3770..cef0dc3 100644 --- a/packages/vector_math/lib/src/vector_math/matrix3.dart +++ b/packages/vector_math/lib/src/vector_math/matrix3.dart @@ -2,11 +2,75 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; /// 3D Matrix. /// Values are stored in column major order. class Matrix3 { + /// New matrix with specified values. + factory Matrix3( + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + ) => + Matrix3.zero() + ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + + /// New matrix from [values]. + factory Matrix3.fromList(List 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; + + /// Copes values from [other]. + factory Matrix3.copy(Matrix3 other) => Matrix3.zero()..setFrom(other); + + /// Constructs a new mat3 from columns. + factory Matrix3.columns(Vector3 arg0, Vector3 arg1, Vector3 arg2) => + Matrix3.zero()..setColumns(arg0, arg1, arg2); + + /// Outer product of [u] and [v]. + factory Matrix3.outer(Vector3 u, Vector3 v) => Matrix3.zero()..setOuter(u, v); + + /// Rotation of [radians] around X axis. + factory Matrix3.rotationX(double radians) => + Matrix3.zero()..setRotationX(radians); + + /// Rotation of [radians] around Y axis. + factory Matrix3.rotationY(double radians) => + Matrix3.zero()..setRotationY(radians); + + /// Rotation of [radians] around Z axis. + factory Matrix3.rotationZ(double radians) => + Matrix3.zero()..setRotationZ(radians); final Float32List _m3storage; /// The components of the matrix. @@ -14,13 +78,13 @@ class Matrix3 { /// Solve [A] * [x] = [b]. static void solve2(Matrix3 A, Vector2 x, Vector2 b) { - final a11 = A.entry(0, 0); - final a12 = A.entry(0, 1); - final a21 = A.entry(1, 0); - final a22 = A.entry(1, 1); - final bx = b.x - A.storage[6]; - final by = b.y - A.storage[7]; - var det = a11 * a22 - a12 * a21; + final double a11 = A.entry(0, 0); + final double a12 = A.entry(0, 1); + final double a21 = A.entry(1, 0); + final double a22 = A.entry(1, 1); + final double bx = b.x - A.storage[6]; + final double by = b.y - A.storage[7]; + double det = a11 * a22 - a12 * a21; if (det != 0.0) { det = 1.0 / det; @@ -33,45 +97,45 @@ class Matrix3 { /// Solve [A] * [x] = [b]. static void solve(Matrix3 A, Vector3 x, Vector3 b) { - final A0x = A.entry(0, 0); - final A0y = A.entry(1, 0); - final A0z = A.entry(2, 0); - final A1x = A.entry(0, 1); - final A1y = A.entry(1, 1); - final A1z = A.entry(2, 1); - final A2x = A.entry(0, 2); - final A2y = A.entry(1, 2); - final A2z = A.entry(2, 2); + final double a0x = A.entry(0, 0); + final double a0y = A.entry(1, 0); + final double a0z = A.entry(2, 0); + final double a1x = A.entry(0, 1); + final double a1y = A.entry(1, 1); + final double a1z = A.entry(2, 1); + final double a2x = A.entry(0, 2); + final double a2y = A.entry(1, 2); + final double a2z = A.entry(2, 2); double rx, ry, rz; double det; // Column1 cross Column 2 - rx = A1y * A2z - A1z * A2y; - ry = A1z * A2x - A1x * A2z; - rz = A1x * A2y - A1y * A2x; + rx = a1y * a2z - a1z * a2y; + ry = a1z * a2x - a1x * a2z; + rz = a1x * a2y - a1y * a2x; // A.getColumn(0).dot(x) - det = A0x * rx + A0y * ry + A0z * rz; + det = a0x * rx + a0y * ry + a0z * rz; if (det != 0.0) { det = 1.0 / det; } // b dot [Column1 cross Column 2] - final x_ = det * (b.x * rx + b.y * ry + b.z * rz); + final double x_ = det * (b.x * rx + b.y * ry + b.z * rz); // Column2 cross b - rx = -(A2y * b.z - A2z * b.y); - ry = -(A2z * b.x - A2x * b.z); - rz = -(A2x * b.y - A2y * b.x); + rx = -(a2y * b.z - a2z * b.y); + ry = -(a2z * b.x - a2x * b.z); + rz = -(a2x * b.y - a2y * b.x); // Column0 dot -[Column2 cross b (Column3)] - final y_ = det * (A0x * rx + A0y * ry + A0z * rz); + final double y_ = det * (a0x * rx + a0y * ry + a0z * rz); // b cross Column 1 - rx = -(b.y * A1z - b.z * A1y); - ry = -(b.z * A1x - b.x * A1z); - rz = -(b.x * A1y - b.y * A1x); + rx = -(b.y * a1z - b.z * a1y); + ry = -(b.z * a1x - b.x * a1z); + rz = -(b.x * a1y - b.y * a1x); // Column0 dot -[b cross Column 1] - final z_ = det * (A0x * rx + A0y * ry + A0z * rz); + final double z_ = det * (a0x * rx + a0y * ry + a0z * rz); x ..x = x_ @@ -98,66 +162,6 @@ class Matrix3 { _m3storage[index(row, col)] = v; } - /// New matrix with specified values. - factory Matrix3( - double arg0, - double arg1, - double arg2, - double arg3, - double arg4, - double arg5, - double arg6, - double arg7, - double arg8, - ) => - Matrix3.zero() - ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - - /// New matrix from [values]. - factory Matrix3.fromList(List 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; - - /// Copes values from [other]. - factory Matrix3.copy(Matrix3 other) => Matrix3.zero()..setFrom(other); - - /// Constructs a new mat3 from columns. - factory Matrix3.columns(Vector3 arg0, Vector3 arg1, Vector3 arg2) => - Matrix3.zero()..setColumns(arg0, arg1, arg2); - - /// Outer product of [u] and [v]. - factory Matrix3.outer(Vector3 u, Vector3 v) => Matrix3.zero()..setOuter(u, v); - - /// Rotation of [radians] around X axis. - factory Matrix3.rotationX(double radians) => - Matrix3.zero()..setRotationX(radians); - - /// Rotation of [radians] around Y axis. - factory Matrix3.rotationY(double radians) => - Matrix3.zero()..setRotationY(radians); - - /// Rotation of [radians] around Z axis. - factory Matrix3.rotationZ(double radians) => - Matrix3.zero()..setRotationZ(radians); - /// Sets the matrix with specified values. void setValues( double arg0, @@ -183,9 +187,9 @@ class Matrix3 { /// Sets the entire matrix to the column values. void setColumns(Vector3 arg0, Vector3 arg1, Vector3 arg2) { - final arg0Storage = arg0._v3storage; - final arg1Storage = arg1._v3storage; - final arg2Storage = arg2._v3storage; + final Float32List arg0Storage = arg0._v3storage; + final Float32List arg1Storage = arg1._v3storage; + final Float32List arg2Storage = arg2._v3storage; _m3storage[0] = arg0Storage[0]; _m3storage[1] = arg0Storage[1]; _m3storage[2] = arg0Storage[2]; @@ -199,7 +203,7 @@ class Matrix3 { /// Sets the entire matrix to the matrix in [arg]. void setFrom(Matrix3 arg) { - final argStorage = arg._m3storage; + final Float32List argStorage = arg._m3storage; _m3storage[8] = argStorage[8]; _m3storage[7] = argStorage[7]; _m3storage[6] = argStorage[6]; @@ -213,8 +217,8 @@ class Matrix3 { /// Set this to the outer product of [u] and [v]. void setOuter(Vector3 u, Vector3 v) { - final uStorage = u._v3storage; - final vStorage = v._v3storage; + final Float32List uStorage = u._v3storage; + final Float32List vStorage = v._v3storage; _m3storage[0] = uStorage[0] * vStorage[0]; _m3storage[1] = uStorage[0] * vStorage[1]; _m3storage[2] = uStorage[0] * vStorage[2]; @@ -242,7 +246,7 @@ class Matrix3 { /// Sets the upper 2x2 of the matrix to be [arg]. void setUpper2x2(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float32List argStorage = arg._m2storage; _m3storage[0] = argStorage[0]; _m3storage[1] = argStorage[1]; _m3storage[3] = argStorage[2]; @@ -266,6 +270,7 @@ class Matrix3 { /// Check if two matrices are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Matrix3) && (_m3storage[0] == other._m3storage[0]) && @@ -279,6 +284,7 @@ class Matrix3 { (_m3storage[8] == other._m3storage[8]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_m3storage); /// Returns row 0 @@ -301,7 +307,7 @@ class Matrix3 { /// Assigns the [row] of to [arg]. void setRow(int row, Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _m3storage[index(row, 0)] = argStorage[0]; _m3storage[index(row, 1)] = argStorage[1]; _m3storage[index(row, 2)] = argStorage[2]; @@ -310,7 +316,7 @@ class Matrix3 { /// Gets the [row] of the matrix Vector3 getRow(int row) { final r = Vector3.zero(); - final rStorage = r._v3storage; + final Float32List rStorage = r._v3storage; rStorage[0] = _m3storage[index(row, 0)]; rStorage[1] = _m3storage[index(row, 1)]; rStorage[2] = _m3storage[index(row, 2)]; @@ -319,8 +325,8 @@ class Matrix3 { /// Assigns the [column] of the matrix [arg] void setColumn(int column, Vector3 arg) { - final argStorage = arg._v3storage; - final entry = column * 3; + final Float32List argStorage = arg._v3storage; + final int entry = column * 3; _m3storage[entry + 2] = argStorage[2]; _m3storage[entry + 1] = argStorage[1]; _m3storage[entry + 0] = argStorage[0]; @@ -329,8 +335,8 @@ class Matrix3 { /// Gets the [column] of the matrix Vector3 getColumn(int column) { final r = Vector3.zero(); - final rStorage = r._v3storage; - final entry = column * 3; + final Float32List rStorage = r._v3storage; + final int entry = column * 3; rStorage[2] = _m3storage[entry + 2]; rStorage[1] = _m3storage[entry + 1]; rStorage[0] = _m3storage[entry + 0]; @@ -342,7 +348,7 @@ class Matrix3 { /// Copy this into [arg]. Matrix3 copyInto(Matrix3 arg) { - final argStorage = arg._m3storage; + final Float32List argStorage = arg._m3storage; argStorage[0] = _m3storage[0]; argStorage[1] = _m3storage[1]; argStorage[2] = _m3storage[2]; @@ -428,7 +434,7 @@ class Matrix3 { /// Returns the component wise absolute value of this. Matrix3 absolute() { final r = Matrix3.zero(); - final rStorage = r._m3storage; + final Float32List rStorage = r._m3storage; rStorage[0] = _m3storage[0].abs(); rStorage[1] = _m3storage[1].abs(); rStorage[2] = _m3storage[2].abs(); @@ -443,13 +449,13 @@ class Matrix3 { /// Returns the determinant of this matrix. double determinant() { - final x = + final double x = _m3storage[0] * ((_m3storage[4] * _m3storage[8]) - (_m3storage[5] * _m3storage[7])); - final y = + final double y = _m3storage[1] * ((_m3storage[3] * _m3storage[8]) - (_m3storage[5] * _m3storage[6])); - final z = + final double z = _m3storage[2] * ((_m3storage[3] * _m3storage[7]) - (_m3storage[4] * _m3storage[6])); return x - y + z; @@ -457,7 +463,7 @@ class Matrix3 { /// Returns the dot product of row [i] and [v]. double dotRow(int i, Vector3 v) { - final vStorage = v._v3storage; + final Float32List vStorage = v._v3storage; return _m3storage[i] * vStorage[0] + _m3storage[3 + i] * vStorage[1] + _m3storage[6 + i] * vStorage[2]; @@ -465,7 +471,7 @@ class Matrix3 { /// Returns the dot product of column [j] and [v]. double dotColumn(int j, Vector3 v) { - final vStorage = v._v3storage; + final Float32List vStorage = v._v3storage; return _m3storage[j * 3] * vStorage[0] + _m3storage[j * 3 + 1] * vStorage[1] + _m3storage[j * 3 + 2] * vStorage[2]; @@ -485,43 +491,43 @@ class Matrix3 { double infinityNorm() { var norm = 0.0; { - var row_norm = 0.0; - row_norm += _m3storage[0].abs(); - row_norm += _m3storage[1].abs(); - row_norm += _m3storage[2].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m3storage[0].abs(); + rowNorm += _m3storage[1].abs(); + rowNorm += _m3storage[2].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m3storage[3].abs(); - row_norm += _m3storage[4].abs(); - row_norm += _m3storage[5].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m3storage[3].abs(); + rowNorm += _m3storage[4].abs(); + rowNorm += _m3storage[5].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m3storage[6].abs(); - row_norm += _m3storage[7].abs(); - row_norm += _m3storage[8].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m3storage[6].abs(); + rowNorm += _m3storage[7].abs(); + rowNorm += _m3storage[8].abs(); + norm = rowNorm > norm ? rowNorm : norm; } return norm; } /// Returns relative error between this and [correct] double relativeError(Matrix3 correct) { - final diff = correct - this; - final correct_norm = correct.infinityNorm(); - final diff_norm = diff.infinityNorm(); - return diff_norm / correct_norm; + final Matrix3 diff = correct - this; + final double correctNorm = correct.infinityNorm(); + final double diffNorm = diff.infinityNorm(); + return diffNorm / correctNorm; } /// Returns absolute error between this and [correct] double absoluteError(Matrix3 correct) { - final this_norm = infinityNorm(); - final correct_norm = correct.infinityNorm(); - final diff_norm = (this_norm - correct_norm).abs(); - return diff_norm; + final double thisNorm = infinityNorm(); + final double correctNorm = correct.infinityNorm(); + final double diffNorm = (thisNorm - correctNorm).abs(); + return diffNorm; } /// Invert the matrix. Returns the determinant. @@ -529,38 +535,38 @@ class Matrix3 { /// Set this matrix to be the inverse of [arg] double copyInverse(Matrix3 arg) { - final det = arg.determinant(); + final double det = arg.determinant(); if (det == 0.0) { setFrom(arg); return 0.0; } - final invDet = 1.0 / det; - final argStorage = arg._m3storage; - final ix = + final double invDet = 1.0 / det; + final Float32List argStorage = arg._m3storage; + final double ix = invDet * (argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]); - final iy = + final double iy = invDet * (argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]); - final iz = + final double iz = invDet * (argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]); - final jx = + final double jx = invDet * (argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]); - final jy = + final double jy = invDet * (argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]); - final jz = + final double jz = invDet * (argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]); - final kx = + final double kx = invDet * (argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]); - final ky = + final double ky = invDet * (argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]); - final kz = + final double kz = invDet * (argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]); _m3storage[0] = ix; @@ -583,8 +589,8 @@ class Matrix3 { /// Turns the matrix into a rotation of [radians] around X void setRotationX(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m3storage[0] = 1.0; _m3storage[1] = 0.0; _m3storage[2] = 0.0; @@ -598,8 +604,8 @@ class Matrix3 { /// Turns the matrix into a rotation of [radians] around Y void setRotationY(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m3storage[0] = c; _m3storage[1] = 0.0; _m3storage[2] = -s; @@ -613,8 +619,8 @@ class Matrix3 { /// Turns the matrix into a rotation of [radians] around Z void setRotationZ(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m3storage[0] = c; _m3storage[1] = s; _m3storage[2] = 0.0; @@ -628,15 +634,15 @@ class Matrix3 { /// Converts into Adjugate matrix and scales by [scale] void scaleAdjoint(double scale) { - final m00 = _m3storage[0]; - final m01 = _m3storage[3]; - final m02 = _m3storage[6]; - final m10 = _m3storage[1]; - final m11 = _m3storage[4]; - final m12 = _m3storage[7]; - final m20 = _m3storage[2]; - final m21 = _m3storage[5]; - final m22 = _m3storage[8]; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[3]; + final double m02 = _m3storage[6]; + final double m10 = _m3storage[1]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[7]; + final double m20 = _m3storage[2]; + final double m21 = _m3storage[5]; + final double m22 = _m3storage[8]; _m3storage[0] = (m11 * m22 - m12 * m21) * scale; _m3storage[1] = (m12 * m20 - m10 * m22) * scale; _m3storage[2] = (m10 * m21 - m11 * m20) * scale; @@ -652,19 +658,19 @@ class Matrix3 { /// Returns [arg]. /// Primarily used by AABB transformation code. Vector3 absoluteRotate(Vector3 arg) { - final m00 = _m3storage[0].abs(); - final m01 = _m3storage[3].abs(); - final m02 = _m3storage[6].abs(); - final m10 = _m3storage[1].abs(); - final m11 = _m3storage[4].abs(); - final m12 = _m3storage[7].abs(); - final m20 = _m3storage[2].abs(); - final m21 = _m3storage[5].abs(); - final m22 = _m3storage[8].abs(); - final argStorage = arg._v3storage; - final x = argStorage[0]; - final y = argStorage[1]; - final z = argStorage[2]; + final double m00 = _m3storage[0].abs(); + final double m01 = _m3storage[3].abs(); + final double m02 = _m3storage[6].abs(); + final double m10 = _m3storage[1].abs(); + final double m11 = _m3storage[4].abs(); + final double m12 = _m3storage[7].abs(); + final double m20 = _m3storage[2].abs(); + final double m21 = _m3storage[5].abs(); + final double m22 = _m3storage[8].abs(); + final Float32List argStorage = arg._v3storage; + final double x = argStorage[0]; + final double y = argStorage[1]; + final double z = argStorage[2]; argStorage[0] = x * m00 + y * m01 + z * m02; argStorage[1] = x * m10 + y * m11 + z * m12; argStorage[2] = x * m20 + y * m21 + z * m22; @@ -675,13 +681,13 @@ class Matrix3 { /// Returns [arg]. /// Primarily used by AABB transformation code. Vector2 absoluteRotate2(Vector2 arg) { - final m00 = _m3storage[0].abs(); - final m01 = _m3storage[3].abs(); - final m10 = _m3storage[1].abs(); - final m11 = _m3storage[4].abs(); - final argStorage = arg._v2storage; - final x = argStorage[0]; - final y = argStorage[1]; + final double m00 = _m3storage[0].abs(); + final double m01 = _m3storage[3].abs(); + final double m10 = _m3storage[1].abs(); + final double m11 = _m3storage[4].abs(); + final Float32List argStorage = arg._v2storage; + final double x = argStorage[0]; + final double y = argStorage[1]; argStorage[0] = x * m00 + y * m01; argStorage[1] = x * m10 + y * m11; return arg; @@ -689,12 +695,12 @@ class Matrix3 { /// Transforms [arg] with this. Vector2 transform2(Vector2 arg) { - final argStorage = arg._v2storage; - final x_ = + final Float32List argStorage = arg._v2storage; + final double x_ = (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + _m3storage[6]; - final y_ = + final double y_ = (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + _m3storage[7]; @@ -721,7 +727,7 @@ class Matrix3 { /// Add [o] to this. void add(Matrix3 o) { - final oStorage = o._m3storage; + final Float32List oStorage = o._m3storage; _m3storage[0] = _m3storage[0] + oStorage[0]; _m3storage[1] = _m3storage[1] + oStorage[1]; _m3storage[2] = _m3storage[2] + oStorage[2]; @@ -735,7 +741,7 @@ class Matrix3 { /// Subtract [o] from this. void sub(Matrix3 o) { - final oStorage = o._m3storage; + final Float32List oStorage = o._m3storage; _m3storage[0] = _m3storage[0] - oStorage[0]; _m3storage[1] = _m3storage[1] - oStorage[1]; _m3storage[2] = _m3storage[2] - oStorage[2]; @@ -762,25 +768,25 @@ class Matrix3 { /// Multiply this by [arg]. void multiply(Matrix3 arg) { - final m00 = _m3storage[0]; - final m01 = _m3storage[3]; - final m02 = _m3storage[6]; - final m10 = _m3storage[1]; - final m11 = _m3storage[4]; - final m12 = _m3storage[7]; - final m20 = _m3storage[2]; - final m21 = _m3storage[5]; - final m22 = _m3storage[8]; - final argStorage = arg._m3storage; - final n00 = argStorage[0]; - final n01 = argStorage[3]; - final n02 = argStorage[6]; - final n10 = argStorage[1]; - final n11 = argStorage[4]; - final n12 = argStorage[7]; - final n20 = argStorage[2]; - final n21 = argStorage[5]; - final n22 = argStorage[8]; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[3]; + final double m02 = _m3storage[6]; + final double m10 = _m3storage[1]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[7]; + final double m20 = _m3storage[2]; + final double m21 = _m3storage[5]; + final double m22 = _m3storage[8]; + final Float32List argStorage = arg._m3storage; + final double n00 = argStorage[0]; + final double n01 = argStorage[3]; + final double n02 = argStorage[6]; + final double n10 = argStorage[1]; + final double n11 = argStorage[4]; + final double n12 = argStorage[7]; + final double n20 = argStorage[2]; + final double n21 = argStorage[5]; + final double n22 = argStorage[8]; _m3storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20); _m3storage[3] = (m00 * n01) + (m01 * n11) + (m02 * n21); _m3storage[6] = (m00 * n02) + (m01 * n12) + (m02 * n22); @@ -796,16 +802,16 @@ class Matrix3 { Matrix3 multiplied(Matrix3 arg) => clone()..multiply(arg); void transposeMultiply(Matrix3 arg) { - final m00 = _m3storage[0]; - final m01 = _m3storage[1]; - final m02 = _m3storage[2]; - final m10 = _m3storage[3]; - final m11 = _m3storage[4]; - final m12 = _m3storage[5]; - final m20 = _m3storage[6]; - final m21 = _m3storage[7]; - final m22 = _m3storage[8]; - final argStorage = arg._m3storage; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[1]; + final double m02 = _m3storage[2]; + final double m10 = _m3storage[3]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[5]; + final double m20 = _m3storage[6]; + final double m21 = _m3storage[7]; + final double m22 = _m3storage[8]; + final Float32List argStorage = arg._m3storage; _m3storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]) + (m02 * argStorage[2]); _m3storage[3] = @@ -827,16 +833,16 @@ class Matrix3 { } void multiplyTranspose(Matrix3 arg) { - final m00 = _m3storage[0]; - final m01 = _m3storage[3]; - final m02 = _m3storage[6]; - final m10 = _m3storage[1]; - final m11 = _m3storage[4]; - final m12 = _m3storage[7]; - final m20 = _m3storage[2]; - final m21 = _m3storage[5]; - final m22 = _m3storage[8]; - final argStorage = arg._m3storage; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[3]; + final double m02 = _m3storage[6]; + final double m10 = _m3storage[1]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[7]; + final double m20 = _m3storage[2]; + final double m21 = _m3storage[5]; + final double m22 = _m3storage[8]; + final Float32List argStorage = arg._m3storage; _m3storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[3]) + (m02 * argStorage[6]); _m3storage[3] = @@ -860,16 +866,16 @@ class Matrix3 { /// Transform [arg] of type [Vector3] using the transformation defined by /// this. Vector3 transform(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float32List argStorage = arg._v3storage; + final double x_ = (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + (_m3storage[6] * argStorage[2]); - final y_ = + final double y_ = (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + (_m3storage[7] * argStorage[2]); - final z_ = + final double z_ = (_m3storage[2] * argStorage[0]) + (_m3storage[5] * argStorage[1]) + (_m3storage[8] * argStorage[2]); @@ -933,23 +939,23 @@ class Matrix3 { } Vector3 get right { - final x = _m3storage[0]; - final y = _m3storage[1]; - final z = _m3storage[2]; + final double x = _m3storage[0]; + final double y = _m3storage[1]; + final double z = _m3storage[2]; return Vector3(x, y, z); } Vector3 get up { - final x = _m3storage[3]; - final y = _m3storage[4]; - final z = _m3storage[5]; + final double x = _m3storage[3]; + final double y = _m3storage[4]; + final double z = _m3storage[5]; return Vector3(x, y, z); } Vector3 get forward { - final x = _m3storage[6]; - final y = _m3storage[7]; - final z = _m3storage[8]; + final double x = _m3storage[6]; + final double y = _m3storage[7]; + final double z = _m3storage[8]; return Vector3(x, y, z); } diff --git a/packages/vector_math/lib/src/vector_math/matrix4.dart b/packages/vector_math/lib/src/vector_math/matrix4.dart index 063646f..b29b760 100644 --- a/packages/vector_math/lib/src/vector_math/matrix4.dart +++ b/packages/vector_math/lib/src/vector_math/matrix4.dart @@ -2,186 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; /// 4D Matrix. /// Values are stored in column major order. class Matrix4 { - final Float32List _m4storage; - - /// The components of the matrix. - Float32List get storage => _m4storage; - - /// Solve [A] * [x] = [b]. - static void solve2(Matrix4 A, Vector2 x, Vector2 b) { - final a11 = A.entry(0, 0); - final a12 = A.entry(0, 1); - final a21 = A.entry(1, 0); - final a22 = A.entry(1, 1); - final bx = b.x - A._m4storage[8]; - final by = b.y - A._m4storage[9]; - var det = a11 * a22 - a12 * a21; - - if (det != 0.0) { - det = 1.0 / det; - } - - x - ..x = det * (a22 * bx - a12 * by) - ..y = det * (a11 * by - a21 * bx); - } - - /// Solve [A] * [x] = [b]. - static void solve3(Matrix4 A, Vector3 x, Vector3 b) { - final A0x = A.entry(0, 0); - final A0y = A.entry(1, 0); - final A0z = A.entry(2, 0); - final A1x = A.entry(0, 1); - final A1y = A.entry(1, 1); - final A1z = A.entry(2, 1); - final A2x = A.entry(0, 2); - final A2y = A.entry(1, 2); - final A2z = A.entry(2, 2); - final bx = b.x - A._m4storage[12]; - final by = b.y - A._m4storage[13]; - final bz = b.z - A._m4storage[14]; - double rx, ry, rz; - double det; - - // Column1 cross Column 2 - rx = A1y * A2z - A1z * A2y; - ry = A1z * A2x - A1x * A2z; - rz = A1x * A2y - A1y * A2x; - - // A.getColumn(0).dot(x) - det = A0x * rx + A0y * ry + A0z * rz; - if (det != 0.0) { - det = 1.0 / det; - } - - // b dot [Column1 cross Column 2] - final x_ = det * (bx * rx + by * ry + bz * rz); - - // Column2 cross b - rx = -(A2y * bz - A2z * by); - ry = -(A2z * bx - A2x * bz); - rz = -(A2x * by - A2y * bx); - // Column0 dot -[Column2 cross b (Column3)] - final y_ = det * (A0x * rx + A0y * ry + A0z * rz); - - // b cross Column 1 - rx = -(by * A1z - bz * A1y); - ry = -(bz * A1x - bx * A1z); - rz = -(bx * A1y - by * A1x); - // Column0 dot -[b cross Column 1] - final z_ = det * (A0x * rx + A0y * ry + A0z * rz); - - x - ..x = x_ - ..y = y_ - ..z = z_; - } - - /// Solve [A] * [x] = [b]. - static void solve(Matrix4 A, Vector4 x, Vector4 b) { - final a00 = A._m4storage[0]; - final a01 = A._m4storage[1]; - final a02 = A._m4storage[2]; - final a03 = A._m4storage[3]; - final a10 = A._m4storage[4]; - final a11 = A._m4storage[5]; - final a12 = A._m4storage[6]; - final a13 = A._m4storage[7]; - final a20 = A._m4storage[8]; - final a21 = A._m4storage[9]; - final a22 = A._m4storage[10]; - final a23 = A._m4storage[11]; - final a30 = A._m4storage[12]; - final a31 = A._m4storage[13]; - final a32 = A._m4storage[14]; - final a33 = A._m4storage[15]; - final b00 = a00 * a11 - a01 * a10; - final b01 = a00 * a12 - a02 * a10; - final b02 = a00 * a13 - a03 * a10; - final b03 = a01 * a12 - a02 * a11; - final b04 = a01 * a13 - a03 * a11; - final b05 = a02 * a13 - a03 * a12; - final b06 = a20 * a31 - a21 * a30; - final b07 = a20 * a32 - a22 * a30; - final b08 = a20 * a33 - a23 * a30; - final b09 = a21 * a32 - a22 * a31; - final b10 = a21 * a33 - a23 * a31; - final b11 = a22 * a33 - a23 * a32; - - final bX = b.storage[0]; - final bY = b.storage[1]; - final bZ = b.storage[2]; - final bW = b.storage[3]; - - var det = - b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; - - if (det != 0.0) { - det = 1.0 / det; - } - - x - ..x = - det * - ((a11 * b11 - a12 * b10 + a13 * b09) * bX - - (a10 * b11 - a12 * b08 + a13 * b07) * bY + - (a10 * b10 - a11 * b08 + a13 * b06) * bZ - - (a10 * b09 - a11 * b07 + a12 * b06) * bW) - ..y = - det * - -((a01 * b11 - a02 * b10 + a03 * b09) * bX - - (a00 * b11 - a02 * b08 + a03 * b07) * bY + - (a00 * b10 - a01 * b08 + a03 * b06) * bZ - - (a00 * b09 - a01 * b07 + a02 * b06) * bW) - ..z = - det * - ((a31 * b05 - a32 * b04 + a33 * b03) * bX - - (a30 * b05 - a32 * b02 + a33 * b01) * bY + - (a30 * b04 - a31 * b02 + a33 * b00) * bZ - - (a30 * b03 - a31 * b01 + a32 * b00) * bW) - ..w = - det * - -((a21 * b05 - a22 * b04 + a23 * b03) * bX - - (a20 * b05 - a22 * b02 + a23 * b01) * bY + - (a20 * b04 - a21 * b02 + a23 * b00) * bZ - - (a20 * b03 - a21 * b01 + a22 * b00) * bW); - } - - /// Returns a matrix that is the inverse of [other] if [other] is invertible, - /// otherwise `null`. - static Matrix4? tryInvert(Matrix4 other) { - final r = Matrix4.zero(); - final determinant = r.copyInverse(other); - if (determinant == 0.0) { - return null; - } - return r; - } - - /// Return index in storage for [row], [col] value. - int index(int row, int col) => (col * 4) + row; - - /// Value at [row], [col]. - double entry(int row, int col) { - assert((row >= 0) && (row < dimension)); - assert((col >= 0) && (col < dimension)); - - return _m4storage[index(row, col)]; - } - - /// Set value at [row], [col] to be [v]. - void setEntry(int row, int col, double v) { - assert((row >= 0) && (row < dimension)); - assert((col >= 0) && (col < dimension)); - - _m4storage[index(row, col)] = v; - } - /// Constructs a new mat4. factory Matrix4( double arg0, @@ -200,56 +29,57 @@ 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 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 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); @@ -257,7 +87,7 @@ class Matrix4 { /// Constructs a matrix that is the inverse of [other]. factory Matrix4.inverted(Matrix4 other) { final r = Matrix4.zero(); - final determinant = r.copyInverse(other); + final double determinant = r.copyInverse(other); if (determinant == 0.0) { throw ArgumentError.value(other, 'other', 'Matrix cannot be inverted'); } @@ -276,24 +106,28 @@ 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) => @@ -304,8 +138,8 @@ class Matrix4 { /// Scale matrix. factory Matrix4.diagonal3(Vector3 scale) { final m = Matrix4.zero(); - final mStorage = m._m4storage; - final scaleStorage = scale._v3storage; + final Float32List mStorage = m._m4storage; + final Float32List scaleStorage = scale._v3storage; mStorage[15] = 1.0; mStorage[10] = scaleStorage[2]; mStorage[5] = scaleStorage[1]; @@ -359,6 +193,180 @@ class Matrix4 { ) => Matrix4.zero() ..setFromTranslationRotationScale(translation, rotation, scale); + final Float32List _m4storage; + + /// The components of the matrix. + Float32List get storage => _m4storage; + + /// Solve [A] * [x] = [b]. + static void solve2(Matrix4 A, Vector2 x, Vector2 b) { + final double a11 = A.entry(0, 0); + final double a12 = A.entry(0, 1); + final double a21 = A.entry(1, 0); + final double a22 = A.entry(1, 1); + final double bx = b.x - A._m4storage[8]; + final double by = b.y - A._m4storage[9]; + double det = a11 * a22 - a12 * a21; + + if (det != 0.0) { + det = 1.0 / det; + } + + x + ..x = det * (a22 * bx - a12 * by) + ..y = det * (a11 * by - a21 * bx); + } + + /// Solve [A] * [x] = [b]. + static void solve3(Matrix4 A, Vector3 x, Vector3 b) { + final double a0x = A.entry(0, 0); + final double a0y = A.entry(1, 0); + final double a0z = A.entry(2, 0); + final double a1x = A.entry(0, 1); + final double a1y = A.entry(1, 1); + final double a1z = A.entry(2, 1); + final double a2x = A.entry(0, 2); + final double a2y = A.entry(1, 2); + final double a2z = A.entry(2, 2); + final double bx = b.x - A._m4storage[12]; + final double by = b.y - A._m4storage[13]; + final double bz = b.z - A._m4storage[14]; + double rx, ry, rz; + double det; + + // Column1 cross Column 2 + rx = a1y * a2z - a1z * a2y; + ry = a1z * a2x - a1x * a2z; + rz = a1x * a2y - a1y * a2x; + + // A.getColumn(0).dot(x) + det = a0x * rx + a0y * ry + a0z * rz; + if (det != 0.0) { + det = 1.0 / det; + } + + // b dot [Column1 cross Column 2] + final double x_ = det * (bx * rx + by * ry + bz * rz); + + // Column2 cross b + rx = -(a2y * bz - a2z * by); + ry = -(a2z * bx - a2x * bz); + rz = -(a2x * by - a2y * bx); + // Column0 dot -[Column2 cross b (Column3)] + final double y_ = det * (a0x * rx + a0y * ry + a0z * rz); + + // b cross Column 1 + rx = -(by * a1z - bz * a1y); + ry = -(bz * a1x - bx * a1z); + rz = -(bx * a1y - by * a1x); + // Column0 dot -[b cross Column 1] + final double z_ = det * (a0x * rx + a0y * ry + a0z * rz); + + x + ..x = x_ + ..y = y_ + ..z = z_; + } + + /// Solve [A] * [x] = [b]. + static void solve(Matrix4 A, Vector4 x, Vector4 b) { + final double a00 = A._m4storage[0]; + final double a01 = A._m4storage[1]; + final double a02 = A._m4storage[2]; + final double a03 = A._m4storage[3]; + final double a10 = A._m4storage[4]; + final double a11 = A._m4storage[5]; + final double a12 = A._m4storage[6]; + final double a13 = A._m4storage[7]; + final double a20 = A._m4storage[8]; + final double a21 = A._m4storage[9]; + final double a22 = A._m4storage[10]; + final double a23 = A._m4storage[11]; + final double a30 = A._m4storage[12]; + final double a31 = A._m4storage[13]; + final double a32 = A._m4storage[14]; + final double a33 = A._m4storage[15]; + final double b00 = a00 * a11 - a01 * a10; + final double b01 = a00 * a12 - a02 * a10; + final double b02 = a00 * a13 - a03 * a10; + final double b03 = a01 * a12 - a02 * a11; + final double b04 = a01 * a13 - a03 * a11; + final double b05 = a02 * a13 - a03 * a12; + final double b06 = a20 * a31 - a21 * a30; + final double b07 = a20 * a32 - a22 * a30; + final double b08 = a20 * a33 - a23 * a30; + final double b09 = a21 * a32 - a22 * a31; + final double b10 = a21 * a33 - a23 * a31; + final double b11 = a22 * a33 - a23 * a32; + + final double bX = b.storage[0]; + final double bY = b.storage[1]; + final double bZ = b.storage[2]; + final double bW = b.storage[3]; + + double det = + b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (det != 0.0) { + det = 1.0 / det; + } + + x + ..x = + det * + ((a11 * b11 - a12 * b10 + a13 * b09) * bX - + (a10 * b11 - a12 * b08 + a13 * b07) * bY + + (a10 * b10 - a11 * b08 + a13 * b06) * bZ - + (a10 * b09 - a11 * b07 + a12 * b06) * bW) + ..y = + det * + -((a01 * b11 - a02 * b10 + a03 * b09) * bX - + (a00 * b11 - a02 * b08 + a03 * b07) * bY + + (a00 * b10 - a01 * b08 + a03 * b06) * bZ - + (a00 * b09 - a01 * b07 + a02 * b06) * bW) + ..z = + det * + ((a31 * b05 - a32 * b04 + a33 * b03) * bX - + (a30 * b05 - a32 * b02 + a33 * b01) * bY + + (a30 * b04 - a31 * b02 + a33 * b00) * bZ - + (a30 * b03 - a31 * b01 + a32 * b00) * bW) + ..w = + det * + -((a21 * b05 - a22 * b04 + a23 * b03) * bX - + (a20 * b05 - a22 * b02 + a23 * b01) * bY + + (a20 * b04 - a21 * b02 + a23 * b00) * bZ - + (a20 * b03 - a21 * b01 + a22 * b00) * bW); + } + + /// Returns a matrix that is the inverse of [other] if [other] is invertible, + /// otherwise `null`. + static Matrix4? tryInvert(Matrix4 other) { + final r = Matrix4.zero(); + final double determinant = r.copyInverse(other); + if (determinant == 0.0) { + return null; + } + return r; + } + + /// Return index in storage for [row], [col] value. + int index(int row, int col) => (col * 4) + row; + + /// Value at [row], [col]. + double entry(int row, int col) { + assert((row >= 0) && (row < dimension)); + assert((col >= 0) && (col < dimension)); + + return _m4storage[index(row, col)]; + } + + /// Set value at [row], [col] to be [v]. + void setEntry(int row, int col, double v) { + assert((row >= 0) && (row < dimension)); + assert((col >= 0) && (col < dimension)); + + _m4storage[index(row, col)] = v; + } /// Sets the diagonal to [arg]. void splatDiagonal(double arg) { @@ -407,10 +415,10 @@ class Matrix4 { /// Sets the entire matrix to the column values. void setColumns(Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) { - final arg0Storage = arg0._v4storage; - final arg1Storage = arg1._v4storage; - final arg2Storage = arg2._v4storage; - final arg3Storage = arg3._v4storage; + final Float32List arg0Storage = arg0._v4storage; + final Float32List arg1Storage = arg1._v4storage; + final Float32List arg2Storage = arg2._v4storage; + final Float32List arg3Storage = arg3._v4storage; _m4storage[0] = arg0Storage[0]; _m4storage[1] = arg0Storage[1]; _m4storage[2] = arg0Storage[2]; @@ -431,7 +439,7 @@ class Matrix4 { /// Sets the entire matrix to the matrix in [arg]. void setFrom(Matrix4 arg) { - final argStorage = arg._m4storage; + final Float32List argStorage = arg._m4storage; _m4storage[15] = argStorage[15]; _m4storage[14] = argStorage[14]; _m4storage[13] = argStorage[13]; @@ -452,25 +460,25 @@ class Matrix4 { /// Sets the matrix from translation [arg0] and rotation [arg1]. void setFromTranslationRotation(Vector3 arg0, Quaternion arg1) { - final arg1Storage = arg1._qStorage; - final x = arg1Storage[0]; - final y = arg1Storage[1]; - final z = arg1Storage[2]; - final w = arg1Storage[3]; - final x2 = x + x; - final y2 = y + y; - final z2 = z + z; - final xx = x * x2; - final xy = x * y2; - final xz = x * z2; - final yy = y * y2; - final yz = y * z2; - final zz = z * z2; - final wx = w * x2; - final wy = w * y2; - final wz = w * z2; - - final arg0Storage = arg0._v3storage; + final Float32List arg1Storage = arg1._qStorage; + final double x = arg1Storage[0]; + final double y = arg1Storage[1]; + final double z = arg1Storage[2]; + final double w = arg1Storage[3]; + final double x2 = x + x; + final double y2 = y + y; + final double z2 = z + z; + final double xx = x * x2; + final double xy = x * y2; + final double xz = x * z2; + final double yy = y * y2; + final double yz = y * z2; + final double zz = z * z2; + final double wx = w * x2; + final double wy = w * y2; + final double wz = w * z2; + + final Float32List arg0Storage = arg0._v3storage; _m4storage[0] = 1.0 - (yy + zz); _m4storage[1] = xy + wz; _m4storage[2] = xz - wy; @@ -501,7 +509,7 @@ class Matrix4 { /// Sets the upper 2x2 of the matrix to be [arg]. void setUpper2x2(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float32List argStorage = arg._m2storage; _m4storage[0] = argStorage[0]; _m4storage[1] = argStorage[1]; _m4storage[4] = argStorage[2]; @@ -510,7 +518,7 @@ class Matrix4 { /// Sets the diagonal of the matrix to be [arg]. void setDiagonal(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _m4storage[0] = argStorage[0]; _m4storage[5] = argStorage[1]; _m4storage[10] = argStorage[2]; @@ -518,8 +526,8 @@ class Matrix4 { } void setOuter(Vector4 u, Vector4 v) { - final uStorage = u._v4storage; - final vStorage = v._v4storage; + final Float32List uStorage = u._v4storage; + final Float32List vStorage = v._v4storage; _m4storage[0] = uStorage[0] * vStorage[0]; _m4storage[1] = uStorage[0] * vStorage[1]; _m4storage[2] = uStorage[0] * vStorage[2]; @@ -557,6 +565,7 @@ class Matrix4 { /// Check if two matrices are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Matrix4) && (_m4storage[0] == other._m4storage[0]) && @@ -577,6 +586,7 @@ class Matrix4 { (_m4storage[15] == other._m4storage[15]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_m4storage); /// Returns row 0 @@ -605,7 +615,7 @@ class Matrix4 { /// Assigns the [row] of the matrix [arg] void setRow(int row, Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _m4storage[index(row, 0)] = argStorage[0]; _m4storage[index(row, 1)] = argStorage[1]; _m4storage[index(row, 2)] = argStorage[2]; @@ -615,7 +625,7 @@ class Matrix4 { /// Gets the [row] of the matrix Vector4 getRow(int row) { final r = Vector4.zero(); - final rStorage = r._v4storage; + final Float32List rStorage = r._v4storage; rStorage[0] = _m4storage[index(row, 0)]; rStorage[1] = _m4storage[index(row, 1)]; rStorage[2] = _m4storage[index(row, 2)]; @@ -625,8 +635,8 @@ class Matrix4 { /// Assigns the [column] of the matrix [arg] void setColumn(int column, Vector4 arg) { - final entry = column * 4; - final argStorage = arg._v4storage; + final int entry = column * 4; + final Float32List argStorage = arg._v4storage; _m4storage[entry + 3] = argStorage[3]; _m4storage[entry + 2] = argStorage[2]; _m4storage[entry + 1] = argStorage[1]; @@ -636,8 +646,8 @@ class Matrix4 { /// Gets the [column] of the matrix Vector4 getColumn(int column) { final r = Vector4.zero(); - final rStorage = r._v4storage; - final entry = column * 4; + final Float32List rStorage = r._v4storage; + final int entry = column * 4; rStorage[3] = _m4storage[entry + 3]; rStorage[2] = _m4storage[entry + 2]; rStorage[1] = _m4storage[entry + 1]; @@ -650,7 +660,7 @@ class Matrix4 { /// Copy into [arg]. Matrix4 copyInto(Matrix4 arg) { - final argStorage = arg._m4storage; + final Float32List argStorage = arg._m4storage; argStorage[0] = _m4storage[0]; argStorage[1] = _m4storage[1]; argStorage[2] = _m4storage[2]; @@ -730,28 +740,28 @@ class Matrix4 { /// Translate this matrix by x, y, z, w. void translateByDouble(double tx, double ty, double tz, double tw) { - final t1 = + final double t1 = _m4storage[0] * tx + _m4storage[4] * ty + _m4storage[8] * tz + _m4storage[12] * tw; _m4storage[12] = t1; - final t2 = + final double t2 = _m4storage[1] * tx + _m4storage[5] * ty + _m4storage[9] * tz + _m4storage[13] * tw; _m4storage[13] = t2; - final t3 = + final double t3 = _m4storage[2] * tx + _m4storage[6] * ty + _m4storage[10] * tz + _m4storage[14] * tw; _m4storage[14] = t3; - final t4 = + final double t4 = _m4storage[3] * tx + _m4storage[7] * ty + _m4storage[11] * tz + @@ -810,28 +820,28 @@ class Matrix4 { /// Multiply this by a translation from the left. void leftTranslateByDouble(double tx, double ty, double tz, double tw) { // Column 1 - final r1 = _m4storage[3]; + final double r1 = _m4storage[3]; _m4storage[0] += tx * r1; _m4storage[1] += ty * r1; _m4storage[2] += tz * r1; _m4storage[3] = tw * r1; // Column 2 - final r2 = _m4storage[7]; + final double r2 = _m4storage[7]; _m4storage[4] += tx * r2; _m4storage[5] += ty * r2; _m4storage[6] += tz * r2; _m4storage[7] = tw * r2; // Column 3 - final r3 = _m4storage[11]; + final double r3 = _m4storage[11]; _m4storage[8] += tx * r3; _m4storage[9] += ty * r3; _m4storage[10] += tz * r3; _m4storage[11] = tw * r3; // Column 4 - final r4 = _m4storage[15]; + final double r4 = _m4storage[15]; _m4storage[12] += tx * r4; _m4storage[13] += ty * r4; _m4storage[14] += tz * r4; @@ -861,36 +871,46 @@ class Matrix4 { /// Rotate this [angle] radians around [axis] void rotate(Vector3 axis, double angle) { - final len = axis.length; - final axisStorage = axis._v3storage; - final x = axisStorage[0] / len; - final y = axisStorage[1] / len; - final z = axisStorage[2] / len; - final c = math.cos(angle); - final s = math.sin(angle); - final C = 1.0 - c; - final m11 = x * x * C + c; - final m12 = x * y * C - z * s; - final m13 = x * z * C + y * s; - final m21 = y * x * C + z * s; - final m22 = y * y * C + c; - final m23 = y * z * C - x * s; - final m31 = z * x * C - y * s; - final m32 = z * y * C + x * s; - final m33 = z * z * C + c; - final t1 = _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31; - final t2 = _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31; - final t3 = _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31; - final t4 = _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31; - final t5 = _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32; - final t6 = _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32; - final t7 = _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32; - final t8 = _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32; - final t9 = _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33; - final t10 = _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33; - final t11 = + final double len = axis.length; + final Float32List axisStorage = axis._v3storage; + final double x = axisStorage[0] / len; + final double y = axisStorage[1] / len; + final double z = axisStorage[2] / len; + final double c = math.cos(angle); + final double s = math.sin(angle); + final double C = 1.0 - c; + final double m11 = x * x * C + c; + final double m12 = x * y * C - z * s; + final double m13 = x * z * C + y * s; + final double m21 = y * x * C + z * s; + final double m22 = y * y * C + c; + final double m23 = y * z * C - x * s; + final double m31 = z * x * C - y * s; + final double m32 = z * y * C + x * s; + final double m33 = z * z * C + c; + final double t1 = + _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31; + final double t2 = + _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31; + final double t3 = + _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31; + final double t4 = + _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31; + final double t5 = + _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32; + final double t6 = + _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32; + final double t7 = + _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32; + final double t8 = + _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32; + final double t9 = + _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33; + final double t10 = + _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33; + final double t11 = _m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33; - final t12 = + final double t12 = _m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33; _m4storage[0] = t1; _m4storage[1] = t2; @@ -908,16 +928,16 @@ class Matrix4 { /// Rotate this [angle] radians around X void rotateX(double angle) { - final cosAngle = math.cos(angle); - final sinAngle = math.sin(angle); - final t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle; - final t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle; - final t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle; - final t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle; - final t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle; - final t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle; - final t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle; - final t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle; + final double cosAngle = math.cos(angle); + final double sinAngle = math.sin(angle); + final double t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle; + final double t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle; + final double t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle; + final double t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle; + final double t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle; + final double t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle; + final double t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle; + final double t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle; _m4storage[4] = t1; _m4storage[5] = t2; _m4storage[6] = t3; @@ -930,16 +950,16 @@ class Matrix4 { /// Rotate this matrix [angle] radians around Y void rotateY(double angle) { - final cosAngle = math.cos(angle); - final sinAngle = math.sin(angle); - final t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle; - final t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle; - final t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle; - final t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle; - final t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle; - final t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle; - final t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle; - final t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle; + final double cosAngle = math.cos(angle); + final double sinAngle = math.sin(angle); + final double t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle; + final double t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle; + final double t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle; + final double t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle; + final double t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle; + final double t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle; + final double t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle; + final double t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle; _m4storage[0] = t1; _m4storage[1] = t2; _m4storage[2] = t3; @@ -952,16 +972,16 @@ class Matrix4 { /// Rotate this matrix [angle] radians around Z void rotateZ(double angle) { - final cosAngle = math.cos(angle); - final sinAngle = math.sin(angle); - final t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle; - final t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle; - final t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle; - final t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle; - final t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle; - final t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle; - final t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle; - final t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle; + final double cosAngle = math.cos(angle); + final double sinAngle = math.sin(angle); + final double t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle; + final double t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle; + final double t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle; + final double t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle; + final double t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle; + final double t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle; + final double t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle; + final double t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle; _m4storage[0] = t1; _m4storage[1] = t2; _m4storage[2] = t3; @@ -1119,7 +1139,7 @@ class Matrix4 { /// Returns the component wise absolute value of this. Matrix4 absolute() { final r = Matrix4.zero(); - final rStorage = r._m4storage; + final Float32List rStorage = r._m4storage; rStorage[0] = _m4storage[0].abs(); rStorage[1] = _m4storage[1].abs(); rStorage[2] = _m4storage[2].abs(); @@ -1141,31 +1161,31 @@ class Matrix4 { /// Returns the determinant of this matrix. double determinant() { - final det2_01_01 = + final double det2_01_01 = _m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4]; - final det2_01_02 = + final double det2_01_02 = _m4storage[0] * _m4storage[6] - _m4storage[2] * _m4storage[4]; - final det2_01_03 = + final double det2_01_03 = _m4storage[0] * _m4storage[7] - _m4storage[3] * _m4storage[4]; - final det2_01_12 = + final double det2_01_12 = _m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5]; - final det2_01_13 = + final double det2_01_13 = _m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5]; - final det2_01_23 = + final double det2_01_23 = _m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6]; - final det3_201_012 = + final double det3_201_012 = _m4storage[8] * det2_01_12 - _m4storage[9] * det2_01_02 + _m4storage[10] * det2_01_01; - final det3_201_013 = + final double det3_201_013 = _m4storage[8] * det2_01_13 - _m4storage[9] * det2_01_03 + _m4storage[11] * det2_01_01; - final det3_201_023 = + final double det3_201_023 = _m4storage[8] * det2_01_23 - _m4storage[10] * det2_01_03 + _m4storage[11] * det2_01_02; - final det3_201_123 = + final double det3_201_123 = _m4storage[9] * det2_01_23 - _m4storage[10] * det2_01_13 + _m4storage[11] * det2_01_12; @@ -1177,7 +1197,7 @@ class Matrix4 { /// Returns the dot product of row [i] and [v]. double dotRow(int i, Vector4 v) { - final vStorage = v._v4storage; + final Float32List vStorage = v._v4storage; return _m4storage[i] * vStorage[0] + _m4storage[4 + i] * vStorage[1] + _m4storage[8 + i] * vStorage[2] + @@ -1186,7 +1206,7 @@ class Matrix4 { /// Returns the dot product of column [j] and [v]. double dotColumn(int j, Vector4 v) { - final vStorage = v._v4storage; + final Float32List vStorage = v._v4storage; return _m4storage[j * 4] * vStorage[0] + _m4storage[j * 4 + 1] * vStorage[1] + _m4storage[j * 4 + 2] * vStorage[2] + @@ -1208,71 +1228,71 @@ class Matrix4 { double infinityNorm() { var norm = 0.0; { - var row_norm = 0.0; - row_norm += _m4storage[0].abs(); - row_norm += _m4storage[1].abs(); - row_norm += _m4storage[2].abs(); - row_norm += _m4storage[3].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[0].abs(); + rowNorm += _m4storage[1].abs(); + rowNorm += _m4storage[2].abs(); + rowNorm += _m4storage[3].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m4storage[4].abs(); - row_norm += _m4storage[5].abs(); - row_norm += _m4storage[6].abs(); - row_norm += _m4storage[7].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[4].abs(); + rowNorm += _m4storage[5].abs(); + rowNorm += _m4storage[6].abs(); + rowNorm += _m4storage[7].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m4storage[8].abs(); - row_norm += _m4storage[9].abs(); - row_norm += _m4storage[10].abs(); - row_norm += _m4storage[11].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[8].abs(); + rowNorm += _m4storage[9].abs(); + rowNorm += _m4storage[10].abs(); + rowNorm += _m4storage[11].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m4storage[12].abs(); - row_norm += _m4storage[13].abs(); - row_norm += _m4storage[14].abs(); - row_norm += _m4storage[15].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[12].abs(); + rowNorm += _m4storage[13].abs(); + rowNorm += _m4storage[14].abs(); + rowNorm += _m4storage[15].abs(); + norm = rowNorm > norm ? rowNorm : norm; } return norm; } /// Returns relative error between this and [correct] double relativeError(Matrix4 correct) { - final diff = correct - this; - final correct_norm = correct.infinityNorm(); - final diff_norm = diff.infinityNorm(); - return diff_norm / correct_norm; + final Matrix4 diff = correct - this; + final double correctNorm = correct.infinityNorm(); + final double diffNorm = diff.infinityNorm(); + return diffNorm / correctNorm; } /// Returns absolute error between this and [correct] double absoluteError(Matrix4 correct) { - final this_norm = infinityNorm(); - final correct_norm = correct.infinityNorm(); - final diff_norm = (this_norm - correct_norm).abs(); - return diff_norm; + final double thisNorm = infinityNorm(); + final double correctNorm = correct.infinityNorm(); + final double diffNorm = (thisNorm - correctNorm).abs(); + return diffNorm; } /// Returns the translation vector from this homogeneous transformation /// matrix. Vector3 getTranslation() { - final z = _m4storage[14]; - final y = _m4storage[13]; - final x = _m4storage[12]; + final double z = _m4storage[14]; + final double y = _m4storage[13]; + final double x = _m4storage[12]; return Vector3(x, y, z); } /// Sets the translation vector in this homogeneous transformation matrix. void setTranslation(Vector3 t) { - final tStorage = t._v3storage; - final z = tStorage[2]; - final y = tStorage[1]; - final x = tStorage[0]; + final Float32List tStorage = t._v3storage; + final double z = tStorage[2]; + final double y = tStorage[1]; + final double x = tStorage[0]; _m4storage[14] = z; _m4storage[13] = y; _m4storage[12] = x; @@ -1295,7 +1315,7 @@ class Matrix4 { /// Copies the rotation matrix from this homogeneous transformation matrix /// into [rotation]. void copyRotation(Matrix3 rotation) { - final rStorage = rotation._m3storage; + final Float32List rStorage = rotation._m3storage; rStorage[0] = _m4storage[0]; rStorage[1] = _m4storage[1]; rStorage[2] = _m4storage[2]; @@ -1309,7 +1329,7 @@ class Matrix4 { /// Sets the rotation matrix in this homogeneous transformation matrix. void setRotation(Matrix3 r) { - final rStorage = r._m3storage; + final Float32List rStorage = r._m3storage; _m4storage[0] = rStorage[0]; _m4storage[1] = rStorage[1]; _m4storage[2] = rStorage[2]; @@ -1329,15 +1349,15 @@ class Matrix4 { /// Returns the max scale value of the 3 axes. double getMaxScaleOnAxis() { - final scaleXSq = + final double scaleXSq = _m4storage[0] * _m4storage[0] + _m4storage[1] * _m4storage[1] + _m4storage[2] * _m4storage[2]; - final scaleYSq = + final double scaleYSq = _m4storage[4] * _m4storage[4] + _m4storage[5] * _m4storage[5] + _m4storage[6] * _m4storage[6]; - final scaleZSq = + final double scaleZSq = _m4storage[8] * _m4storage[8] + _m4storage[9] * _m4storage[9] + _m4storage[10] * _m4storage[10]; @@ -1372,42 +1392,42 @@ class Matrix4 { /// Set this matrix to be the inverse of [arg] double copyInverse(Matrix4 arg) { - final argStorage = arg._m4storage; - final a00 = argStorage[0]; - final a01 = argStorage[1]; - final a02 = argStorage[2]; - final a03 = argStorage[3]; - final a10 = argStorage[4]; - final a11 = argStorage[5]; - final a12 = argStorage[6]; - final a13 = argStorage[7]; - final a20 = argStorage[8]; - final a21 = argStorage[9]; - final a22 = argStorage[10]; - final a23 = argStorage[11]; - final a30 = argStorage[12]; - final a31 = argStorage[13]; - final a32 = argStorage[14]; - final a33 = argStorage[15]; - final b00 = a00 * a11 - a01 * a10; - final b01 = a00 * a12 - a02 * a10; - final b02 = a00 * a13 - a03 * a10; - final b03 = a01 * a12 - a02 * a11; - final b04 = a01 * a13 - a03 * a11; - final b05 = a02 * a13 - a03 * a12; - final b06 = a20 * a31 - a21 * a30; - final b07 = a20 * a32 - a22 * a30; - final b08 = a20 * a33 - a23 * a30; - final b09 = a21 * a32 - a22 * a31; - final b10 = a21 * a33 - a23 * a31; - final b11 = a22 * a33 - a23 * a32; - final det = + final Float32List argStorage = arg._m4storage; + final double a00 = argStorage[0]; + final double a01 = argStorage[1]; + final double a02 = argStorage[2]; + final double a03 = argStorage[3]; + final double a10 = argStorage[4]; + final double a11 = argStorage[5]; + final double a12 = argStorage[6]; + final double a13 = argStorage[7]; + final double a20 = argStorage[8]; + final double a21 = argStorage[9]; + final double a22 = argStorage[10]; + final double a23 = argStorage[11]; + final double a30 = argStorage[12]; + final double a31 = argStorage[13]; + final double a32 = argStorage[14]; + final double a33 = argStorage[15]; + final double b00 = a00 * a11 - a01 * a10; + final double b01 = a00 * a12 - a02 * a10; + final double b02 = a00 * a13 - a03 * a10; + final double b03 = a01 * a12 - a02 * a11; + final double b04 = a01 * a13 - a03 * a11; + final double b05 = a02 * a13 - a03 * a12; + final double b06 = a20 * a31 - a21 * a30; + final double b07 = a20 * a32 - a22 * a30; + final double b08 = a20 * a33 - a23 * a30; + final double b09 = a21 * a32 - a22 * a31; + final double b10 = a21 * a33 - a23 * a31; + final double b11 = a22 * a33 - a23 * a32; + final double det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; if (det == 0.0) { setFrom(arg); return 0.0; } - final invDet = 1.0 / det; + final double invDet = 1.0 / det; _m4storage[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet; _m4storage[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet; _m4storage[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet; @@ -1428,11 +1448,11 @@ class Matrix4 { } double invertRotation() { - final det = determinant(); + final double det = determinant(); if (det == 0.0) { return 0.0; } - final invDet = 1.0 / det; + final double invDet = 1.0 / det; double ix; double iy; double iz; @@ -1483,8 +1503,8 @@ class Matrix4 { /// Sets the upper 3x3 to a rotation of [radians] around X void setRotationX(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m4storage[0] = 1.0; _m4storage[1] = 0.0; _m4storage[2] = 0.0; @@ -1501,8 +1521,8 @@ class Matrix4 { /// Sets the upper 3x3 to a rotation of [radians] around Y void setRotationY(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m4storage[0] = c; _m4storage[1] = 0.0; _m4storage[2] = -s; @@ -1519,8 +1539,8 @@ class Matrix4 { /// Sets the upper 3x3 to a rotation of [radians] around Z void setRotationZ(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m4storage[0] = c; _m4storage[1] = s; _m4storage[2] = 0.0; @@ -1538,22 +1558,22 @@ class Matrix4 { /// Converts into Adjugate matrix and scales by [scale] void scaleAdjoint(double scale) { // Adapted from code by Richard Carling. - final a1 = _m4storage[0]; - final b1 = _m4storage[4]; - final c1 = _m4storage[8]; - final d1 = _m4storage[12]; - final a2 = _m4storage[1]; - final b2 = _m4storage[5]; - final c2 = _m4storage[9]; - final d2 = _m4storage[13]; - final a3 = _m4storage[2]; - final b3 = _m4storage[6]; - final c3 = _m4storage[10]; - final d3 = _m4storage[14]; - final a4 = _m4storage[3]; - final b4 = _m4storage[7]; - final c4 = _m4storage[11]; - final d4 = _m4storage[15]; + final double a1 = _m4storage[0]; + final double b1 = _m4storage[4]; + final double c1 = _m4storage[8]; + final double d1 = _m4storage[12]; + final double a2 = _m4storage[1]; + final double b2 = _m4storage[5]; + final double c2 = _m4storage[9]; + final double d2 = _m4storage[13]; + final double a3 = _m4storage[2]; + final double b3 = _m4storage[6]; + final double c3 = _m4storage[10]; + final double d3 = _m4storage[14]; + final double a4 = _m4storage[3]; + final double b4 = _m4storage[7]; + final double c4 = _m4storage[11]; + final double d4 = _m4storage[15]; _m4storage[0] = (b2 * (c3 * d4 - c4 * d3) - c2 * (b3 * d4 - b4 * d3) + @@ -1640,19 +1660,19 @@ class Matrix4 { /// Returns [arg]. /// Primarily used by AABB transformation code. Vector3 absoluteRotate(Vector3 arg) { - final m00 = _m4storage[0].abs(); - final m01 = _m4storage[4].abs(); - final m02 = _m4storage[8].abs(); - final m10 = _m4storage[1].abs(); - final m11 = _m4storage[5].abs(); - final m12 = _m4storage[9].abs(); - final m20 = _m4storage[2].abs(); - final m21 = _m4storage[6].abs(); - final m22 = _m4storage[10].abs(); - final argStorage = arg._v3storage; - final x = argStorage[0]; - final y = argStorage[1]; - final z = argStorage[2]; + final double m00 = _m4storage[0].abs(); + final double m01 = _m4storage[4].abs(); + final double m02 = _m4storage[8].abs(); + final double m10 = _m4storage[1].abs(); + final double m11 = _m4storage[5].abs(); + final double m12 = _m4storage[9].abs(); + final double m20 = _m4storage[2].abs(); + final double m21 = _m4storage[6].abs(); + final double m22 = _m4storage[10].abs(); + final Float32List argStorage = arg._v3storage; + final double x = argStorage[0]; + final double y = argStorage[1]; + final double z = argStorage[2]; argStorage[0] = x * m00 + y * m01 + z * m02 + 0.0 * 0.0; argStorage[1] = x * m10 + y * m11 + z * m12 + 0.0 * 0.0; argStorage[2] = x * m20 + y * m21 + z * m22 + 0.0 * 0.0; @@ -1661,7 +1681,7 @@ class Matrix4 { /// Adds [o] to this. void add(Matrix4 o) { - final oStorage = o._m4storage; + final Float32List oStorage = o._m4storage; _m4storage[0] = _m4storage[0] + oStorage[0]; _m4storage[1] = _m4storage[1] + oStorage[1]; _m4storage[2] = _m4storage[2] + oStorage[2]; @@ -1682,7 +1702,7 @@ class Matrix4 { /// Subtracts [o] from this. void sub(Matrix4 o) { - final oStorage = o._m4storage; + final Float32List oStorage = o._m4storage; _m4storage[0] = _m4storage[0] - oStorage[0]; _m4storage[1] = _m4storage[1] - oStorage[1]; _m4storage[2] = _m4storage[2] - oStorage[2]; @@ -1723,39 +1743,39 @@ class Matrix4 { /// Multiply this by [arg]. void multiply(Matrix4 arg) { - final m00 = _m4storage[0]; - final m01 = _m4storage[4]; - final m02 = _m4storage[8]; - final m03 = _m4storage[12]; - final m10 = _m4storage[1]; - final m11 = _m4storage[5]; - final m12 = _m4storage[9]; - final m13 = _m4storage[13]; - final m20 = _m4storage[2]; - final m21 = _m4storage[6]; - final m22 = _m4storage[10]; - final m23 = _m4storage[14]; - final m30 = _m4storage[3]; - final m31 = _m4storage[7]; - final m32 = _m4storage[11]; - final m33 = _m4storage[15]; - final argStorage = arg._m4storage; - final n00 = argStorage[0]; - final n01 = argStorage[4]; - final n02 = argStorage[8]; - final n03 = argStorage[12]; - final n10 = argStorage[1]; - final n11 = argStorage[5]; - final n12 = argStorage[9]; - final n13 = argStorage[13]; - final n20 = argStorage[2]; - final n21 = argStorage[6]; - final n22 = argStorage[10]; - final n23 = argStorage[14]; - final n30 = argStorage[3]; - final n31 = argStorage[7]; - final n32 = argStorage[11]; - final n33 = argStorage[15]; + final double m00 = _m4storage[0]; + final double m01 = _m4storage[4]; + final double m02 = _m4storage[8]; + final double m03 = _m4storage[12]; + final double m10 = _m4storage[1]; + final double m11 = _m4storage[5]; + final double m12 = _m4storage[9]; + final double m13 = _m4storage[13]; + final double m20 = _m4storage[2]; + final double m21 = _m4storage[6]; + final double m22 = _m4storage[10]; + final double m23 = _m4storage[14]; + final double m30 = _m4storage[3]; + final double m31 = _m4storage[7]; + final double m32 = _m4storage[11]; + final double m33 = _m4storage[15]; + final Float32List argStorage = arg._m4storage; + final double n00 = argStorage[0]; + final double n01 = argStorage[4]; + final double n02 = argStorage[8]; + final double n03 = argStorage[12]; + final double n10 = argStorage[1]; + final double n11 = argStorage[5]; + final double n12 = argStorage[9]; + final double n13 = argStorage[13]; + final double n20 = argStorage[2]; + final double n21 = argStorage[6]; + final double n22 = argStorage[10]; + final double n23 = argStorage[14]; + final double n30 = argStorage[3]; + final double n31 = argStorage[7]; + final double n32 = argStorage[11]; + final double n33 = argStorage[15]; _m4storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30); _m4storage[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31); _m4storage[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32); @@ -1779,40 +1799,40 @@ class Matrix4 { /// /// This method does not alter the [Matrix4] in [arg]. void leftMultiply(Matrix4 arg) { - final argStorage = arg._m4storage; - final m00 = argStorage[0]; - final m01 = argStorage[4]; - final m02 = argStorage[8]; - final m03 = argStorage[12]; - final m10 = argStorage[1]; - final m11 = argStorage[5]; - final m12 = argStorage[9]; - final m13 = argStorage[13]; - final m20 = argStorage[2]; - final m21 = argStorage[6]; - final m22 = argStorage[10]; - final m23 = argStorage[14]; - final m30 = argStorage[3]; - final m31 = argStorage[7]; - final m32 = argStorage[11]; - final m33 = argStorage[15]; - final bStorage = _m4storage; - final n00 = bStorage[0]; - final n01 = bStorage[4]; - final n02 = bStorage[8]; - final n03 = bStorage[12]; - final n10 = bStorage[1]; - final n11 = bStorage[5]; - final n12 = bStorage[9]; - final n13 = bStorage[13]; - final n20 = bStorage[2]; - final n21 = bStorage[6]; - final n22 = bStorage[10]; - final n23 = bStorage[14]; - final n30 = bStorage[3]; - final n31 = bStorage[7]; - final n32 = bStorage[11]; - final n33 = bStorage[15]; + final Float32List argStorage = arg._m4storage; + final double m00 = argStorage[0]; + final double m01 = argStorage[4]; + final double m02 = argStorage[8]; + final double m03 = argStorage[12]; + final double m10 = argStorage[1]; + final double m11 = argStorage[5]; + final double m12 = argStorage[9]; + final double m13 = argStorage[13]; + final double m20 = argStorage[2]; + final double m21 = argStorage[6]; + final double m22 = argStorage[10]; + final double m23 = argStorage[14]; + final double m30 = argStorage[3]; + final double m31 = argStorage[7]; + final double m32 = argStorage[11]; + final double m33 = argStorage[15]; + final Float32List bStorage = _m4storage; + final double n00 = bStorage[0]; + final double n01 = bStorage[4]; + final double n02 = bStorage[8]; + final double n03 = bStorage[12]; + final double n10 = bStorage[1]; + final double n11 = bStorage[5]; + final double n12 = bStorage[9]; + final double n13 = bStorage[13]; + final double n20 = bStorage[2]; + final double n21 = bStorage[6]; + final double n22 = bStorage[10]; + final double n23 = bStorage[14]; + final double n30 = bStorage[3]; + final double n31 = bStorage[7]; + final double n32 = bStorage[11]; + final double n33 = bStorage[15]; bStorage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30); bStorage[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31); bStorage[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32); @@ -1836,23 +1856,23 @@ class Matrix4 { /// Multiply a transposed this with [arg]. void transposeMultiply(Matrix4 arg) { - final m00 = _m4storage[0]; - final m01 = _m4storage[1]; - final m02 = _m4storage[2]; - final m03 = _m4storage[3]; - final m10 = _m4storage[4]; - final m11 = _m4storage[5]; - final m12 = _m4storage[6]; - final m13 = _m4storage[7]; - final m20 = _m4storage[8]; - final m21 = _m4storage[9]; - final m22 = _m4storage[10]; - final m23 = _m4storage[11]; - final m30 = _m4storage[12]; - final m31 = _m4storage[13]; - final m32 = _m4storage[14]; - final m33 = _m4storage[15]; - final argStorage = arg._m4storage; + final double m00 = _m4storage[0]; + final double m01 = _m4storage[1]; + final double m02 = _m4storage[2]; + final double m03 = _m4storage[3]; + final double m10 = _m4storage[4]; + final double m11 = _m4storage[5]; + final double m12 = _m4storage[6]; + final double m13 = _m4storage[7]; + final double m20 = _m4storage[8]; + final double m21 = _m4storage[9]; + final double m22 = _m4storage[10]; + final double m23 = _m4storage[11]; + final double m30 = _m4storage[12]; + final double m31 = _m4storage[13]; + final double m32 = _m4storage[14]; + final double m33 = _m4storage[15]; + final Float32List argStorage = arg._m4storage; _m4storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]) + @@ -1937,23 +1957,23 @@ class Matrix4 { /// Multiply this with a transposed [arg]. void multiplyTranspose(Matrix4 arg) { - final m00 = _m4storage[0]; - final m01 = _m4storage[4]; - final m02 = _m4storage[8]; - final m03 = _m4storage[12]; - final m10 = _m4storage[1]; - final m11 = _m4storage[5]; - final m12 = _m4storage[9]; - final m13 = _m4storage[13]; - final m20 = _m4storage[2]; - final m21 = _m4storage[6]; - final m22 = _m4storage[10]; - final m23 = _m4storage[14]; - final m30 = _m4storage[3]; - final m31 = _m4storage[7]; - final m32 = _m4storage[11]; - final m33 = _m4storage[15]; - final argStorage = arg._m4storage; + final double m00 = _m4storage[0]; + final double m01 = _m4storage[4]; + final double m02 = _m4storage[8]; + final double m03 = _m4storage[12]; + final double m10 = _m4storage[1]; + final double m11 = _m4storage[5]; + final double m12 = _m4storage[9]; + final double m13 = _m4storage[13]; + final double m20 = _m4storage[2]; + final double m21 = _m4storage[6]; + final double m22 = _m4storage[10]; + final double m23 = _m4storage[14]; + final double m30 = _m4storage[3]; + final double m31 = _m4storage[7]; + final double m32 = _m4storage[11]; + final double m33 = _m4storage[15]; + final Float32List argStorage = arg._m4storage; _m4storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[4]) + @@ -2038,11 +2058,12 @@ class Matrix4 { /// Decomposes this into [translation], [rotation] and [scale] components. void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) { - final v = _decomposeV ??= Vector3.zero(); - var sx = (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length; - final sy = + final Vector3 v = _decomposeV ??= Vector3.zero(); + double sx = + (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length; + final double sy = (v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length; - final sz = + final double sz = (v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length; if (determinant() < 0) { @@ -2053,11 +2074,11 @@ class Matrix4 { translation._v3storage[1] = _m4storage[13]; translation._v3storage[2] = _m4storage[14]; - final invSX = 1.0 / sx; - final invSY = 1.0 / sy; - final invSZ = 1.0 / sz; + final double invSX = 1.0 / sx; + final double invSY = 1.0 / sy; + final double invSZ = 1.0 / sz; - final m = _decomposeM ??= Matrix4.zero(); + final Matrix4 m = _decomposeM ??= Matrix4.zero(); m.setFrom(this); m._m4storage[0] *= invSX; m._m4storage[1] *= invSX; @@ -2069,7 +2090,7 @@ class Matrix4 { m._m4storage[9] *= invSZ; m._m4storage[10] *= invSZ; - final r = _decomposeR ??= Matrix3.zero(); + final Matrix3 r = _decomposeR ??= Matrix3.zero(); m.copyRotation(r); rotation.setFromRotation(r); @@ -2084,16 +2105,16 @@ class Matrix4 { /// Rotate [arg] of type [Vector3] using the rotation defined by this. Vector3 rotate3(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float32List argStorage = arg._v3storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]); - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]); - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]); @@ -2117,18 +2138,18 @@ class Matrix4 { /// Transform [arg] of type [Vector3] using the transformation defined by /// this. Vector3 transform3(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float32List argStorage = arg._v3storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + @@ -2154,23 +2175,23 @@ class Matrix4 { /// Transform [arg] of type [Vector4] using the transformation defined by /// this. Vector4 transform(Vector4 arg) { - final argStorage = arg._v4storage; - final x_ = + final Float32List argStorage = arg._v4storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + (_m4storage[12] * argStorage[3]); - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + (_m4storage[13] * argStorage[3]); - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + (_m4storage[14] * argStorage[3]); - final w_ = + final double w_ = (_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + (_m4storage[11] * argStorage[2]) + @@ -2185,23 +2206,23 @@ class Matrix4 { /// Transform [arg] of type [Vector3] using the perspective transformation /// defined by this. Vector3 perspectiveTransform(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float32List argStorage = arg._v3storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + _m4storage[14]; - final w_ = + final double w_ = 1.0 / ((_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + @@ -2280,23 +2301,23 @@ class Matrix4 { } Vector3 get right { - final x = _m4storage[0]; - final y = _m4storage[1]; - final z = _m4storage[2]; + final double x = _m4storage[0]; + final double y = _m4storage[1]; + final double z = _m4storage[2]; return Vector3(x, y, z); } Vector3 get up { - final x = _m4storage[4]; - final y = _m4storage[5]; - final z = _m4storage[6]; + final double x = _m4storage[4]; + final double y = _m4storage[5]; + final double z = _m4storage[6]; return Vector3(x, y, z); } Vector3 get forward { - final x = _m4storage[8]; - final y = _m4storage[9]; - final z = _m4storage[10]; + final double x = _m4storage[8]; + final double y = _m4storage[9]; + final double z = _m4storage[10]; return Vector3(x, y, z); } diff --git a/packages/vector_math/lib/src/vector_math/obb3.dart b/packages/vector_math/lib/src/vector_math/obb3.dart index 9a9c73a..1ca01d8 100644 --- a/packages/vector_math/lib/src/vector_math/obb3.dart +++ b/packages/vector_math/lib/src/vector_math/obb3.dart @@ -6,27 +6,6 @@ part of '../../vector_math.dart'; /// Defines a 3-dimensional oriented bounding box defined with a [center], /// [halfExtents] and axes. class Obb3 { - final Vector3 _center; - final Vector3 _halfExtents; - final Vector3 _axis0; - final Vector3 _axis1; - final Vector3 _axis2; - - /// The center of the OBB. - Vector3 get center => _center; - - /// The half extends of the OBB. - Vector3 get halfExtents => _halfExtents; - - /// The first axis of the OBB. - Vector3 get axis0 => _axis0; - - /// The second axis of the OBB. - Vector3 get axis1 => _axis1; - - /// The third axis of the OBB. - Vector3 get axis2 => _axis2; - /// Create a new OBB with erverything set to zero. Obb3() : _center = Vector3.zero(), @@ -55,6 +34,26 @@ class Obb3 { _axis0 = Vector3.copy(axis0), _axis1 = Vector3.copy(axis1), _axis2 = Vector3.copy(axis2); + final Vector3 _center; + final Vector3 _halfExtents; + final Vector3 _axis0; + final Vector3 _axis1; + final Vector3 _axis2; + + /// The center of the OBB. + Vector3 get center => _center; + + /// The half extends of the OBB. + Vector3 get halfExtents => _halfExtents; + + /// The first axis of the OBB. + Vector3 get axis0 => _axis0; + + /// The second axis of the OBB. + Vector3 get axis1 => _axis1; + + /// The third axis of the OBB. + Vector3 get axis2 => _axis2; /// Copy from [other] into this. void copyFrom(Obb3 other) { @@ -125,69 +124,61 @@ class Obb3 { ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 1: corner ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; case 2: corner ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 3: corner ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; case 4: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 5: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; case 6: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 7: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; } } /// Find the closest point [q] on the OBB to the point [p] and store it in /// [q]. void closestPointTo(Vector3 p, Vector3 q) { - final d = p - _center; + final Vector3 d = p - _center; q.setFrom(_center); - var dist = d.dot(_axis0); - dist = dist.clamp(-_halfExtents.x, _halfExtents.x).toDouble(); + double dist = d.dot(_axis0); + dist = dist.clamp(-_halfExtents.x, _halfExtents.x); q.addScaled(_axis0, dist); dist = d.dot(_axis1); - dist = dist.clamp(-_halfExtents.y, _halfExtents.y).toDouble(); + dist = dist.clamp(-_halfExtents.y, _halfExtents.y); q.addScaled(_axis1, dist); dist = d.dot(_axis2); - dist = dist.clamp(-_halfExtents.z, _halfExtents.z).toDouble(); + dist = dist.clamp(-_halfExtents.z, _halfExtents.z); q.addScaled(_axis2, dist); } diff --git a/packages/vector_math/lib/src/vector_math/opengl.dart b/packages/vector_math/lib/src/vector_math/opengl.dart index 1f6caea..c837cb4 100644 --- a/packages/vector_math/lib/src/vector_math/opengl.dart +++ b/packages/vector_math/lib/src/vector_math/opengl.dart @@ -65,10 +65,10 @@ void setModelMatrix( double ty, double tz, ) { - final right = forwardDirection.cross(upDirection)..normalize(); + final Vector3 right = forwardDirection.cross(upDirection)..normalize(); final c1 = right; final c2 = upDirection; - final c3 = -forwardDirection; + final Vector3 c3 = -forwardDirection; modelMatrix.setValues( c1[0], c1[1], @@ -103,13 +103,13 @@ void setViewMatrix( Vector3 cameraFocusPosition, Vector3 upDirection, ) { - final z = (cameraPosition - cameraFocusPosition)..normalize(); - final x = upDirection.cross(z)..normalize(); - final y = z.cross(x)..normalize(); + final Vector3 z = (cameraPosition - cameraFocusPosition)..normalize(); + final Vector3 x = upDirection.cross(z)..normalize(); + final Vector3 y = z.cross(x)..normalize(); - final rotatedEyeX = -x.dot(cameraPosition); - final rotatedEyeY = -y.dot(cameraPosition); - final rotatedEyeZ = -z.dot(cameraPosition); + final double rotatedEyeX = -x.dot(cameraPosition); + final double rotatedEyeY = -y.dot(cameraPosition); + final double rotatedEyeZ = -z.dot(cameraPosition); viewMatrix.setValues( x[0], @@ -163,17 +163,17 @@ void setPerspectiveMatrix( double zNear, double zFar, ) { - final height = math.tan(fovYRadians * 0.5); - final width = height * aspectRatio; - final near_minus_far = zNear - zFar; + final double height = math.tan(fovYRadians * 0.5); + final double width = height * aspectRatio; + final double nearMinusFar = zNear - zFar; perspectiveMatrix ..setZero() ..setEntry(0, 0, 1.0 / width) ..setEntry(1, 1, 1.0 / height) - ..setEntry(2, 2, (zFar + zNear) / near_minus_far) + ..setEntry(2, 2, (zFar + zNear) / nearMinusFar) ..setEntry(3, 2, -1.0) - ..setEntry(2, 3, (2.0 * zNear * zFar) / near_minus_far); + ..setEntry(2, 3, (2.0 * zNear * zFar) / nearMinusFar); } /// Constructs a new OpenGL perspective projection matrix. @@ -210,8 +210,8 @@ void setInfiniteMatrix( double aspectRatio, double zNear, ) { - final height = math.tan(fovYRadians * 0.5); - final width = height * aspectRatio; + final double height = math.tan(fovYRadians * 0.5); + final double width = height * aspectRatio; infiniteMatrix ..setZero() @@ -257,19 +257,19 @@ void setFrustumMatrix( double near, double far, ) { - final two_near = 2.0 * near; - final right_minus_left = right - left; - final top_minus_bottom = top - bottom; - final far_minus_near = far - near; + final double twoNear = 2.0 * near; + final double rightMinusLeft = right - left; + final double topMinusBottom = top - bottom; + final double farMinusNear = far - near; perspectiveMatrix ..setZero() - ..setEntry(0, 0, two_near / right_minus_left) - ..setEntry(1, 1, two_near / top_minus_bottom) - ..setEntry(0, 2, (right + left) / right_minus_left) - ..setEntry(1, 2, (top + bottom) / top_minus_bottom) - ..setEntry(2, 2, -(far + near) / far_minus_near) + ..setEntry(0, 0, twoNear / rightMinusLeft) + ..setEntry(1, 1, twoNear / topMinusBottom) + ..setEntry(0, 2, (right + left) / rightMinusLeft) + ..setEntry(1, 2, (top + bottom) / topMinusBottom) + ..setEntry(2, 2, -(far + near) / farMinusNear) ..setEntry(3, 2, -1.0) - ..setEntry(2, 3, -(two_near * far) / far_minus_near); + ..setEntry(2, 3, -(twoNear * far) / farMinusNear); } /// Constructs a new OpenGL perspective projection matrix. @@ -310,12 +310,12 @@ void setOrthographicMatrix( double near, double far, ) { - final rml = right - left; - final rpl = right + left; - final tmb = top - bottom; - final tpb = top + bottom; - final fmn = far - near; - final fpn = far + near; + final double rml = right - left; + final double rpl = right + left; + final double tmb = top - bottom; + final double tpb = top + bottom; + final double fmn = far - near; + final double fpn = far + near; orthographicMatrix ..setZero() ..setEntry(0, 0, 2.0 / rml) @@ -360,7 +360,9 @@ Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) { final outer = Matrix4.outer(v, v); var r = Matrix4.zero(); r = r - outer; - final scaledNormal = planeNormal.scaled(dot3(planePoint, planeNormal)); + final Vector3 scaledNormal = planeNormal.scaled( + dot3(planePoint, planeNormal), + ); final T = Vector4( scaledNormal.storage[0], scaledNormal.storage[1], @@ -383,8 +385,8 @@ Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) { final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0, 1.0); var r = Matrix4.zero(); r = r - outer; - final scale = 2.0 * planePoint.dot(planeNormal); - final scaledNormal = planeNormal.scaled(scale); + final double scale = 2.0 * planePoint.dot(planeNormal); + final Vector3 scaledNormal = planeNormal.scaled(scale); final T = Vector4( scaledNormal.storage[0], scaledNormal.storage[1], @@ -449,7 +451,7 @@ bool unproject( if (v.w == 0.0) { return false; } - final invW = 1.0 / v.w; + final double invW = 1.0 / v.w; pickWorld ..x = v.x * invW ..y = v.y * invW diff --git a/packages/vector_math/lib/src/vector_math/plane.dart b/packages/vector_math/lib/src/vector_math/plane.dart index 8ed8d3e..74b9fe1 100644 --- a/packages/vector_math/lib/src/vector_math/plane.dart +++ b/packages/vector_math/lib/src/vector_math/plane.dart @@ -2,9 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; class Plane { + Plane() : _normal = Vector3.zero(), constant = 0.0; + + Plane.copy(Plane other) + : _normal = Vector3.copy(other._normal), + constant = other.constant; + + Plane.components(double x, double y, double z, this.constant) + : _normal = Vector3(x, y, z); + + Plane.normalconstant(Vector3 normal_, this.constant) + : _normal = Vector3.copy(normal_); final Vector3 _normal; double constant; @@ -15,17 +30,17 @@ class Plane { b.normal.crossInto(c.normal, cross); - final f = -a.normal.dot(cross); + final double f = -a.normal.dot(cross); - final v1 = cross.scaled(a.constant); + final Vector3 v1 = cross.scaled(a.constant); c.normal.crossInto(a.normal, cross); - final v2 = cross.scaled(b.constant); + final Vector3 v2 = cross.scaled(b.constant); a.normal.crossInto(b.normal, cross); - final v3 = cross.scaled(c.constant); + final Vector3 v3 = cross.scaled(c.constant); result ..x = (v1.x + v2.x + v3.x) / f @@ -35,18 +50,6 @@ class Plane { Vector3 get normal => _normal; - Plane() : _normal = Vector3.zero(), constant = 0.0; - - Plane.copy(Plane other) - : _normal = Vector3.copy(other._normal), - constant = other.constant; - - Plane.components(double x, double y, double z, this.constant) - : _normal = Vector3(x, y, z); - - Plane.normalconstant(Vector3 normal_, this.constant) - : _normal = Vector3.copy(normal_); - void copyFrom(Plane o) { _normal.setFrom(o._normal); constant = o.constant; @@ -58,7 +61,7 @@ class Plane { } void normalize() { - final inverseLength = 1.0 / normal.length; + final double inverseLength = 1.0 / normal.length; _normal.scale(inverseLength); constant *= inverseLength; } diff --git a/packages/vector_math/lib/src/vector_math/quad.dart b/packages/vector_math/lib/src/vector_math/quad.dart index 0cc9864..0e9b96b 100644 --- a/packages/vector_math/lib/src/vector_math/quad.dart +++ b/packages/vector_math/lib/src/vector_math/quad.dart @@ -6,23 +6,6 @@ part of '../../vector_math.dart'; /// Defines a quad by four points. class Quad { - final Vector3 _point0; - final Vector3 _point1; - final Vector3 _point2; - final Vector3 _point3; - - /// The first point of the quad. - Vector3 get point0 => _point0; - - /// The second point of the quad. - Vector3 get point1 => _point1; - - /// The third point of the quad. - Vector3 get point2 => _point2; - - /// The fourth point of the quad. - Vector3 get point3 => _point3; - /// Create a new, uninitialized quad. Quad() : _point0 = Vector3.zero(), @@ -43,6 +26,22 @@ class Quad { _point1 = Vector3.copy(point1), _point2 = Vector3.copy(point2), _point3 = Vector3.copy(point3); + final Vector3 _point0; + final Vector3 _point1; + final Vector3 _point2; + final Vector3 _point3; + + /// The first point of the quad. + Vector3 get point0 => _point0; + + /// The second point of the quad. + Vector3 get point1 => _point1; + + /// The third point of the quad. + Vector3 get point2 => _point2; + + /// The fourth point of the quad. + Vector3 get point3 => _point3; /// Copy the quad from [other] into this. void copyFrom(Quad other) { @@ -54,7 +53,7 @@ class Quad { /// Copy the normal of this into [normal]. void copyNormalInto(Vector3 normal) { - final v0 = _point0.clone()..sub(_point1); + final Vector3 v0 = _point0.clone()..sub(_point1); normal ..setFrom(_point2) ..sub(_point1) @@ -97,6 +96,7 @@ class Quad { /// Check if two quad are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Quad) && (_point3 == other._point3) && @@ -105,5 +105,6 @@ class Quad { (_point0 == other._point0); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hash(_point0, _point1, _point2, _point3); } diff --git a/packages/vector_math/lib/src/vector_math/quaternion.dart b/packages/vector_math/lib/src/vector_math/quaternion.dart index 7c2c2bb..c1b1b8b 100644 --- a/packages/vector_math/lib/src/vector_math/quaternion.dart +++ b/packages/vector_math/lib/src/vector_math/quaternion.dart @@ -11,41 +11,12 @@ part of '../../vector_math.dart'; /// [gimbal lock](http://de.wikipedia.org/wiki/Gimbal_Lock) problem compared to /// euler rotations. class Quaternion { - final Float32List _qStorage; - - /// Access the internal [storage] of the quaternions components. - Float32List get storage => _qStorage; - - /// Access the [x] component of the quaternion. - double get x => _qStorage[0]; - set x(double x) { - _qStorage[0] = x; - } - - /// Access the [y] component of the quaternion. - double get y => _qStorage[1]; - set y(double y) { - _qStorage[1] = y; - } - - /// Access the [z] component of the quaternion. - double get z => _qStorage[2]; - set z(double z) { - _qStorage[2] = z; - } - - /// Access the [w] component of the quaternion. - double get w => _qStorage[3]; - set w(double w) { - _qStorage[3] = w; - } - - Quaternion._() : _qStorage = Float32List(4); - /// Constructs a quaternion using the raw values [x], [y], [z], and [w]. factory Quaternion(double x, double y, double z, double w) => Quaternion._()..setValues(x, y, z, w); + Quaternion._() : _qStorage = Float32List(4); + /// Constructs a quaternion from a rotation matrix [rotationMatrix]. factory Quaternion.fromRotation(Matrix3 rotationMatrix) => Quaternion._()..setFromRotation(rotationMatrix); @@ -86,13 +57,41 @@ class Quaternion { /// [Float32List.bytesPerElement]. Quaternion.fromBuffer(ByteBuffer buffer, int offset) : _qStorage = Float32List.view(buffer, offset, 4); + final Float32List _qStorage; + + /// Access the internal [storage] of the quaternions components. + Float32List get storage => _qStorage; + + /// Access the [x] component of the quaternion. + double get x => _qStorage[0]; + set x(double x) { + _qStorage[0] = x; + } + + /// Access the [y] component of the quaternion. + double get y => _qStorage[1]; + set y(double y) { + _qStorage[1] = y; + } + + /// Access the [z] component of the quaternion. + double get z => _qStorage[2]; + set z(double z) { + _qStorage[2] = z; + } + + /// Access the [w] component of the quaternion. + double get w => _qStorage[3]; + set w(double w) { + _qStorage[3] = w; + } /// Returns a new copy of this. Quaternion clone() => Quaternion.copy(this); /// Copy [source] into this. void setFrom(Quaternion source) { - final sourceStorage = source._qStorage; + final Float32List sourceStorage = source._qStorage; _qStorage[0] = sourceStorage[0]; _qStorage[1] = sourceStorage[1]; _qStorage[2] = sourceStorage[2]; @@ -109,12 +108,12 @@ class Quaternion { /// Set the quaternion with rotation of [radians] around [axis]. void setAxisAngle(Vector3 axis, double radians) { - final len = axis.length; + final double len = axis.length; if (len == 0.0) { return; } - final halfSin = math.sin(radians * 0.5) / len; - final axisStorage = axis.storage; + final double halfSin = math.sin(radians * 0.5) / len; + final Float32List axisStorage = axis.storage; _qStorage[0] = axisStorage[0] * halfSin; _qStorage[1] = axisStorage[1] * halfSin; _qStorage[2] = axisStorage[2] * halfSin; @@ -123,22 +122,23 @@ class Quaternion { /// Set the quaternion with rotation from a rotation matrix [rotationMatrix]. void setFromRotation(Matrix3 rotationMatrix) { - final rotationMatrixStorage = rotationMatrix.storage; - final trace = rotationMatrix.trace(); + final Float32List rotationMatrixStorage = rotationMatrix.storage; + final double trace = rotationMatrix.trace(); if (trace > 0.0) { - var s = math.sqrt(trace + 1.0); + double s = math.sqrt(trace + 1.0); _qStorage[3] = s * 0.5; s = 0.5 / s; _qStorage[0] = (rotationMatrixStorage[5] - rotationMatrixStorage[7]) * s; _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 j = (i + 1) % 3; - final k = (i + 2) % 3; - var s = math.sqrt( + 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( rotationMatrixStorage[rotationMatrix.index(i, i)] - rotationMatrixStorage[rotationMatrix.index(j, j)] - rotationMatrixStorage[rotationMatrix.index(k, k)] + @@ -161,13 +161,16 @@ class Quaternion { } } + // TODO(stuartmorgan): Remove this and add the missing docs. + // https://github.com/flutter/flutter/issues/186827 + // ignore: public_member_api_docs void setFromTwoVectors(Vector3 a, Vector3 b) { - final v1 = a.normalized(); - final v2 = b.normalized(); + final Vector3 v1 = a.normalized(); + final Vector3 v2 = b.normalized(); - final c = v1.dot(v2); - var angle = math.acos(c); - var axis = v1.cross(v2); + final double c = v1.dot(v2); + double angle = math.acos(c); + Vector3 axis = v1.cross(v2); if ((1.0 + c).abs() < 0.0005) { // c \approx -1 indicates 180 degree rotation @@ -199,15 +202,15 @@ class Quaternion { void setRandom(math.Random rn) { // From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III, // pg. 124-132. - final x0 = rn.nextDouble(); - final r1 = math.sqrt(1.0 - x0); - final r2 = math.sqrt(x0); - final t1 = math.pi * 2.0 * rn.nextDouble(); - final t2 = math.pi * 2.0 * rn.nextDouble(); - final c1 = math.cos(t1); - final s1 = math.sin(t1); - final c2 = math.cos(t2); - final s2 = math.sin(t2); + final double x0 = rn.nextDouble(); + final double r1 = math.sqrt(1.0 - x0); + final double r2 = math.sqrt(x0); + final double t1 = math.pi * 2.0 * rn.nextDouble(); + final double t2 = math.pi * 2.0 * rn.nextDouble(); + final double c1 = math.cos(t1); + final double s1 = math.sin(t1); + final double c2 = math.cos(t2); + final double s2 = math.sin(t2); _qStorage[0] = s1 * r1; _qStorage[1] = c1 * r1; _qStorage[2] = s2 * r2; @@ -217,19 +220,19 @@ class Quaternion { /// Set the quaternion to the time derivative of [q] with angular velocity /// [omega]. void setDQ(Quaternion q, Vector3 omega) { - final qStorage = q._qStorage; - final omegaStorage = omega.storage; - final qx = qStorage[0]; - final qy = qStorage[1]; - final qz = qStorage[2]; - final qw = qStorage[3]; - final ox = omegaStorage[0]; - final oy = omegaStorage[1]; - final oz = omegaStorage[2]; - final x = ox * qw + oy * qz - oz * qy; - final y = oy * qw + oz * qx - ox * qz; - final z = oz * qw + ox * qy - oy * qx; - final w = -ox * qx - oy * qy - oz * qz; + final Float32List qStorage = q._qStorage; + final Float32List omegaStorage = omega.storage; + final double qx = qStorage[0]; + final double qy = qStorage[1]; + final double qz = qStorage[2]; + final double qw = qStorage[3]; + final double ox = omegaStorage[0]; + final double oy = omegaStorage[1]; + final double oz = omegaStorage[2]; + final double x = ox * qw + oy * qz - oz * qy; + final double y = oy * qw + oz * qx - ox * qz; + final double z = oz * qw + ox * qy - oy * qx; + final double w = -ox * qx - oy * qy - oz * qz; _qStorage[0] = x * 0.5; _qStorage[1] = y * 0.5; _qStorage[2] = z * 0.5; @@ -238,15 +241,15 @@ class Quaternion { /// Set quaternion with rotation of [yaw], [pitch] and [roll]. void setEuler(double yaw, double pitch, double roll) { - final halfYaw = yaw * 0.5; - final halfPitch = pitch * 0.5; - final halfRoll = roll * 0.5; - final cosYaw = math.cos(halfYaw); - final sinYaw = math.sin(halfYaw); - final cosPitch = math.cos(halfPitch); - final sinPitch = math.sin(halfPitch); - final cosRoll = math.cos(halfRoll); - final sinRoll = math.sin(halfRoll); + final double halfYaw = yaw * 0.5; + final double halfPitch = pitch * 0.5; + final double halfRoll = roll * 0.5; + final double cosYaw = math.cos(halfYaw); + final double sinYaw = math.sin(halfYaw); + final double cosPitch = math.cos(halfPitch); + final double sinPitch = math.sin(halfPitch); + final double cosRoll = math.cos(halfRoll); + final double sinRoll = math.sin(halfRoll); _qStorage[0] = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw; _qStorage[1] = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw; _qStorage[2] = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw; @@ -255,11 +258,11 @@ class Quaternion { /// Normalize this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _qStorage[0] *= d; _qStorage[1] *= d; _qStorage[2] *= d; @@ -282,7 +285,7 @@ class Quaternion { /// Invert this. void inverse() { - final l = 1.0 / length2; + final double l = 1.0 / length2; _qStorage[3] = _qStorage[3] * l; _qStorage[2] = -_qStorage[2] * l; _qStorage[1] = -_qStorage[1] * l; @@ -306,13 +309,13 @@ class Quaternion { /// [axis] of rotation. Vector3 get axis { - final den = 1.0 - (_qStorage[3] * _qStorage[3]); + final double den = 1.0 - (_qStorage[3] * _qStorage[3]); if (den < 0.00002) { // 0-angle rotation, so axis does not matter return Vector3.zero(); } - final scale = 1.0 / math.sqrt(den); + final double scale = 1.0 / math.sqrt(den); return Vector3( _qStorage[0] * scale, _qStorage[1] * scale, @@ -322,10 +325,10 @@ class Quaternion { /// Length squared. double get length2 { - final x = _qStorage[0]; - final y = _qStorage[1]; - final z = _qStorage[2]; - final w = _qStorage[3]; + final double x = _qStorage[0]; + final double y = _qStorage[1]; + final double z = _qStorage[2]; + final double w = _qStorage[3]; return (x * x) + (y * y) + (z * z) + (w * w); } @@ -334,7 +337,7 @@ class Quaternion { /// Returns a copy of [v] rotated by quaternion. Vector3 rotated(Vector3 v) { - final out = v.clone(); + final Vector3 out = v.clone(); rotate(out); return out; } @@ -342,31 +345,31 @@ class Quaternion { /// Rotates [v] by this. Vector3 rotate(Vector3 v) { // conjugate(this) * [v,0] * this - final w = _qStorage[3]; - final z = _qStorage[2]; - final y = _qStorage[1]; - final x = _qStorage[0]; + final double w = _qStorage[3]; + final double z = _qStorage[2]; + final double y = _qStorage[1]; + final double x = _qStorage[0]; final tiw = w; - final tiz = -z; - final tiy = -y; - final tix = -x; - final tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y; - final ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z; - final tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x; - final tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z; - final result_x = tw * x + tx * w + ty * z - tz * y; - final result_y = tw * y + ty * w + tz * x - tx * z; - final result_z = tw * z + tz * w + tx * y - ty * x; - final vStorage = v.storage; - vStorage[2] = result_z; - vStorage[1] = result_y; - vStorage[0] = result_x; + final double tiz = -z; + final double tiy = -y; + final double tix = -x; + final double tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y; + final double ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z; + final double tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x; + final double tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z; + final double resultX = tw * x + tx * w + ty * z - tz * y; + final double resultY = tw * y + ty * w + tz * x - tx * z; + final double resultZ = tw * z + tz * w + tx * y - ty * x; + final Float32List vStorage = v.storage; + vStorage[2] = resultZ; + vStorage[1] = resultY; + vStorage[0] = resultX; return v; } /// Add [arg] to this. void add(Quaternion arg) { - final argStorage = arg._qStorage; + final Float32List argStorage = arg._qStorage; _qStorage[0] = _qStorage[0] + argStorage[0]; _qStorage[1] = _qStorage[1] + argStorage[1]; _qStorage[2] = _qStorage[2] + argStorage[2]; @@ -375,7 +378,7 @@ class Quaternion { /// Subtracts [arg] from this. void sub(Quaternion arg) { - final argStorage = arg._qStorage; + final Float32List argStorage = arg._qStorage; _qStorage[0] = _qStorage[0] - argStorage[0]; _qStorage[1] = _qStorage[1] - argStorage[1]; _qStorage[2] = _qStorage[2] - argStorage[2]; @@ -395,15 +398,15 @@ class Quaternion { /// this rotated by [other]. Quaternion operator *(Quaternion other) { - final w = _qStorage[3]; - final z = _qStorage[2]; - final y = _qStorage[1]; - final x = _qStorage[0]; - final otherStorage = other._qStorage; - final ow = otherStorage[3]; - final oz = otherStorage[2]; - final oy = otherStorage[1]; - final ox = otherStorage[0]; + final double w = _qStorage[3]; + final double z = _qStorage[2]; + final double y = _qStorage[1]; + final double x = _qStorage[0]; + final Float32List otherStorage = other._qStorage; + final double ow = otherStorage[3]; + final double oz = otherStorage[2]; + final double oy = otherStorage[1]; + final double ox = otherStorage[0]; return Quaternion( w * ox + x * ow + y * oz - z * oy, w * oy + y * ow + z * ox - x * oz, @@ -414,6 +417,7 @@ class Quaternion { /// Check if two quaternions are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Quaternion) && (_qStorage[3] == other._qStorage[3]) && @@ -422,6 +426,7 @@ class Quaternion { (_qStorage[0] == other._qStorage[0]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_qStorage); /// Returns copy of this + [other]. @@ -447,32 +452,32 @@ class Quaternion { /// Set [rotationMatrix] to a rotation matrix containing the same rotation as /// this. Matrix3 copyRotationInto(Matrix3 rotationMatrix) { - final d = length2; + final double d = length2; assert(d != 0.0); - final s = 2.0 / d; + final double s = 2.0 / d; - final x = _qStorage[0]; - final y = _qStorage[1]; - final z = _qStorage[2]; - final w = _qStorage[3]; + final double x = _qStorage[0]; + final double y = _qStorage[1]; + final double z = _qStorage[2]; + final double w = _qStorage[3]; - final xs = x * s; - final ys = y * s; - final zs = z * s; + final double xs = x * s; + final double ys = y * s; + final double zs = z * s; - final wx = w * xs; - final wy = w * ys; - final wz = w * zs; + final double wx = w * xs; + final double wy = w * ys; + final double wz = w * zs; - final xx = x * xs; - final xy = x * ys; - final xz = x * zs; + final double xx = x * xs; + final double xy = x * ys; + final double xz = x * zs; - final yy = y * ys; - final yz = y * zs; - final zz = z * zs; + final double yy = y * ys; + final double yz = y * zs; + final double zz = z * zs; - final rotationMatrixStorage = rotationMatrix.storage; + final Float32List rotationMatrixStorage = rotationMatrix.storage; rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0 rotationMatrixStorage[1] = xy + wz; rotationMatrixStorage[2] = xz - wy; @@ -493,17 +498,17 @@ class Quaternion { /// Relative error between this and [correct]. double relativeError(Quaternion correct) { - final diff = correct - this; - final norm_diff = diff.length; - final correct_norm = correct.length; - return norm_diff / correct_norm; + final Quaternion diff = correct - this; + final double normDiff = diff.length; + final double correctNorm = correct.length; + return normDiff / correctNorm; } /// Absolute error between this and [correct]. double absoluteError(Quaternion correct) { - final this_norm = length; - final correct_norm = correct.length; - final norm_diff = (this_norm - correct_norm).abs(); - return norm_diff; + final double thisNorm = length; + final double correctNorm = correct.length; + final double normDiff = (thisNorm - correctNorm).abs(); + return normDiff; } } diff --git a/packages/vector_math/lib/src/vector_math/ray.dart b/packages/vector_math/lib/src/vector_math/ray.dart index fb4932e..593c5eb 100644 --- a/packages/vector_math/lib/src/vector_math/ray.dart +++ b/packages/vector_math/lib/src/vector_math/ray.dart @@ -6,15 +6,6 @@ part of '../../vector_math.dart'; /// Defines a [Ray] by an [origin] and a [direction]. class Ray { - final Vector3 _origin; - final Vector3 _direction; - - /// The [origin] of the ray. - Vector3 get origin => _origin; - - /// The [direction] of the ray. - Vector3 get direction => _direction; - /// Create a new, uninitialized ray. Ray() : _origin = Vector3.zero(), _direction = Vector3.zero(); @@ -27,6 +18,14 @@ class Ray { Ray.originDirection(Vector3 origin, Vector3 direction) : _origin = Vector3.copy(origin), _direction = Vector3.copy(direction); + final Vector3 _origin; + final Vector3 _direction; + + /// The [origin] of the ray. + Vector3 get origin => _origin; + + /// The [direction] of the ray. + Vector3 get direction => _direction; /// Copy the [origin] and [direction] from [other] into this. void copyFrom(Ray other) { @@ -49,19 +48,19 @@ class Ray { /// Return the distance from the origin of this to the intersection with /// [other] if this intersects with [other], or null if the don't intersect. double? intersectsWithSphere(Sphere other) { - final r = other.radius; - final r2 = r * r; - final l = other._center.clone()..sub(_origin); - final s = l.dot(_direction); - final l2 = l.dot(l); + final double r = other.radius; + final double r2 = r * r; + final Vector3 l = other._center.clone()..sub(_origin); + final double s = l.dot(_direction); + final double l2 = l.dot(l); if (s < 0 && l2 > r2) { return null; } - final m2 = l2 - s * s; + final double m2 = l2 - s * s; if (m2 > r2) { return null; } - final q = math.sqrt(r2 - m2); + final double q = math.sqrt(r2 - m2); return (l2 > r2) ? s - q : s + q; } @@ -80,9 +79,9 @@ class Ray { double? intersectsWithTriangle(Triangle other) { const epsilon = 10e-6; - final point0 = other._point0; - final point1 = other._point1; - final point2 = other._point2; + final Vector3 point0 = other._point0; + final Vector3 point1 = other._point1; + final Vector3 point2 = other._point2; _e1 ..setFrom(point1) @@ -92,30 +91,30 @@ class Ray { ..sub(point0); _direction.crossInto(_e2, _q); - final a = _e1.dot(_q); + final double a = _e1.dot(_q); if (a > -epsilon && a < epsilon) { return null; } - final f = 1 / a; + final double f = 1 / a; _s ..setFrom(_origin) ..sub(point0); - final u = f * (_s.dot(_q)); + final double u = f * (_s.dot(_q)); if (u < 0.0) { return null; } _s.crossInto(_e1, _r); - final v = f * (_direction.dot(_r)); + final double v = f * (_direction.dot(_r)); if (v < -epsilon || u + v > 1.0 + epsilon) { return null; } - final t = f * (_e2.dot(_r)); + final double t = f * (_e2.dot(_r)); return t; } @@ -126,9 +125,9 @@ class Ray { const epsilon = 10e-6; // First triangle - var point0 = other._point0; - var point1 = other._point1; - var point2 = other._point2; + Vector3 point0 = other._point0; + Vector3 point1 = other._point1; + Vector3 point2 = other._point2; _e1 ..setFrom(point1) @@ -138,21 +137,21 @@ class Ray { ..sub(point0); _direction.crossInto(_e2, _q); - final a0 = _e1.dot(_q); + final double a0 = _e1.dot(_q); if (!(a0 > -epsilon && a0 < epsilon)) { - final f = 1 / a0; + final double f = 1 / a0; _s ..setFrom(_origin) ..sub(point0); - final u = f * (_s.dot(_q)); + final double u = f * (_s.dot(_q)); if (u >= 0.0) { _s.crossInto(_e1, _r); - final v = f * (_direction.dot(_r)); + final double v = f * (_direction.dot(_r)); if (!(v < -epsilon || u + v > 1.0 + epsilon)) { - final t = f * (_e2.dot(_r)); + final double t = f * (_e2.dot(_r)); return t; } @@ -172,21 +171,21 @@ class Ray { ..sub(point0); _direction.crossInto(_e2, _q); - final a1 = _e1.dot(_q); + final double a1 = _e1.dot(_q); if (!(a1 > -epsilon && a1 < epsilon)) { - final f = 1 / a1; + final double f = 1 / a1; _s ..setFrom(_origin) ..sub(point0); - final u = f * (_s.dot(_q)); + final double u = f * (_s.dot(_q)); if (u >= 0.0) { _s.crossInto(_e1, _r); - final v = f * (_direction.dot(_r)); + final double v = f * (_direction.dot(_r)); if (!(v < -epsilon || u + v > 1.0 + epsilon)) { - final t = f * (_e2.dot(_r)); + final double t = f * (_e2.dot(_r)); return t; } @@ -199,11 +198,11 @@ class Ray { /// Return the distance from the origin of this to the intersection with /// [other] if this intersects with [other], or null if the don't intersect. double? intersectsWithAabb3(Aabb3 other) { - final otherMin = other.min; - final otherMax = other.max; + final Vector3 otherMin = other.min; + final Vector3 otherMax = other.max; - var tNear = -double.maxFinite; - var tFar = double.maxFinite; + double tNear = -double.maxFinite; + double tFar = double.maxFinite; for (var i = 0; i < 3; ++i) { if (_direction[i] == 0.0) { @@ -211,8 +210,8 @@ class Ray { return null; } } else { - var t1 = (otherMin[i] - _origin[i]) / _direction[i]; - var t2 = (otherMax[i] - _origin[i]) / _direction[i]; + double t1 = (otherMin[i] - _origin[i]) / _direction[i]; + double t2 = (otherMax[i] - _origin[i]) / _direction[i]; if (t1 > t2) { final temp = t1; diff --git a/packages/vector_math/lib/src/vector_math/sphere.dart b/packages/vector_math/lib/src/vector_math/sphere.dart index 6051147..9fac298 100644 --- a/packages/vector_math/lib/src/vector_math/sphere.dart +++ b/packages/vector_math/lib/src/vector_math/sphere.dart @@ -6,14 +6,6 @@ part of '../../vector_math.dart'; /// Defines a sphere with a [center] and a [radius]. class Sphere { - final Vector3 _center; - - /// The [radius] of the sphere. - double radius; - - /// The [center] of the sphere. - Vector3 get center => _center; - /// Create a new, uninitialized sphere. Sphere() : _center = Vector3.zero(), radius = 0.0; @@ -25,6 +17,13 @@ class Sphere { /// Create a sphere from a [center] and a [radius]. Sphere.centerRadius(Vector3 center, this.radius) : _center = Vector3.copy(center); + final Vector3 _center; + + /// The [radius] of the sphere. + double radius; + + /// The [center] of the sphere. + Vector3 get center => _center; /// Copy the sphere from [other] into this. void copyFrom(Sphere other) { @@ -42,7 +41,7 @@ class Sphere { /// Return if this intersects with [other]. bool intersectsWithSphere(Sphere other) { - final radiusSum = radius + other.radius; + final double radiusSum = radius + other.radius; return other.center.distanceToSquared(center) <= (radiusSum * radiusSum); } diff --git a/packages/vector_math/lib/src/vector_math/triangle.dart b/packages/vector_math/lib/src/vector_math/triangle.dart index 941fbcc..317c258 100644 --- a/packages/vector_math/lib/src/vector_math/triangle.dart +++ b/packages/vector_math/lib/src/vector_math/triangle.dart @@ -6,19 +6,6 @@ part of '../../vector_math.dart'; /// Defines a triangle by three points. class Triangle { - final Vector3 _point0; - final Vector3 _point1; - final Vector3 _point2; - - /// The first point of the triangle. - Vector3 get point0 => _point0; - - /// The second point of the triangle. - Vector3 get point1 => _point1; - - /// The third point of the triangle. - Vector3 get point2 => _point2; - /// Create a new, uninitialized triangle. Triangle() : _point0 = Vector3.zero(), @@ -36,6 +23,18 @@ class Triangle { : _point0 = Vector3.copy(point0), _point1 = Vector3.copy(point1), _point2 = Vector3.copy(point2); + final Vector3 _point0; + final Vector3 _point1; + final Vector3 _point2; + + /// The first point of the triangle. + Vector3 get point0 => _point0; + + /// The second point of the triangle. + Vector3 get point1 => _point1; + + /// The third point of the triangle. + Vector3 get point2 => _point2; /// Copy the triangle from [other] into this. void copyFrom(Triangle other) { @@ -46,7 +45,7 @@ class Triangle { /// Copy the normal of this into [normal]. void copyNormalInto(Vector3 normal) { - final v0 = point0.clone()..sub(point1); + final Vector3 v0 = point0.clone()..sub(point1); normal ..setFrom(point2) ..sub(point1) diff --git a/packages/vector_math/lib/src/vector_math/utilities.dart b/packages/vector_math/lib/src/vector_math/utilities.dart index 748348e..560bcee 100644 --- a/packages/vector_math/lib/src/vector_math/utilities.dart +++ b/packages/vector_math/lib/src/vector_math/utilities.dart @@ -18,7 +18,7 @@ double mix(double min, double max, double a) => min + a * (max - min); /// [edge1] by [amount]. The computation is equivalent to the GLSL function /// smoothstep. double smoothStep(double edge0, double edge1, double amount) { - final t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble(); + final double t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0); return t * t * (3.0 - 2.0 * t); } diff --git a/packages/vector_math/lib/src/vector_math/vector.dart b/packages/vector_math/lib/src/vector_math/vector.dart index 60f7868..1be1fd3 100644 --- a/packages/vector_math/lib/src/vector_math/vector.dart +++ b/packages/vector_math/lib/src/vector_math/vector.dart @@ -20,7 +20,7 @@ double cross2(Vector2 x, Vector2 y) => x.cross(y); /// 2D cross product. double x vec2. void cross2A(double x, Vector2 y, Vector2 out) { - final tempy = x * y.x; + final double tempy = x * y.x; out ..x = -x * y.y ..y = tempy; @@ -28,7 +28,7 @@ void cross2A(double x, Vector2 y, Vector2 out) { /// 2D cross product. vec2 x double. void cross2B(Vector2 x, double y, Vector2 out) { - final tempy = -y * x.x; + final double tempy = -y * x.x; out ..x = y * x.y ..y = tempy; @@ -39,8 +39,9 @@ void cross2B(Vector2 x, double y, Vector2 out) { void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) { if (planeNormal.z.abs() > math.sqrt1_2) { // choose u in y-z plane - final a = planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z; - final k = 1.0 / math.sqrt(a); + final double a = + planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z; + final double k = 1.0 / math.sqrt(a); u ..x = 0.0 ..y = -planeNormal.z * k @@ -52,8 +53,9 @@ void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) { ..z = planeNormal[0] * (-planeNormal[2] * k); } else { // choose u in x-y plane - final a = planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y; - final k = 1.0 / math.sqrt(a); + final double a = + planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y; + final double k = 1.0 / math.sqrt(a); u ..x = -planeNormal[1] * k ..y = planeNormal[0] * k @@ -68,5 +70,6 @@ void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) { /// Base class for vectors abstract class Vector { + /// The values in the vector. List get storage; } diff --git a/packages/vector_math/lib/src/vector_math/vector2.dart b/packages/vector_math/lib/src/vector_math/vector2.dart index 9070071..74095f8 100644 --- a/packages/vector_math/lib/src/vector_math/vector2.dart +++ b/packages/vector_math/lib/src/vector_math/vector2.dart @@ -2,38 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Too many vector accessors that don't benefit from comments. +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; /// 2D column vector. class Vector2 implements Vector { - final Float32List _v2storage; - - /// The components of the vector. - @override - Float32List get storage => _v2storage; - - /// Set the values of [result] to the minimum of [a] and [b] for each line. - static void min(Vector2 a, Vector2 b, Vector2 result) { - result - ..x = math.min(a.x, b.x) - ..y = math.min(a.y, b.y); - } - - /// Set the values of [result] to the maximum of [a] and [b] for each line. - static void max(Vector2 a, Vector2 b, Vector2 result) { - result - ..x = math.max(a.x, b.x) - ..y = math.max(a.y, b.y); - } - - /// Interpolate between [min] and [max] with the amount of [a] using a linear - /// interpolation and store the values in [result]. - static void mix(Vector2 min, Vector2 max, double a, Vector2 result) { - result - ..x = min.x + a * (max.x - min.x) - ..y = min.y + a * (max.y - min.y); - } - /// Construct a new vector with the specified values. factory Vector2(double x, double y) => Vector2.zero()..setValues(x, y); @@ -64,6 +39,33 @@ class Vector2 implements Vector { rng ??= math.Random(); return Vector2(rng.nextDouble(), rng.nextDouble()); } + final Float32List _v2storage; + + /// The components of the vector. + @override + Float32List get storage => _v2storage; + + /// Set the values of [result] to the minimum of [a] and [b] for each line. + static void min(Vector2 a, Vector2 b, Vector2 result) { + result + ..x = math.min(a.x, b.x) + ..y = math.min(a.y, b.y); + } + + /// Set the values of [result] to the maximum of [a] and [b] for each line. + static void max(Vector2 a, Vector2 b, Vector2 result) { + result + ..x = math.max(a.x, b.x) + ..y = math.max(a.y, b.y); + } + + /// Interpolate between [min] and [max] with the amount of [a] using a linear + /// interpolation and store the values in [result]. + static void mix(Vector2 min, Vector2 max, double a, Vector2 result) { + result + ..x = min.x + a * (max.x - min.x) + ..y = min.y + a * (max.y - min.y); + } /// Set the values of the vector. void setValues(double x_, double y_) { @@ -79,7 +81,7 @@ class Vector2 implements Vector { /// Set the values by copying them from [other]. void setFrom(Vector2 other) { - final otherStorage = other._v2storage; + final Float32List otherStorage = other._v2storage; _v2storage[1] = otherStorage[1]; _v2storage[0] = otherStorage[0]; } @@ -96,12 +98,14 @@ class Vector2 implements Vector { /// Check if two vectors are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => other is Vector2 && _v2storage[1] == other._v2storage[1] && _v2storage[0] == other._v2storage[0]; @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_v2storage); /// Negate. @@ -133,7 +137,7 @@ class Vector2 implements Vector { if (value == 0.0) { setZero(); } else { - var l = length; + double l = length; if (l == 0.0) { return; } @@ -152,11 +156,11 @@ class Vector2 implements Vector { /// Normalize this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _v2storage[1] *= d; _v2storage[0] *= d; return l; @@ -182,40 +186,40 @@ class Vector2 implements Vector { /// Squared distance from this to [arg] double distanceToSquared(Vector2 arg) { - final dx = x - arg.x; - final dy = y - arg.y; + final double dx = x - arg.x; + final double dy = y - arg.y; return dx * dx + dy * dy; } /// Returns the angle between this vector and [other] in radians. double angleTo(Vector2 other) { - final otherStorage = other._v2storage; + final Float32List otherStorage = other._v2storage; if (_v2storage[1] == otherStorage[1] && _v2storage[0] == otherStorage[0]) { return 0.0; } - final d = dot(other) / (length * other.length); + final double d = dot(other) / (length * other.length); return math.acos(d.clamp(-1.0, 1.0)); } /// Returns the signed angle between this and [other] in radians. double angleToSigned(Vector2 other) { - final otherStorage = other._v2storage; + final Float32List otherStorage = other._v2storage; if (_v2storage[1] == otherStorage[1] && _v2storage[0] == otherStorage[0]) { return 0.0; } - final s = cross(other); - final c = dot(other); + final double s = cross(other); + final double c = dot(other); return math.atan2(s, c); } /// Inner product. double dot(Vector2 other) { - final otherStorage = other._v2storage; + final Float32List otherStorage = other._v2storage; return _v2storage[1] * otherStorage[1] + _v2storage[0] * otherStorage[0]; } @@ -225,16 +229,16 @@ class Vector2 implements Vector { /// applying, the inverse of the transformation. /// void postmultiply(Matrix2 arg) { - final argStorage = arg.storage; - final v1 = _v2storage[1]; - final v0 = _v2storage[0]; + final Float32List argStorage = arg.storage; + final double v1 = _v2storage[1]; + final double v0 = _v2storage[0]; _v2storage[1] = v0 * argStorage[2] + v1 * argStorage[3]; _v2storage[0] = v0 * argStorage[0] + v1 * argStorage[1]; } /// Cross product. double cross(Vector2 other) { - final otherStorage = other._v2storage; + final Float32List otherStorage = other._v2storage; return _v2storage[0] * otherStorage[1] - _v2storage[1] * otherStorage[0]; } @@ -248,7 +252,7 @@ class Vector2 implements Vector { /// Reflect this. void reflect(Vector2 normal) { - final dotProduct = normal.dot(this) * 2; + final double dotProduct = normal.dot(this) * 2; _v2storage[1] -= normal._v2storage[1] * dotProduct; _v2storage[0] -= normal._v2storage[0] * dotProduct; } @@ -262,8 +266,8 @@ class Vector2 implements Vector { /// Absolute error between this and [correct] double absoluteError(Vector2 correct) { - final yDiff = _v2storage[1] - correct._v2storage[1]; - final xDiff = _v2storage[0] - correct._v2storage[0]; + final double yDiff = _v2storage[1] - correct._v2storage[1]; + final double xDiff = _v2storage[0] - correct._v2storage[0]; return math.sqrt(xDiff * xDiff + yDiff * yDiff); } @@ -275,35 +279,35 @@ class Vector2 implements Vector { /// Add [arg] to this. void add(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] += argStorage[1]; _v2storage[0] += argStorage[0]; } /// Add [arg] scaled by [factor] to this. void addScaled(Vector2 arg, double factor) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] += argStorage[1] * factor; _v2storage[0] += argStorage[0] * factor; } /// Subtract [arg] from this. void sub(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] -= argStorage[1]; _v2storage[0] -= argStorage[0]; } /// Multiply entries in this with entries in [arg]. void multiply(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] *= argStorage[1]; _v2storage[0] *= argStorage[0]; } /// Divide entries in this with entries in [arg]. void divide(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] /= argStorage[1]; _v2storage[0] /= argStorage[0]; } @@ -331,20 +335,16 @@ class Vector2 implements Vector { /// Clamp each entry `n` in this in the range `[min[n]]-[max[n]]`. void clamp(Vector2 min, Vector2 max) { - final minStorage = min._v2storage; - final maxStorage = max._v2storage; - _v2storage[1] = _v2storage[1] - .clamp(minStorage[1], maxStorage[1]) - .toDouble(); - _v2storage[0] = _v2storage[0] - .clamp(minStorage[0], maxStorage[0]) - .toDouble(); + final Float32List minStorage = min._v2storage; + final Float32List maxStorage = max._v2storage; + _v2storage[1] = _v2storage[1].clamp(minStorage[1], maxStorage[1]); + _v2storage[0] = _v2storage[0].clamp(minStorage[0], maxStorage[0]); } /// Clamp entries this in the range [min]-[max]. void clampScalar(double min, double max) { - _v2storage[1] = _v2storage[1].clamp(min, max).toDouble(); - _v2storage[0] = _v2storage[0].clamp(min, max).toDouble(); + _v2storage[1] = _v2storage[1].clamp(min, max); + _v2storage[0] = _v2storage[0].clamp(min, max); } /// Floor entries in this. @@ -367,12 +367,14 @@ 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. @@ -380,7 +382,7 @@ class Vector2 implements Vector { /// Copy this into [arg]. Returns [arg]. Vector2 copyInto(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; argStorage[1] = _v2storage[1]; argStorage[0] = _v2storage[0]; return arg; @@ -399,13 +401,13 @@ class Vector2 implements Vector { } set xy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] = argStorage[1]; _v2storage[0] = argStorage[0]; } set yx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v2storage[1] = argStorage[0]; _v2storage[0] = argStorage[1]; } diff --git a/packages/vector_math/lib/src/vector_math/vector3.dart b/packages/vector_math/lib/src/vector_math/vector3.dart index 3a4746c..ebaad7b 100644 --- a/packages/vector_math/lib/src/vector_math/vector3.dart +++ b/packages/vector_math/lib/src/vector_math/vector3.dart @@ -2,41 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Too many vector accessors that don't benefit from comments. +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; /// 3D column vector. class Vector3 implements Vector { - final Float32List _v3storage; - - /// The components of the vector. - @override - Float32List get storage => _v3storage; - - /// Set the values of [result] to the minimum of [a] and [b] for each line. - static void min(Vector3 a, Vector3 b, Vector3 result) { - result - ..x = math.min(a.x, b.x) - ..y = math.min(a.y, b.y) - ..z = math.min(a.z, b.z); - } - - /// Set the values of [result] to the maximum of [a] and [b] for each line. - static void max(Vector3 a, Vector3 b, Vector3 result) { - result - ..x = math.max(a.x, b.x) - ..y = math.max(a.y, b.y) - ..z = math.max(a.z, b.z); - } - - /// Interpolate between [min] and [max] with the amount of [a] using a linear - /// interpolation and store the values in [result]. - static void mix(Vector3 min, Vector3 max, double a, Vector3 result) { - result - ..x = min.x + a * (max.x - min.x) - ..y = min.y + a * (max.y - min.y) - ..z = min.z + a * (max.z - min.z); - } - /// Construct a new vector with the specified values. factory Vector3(double x, double y, double z) => Vector3.zero()..setValues(x, y, z); @@ -68,6 +40,36 @@ class Vector3 implements Vector { rng ??= math.Random(); return Vector3(rng.nextDouble(), rng.nextDouble(), rng.nextDouble()); } + final Float32List _v3storage; + + /// The components of the vector. + @override + Float32List get storage => _v3storage; + + /// Set the values of [result] to the minimum of [a] and [b] for each line. + static void min(Vector3 a, Vector3 b, Vector3 result) { + result + ..x = math.min(a.x, b.x) + ..y = math.min(a.y, b.y) + ..z = math.min(a.z, b.z); + } + + /// Set the values of [result] to the maximum of [a] and [b] for each line. + static void max(Vector3 a, Vector3 b, Vector3 result) { + result + ..x = math.max(a.x, b.x) + ..y = math.max(a.y, b.y) + ..z = math.max(a.z, b.z); + } + + /// Interpolate between [min] and [max] with the amount of [a] using a linear + /// interpolation and store the values in [result]. + static void mix(Vector3 min, Vector3 max, double a, Vector3 result) { + result + ..x = min.x + a * (max.x - min.x) + ..y = min.y + a * (max.y - min.y) + ..z = min.z + a * (max.z - min.z); + } /// Set the values of the vector. void setValues(double x, double y, double z) { @@ -85,7 +87,7 @@ class Vector3 implements Vector { /// Set the values by copying them from [other]. void setFrom(Vector3 other) { - final otherStorage = other._v3storage; + final Float32List otherStorage = other._v3storage; _v3storage[2] = otherStorage[2]; _v3storage[1] = otherStorage[1]; _v3storage[0] = otherStorage[0]; @@ -104,6 +106,7 @@ class Vector3 implements Vector { /// Check if two vectors are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Vector3) && (_v3storage[2] == other._v3storage[2]) && @@ -111,6 +114,7 @@ class Vector3 implements Vector { (_v3storage[0] == other._v3storage[0]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_v3storage); /// Negate @@ -142,7 +146,7 @@ class Vector3 implements Vector { if (value == 0.0) { setZero(); } else { - var l = length; + double l = length; if (l == 0.0) { return; } @@ -167,11 +171,11 @@ class Vector3 implements Vector { /// Normalizes this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _v3storage[2] *= d; _v3storage[1] *= d; _v3storage[0] *= d; @@ -198,24 +202,24 @@ class Vector3 implements Vector { /// Squared distance from this to [arg] double distanceToSquared(Vector3 arg) { - final argStorage = arg._v3storage; - final dz = _v3storage[2] - argStorage[2]; - final dy = _v3storage[1] - argStorage[1]; - final dx = _v3storage[0] - argStorage[0]; + final Float32List argStorage = arg._v3storage; + final double dz = _v3storage[2] - argStorage[2]; + final double dy = _v3storage[1] - argStorage[1]; + final double dx = _v3storage[0] - argStorage[0]; return dx * dx + dy * dy + dz * dz; } /// Returns the angle between this vector and [other] in radians. double angleTo(Vector3 other) { - final otherStorage = other._v3storage; + final Float32List otherStorage = other._v3storage; if (_v3storage[2] == otherStorage[2] && _v3storage[1] == otherStorage[1] && _v3storage[0] == otherStorage[0]) { return 0.0; } - final d = dot(other) / (length * other.length); + final double d = dot(other) / (length * other.length); return math.acos(d.clamp(-1.0, 1.0)); } @@ -223,16 +227,16 @@ class Vector3 implements Vector { /// Returns the signed angle between this and [other] around [normal] /// in radians. double angleToSigned(Vector3 other, Vector3 normal) { - final angle = angleTo(other); - final c = cross(other); - final d = c.dot(normal); + final double angle = angleTo(other); + final Vector3 c = cross(other); + final double d = c.dot(normal); return d < 0.0 ? -angle : angle; } /// Inner product. double dot(Vector3 other) { - final otherStorage = other._v3storage; + final Float32List otherStorage = other._v3storage; return _v3storage[2] * otherStorage[2] + _v3storage[1] * otherStorage[1] + _v3storage[0] * otherStorage[0]; @@ -244,10 +248,10 @@ class Vector3 implements Vector { /// If [arg] is a rotation matrix, this is a computational shortcut for /// applying, the inverse of the transformation. void postmultiply(Matrix3 arg) { - final argStorage = arg._m3storage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; + final Float32List argStorage = arg._m3storage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; _v3storage[2] = v0 * argStorage[6] + v1 * argStorage[7] + v2 * argStorage[8]; @@ -259,26 +263,26 @@ class Vector3 implements Vector { /// Cross product. Vector3 cross(Vector3 other) { - final z = _v3storage[2]; - final y = _v3storage[1]; - final x = _v3storage[0]; - final otherStorage = other._v3storage; - final oz = otherStorage[2]; - final oy = otherStorage[1]; - final ox = otherStorage[0]; + final double z = _v3storage[2]; + final double y = _v3storage[1]; + final double x = _v3storage[0]; + final Float32List otherStorage = other._v3storage; + final double oz = otherStorage[2]; + final double oy = otherStorage[1]; + final double ox = otherStorage[0]; return Vector3(y * oz - z * oy, z * ox - x * oz, x * oy - y * ox); } /// Cross product. Stores result in [out]. Vector3 crossInto(Vector3 other, Vector3 out) { - final z = _v3storage[2]; - final y = _v3storage[1]; - final x = _v3storage[0]; - final otherStorage = other._v3storage; - final oz = otherStorage[2]; - final oy = otherStorage[1]; - final ox = otherStorage[0]; - final outStorage = out._v3storage; + final double z = _v3storage[2]; + final double y = _v3storage[1]; + final double x = _v3storage[0]; + final Float32List otherStorage = other._v3storage; + final double oz = otherStorage[2]; + final double oy = otherStorage[1]; + final double ox = otherStorage[0]; + final Float32List outStorage = out._v3storage; outStorage[2] = x * oy - y * ox; outStorage[1] = z * ox - x * oz; outStorage[0] = y * oz - z * oy; @@ -287,7 +291,7 @@ class Vector3 implements Vector { /// Reflect this. void reflect(Vector3 normal) { - final dotProduct = 2.0 * normal.dot(this); + final double dotProduct = 2.0 * normal.dot(this); _v3storage[2] -= normal._v3storage[2] * dotProduct; _v3storage[1] -= normal._v3storage[1] * dotProduct; _v3storage[0] -= normal._v3storage[0] * dotProduct; @@ -298,11 +302,11 @@ class Vector3 implements Vector { /// Projects this using the projection matrix [arg] void applyProjection(Matrix4 arg) { - final argStorage = arg._m4storage; - final z = _v3storage[2]; - final y = _v3storage[1]; - final x = _v3storage[0]; - final d = + final Float32List argStorage = arg._m4storage; + final double z = _v3storage[2]; + final double y = _v3storage[1]; + final double x = _v3storage[0]; + final double d = 1.0 / (argStorage[15] + argStorage[11] * z + @@ -335,18 +339,18 @@ class Vector3 implements Vector { /// Applies a quaternion transform. void applyQuaternion(Quaternion arg) { - final argStorage = arg._qStorage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; - final qw = argStorage[3]; - final qz = argStorage[2]; - final qy = argStorage[1]; - final qx = argStorage[0]; - final ix = qw * v0 + qy * v2 - qz * v1; - final iy = qw * v1 + qz * v0 - qx * v2; - final iz = qw * v2 + qx * v1 - qy * v0; - final iw = -qx * v0 - qy * v1 - qz * v2; + final Float32List argStorage = arg._qStorage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; + final double qw = argStorage[3]; + final double qz = argStorage[2]; + final double qy = argStorage[1]; + final double qx = argStorage[0]; + final double ix = qw * v0 + qy * v2 - qz * v1; + final double iy = qw * v1 + qz * v0 - qx * v2; + final double iz = qw * v2 + qx * v1 - qy * v0; + final double iw = -qx * v0 - qy * v1 - qz * v2; _v3storage[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; _v3storage[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; _v3storage[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; @@ -354,10 +358,10 @@ class Vector3 implements Vector { /// Multiplies this by [arg]. void applyMatrix3(Matrix3 arg) { - final argStorage = arg._m3storage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; + final Float32List argStorage = arg._m3storage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; _v3storage[2] = argStorage[2] * v0 + argStorage[5] * v1 + argStorage[8] * v2; _v3storage[1] = @@ -369,10 +373,10 @@ class Vector3 implements Vector { /// Multiplies this by a 4x3 subset of [arg]. Expects [arg] to be an affine /// transformation matrix. void applyMatrix4(Matrix4 arg) { - final argStorage = arg._m4storage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; + final Float32List argStorage = arg._m4storage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; _v3storage[2] = argStorage[2] * v0 + argStorage[6] * v1 + @@ -396,9 +400,9 @@ class Vector3 implements Vector { /// Absolute error between this and [correct] double absoluteError(Vector3 correct) { - final zDiff = _v3storage[2] - correct._v3storage[2]; - final yDiff = _v3storage[1] - correct._v3storage[1]; - final xDiff = _v3storage[0] - correct._v3storage[0]; + final double zDiff = _v3storage[2] - correct._v3storage[2]; + final double yDiff = _v3storage[1] - correct._v3storage[1]; + final double xDiff = _v3storage[0] - correct._v3storage[0]; return math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff); } @@ -414,7 +418,7 @@ class Vector3 implements Vector { /// Add [arg] to this. void add(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] += argStorage[2]; _v3storage[1] += argStorage[1]; _v3storage[0] += argStorage[0]; @@ -422,7 +426,7 @@ class Vector3 implements Vector { /// Add [arg] scaled by [factor] to this. void addScaled(Vector3 arg, double factor) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] += argStorage[2] * factor; _v3storage[1] += argStorage[1] * factor; _v3storage[0] += argStorage[0] * factor; @@ -430,7 +434,7 @@ class Vector3 implements Vector { /// Subtract [arg] from this. void sub(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] -= argStorage[2]; _v3storage[1] -= argStorage[1]; _v3storage[0] -= argStorage[0]; @@ -438,7 +442,7 @@ class Vector3 implements Vector { /// Multiply entries in this with entries in [arg]. void multiply(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] *= argStorage[2]; _v3storage[1] *= argStorage[1]; _v3storage[0] *= argStorage[0]; @@ -446,7 +450,7 @@ class Vector3 implements Vector { /// Divide entries in this with entries in [arg]. void divide(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] /= argStorage[2]; _v3storage[1] /= argStorage[1]; _v3storage[0] /= argStorage[0]; @@ -478,24 +482,18 @@ class Vector3 implements Vector { /// Clamp each entry `n` in this in the range `[min[n]]-[max[n]]`. void clamp(Vector3 min, Vector3 max) { - final minStorage = min.storage; - final maxStorage = max.storage; - _v3storage[2] = _v3storage[2] - .clamp(minStorage[2], maxStorage[2]) - .toDouble(); - _v3storage[1] = _v3storage[1] - .clamp(minStorage[1], maxStorage[1]) - .toDouble(); - _v3storage[0] = _v3storage[0] - .clamp(minStorage[0], maxStorage[0]) - .toDouble(); + final Float32List minStorage = min.storage; + final Float32List maxStorage = max.storage; + _v3storage[2] = _v3storage[2].clamp(minStorage[2], maxStorage[2]); + _v3storage[1] = _v3storage[1].clamp(minStorage[1], maxStorage[1]); + _v3storage[0] = _v3storage[0].clamp(minStorage[0], maxStorage[0]); } /// Clamp entries in this in the range [min]-[max]. void clampScalar(double min, double max) { - _v3storage[2] = _v3storage[2].clamp(min, max).toDouble(); - _v3storage[1] = _v3storage[1].clamp(min, max).toDouble(); - _v3storage[0] = _v3storage[0].clamp(min, max).toDouble(); + _v3storage[2] = _v3storage[2].clamp(min, max); + _v3storage[1] = _v3storage[1].clamp(min, max); + _v3storage[0] = _v3storage[0].clamp(min, max); } /// Floor entries in this. @@ -521,15 +519,18 @@ 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. @@ -537,7 +538,7 @@ class Vector3 implements Vector { /// Copy this into [arg]. Vector3 copyInto(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; argStorage[2] = _v3storage[2]; argStorage[1] = _v3storage[1]; argStorage[0] = _v3storage[0]; @@ -559,78 +560,78 @@ class Vector3 implements Vector { } set xy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v3storage[1] = argStorage[1]; _v3storage[0] = argStorage[0]; } set xz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v3storage[2] = argStorage[1]; _v3storage[0] = argStorage[0]; } set yx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v3storage[1] = argStorage[0]; _v3storage[0] = argStorage[1]; } set yz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v3storage[2] = argStorage[1]; _v3storage[1] = argStorage[0]; } set zx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v3storage[2] = argStorage[0]; _v3storage[0] = argStorage[1]; } set zy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v3storage[2] = argStorage[0]; _v3storage[1] = argStorage[1]; } set xyz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] = argStorage[2]; _v3storage[1] = argStorage[1]; _v3storage[0] = argStorage[0]; } set xzy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[0] = argStorage[0]; _v3storage[2] = argStorage[1]; _v3storage[1] = argStorage[2]; } set yxz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] = argStorage[2]; _v3storage[1] = argStorage[0]; _v3storage[0] = argStorage[1]; } set yzx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] = argStorage[1]; _v3storage[1] = argStorage[0]; _v3storage[0] = argStorage[2]; } set zxy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] = argStorage[0]; _v3storage[0] = argStorage[1]; _v3storage[1] = argStorage[2]; } set zyx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v3storage[2] = argStorage[0]; _v3storage[1] = argStorage[1]; _v3storage[0] = argStorage[2]; diff --git a/packages/vector_math/lib/src/vector_math/vector4.dart b/packages/vector_math/lib/src/vector_math/vector4.dart index 34c60e8..ff93275 100644 --- a/packages/vector_math/lib/src/vector_math/vector4.dart +++ b/packages/vector_math/lib/src/vector_math/vector4.dart @@ -2,44 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Too many vector accessors that don't benefit from comments. +// ignore_for_file: public_member_api_docs + part of '../../vector_math.dart'; /// 4D column vector. class Vector4 implements Vector { - final Float32List _v4storage; - - /// Set the values of [result] to the minimum of [a] and [b] for each line. - static void min(Vector4 a, Vector4 b, Vector4 result) { - result - ..x = math.min(a.x, b.x) - ..y = math.min(a.y, b.y) - ..z = math.min(a.z, b.z) - ..w = math.min(a.w, b.w); - } - - /// Set the values of [result] to the maximum of [a] and [b] for each line. - static void max(Vector4 a, Vector4 b, Vector4 result) { - result - ..x = math.max(a.x, b.x) - ..y = math.max(a.y, b.y) - ..z = math.max(a.z, b.z) - ..w = math.max(a.w, b.w); - } - - /// Interpolate between [min] and [max] with the amount of [a] using a linear - /// interpolation and store the values in [result]. - static void mix(Vector4 min, Vector4 max, double a, Vector4 result) { - result - ..x = min.x + a * (max.x - min.x) - ..y = min.y + a * (max.y - min.y) - ..z = min.z + a * (max.z - min.z) - ..w = min.w + a * (max.w - min.w); - } - - /// The components of the vector. - @override - Float32List get storage => _v4storage; - /// Construct a new vector with the specified values. factory Vector4(double x, double y, double z, double w) => Vector4.zero()..setValues(x, y, z, w); @@ -79,6 +48,39 @@ class Vector4 implements Vector { rng.nextDouble(), ); } + final Float32List _v4storage; + + /// Set the values of [result] to the minimum of [a] and [b] for each line. + static void min(Vector4 a, Vector4 b, Vector4 result) { + result + ..x = math.min(a.x, b.x) + ..y = math.min(a.y, b.y) + ..z = math.min(a.z, b.z) + ..w = math.min(a.w, b.w); + } + + /// Set the values of [result] to the maximum of [a] and [b] for each line. + static void max(Vector4 a, Vector4 b, Vector4 result) { + result + ..x = math.max(a.x, b.x) + ..y = math.max(a.y, b.y) + ..z = math.max(a.z, b.z) + ..w = math.max(a.w, b.w); + } + + /// Interpolate between [min] and [max] with the amount of [a] using a linear + /// interpolation and store the values in [result]. + static void mix(Vector4 min, Vector4 max, double a, Vector4 result) { + result + ..x = min.x + a * (max.x - min.x) + ..y = min.y + a * (max.y - min.y) + ..z = min.z + a * (max.z - min.z) + ..w = min.w + a * (max.w - min.w); + } + + /// The components of the vector. + @override + Float32List get storage => _v4storage; /// Set the values of the vector. void setValues(double x, double y, double z, double w) { @@ -106,7 +108,7 @@ class Vector4 implements Vector { /// Set the values by copying them from [other]. void setFrom(Vector4 other) { - final otherStorage = other._v4storage; + final Float32List otherStorage = other._v4storage; _v4storage[3] = otherStorage[3]; _v4storage[2] = otherStorage[2]; _v4storage[1] = otherStorage[1]; @@ -129,6 +131,7 @@ class Vector4 implements Vector { /// Check if two vectors are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Vector4) && (_v4storage[3] == other._v4storage[3]) && @@ -137,6 +140,7 @@ class Vector4 implements Vector { (_v4storage[0] == other._v4storage[0]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_v4storage); /// Negate. @@ -168,7 +172,7 @@ class Vector4 implements Vector { if (value == 0.0) { setZero(); } else { - var l = length; + double l = length; if (l == 0.0) { return; } @@ -192,11 +196,11 @@ class Vector4 implements Vector { /// Normalizes this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _v4storage[3] *= d; _v4storage[2] *= d; _v4storage[1] *= d; @@ -224,18 +228,18 @@ class Vector4 implements Vector { /// Squared distance from this to [arg] double distanceToSquared(Vector4 arg) { - final argStorage = arg._v4storage; - final dw = _v4storage[3] - argStorage[3]; - final dz = _v4storage[2] - argStorage[2]; - final dy = _v4storage[1] - argStorage[1]; - final dx = _v4storage[0] - argStorage[0]; + final Float32List argStorage = arg._v4storage; + final double dw = _v4storage[3] - argStorage[3]; + final double dz = _v4storage[2] - argStorage[2]; + final double dy = _v4storage[1] - argStorage[1]; + final double dx = _v4storage[0] - argStorage[0]; return dx * dx + dy * dy + dz * dz + dw * dw; } /// Inner product. double dot(Vector4 other) { - final otherStorage = other._v4storage; + final Float32List otherStorage = other._v4storage; return _v4storage[3] * otherStorage[3] + _v4storage[2] * otherStorage[2] + _v4storage[1] * otherStorage[1] + @@ -244,11 +248,11 @@ class Vector4 implements Vector { /// Multiplies this by [arg]. void applyMatrix4(Matrix4 arg) { - final v4 = _v4storage[3]; - final v3 = _v4storage[2]; - final v2 = _v4storage[1]; - final v1 = _v4storage[0]; - final argStorage = arg._m4storage; + final double v4 = _v4storage[3]; + final double v3 = _v4storage[2]; + final double v2 = _v4storage[1]; + final double v1 = _v4storage[0]; + final Float32List argStorage = arg._m4storage; _v4storage[3] = argStorage[3] * v1 + argStorage[7] * v2 + @@ -277,10 +281,10 @@ class Vector4 implements Vector { /// Absolute error between this and [correct] double absoluteError(Vector4 correct) { - final wDiff = _v4storage[3] - correct._v4storage[3]; - final zDiff = _v4storage[2] - correct._v4storage[2]; - final yDiff = _v4storage[1] - correct._v4storage[1]; - final xDiff = _v4storage[0] - correct._v4storage[0]; + final double wDiff = _v4storage[3] - correct._v4storage[3]; + final double zDiff = _v4storage[2] - correct._v4storage[2]; + final double yDiff = _v4storage[1] - correct._v4storage[1]; + final double xDiff = _v4storage[0] - correct._v4storage[0]; return math.sqrt( xDiff * xDiff + yDiff * yDiff + zDiff * zDiff + wDiff * wDiff, ); @@ -301,7 +305,7 @@ class Vector4 implements Vector { _v4storage[0].isNaN; void add(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] += argStorage[3]; _v4storage[2] += argStorage[2]; _v4storage[1] += argStorage[1]; @@ -310,7 +314,7 @@ class Vector4 implements Vector { /// Add [arg] scaled by [factor] to this. void addScaled(Vector4 arg, double factor) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] += argStorage[3] * factor; _v4storage[2] += argStorage[2] * factor; _v4storage[1] += argStorage[1] * factor; @@ -319,7 +323,7 @@ class Vector4 implements Vector { /// Subtract [arg] from this. void sub(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] -= argStorage[3]; _v4storage[2] -= argStorage[2]; _v4storage[1] -= argStorage[1]; @@ -328,7 +332,7 @@ class Vector4 implements Vector { /// Multiply this by [arg]. void multiply(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] *= argStorage[3]; _v4storage[2] *= argStorage[2]; _v4storage[1] *= argStorage[1]; @@ -337,7 +341,7 @@ class Vector4 implements Vector { /// Divide this by [arg]. void div(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] /= argStorage[3]; _v4storage[2] /= argStorage[2]; _v4storage[1] /= argStorage[1]; @@ -373,28 +377,20 @@ class Vector4 implements Vector { /// Clamp each entry `n` in this in the range `[min[n]]-[max[n]]`. void clamp(Vector4 min, Vector4 max) { - final minStorage = min.storage; - final maxStorage = max.storage; - _v4storage[3] = _v4storage[3] - .clamp(minStorage[3], maxStorage[3]) - .toDouble(); - _v4storage[2] = _v4storage[2] - .clamp(minStorage[2], maxStorage[2]) - .toDouble(); - _v4storage[1] = _v4storage[1] - .clamp(minStorage[1], maxStorage[1]) - .toDouble(); - _v4storage[0] = _v4storage[0] - .clamp(minStorage[0], maxStorage[0]) - .toDouble(); + final Float32List minStorage = min.storage; + final Float32List maxStorage = max.storage; + _v4storage[3] = _v4storage[3].clamp(minStorage[3], maxStorage[3]); + _v4storage[2] = _v4storage[2].clamp(minStorage[2], maxStorage[2]); + _v4storage[1] = _v4storage[1].clamp(minStorage[1], maxStorage[1]); + _v4storage[0] = _v4storage[0].clamp(minStorage[0], maxStorage[0]); } /// Clamp entries in this in the range [min]-[max]. void clampScalar(double min, double max) { - _v4storage[3] = _v4storage[3].clamp(min, max).toDouble(); - _v4storage[2] = _v4storage[2].clamp(min, max).toDouble(); - _v4storage[1] = _v4storage[1].clamp(min, max).toDouble(); - _v4storage[0] = _v4storage[0].clamp(min, max).toDouble(); + _v4storage[3] = _v4storage[3].clamp(min, max); + _v4storage[2] = _v4storage[2].clamp(min, max); + _v4storage[1] = _v4storage[1].clamp(min, max); + _v4storage[0] = _v4storage[0].clamp(min, max); } /// Floor entries in this. @@ -423,18 +419,22 @@ 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. @@ -442,7 +442,7 @@ class Vector4 implements Vector { /// Copy this Vector4 copyInto(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; argStorage[3] = _v4storage[3]; argStorage[2] = _v4storage[2]; argStorage[1] = _v4storage[1]; @@ -467,247 +467,247 @@ class Vector4 implements Vector { } set xy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[2] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xw(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[3] = argStorage[1]; _v4storage[0] = argStorage[0]; } set yx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[1]; } set yz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; } set yw(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[0]; } set zx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[1]; } set zy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; } set zw(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[2] = argStorage[0]; _v4storage[3] = argStorage[1]; } set wx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[1]; } set wy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[1]; } set wz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float32List argStorage = arg._v2storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[1]; } set xyz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xyw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xzy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[2]; _v4storage[0] = argStorage[0]; } set xzw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xwy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[2]; _v4storage[0] = argStorage[0]; } set xwz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[2]; _v4storage[0] = argStorage[0]; } set yxz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[1]; } set yxw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[1]; } set yzx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[1] = argStorage[0]; _v4storage[2] = argStorage[1]; _v4storage[0] = argStorage[2]; } set yzw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; } set ywx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[2]; } set ywz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[0]; } set zxy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[1]; _v4storage[1] = argStorage[2]; } set zxw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[1]; } set zyx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[2]; } set zyw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; } set zwx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[2]; } set zwy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[2]; } set wxy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[2]; _v4storage[0] = argStorage[1]; } set wxz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[2]; _v4storage[0] = argStorage[1]; } set wyx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[2]; _v4storage[1] = argStorage[1]; } set wyz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[1]; } set wzx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[2]; _v4storage[2] = argStorage[1]; } set wzy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float32List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[2]; _v4storage[2] = argStorage[1]; } set xyzw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[1]; @@ -715,7 +715,7 @@ class Vector4 implements Vector { } set xywz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[1]; @@ -723,7 +723,7 @@ class Vector4 implements Vector { } set xzyw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[2]; @@ -731,7 +731,7 @@ class Vector4 implements Vector { } set xzwy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[3]; @@ -739,7 +739,7 @@ class Vector4 implements Vector { } set xwyz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[2]; @@ -747,7 +747,7 @@ class Vector4 implements Vector { } set xwzy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[3]; @@ -755,7 +755,7 @@ class Vector4 implements Vector { } set yxzw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[0]; @@ -763,7 +763,7 @@ class Vector4 implements Vector { } set yxwz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[0]; @@ -771,7 +771,7 @@ class Vector4 implements Vector { } set yzxw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; @@ -779,7 +779,7 @@ class Vector4 implements Vector { } set yzwx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; @@ -787,7 +787,7 @@ class Vector4 implements Vector { } set ywxz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[0]; @@ -795,7 +795,7 @@ class Vector4 implements Vector { } set ywzx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[2]; @@ -803,7 +803,7 @@ class Vector4 implements Vector { } set zxyw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[2]; @@ -811,7 +811,7 @@ class Vector4 implements Vector { } set zxwy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -819,7 +819,7 @@ class Vector4 implements Vector { } set zyxw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; @@ -827,7 +827,7 @@ class Vector4 implements Vector { } set zywx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -835,7 +835,7 @@ class Vector4 implements Vector { } set zwxy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -843,7 +843,7 @@ class Vector4 implements Vector { } set zwyx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -851,7 +851,7 @@ class Vector4 implements Vector { } set wxyz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[2]; @@ -859,7 +859,7 @@ class Vector4 implements Vector { } set wxzy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[2]; @@ -867,7 +867,7 @@ class Vector4 implements Vector { } set wyxz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[1]; @@ -875,7 +875,7 @@ class Vector4 implements Vector { } set wyzx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[2]; @@ -883,7 +883,7 @@ class Vector4 implements Vector { } set wzxy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[1]; @@ -891,7 +891,7 @@ class Vector4 implements Vector { } set wzyx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float32List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[3]; _v4storage[1] = argStorage[2]; diff --git a/packages/vector_math/lib/src/vector_math_64/aabb2.dart b/packages/vector_math/lib/src/vector_math_64/aabb2.dart index 5221921..16ceb93 100644 --- a/packages/vector_math/lib/src/vector_math_64/aabb2.dart +++ b/packages/vector_math/lib/src/vector_math_64/aabb2.dart @@ -7,20 +7,6 @@ part of '../../vector_math_64.dart'; /// Defines a 2-dimensional axis-aligned bounding box between a [min] and a /// [max] position. class Aabb2 { - final Vector2 _min; - final Vector2 _max; - - /// The minimum point defining the AABB. - Vector2 get min => _min; - - /// The maximum point defining the AABB. - Vector2 get max => _max; - - /// The center of the AABB. - 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(); @@ -47,6 +33,20 @@ class Aabb2 { buffer, offset + Float64List.bytesPerElement * 2, ); + final Vector2 _min; + final Vector2 _max; + + /// The minimum point defining the AABB. + Vector2 get min => _min; + + /// The maximum point defining the AABB. + Vector2 get max => _max; + + /// The center of the AABB. + Vector2 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector2 center, Vector2 halfExtents) { @@ -109,15 +109,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]. @@ -134,8 +136,8 @@ class Aabb2 { /// Return if this contains [other]. bool containsAabb2(Aabb2 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector2 otherMax = other._max; + final Vector2 otherMin = other._min; return (_min.x < otherMin.x) && (_min.y < otherMin.y) && @@ -152,8 +154,8 @@ class Aabb2 { /// Return if this intersects with [other]. bool intersectsWithAabb2(Aabb2 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector2 otherMax = other._max; + final Vector2 otherMin = other._min; return (_min.x <= otherMax.x) && (_min.y <= otherMax.y) && diff --git a/packages/vector_math/lib/src/vector_math_64/aabb3.dart b/packages/vector_math/lib/src/vector_math_64/aabb3.dart index 5cd2385..405a26e 100644 --- a/packages/vector_math/lib/src/vector_math_64/aabb3.dart +++ b/packages/vector_math/lib/src/vector_math_64/aabb3.dart @@ -2,22 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; /// Defines a 3-dimensional axis-aligned bounding box between a [min] and a /// [max] position. class Aabb3 { - final Vector3 _min; - final Vector3 _max; - - Vector3 get min => _min; - Vector3 get max => _max; - - /// The center of the AABB. - 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(); @@ -62,6 +55,17 @@ class Aabb3 { buffer, offset + Float64List.bytesPerElement * 3, ); + final Vector3 _min; + final Vector3 _max; + + Vector3 get min => _min; + Vector3 get max => _max; + + /// The center of the AABB. + Vector3 get center => + _min.clone() + ..add(_max) + ..scale(0.5); /// Set the AABB by a [center] and [halfExtents]. void setCenterAndHalfExtents(Vector3 center, Vector3 halfExtents) { @@ -185,19 +189,19 @@ class Aabb3 { ..copyAt(_max, limitMax); if (_max.x < _min.x) { - final temp = _max.x; + final double temp = _max.x; _max.x = _min.x; _min.x = temp; } if (_max.y < _min.y) { - final temp = _max.y; + final double temp = _max.y; _max.y = _min.y; _min.y = temp; } if (_max.z < _min.z) { - final temp = _max.z; + final double temp = _max.z; _max.z = _min.z; _min.z = temp; } @@ -262,15 +266,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) { @@ -313,8 +319,8 @@ class Aabb3 { /// Return if this contains [other]. bool containsAabb3(Aabb3 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector3 otherMax = other._max; + final Vector3 otherMin = other._min; return (_min.x < otherMin.x) && (_min.y < otherMin.y) && @@ -349,8 +355,8 @@ class Aabb3 { /// Return if this intersects with [other]. bool intersectsWithAabb3(Aabb3 other) { - final otherMax = other._max; - final otherMin = other._min; + final Vector3 otherMax = other._max; + final Vector3 otherMin = other._min; return (_min.x <= otherMax.x) && (_min.y <= otherMax.y) && @@ -362,8 +368,8 @@ class Aabb3 { /// Return if this intersects with [other]. bool intersectsWithSphere(Sphere other) { - final center = other._center; - final radius = other.radius; + final Vector3 center = other._center; + final double radius = other.radius; var d = 0.0; var e = 0.0; @@ -666,15 +672,15 @@ class Aabb3 { copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents); // Compute the projection interval radius of b onto L(t) = b.c + t * p.n - final r = + final double 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 - final s = other.normal.dot(_aabbCenter) - other.constant; + final double s = other.normal.dot(_aabbCenter) - other.constant; // Intersection occurs when distance s falls within [-r,+r] interval if (s.abs() <= r) { - final a = s - r; + final double a = s - r; if (result != null && (result._depth == null || (result._depth!) < a)) { result._depth = a; result.axis.setFrom(other.normal); diff --git a/packages/vector_math/lib/src/vector_math_64/colors.dart b/packages/vector_math/lib/src/vector_math_64/colors.dart index 2231324..c5c07d7 100644 --- a/packages/vector_math/lib/src/vector_math_64/colors.dart +++ b/packages/vector_math/lib/src/vector_math_64/colors.dart @@ -8,6 +8,7 @@ part of '../../vector_math_64.dart'; /// manipulating colors. In addition to that, some known colors can be accessed /// for fast prototyping. class Colors { + Colors._(); static final _hexStringFullRegex = RegExp( r'\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})(?:([0-9a-f]{2}))?', caseSensitive: false, @@ -28,42 +29,42 @@ class Colors { /// corresponding color value and store it in [result]. The first group is /// treated as the alpha channel if a [value] with four groups is passed. static void fromHexString(String value, Vector4 result) { - final fullMatch = _hexStringFullRegex.matchAsPrefix(value); + final Match? fullMatch = _hexStringFullRegex.matchAsPrefix(value); if (fullMatch != null) { if (fullMatch[4] == null) { - final r = int.parse(fullMatch[1]!, radix: 16); - final g = int.parse(fullMatch[2]!, radix: 16); - final b = int.parse(fullMatch[3]!, radix: 16); + final int r = int.parse(fullMatch[1]!, radix: 16); + final int g = int.parse(fullMatch[2]!, radix: 16); + final int b = int.parse(fullMatch[3]!, radix: 16); fromRgba(r, g, b, 255, result); return; } else { - final a = int.parse(fullMatch[1]!, radix: 16); - final r = int.parse(fullMatch[2]!, radix: 16); - final g = int.parse(fullMatch[3]!, radix: 16); - final b = int.parse(fullMatch[4]!, radix: 16); + final int a = int.parse(fullMatch[1]!, radix: 16); + final int r = int.parse(fullMatch[2]!, radix: 16); + final int g = int.parse(fullMatch[3]!, radix: 16); + final int b = int.parse(fullMatch[4]!, radix: 16); fromRgba(r, g, b, a, result); return; } } - final smallMatch = _hexStringSmallRegex.matchAsPrefix(value); + final Match? smallMatch = _hexStringSmallRegex.matchAsPrefix(value); if (smallMatch != null) { if (smallMatch[4] == null) { - final r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); - final g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); - final b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); + final int r = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); + final int g = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); + final int b = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); fromRgba(r, g, b, 255, result); return; } else { - final a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); - final r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); - final g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); - final b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16); + final int a = int.parse(smallMatch[1]! + smallMatch[1]!, radix: 16); + final int r = int.parse(smallMatch[2]! + smallMatch[2]!, radix: 16); + final int g = int.parse(smallMatch[3]! + smallMatch[3]!, radix: 16); + final int b = int.parse(smallMatch[4]! + smallMatch[4]!, radix: 16); fromRgba(r, g, b, a, result); return; @@ -82,12 +83,12 @@ class Colors { bool alpha = false, bool short = false, }) { - final r = (input.r * 0xFF).floor() & 0xFF; - final g = (input.g * 0xFF).floor() & 0xFF; - final b = (input.b * 0xFF).floor() & 0xFF; - final a = (input.a * 0xFF).floor() & 0xFF; + final int r = (input.r * 0xFF).floor() & 0xFF; + final int g = (input.g * 0xFF).floor() & 0xFF; + final int b = (input.b * 0xFF).floor() & 0xFF; + final int a = (input.a * 0xFF).floor() & 0xFF; - final isShort = + final bool isShort = short && ((r >> 4) == (r & 0xF)) && ((g >> 4) == (g & 0xF)) && @@ -95,14 +96,14 @@ class Colors { (!alpha || (a >> 4) == (a & 0xF)); if (isShort) { - final rgb = + final String rgb = (r & 0xF).toRadixString(16) + (g & 0xF).toRadixString(16) + (b & 0xF).toRadixString(16); return alpha ? (a & 0xF).toRadixString(16) + rgb : rgb; } else { - final rgb = + final String rgb = r.toRadixString(16).padLeft(2, '0') + g.toRadixString(16).padLeft(2, '0') + b.toRadixString(16).padLeft(2, '0'); @@ -118,18 +119,18 @@ class Colors { Vector4 background, Vector4 result, ) { - final a = foreground.a + (1.0 - foreground.a) * background.a; - final factor = 1.0 / a; + final double a = foreground.a + (1.0 - foreground.a) * background.a; + final double factor = 1.0 / a; - final r = + final double r = factor * (foreground.a * foreground.r + (1.0 - foreground.a) * background.a * background.r); - final g = + final double g = factor * (foreground.a * foreground.g + (1.0 - foreground.a) * background.a * background.g); - final b = + final double b = factor * (foreground.a * foreground.b + (1.0 - foreground.a) * background.a * background.b); @@ -139,7 +140,7 @@ class Colors { /// Convert a [input] color to a gray scaled color and store it in [result]. static void toGrayscale(Vector4 input, Vector4 result) { - final value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b; + final double value = 0.21 * input.r + 0.71 * input.g + 0.07 * input.b; result ..r = value @@ -156,7 +157,7 @@ class Colors { Vector4 gammaColor, [ double gamma = 2.2, ]) { - final exponent = 1.0 / gamma; + final double exponent = 1.0 / gamma; gammaColor ..r = math.pow(linearColor.r, exponent).toDouble() @@ -183,11 +184,11 @@ class Colors { /// Convert [rgbColor] from rgb color model to the hue, saturation, and value /// (HSV) color model and store it in [hsvColor]. static void rgbToHsv(Vector4 rgbColor, Vector4 hsvColor) { - final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); - final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); - final d = max - min; + final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); + final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); + final double d = max - min; final v = max; - final s = max == 0.0 ? 0.0 : d / max; + final double s = max == 0.0 ? 0.0 : d / max; var h = 0.0; if (max != min) { @@ -210,45 +211,39 @@ class Colors { /// Convert [hsvColor] from hue, saturation, and value (HSV) color model to /// the RGB color model and store it in [rgbColor]. static void hsvToRgb(Vector4 hsvColor, Vector4 rgbColor) { - final i = (hsvColor.x * 6.0).floor(); - final f = hsvColor.x * 6.0 - i.toDouble(); - final p = hsvColor.z * (1.0 - hsvColor.y); - final q = hsvColor.z * (1.0 - f * hsvColor.y); - final t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y); + final int i = (hsvColor.x * 6.0).floor(); + final double f = hsvColor.x * 6.0 - i.toDouble(); + final double p = hsvColor.z * (1.0 - hsvColor.y); + final double q = hsvColor.z * (1.0 - f * hsvColor.y); + final double t = hsvColor.z * (1.0 - (1.0 - f) * hsvColor.y); switch (i % 6) { case 0: rgbColor.setValues(hsvColor.z, t, p, hsvColor.a); - break; case 1: rgbColor.setValues(q, hsvColor.z, p, hsvColor.a); - break; case 2: rgbColor.setValues(p, hsvColor.z, t, hsvColor.a); - break; case 3: rgbColor.setValues(p, q, hsvColor.z, hsvColor.a); - break; case 4: rgbColor.setValues(t, p, hsvColor.z, hsvColor.a); - break; case 5: rgbColor.setValues(hsvColor.z, p, q, hsvColor.a); - break; } } /// Convert [rgbColor] from rgb color model to the hue, saturation, and /// lightness (HSL) color model and store it in [hslColor]. static void rgbToHsl(Vector4 rgbColor, Vector4 hslColor) { - final max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); - final min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); - final l = (max + min) / 2.0; + final double max = math.max(math.max(rgbColor.r, rgbColor.g), rgbColor.b); + final double min = math.min(math.min(rgbColor.r, rgbColor.g), rgbColor.b); + final double l = (max + min) / 2.0; var h = 0.0; var s = 0.0; if (max != min) { - final d = max - min; + final double d = max - min; s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min); @@ -274,14 +269,15 @@ class Colors { if (hslColor.y == 0.0) { rgbColor.setValues(hslColor.z, hslColor.z, hslColor.z, hslColor.a); } else { - final q = hslColor.z < 0.5 - ? hslColor.z * (1.0 + hslColor.y) - : hslColor.z + hslColor.y - hslColor.z * hslColor.y; - final p = 2.0 * hslColor.z - q; + 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 r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0); - final g = _hueToRgb(p, q, hslColor.x); - final b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0); + final double r = _hueToRgb(p, q, hslColor.x + 1.0 / 3.0); + final double g = _hueToRgb(p, q, hslColor.x); + final double b = _hueToRgb(p, q, hslColor.x - 1.0 / 3.0); rgbColor.setValues(r, g, b, hslColor.a); } @@ -305,288 +301,567 @@ class Colors { } } + /// RGBA values for the named CSS color 'transparent'. static Vector4 get transparent => Vector4(255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0); + + /// RGBA values for the named CSS color 'aliceblue'. static Vector4 get aliceBlue => Vector4(240.0 / 255.0, 248.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'antiquewhite'. static Vector4 get antiqueWhite => Vector4(250.0 / 255.0, 235.0 / 255.0, 215.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'aqua'. static Vector4 get aqua => Vector4(0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'aquamarine'. static Vector4 get aquamarine => Vector4(127.0 / 255.0, 255.0 / 255.0, 212.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'azure'. static Vector4 get azure => Vector4(240.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'beige'. static Vector4 get beige => Vector4(245.0 / 255.0, 245.0 / 255.0, 220.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'bisque'. static Vector4 get bisque => Vector4(255.0 / 255.0, 228.0 / 255.0, 196.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'black'. static Vector4 get black => Vector4(0.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'blanchedalmond'. static Vector4 get blanchedAlmond => Vector4(255.0 / 255.0, 235.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'blue'. static Vector4 get blue => Vector4(0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'blueviolet'. static Vector4 get blueViolet => Vector4(138.0 / 255.0, 43.0 / 255.0, 226.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'brown'. static Vector4 get brown => Vector4(165.0 / 255.0, 42.0 / 255.0, 42.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'burlywood'. static Vector4 get burlyWood => Vector4(222.0 / 255.0, 184.0 / 255.0, 135.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cadetblue'. static Vector4 get cadetBlue => Vector4(95.0 / 255.0, 158.0 / 255.0, 160.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'chartreuse'. static Vector4 get chartreuse => Vector4(127.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'chocolate'. static Vector4 get chocolate => Vector4(210.0 / 255.0, 105.0 / 255.0, 30.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'coral'. static Vector4 get coral => Vector4(255.0 / 255.0, 127.0 / 255.0, 80.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cornflowerblue'. static Vector4 get cornflowerBlue => Vector4(100.0 / 255.0, 149.0 / 255.0, 237.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cornsilk'. static Vector4 get cornsilk => Vector4(255.0 / 255.0, 248.0 / 255.0, 220.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'crimson'. static Vector4 get crimson => Vector4(220.0 / 255.0, 20.0 / 255.0, 60.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'cyan'. static Vector4 get cyan => Vector4(0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkblue'. static Vector4 get darkBlue => Vector4(0.0 / 255.0, 0.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkcyan'. static Vector4 get darkCyan => Vector4(0.0 / 255.0, 139.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkgoldenrod'. static Vector4 get darkGoldenrod => Vector4(184.0 / 255.0, 134.0 / 255.0, 11.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkgray'. static Vector4 get darkGray => Vector4(169.0 / 255.0, 169.0 / 255.0, 169.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkgreen'. static Vector4 get darkGreen => Vector4(0.0 / 255.0, 100.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkkhaki'. static Vector4 get darkKhaki => Vector4(189.0 / 255.0, 183.0 / 255.0, 107.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkmagenta'. static Vector4 get darkMagenta => Vector4(139.0 / 255.0, 0.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkolivegreen'. static Vector4 get darkOliveGreen => Vector4(85.0 / 255.0, 107.0 / 255.0, 47.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkorange'. static Vector4 get darkOrange => Vector4(255.0 / 255.0, 140.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkorchid'. static Vector4 get darkOrchid => Vector4(153.0 / 255.0, 50.0 / 255.0, 204.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkred'. static Vector4 get darkRed => Vector4(139.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darksalmon'. static Vector4 get darkSalmon => Vector4(233.0 / 255.0, 150.0 / 255.0, 122.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkseagreen'. static Vector4 get darkSeaGreen => Vector4(143.0 / 255.0, 188.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkslateblue'. static Vector4 get darkSlateBlue => Vector4(72.0 / 255.0, 61.0 / 255.0, 139.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkslategray'. static Vector4 get darkSlateGray => Vector4(47.0 / 255.0, 79.0 / 255.0, 79.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkturquoise'. static Vector4 get darkTurquoise => Vector4(0.0 / 255.0, 206.0 / 255.0, 209.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'darkviolet'. static Vector4 get darkViolet => Vector4(148.0 / 255.0, 0.0 / 255.0, 211.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'deeppink'. static Vector4 get deepPink => Vector4(255.0 / 255.0, 20.0 / 255.0, 147.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'deepskyblue'. static Vector4 get deepSkyBlue => Vector4(0.0 / 255.0, 191.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'dimgray'. static Vector4 get dimGray => Vector4(105.0 / 255.0, 105.0 / 255.0, 105.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'dodgerblue'. static Vector4 get dodgerBlue => Vector4(30.0 / 255.0, 144.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'firebrick'. static Vector4 get firebrick => Vector4(178.0 / 255.0, 34.0 / 255.0, 34.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'floralwhite'. static Vector4 get floralWhite => Vector4(255.0 / 255.0, 250.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'forestgreen'. static Vector4 get forestGreen => Vector4(34.0 / 255.0, 139.0 / 255.0, 34.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'fuchsia'. static Vector4 get fuchsia => Vector4(255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'gainsboro'. static Vector4 get gainsboro => Vector4(220.0 / 255.0, 220.0 / 255.0, 220.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'ghostwhite'. static Vector4 get ghostWhite => Vector4(248.0 / 255.0, 248.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'gold'. static Vector4 get gold => Vector4(255.0 / 255.0, 215.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'goldenrod'. static Vector4 get goldenrod => Vector4(218.0 / 255.0, 165.0 / 255.0, 32.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'gray'. static Vector4 get gray => Vector4(128.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'green'. static Vector4 get green => Vector4(0.0 / 255.0, 128.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'greenyellow'. static Vector4 get greenYellow => Vector4(173.0 / 255.0, 255.0 / 255.0, 47.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'honeydew'. static Vector4 get honeydew => Vector4(240.0 / 255.0, 255.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'hotpink'. static Vector4 get hotPink => Vector4(255.0 / 255.0, 105.0 / 255.0, 180.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'indianred'. static Vector4 get indianRed => Vector4(205.0 / 255.0, 92.0 / 255.0, 92.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'indigo'. static Vector4 get indigo => Vector4(75.0 / 255.0, 0.0 / 255.0, 130.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'ivory'. static Vector4 get ivory => Vector4(255.0 / 255.0, 255.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'khaki'. static Vector4 get khaki => Vector4(240.0 / 255.0, 230.0 / 255.0, 140.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lavender'. static Vector4 get lavender => Vector4(230.0 / 255.0, 230.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lavenderblush'. static Vector4 get lavenderBlush => Vector4(255.0 / 255.0, 240.0 / 255.0, 245.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lawngreen'. static Vector4 get lawnGreen => Vector4(124.0 / 255.0, 252.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lemonchiffon'. static Vector4 get lemonChiffon => Vector4(255.0 / 255.0, 250.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightblue'. static Vector4 get lightBlue => Vector4(173.0 / 255.0, 216.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightcoral'. static Vector4 get lightCoral => Vector4(240.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightcyan'. static Vector4 get lightCyan => Vector4(224.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightgoldenrodyellow'. static Vector4 get lightGoldenrodYellow => Vector4(250.0 / 255.0, 250.0 / 255.0, 210.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightgreen'. static Vector4 get lightGreen => Vector4(144.0 / 255.0, 238.0 / 255.0, 144.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightgray'. static Vector4 get lightGray => Vector4(211.0 / 255.0, 211.0 / 255.0, 211.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightpink'. static Vector4 get lightPink => Vector4(255.0 / 255.0, 182.0 / 255.0, 193.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightsalmon'. static Vector4 get lightSalmon => Vector4(255.0 / 255.0, 160.0 / 255.0, 122.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightseagreen'. static Vector4 get lightSeaGreen => Vector4(32.0 / 255.0, 178.0 / 255.0, 170.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightskyblue'. static Vector4 get lightSkyBlue => Vector4(135.0 / 255.0, 206.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightslategray'. static Vector4 get lightSlateGray => Vector4(119.0 / 255.0, 136.0 / 255.0, 153.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightsteelblue'. static Vector4 get lightSteelBlue => Vector4(176.0 / 255.0, 196.0 / 255.0, 222.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lightyellow'. static Vector4 get lightYellow => Vector4(255.0 / 255.0, 255.0 / 255.0, 224.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'lime'. static Vector4 get lime => Vector4(0.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'limegreen'. static Vector4 get limeGreen => Vector4(50.0 / 255.0, 205.0 / 255.0, 50.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'linen'. static Vector4 get linen => Vector4(250.0 / 255.0, 240.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'magenta'. static Vector4 get magenta => Vector4(255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'maroon'. static Vector4 get maroon => Vector4(128.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumaquamarine'. static Vector4 get mediumAquamarine => Vector4(102.0 / 255.0, 205.0 / 255.0, 170.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumblue'. static Vector4 get mediumBlue => Vector4(0.0 / 255.0, 0.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumorchid'. static Vector4 get mediumOrchid => Vector4(186.0 / 255.0, 85.0 / 255.0, 211.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumpurple'. static Vector4 get mediumPurple => Vector4(147.0 / 255.0, 112.0 / 255.0, 219.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumseagreen'. static Vector4 get mediumSeaGreen => Vector4(60.0 / 255.0, 179.0 / 255.0, 113.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumslateblue'. static Vector4 get mediumSlateBlue => Vector4(123.0 / 255.0, 104.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumspringgreen'. static Vector4 get mediumSpringGreen => Vector4(0.0 / 255.0, 250.0 / 255.0, 154.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumturquoise'. static Vector4 get mediumTurquoise => Vector4(72.0 / 255.0, 209.0 / 255.0, 204.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mediumvioletred'. static Vector4 get mediumVioletRed => Vector4(199.0 / 255.0, 21.0 / 255.0, 133.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'midnightblue'. static Vector4 get midnightBlue => Vector4(25.0 / 255.0, 25.0 / 255.0, 112.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mintcream'. static Vector4 get mintCream => Vector4(245.0 / 255.0, 255.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'mistyrose'. static Vector4 get mistyRose => Vector4(255.0 / 255.0, 228.0 / 255.0, 225.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'moccasin'. static Vector4 get moccasin => Vector4(255.0 / 255.0, 228.0 / 255.0, 181.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'navajowhite'. static Vector4 get navajoWhite => Vector4(255.0 / 255.0, 222.0 / 255.0, 173.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'navy'. static Vector4 get navy => Vector4(0.0 / 255.0, 0.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'oldlace'. static Vector4 get oldLace => Vector4(253.0 / 255.0, 245.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'olive'. static Vector4 get olive => Vector4(128.0 / 255.0, 128.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'olivedrab'. static Vector4 get oliveDrab => Vector4(107.0 / 255.0, 142.0 / 255.0, 35.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'orange'. static Vector4 get orange => Vector4(255.0 / 255.0, 165.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'orangered'. static Vector4 get orangeRed => Vector4(255.0 / 255.0, 69.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'orchid'. static Vector4 get orchid => Vector4(218.0 / 255.0, 112.0 / 255.0, 214.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'palegoldenrod'. static Vector4 get paleGoldenrod => Vector4(238.0 / 255.0, 232.0 / 255.0, 170.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'palegreen'. static Vector4 get paleGreen => Vector4(152.0 / 255.0, 251.0 / 255.0, 152.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'paleturquoise'. static Vector4 get paleTurquoise => Vector4(175.0 / 255.0, 238.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'palevioletred'. static Vector4 get paleVioletRed => Vector4(219.0 / 255.0, 112.0 / 255.0, 147.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'papayawhip'. static Vector4 get papayaWhip => Vector4(255.0 / 255.0, 239.0 / 255.0, 213.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'peachpuff'. static Vector4 get peachPuff => Vector4(255.0 / 255.0, 218.0 / 255.0, 185.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'peru'. static Vector4 get peru => Vector4(205.0 / 255.0, 133.0 / 255.0, 63.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'pink'. static Vector4 get pink => Vector4(255.0 / 255.0, 192.0 / 255.0, 203.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'plum'. static Vector4 get plum => Vector4(221.0 / 255.0, 160.0 / 255.0, 221.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'powderblue'. static Vector4 get powderBlue => Vector4(176.0 / 255.0, 224.0 / 255.0, 230.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'purple'. static Vector4 get purple => Vector4(128.0 / 255.0, 0.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'red'. static Vector4 get red => Vector4(255.0 / 255.0, 0.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'rosybrown'. static Vector4 get rosyBrown => Vector4(188.0 / 255.0, 143.0 / 255.0, 143.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'royalblue'. static Vector4 get royalBlue => Vector4(65.0 / 255.0, 105.0 / 255.0, 225.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'saddlebrown'. static Vector4 get saddleBrown => Vector4(139.0 / 255.0, 69.0 / 255.0, 19.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'salmon'. static Vector4 get salmon => Vector4(250.0 / 255.0, 128.0 / 255.0, 114.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'sandybrown'. static Vector4 get sandyBrown => Vector4(244.0 / 255.0, 164.0 / 255.0, 96.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'seagreen'. static Vector4 get seaGreen => Vector4(46.0 / 255.0, 139.0 / 255.0, 87.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'seashell'. static Vector4 get seaShell => Vector4(255.0 / 255.0, 245.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'sienna'. static Vector4 get sienna => Vector4(160.0 / 255.0, 82.0 / 255.0, 45.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'silver'. static Vector4 get silver => Vector4(192.0 / 255.0, 192.0 / 255.0, 192.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'skyblue'. static Vector4 get skyBlue => Vector4(135.0 / 255.0, 206.0 / 255.0, 235.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'slateblue'. static Vector4 get slateBlue => Vector4(106.0 / 255.0, 90.0 / 255.0, 205.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'slategray'. static Vector4 get slateGray => Vector4(112.0 / 255.0, 128.0 / 255.0, 144.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'snow'. static Vector4 get snow => Vector4(255.0 / 255.0, 250.0 / 255.0, 250.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'springgreen'. static Vector4 get springGreen => Vector4(0.0 / 255.0, 255.0 / 255.0, 127.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'steelblue'. static Vector4 get steelBlue => Vector4(70.0 / 255.0, 130.0 / 255.0, 180.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'tan'. static Vector4 get tan => Vector4(210.0 / 255.0, 180.0 / 255.0, 140.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'teal'. static Vector4 get teal => Vector4(0.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'thistle'. static Vector4 get thistle => Vector4(216.0 / 255.0, 191.0 / 255.0, 216.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'tomato'. static Vector4 get tomato => Vector4(255.0 / 255.0, 99.0 / 255.0, 71.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'turquoise'. static Vector4 get turquoise => Vector4(64.0 / 255.0, 224.0 / 255.0, 208.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'violet'. static Vector4 get violet => Vector4(238.0 / 255.0, 130.0 / 255.0, 238.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'wheat'. static Vector4 get wheat => Vector4(245.0 / 255.0, 222.0 / 255.0, 179.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'white'. static Vector4 get white => Vector4(255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'whitesmoke'. static Vector4 get whiteSmoke => Vector4(245.0 / 255.0, 245.0 / 255.0, 245.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'yellow'. static Vector4 get yellow => Vector4(255.0 / 255.0, 255.0 / 255.0, 0.0 / 255.0, 255.0 / 255.0); + + /// RGBA values for the named CSS color 'yellowgreen'. static Vector4 get yellowGreen => Vector4(154.0 / 255.0, 205.0 / 255.0, 50.0 / 255.0, 255.0 / 255.0); - - Colors._(); } diff --git a/packages/vector_math/lib/src/vector_math_64/error_helpers.dart b/packages/vector_math/lib/src/vector_math_64/error_helpers.dart index cdda7f6..f2f6bc2 100644 --- a/packages/vector_math/lib/src/vector_math_64/error_helpers.dart +++ b/packages/vector_math/lib/src/vector_math_64/error_helpers.dart @@ -9,7 +9,7 @@ part of '../../vector_math_64.dart'; /// be any vector, matrix, or quaternion. double relativeError(dynamic calculated, dynamic correct) { if (calculated is num && correct is num) { - final diff = (calculated - correct).abs().toDouble(); + final double diff = (calculated - correct).abs().toDouble(); return diff / correct; } // avoiding an `as double` cast here to maximize speed on dart2js @@ -22,7 +22,7 @@ double relativeError(dynamic calculated, dynamic correct) { /// be any vector, matrix, or quaternion. double absoluteError(dynamic calculated, dynamic correct) { if (calculated is num && correct is num) { - final diff = (calculated - correct).abs().toDouble(); + final double diff = (calculated - correct).abs().toDouble(); return diff; } // avoiding an `as double` cast here to maximize speed on dart2js diff --git a/packages/vector_math/lib/src/vector_math_64/frustum.dart b/packages/vector_math/lib/src/vector_math_64/frustum.dart index 7d9466c..0e35e01 100644 --- a/packages/vector_math/lib/src/vector_math_64/frustum.dart +++ b/packages/vector_math/lib/src/vector_math_64/frustum.dart @@ -6,6 +6,20 @@ part of '../../vector_math_64.dart'; /// Defines a frustum constructed out of six [Plane]s. class Frustum { + /// Create a new frustum without initializing its bounds. + Frustum() + : _plane0 = Plane(), + _plane1 = Plane(), + _plane2 = Plane(), + _plane3 = Plane(), + _plane4 = Plane(), + _plane5 = Plane(); + + /// Create a new frustum as a copy of [other]. + factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other); + + /// Create a new furstum from a [matrix]. + factory Frustum.matrix(Matrix4 matrix) => Frustum()..setFromMatrix(matrix); final Plane _plane0; final Plane _plane1; final Plane _plane2; @@ -31,21 +45,6 @@ class Frustum { /// The sixed plane that defines the bounds of this frustum. Plane get plane5 => _plane5; - /// Create a new frustum without initializing its bounds. - Frustum() - : _plane0 = Plane(), - _plane1 = Plane(), - _plane2 = Plane(), - _plane3 = Plane(), - _plane4 = Plane(), - _plane5 = Plane(); - - /// Create a new frustum as a copy of [other]. - factory Frustum.copy(Frustum other) => Frustum()..copyFrom(other); - - /// Create a new furstum from a [matrix]. - factory Frustum.matrix(Matrix4 matrix) => Frustum()..setFromMatrix(matrix); - /// Copy the [other] frustum into this. void copyFrom(Frustum other) { _plane0.copyFrom(other._plane0); @@ -58,11 +57,11 @@ class Frustum { /// Set this from [matrix]. void setFromMatrix(Matrix4 matrix) { - final me = matrix.storage; - final me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; - final me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; - final me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; - final me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; + final Float64List me = matrix.storage; + final double me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; + final double me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; + final double me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; + final double me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; _plane0 ..setFromComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12) @@ -144,8 +143,8 @@ class Frustum { /// Check if this intersects with [sphere]. bool intersectsWithSphere(Sphere sphere) { - final negativeRadius = -sphere.radius; - final center = sphere.center; + final double negativeRadius = -sphere.radius; + final Vector3 center = sphere.center; if (_plane0.distanceToVector3(center) < negativeRadius) { return false; @@ -223,12 +222,12 @@ class Frustum { outNz = aabb.min.z; } - final d1 = + final double d1 = plane._normal.x * outPx + plane._normal.y * outPy + plane._normal.z * outPz + plane.constant; - final d2 = + final double d2 = plane._normal.x * outNx + plane._normal.y * outNy + plane._normal.z * outNz + diff --git a/packages/vector_math/lib/src/vector_math_64/intersection_result.dart b/packages/vector_math/lib/src/vector_math_64/intersection_result.dart index ffe4e6e..b07d50c 100644 --- a/packages/vector_math/lib/src/vector_math_64/intersection_result.dart +++ b/packages/vector_math/lib/src/vector_math_64/intersection_result.dart @@ -5,6 +5,8 @@ part of '../../vector_math_64.dart'; /// Defines a result of an intersection test. class IntersectionResult { + /// Creates a new mutable result instance, with no initial values. + IntersectionResult(); double? _depth; /// The penetration depth of the intersection. @@ -12,6 +14,4 @@ class IntersectionResult { /// The [axis] of the intersection. final axis = Vector3.zero(); - - IntersectionResult(); } diff --git a/packages/vector_math/lib/src/vector_math_64/matrix2.dart b/packages/vector_math/lib/src/vector_math_64/matrix2.dart index 4e7e06d..9302491 100644 --- a/packages/vector_math/lib/src/vector_math_64/matrix2.dart +++ b/packages/vector_math/lib/src/vector_math_64/matrix2.dart @@ -7,6 +7,36 @@ part of '../../vector_math_64.dart'; /// 2D Matrix. /// Values are stored in column major order. class Matrix2 { + /// New matrix with specified values. + factory Matrix2(double arg0, double arg1, double arg2, double arg3) => + Matrix2.zero()..setValues(arg0, arg1, arg2, arg3); + + /// New matrix from [values]. + factory Matrix2.fromList(List values) => + Matrix2.zero()..setValues(values[0], values[1], values[2], values[3]); + + /// Zero matrix. + Matrix2.zero() : _m2storage = Float64List(4); + + /// Identity matrix. + 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); + + /// Matrix with values from column arguments. + factory Matrix2.columns(Vector2 arg0, Vector2 arg1) => + Matrix2.zero()..setColumns(arg0, arg1); + + /// Outer product of [u] and [v]. + factory Matrix2.outer(Vector2 u, Vector2 v) => Matrix2.zero()..setOuter(u, v); + + /// Rotation of [radians]. + factory Matrix2.rotation(double radians) => + Matrix2.zero()..setRotation(radians); final Float64List _m2storage; /// The components of the matrix. @@ -14,13 +44,13 @@ class Matrix2 { /// Solve [A] * [x] = [b]. static void solve(Matrix2 A, Vector2 x, Vector2 b) { - final a11 = A.entry(0, 0); - final a12 = A.entry(0, 1); - final a21 = A.entry(1, 0); - final a22 = A.entry(1, 1); - final bx = b.x; - final by = b.y; - var det = a11 * a22 - a12 * a21; + final double a11 = A.entry(0, 0); + final double a12 = A.entry(0, 1); + final double a21 = A.entry(1, 0); + final double a22 = A.entry(1, 1); + final double bx = b.x; + final double by = b.y; + double det = a11 * a22 - a12 * a21; if (det != 0.0) { det = 1.0 / det; @@ -50,36 +80,6 @@ class Matrix2 { _m2storage[index(row, col)] = v; } - /// New matrix with specified values. - factory Matrix2(double arg0, double arg1, double arg2, double arg3) => - Matrix2.zero()..setValues(arg0, arg1, arg2, arg3); - - /// New matrix from [values]. - factory Matrix2.fromList(List values) => - Matrix2.zero()..setValues(values[0], values[1], values[2], values[3]); - - /// Zero matrix. - Matrix2.zero() : _m2storage = Float64List(4); - - /// Identity matrix. - 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); - - /// Matrix with values from column arguments. - factory Matrix2.columns(Vector2 arg0, Vector2 arg1) => - Matrix2.zero()..setColumns(arg0, arg1); - - /// Outer product of [u] and [v]. - factory Matrix2.outer(Vector2 u, Vector2 v) => Matrix2.zero()..setOuter(u, v); - - /// Rotation of [radians]. - factory Matrix2.rotation(double radians) => - Matrix2.zero()..setRotation(radians); - /// Sets the matrix with specified values. void setValues(double arg0, double arg1, double arg2, double arg3) { _m2storage[3] = arg3; @@ -90,8 +90,8 @@ class Matrix2 { /// Sets the entire matrix to the column values. void setColumns(Vector2 arg0, Vector2 arg1) { - final arg0Storage = arg0._v2storage; - final arg1Storage = arg1._v2storage; + final Float64List arg0Storage = arg0._v2storage; + final Float64List arg1Storage = arg1._v2storage; _m2storage[0] = arg0Storage[0]; _m2storage[1] = arg0Storage[1]; _m2storage[2] = arg1Storage[0]; @@ -100,7 +100,7 @@ class Matrix2 { /// Sets the entire matrix to the matrix in [arg]. void setFrom(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float64List argStorage = arg._m2storage; _m2storage[3] = argStorage[3]; _m2storage[2] = argStorage[2]; _m2storage[1] = argStorage[1]; @@ -109,8 +109,8 @@ class Matrix2 { /// Set this to the outer product of [u] and [v]. void setOuter(Vector2 u, Vector2 v) { - final uStorage = u._v2storage; - final vStorage = v._v2storage; + final Float64List uStorage = u._v2storage; + final Float64List vStorage = v._v2storage; _m2storage[0] = uStorage[0] * vStorage[0]; _m2storage[1] = uStorage[0] * vStorage[1]; _m2storage[2] = uStorage[1] * vStorage[0]; @@ -125,7 +125,7 @@ class Matrix2 { /// Sets the diagonal of the matrix to be [arg]. void setDiagonal(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _m2storage[0] = argStorage[0]; _m2storage[3] = argStorage[1]; } @@ -147,6 +147,7 @@ class Matrix2 { /// Check if two matrices are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Matrix2) && (_m2storage[0] == other._m2storage[0]) && @@ -155,6 +156,7 @@ class Matrix2 { (_m2storage[3] == other._m2storage[3]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_m2storage); /// Returns row 0 @@ -171,7 +173,7 @@ class Matrix2 { /// Sets [row] of the matrix to values in [arg] void setRow(int row, Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _m2storage[index(row, 0)] = argStorage[0]; _m2storage[index(row, 1)] = argStorage[1]; } @@ -179,7 +181,7 @@ class Matrix2 { /// Gets the [row] of the matrix Vector2 getRow(int row) { final r = Vector2.zero(); - final rStorage = r._v2storage; + final Float64List rStorage = r._v2storage; rStorage[0] = _m2storage[index(row, 0)]; rStorage[1] = _m2storage[index(row, 1)]; return r; @@ -187,8 +189,8 @@ class Matrix2 { /// Assigns the [column] of the matrix [arg] void setColumn(int column, Vector2 arg) { - final argStorage = arg._v2storage; - final entry = column * 2; + final Float64List argStorage = arg._v2storage; + final int entry = column * 2; _m2storage[entry + 1] = argStorage[1]; _m2storage[entry + 0] = argStorage[0]; } @@ -196,8 +198,8 @@ class Matrix2 { /// Gets the [column] of the matrix Vector2 getColumn(int column) { final r = Vector2.zero(); - final entry = column * 2; - final rStorage = r._v2storage; + final int entry = column * 2; + final Float64List rStorage = r._v2storage; rStorage[1] = _m2storage[entry + 1]; rStorage[0] = _m2storage[entry + 0]; return r; @@ -208,7 +210,7 @@ class Matrix2 { /// Copy this into [arg]. Matrix2 copyInto(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float64List argStorage = arg._m2storage; argStorage[0] = _m2storage[0]; argStorage[1] = _m2storage[1]; argStorage[2] = _m2storage[2]; @@ -262,8 +264,9 @@ class Matrix2 { /// Returns the tranpose of this. Matrix2 transposed() => clone()..transpose(); + /// Transposes this matrix in place. void transpose() { - final temp = _m2storage[2]; + final double temp = _m2storage[2]; _m2storage[2] = _m2storage[1]; _m2storage[1] = temp; } @@ -271,7 +274,7 @@ class Matrix2 { /// Returns the component wise absolute value of this. Matrix2 absolute() { final r = Matrix2.zero(); - final rStorage = r._m2storage; + final Float64List rStorage = r._m2storage; rStorage[0] = _m2storage[0].abs(); rStorage[1] = _m2storage[1].abs(); rStorage[2] = _m2storage[2].abs(); @@ -285,13 +288,13 @@ class Matrix2 { /// Returns the dot product of row [i] and [v]. double dotRow(int i, Vector2 v) { - final vStorage = v._v2storage; + final Float64List vStorage = v._v2storage; return _m2storage[i] * vStorage[0] + _m2storage[2 + i] * vStorage[1]; } /// Returns the dot product of column [j] and [v]. double dotColumn(int j, Vector2 v) { - final vStorage = v._v2storage; + final Float64List vStorage = v._v2storage; return _m2storage[j * 2] * vStorage[0] + _m2storage[(j * 2) + 1] * vStorage[1]; } @@ -324,28 +327,28 @@ class Matrix2 { /// Returns relative error between this and [correct] double relativeError(Matrix2 correct) { - final diff = correct - this; - final correctNorm = correct.infinityNorm(); - final diff_norm = diff.infinityNorm(); - return diff_norm / correctNorm; + final Matrix2 diff = correct - this; + final double correctNorm = correct.infinityNorm(); + final double diffNorm = diff.infinityNorm(); + return diffNorm / correctNorm; } /// Returns absolute error between this and [correct] double absoluteError(Matrix2 correct) { - final this_norm = infinityNorm(); - final correct_norm = correct.infinityNorm(); - final diff_norm = (this_norm - correct_norm).abs(); - return diff_norm; + final double thisNorm = infinityNorm(); + final double correctNorm = correct.infinityNorm(); + final double diffNorm = (thisNorm - correctNorm).abs(); + return diffNorm; } /// Invert the matrix. Returns the determinant. double invert() { - final det = determinant(); + final double det = determinant(); if (det == 0.0) { return 0.0; } - final invDet = 1.0 / det; - final temp = _m2storage[0]; + final double invDet = 1.0 / det; + final double temp = _m2storage[0]; _m2storage[0] = _m2storage[3] * invDet; _m2storage[1] = -_m2storage[1] * invDet; _m2storage[2] = -_m2storage[2] * invDet; @@ -355,13 +358,13 @@ class Matrix2 { /// Set this matrix to be the inverse of [arg] double copyInverse(Matrix2 arg) { - final det = arg.determinant(); + final double det = arg.determinant(); if (det == 0.0) { setFrom(arg); return 0.0; } - final invDet = 1.0 / det; - final argStorage = arg._m2storage; + final double invDet = 1.0 / det; + final Float64List argStorage = arg._m2storage; _m2storage[0] = argStorage[3] * invDet; _m2storage[1] = -argStorage[1] * invDet; _m2storage[2] = -argStorage[2] * invDet; @@ -371,8 +374,8 @@ class Matrix2 { /// Turns the matrix into a rotation of [radians] void setRotation(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m2storage[0] = c; _m2storage[1] = s; _m2storage[2] = -s; @@ -381,7 +384,7 @@ class Matrix2 { /// Converts into Adjugate matrix and scales by [scale] void scaleAdjoint(double scale) { - final temp = _m2storage[0]; + final double temp = _m2storage[0]; _m2storage[0] = _m2storage[3] * scale; _m2storage[2] = -_m2storage[2] * scale; _m2storage[1] = -_m2storage[1] * scale; @@ -401,7 +404,7 @@ class Matrix2 { /// Add [o] to this. void add(Matrix2 o) { - final oStorage = o._m2storage; + final Float64List oStorage = o._m2storage; _m2storage[0] = _m2storage[0] + oStorage[0]; _m2storage[1] = _m2storage[1] + oStorage[1]; _m2storage[2] = _m2storage[2] + oStorage[2]; @@ -410,7 +413,7 @@ class Matrix2 { /// Subtract [o] from this. void sub(Matrix2 o) { - final oStorage = o._m2storage; + final Float64List oStorage = o._m2storage; _m2storage[0] = _m2storage[0] - oStorage[0]; _m2storage[1] = _m2storage[1] - oStorage[1]; _m2storage[2] = _m2storage[2] - oStorage[2]; @@ -427,15 +430,15 @@ class Matrix2 { /// Multiply this with [arg] and store it in this. void multiply(Matrix2 arg) { - final m00 = _m2storage[0]; - final m01 = _m2storage[2]; - final m10 = _m2storage[1]; - final m11 = _m2storage[3]; - final argStorage = arg._m2storage; - final n00 = argStorage[0]; - final n01 = argStorage[2]; - final n10 = argStorage[1]; - final n11 = argStorage[3]; + final double m00 = _m2storage[0]; + final double m01 = _m2storage[2]; + final double m10 = _m2storage[1]; + final double m11 = _m2storage[3]; + final Float64List argStorage = arg._m2storage; + final double n00 = argStorage[0]; + final double n01 = argStorage[2]; + final double n10 = argStorage[1]; + final double n11 = argStorage[3]; _m2storage[0] = (m00 * n00) + (m01 * n10); _m2storage[2] = (m00 * n01) + (m01 * n11); _m2storage[1] = (m10 * n00) + (m11 * n10); @@ -447,11 +450,11 @@ class Matrix2 { /// Multiply a transposed this with [arg]. void transposeMultiply(Matrix2 arg) { - final m00 = _m2storage[0]; - final m01 = _m2storage[1]; - final m10 = _m2storage[2]; - final m11 = _m2storage[3]; - final argStorage = arg._m2storage; + final double m00 = _m2storage[0]; + final double m01 = _m2storage[1]; + final double m10 = _m2storage[2]; + final double m11 = _m2storage[3]; + final Float64List argStorage = arg._m2storage; _m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]); _m2storage[2] = (m00 * argStorage[2]) + (m01 * argStorage[3]); _m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[1]); @@ -460,11 +463,11 @@ class Matrix2 { /// Multiply this with a transposed [arg]. void multiplyTranspose(Matrix2 arg) { - final m00 = _m2storage[0]; - final m01 = _m2storage[2]; - final m10 = _m2storage[1]; - final m11 = _m2storage[3]; - final argStorage = arg._m2storage; + final double m00 = _m2storage[0]; + final double m01 = _m2storage[2]; + final double m10 = _m2storage[1]; + final double m11 = _m2storage[3]; + final Float64List argStorage = arg._m2storage; _m2storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[2]); _m2storage[2] = (m00 * argStorage[1]) + (m01 * argStorage[3]); _m2storage[1] = (m10 * argStorage[0]) + (m11 * argStorage[2]); @@ -474,9 +477,11 @@ class Matrix2 { /// Transform [arg] of type [Vector2] using the transformation defined by /// this. Vector2 transform(Vector2 arg) { - final argStorage = arg._v2storage; - final x = (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]); - final y = (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]); + final Float64List argStorage = arg._v2storage; + final double x = + (_m2storage[0] * argStorage[0]) + (_m2storage[2] * argStorage[1]); + final double y = + (_m2storage[1] * argStorage[0]) + (_m2storage[3] * argStorage[1]); argStorage[0] = x; argStorage[1] = y; return arg; diff --git a/packages/vector_math/lib/src/vector_math_64/matrix3.dart b/packages/vector_math/lib/src/vector_math_64/matrix3.dart index 466183a..494d22d 100644 --- a/packages/vector_math/lib/src/vector_math_64/matrix3.dart +++ b/packages/vector_math/lib/src/vector_math_64/matrix3.dart @@ -2,11 +2,75 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; /// 3D Matrix. /// Values are stored in column major order. class Matrix3 { + /// New matrix with specified values. + factory Matrix3( + double arg0, + double arg1, + double arg2, + double arg3, + double arg4, + double arg5, + double arg6, + double arg7, + double arg8, + ) => + Matrix3.zero() + ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + + /// New matrix from [values]. + factory Matrix3.fromList(List 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 = Float64List(9); + + /// Identity matrix. + 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); + + /// Constructs a new mat3 from columns. + factory Matrix3.columns(Vector3 arg0, Vector3 arg1, Vector3 arg2) => + Matrix3.zero()..setColumns(arg0, arg1, arg2); + + /// Outer product of [u] and [v]. + factory Matrix3.outer(Vector3 u, Vector3 v) => Matrix3.zero()..setOuter(u, v); + + /// Rotation of [radians] around X axis. + factory Matrix3.rotationX(double radians) => + Matrix3.zero()..setRotationX(radians); + + /// Rotation of [radians] around Y axis. + factory Matrix3.rotationY(double radians) => + Matrix3.zero()..setRotationY(radians); + + /// Rotation of [radians] around Z axis. + factory Matrix3.rotationZ(double radians) => + Matrix3.zero()..setRotationZ(radians); final Float64List _m3storage; /// The components of the matrix. @@ -14,13 +78,13 @@ class Matrix3 { /// Solve [A] * [x] = [b]. static void solve2(Matrix3 A, Vector2 x, Vector2 b) { - final a11 = A.entry(0, 0); - final a12 = A.entry(0, 1); - final a21 = A.entry(1, 0); - final a22 = A.entry(1, 1); - final bx = b.x - A.storage[6]; - final by = b.y - A.storage[7]; - var det = a11 * a22 - a12 * a21; + final double a11 = A.entry(0, 0); + final double a12 = A.entry(0, 1); + final double a21 = A.entry(1, 0); + final double a22 = A.entry(1, 1); + final double bx = b.x - A.storage[6]; + final double by = b.y - A.storage[7]; + double det = a11 * a22 - a12 * a21; if (det != 0.0) { det = 1.0 / det; @@ -33,45 +97,45 @@ class Matrix3 { /// Solve [A] * [x] = [b]. static void solve(Matrix3 A, Vector3 x, Vector3 b) { - final A0x = A.entry(0, 0); - final A0y = A.entry(1, 0); - final A0z = A.entry(2, 0); - final A1x = A.entry(0, 1); - final A1y = A.entry(1, 1); - final A1z = A.entry(2, 1); - final A2x = A.entry(0, 2); - final A2y = A.entry(1, 2); - final A2z = A.entry(2, 2); + final double a0x = A.entry(0, 0); + final double a0y = A.entry(1, 0); + final double a0z = A.entry(2, 0); + final double a1x = A.entry(0, 1); + final double a1y = A.entry(1, 1); + final double a1z = A.entry(2, 1); + final double a2x = A.entry(0, 2); + final double a2y = A.entry(1, 2); + final double a2z = A.entry(2, 2); double rx, ry, rz; double det; // Column1 cross Column 2 - rx = A1y * A2z - A1z * A2y; - ry = A1z * A2x - A1x * A2z; - rz = A1x * A2y - A1y * A2x; + rx = a1y * a2z - a1z * a2y; + ry = a1z * a2x - a1x * a2z; + rz = a1x * a2y - a1y * a2x; // A.getColumn(0).dot(x) - det = A0x * rx + A0y * ry + A0z * rz; + det = a0x * rx + a0y * ry + a0z * rz; if (det != 0.0) { det = 1.0 / det; } // b dot [Column1 cross Column 2] - final x_ = det * (b.x * rx + b.y * ry + b.z * rz); + final double x_ = det * (b.x * rx + b.y * ry + b.z * rz); // Column2 cross b - rx = -(A2y * b.z - A2z * b.y); - ry = -(A2z * b.x - A2x * b.z); - rz = -(A2x * b.y - A2y * b.x); + rx = -(a2y * b.z - a2z * b.y); + ry = -(a2z * b.x - a2x * b.z); + rz = -(a2x * b.y - a2y * b.x); // Column0 dot -[Column2 cross b (Column3)] - final y_ = det * (A0x * rx + A0y * ry + A0z * rz); + final double y_ = det * (a0x * rx + a0y * ry + a0z * rz); // b cross Column 1 - rx = -(b.y * A1z - b.z * A1y); - ry = -(b.z * A1x - b.x * A1z); - rz = -(b.x * A1y - b.y * A1x); + rx = -(b.y * a1z - b.z * a1y); + ry = -(b.z * a1x - b.x * a1z); + rz = -(b.x * a1y - b.y * a1x); // Column0 dot -[b cross Column 1] - final z_ = det * (A0x * rx + A0y * ry + A0z * rz); + final double z_ = det * (a0x * rx + a0y * ry + a0z * rz); x ..x = x_ @@ -98,66 +162,6 @@ class Matrix3 { _m3storage[index(row, col)] = v; } - /// New matrix with specified values. - factory Matrix3( - double arg0, - double arg1, - double arg2, - double arg3, - double arg4, - double arg5, - double arg6, - double arg7, - double arg8, - ) => - Matrix3.zero() - ..setValues(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - - /// New matrix from [values]. - factory Matrix3.fromList(List 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 = Float64List(9); - - /// Identity matrix. - 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); - - /// Constructs a new mat3 from columns. - factory Matrix3.columns(Vector3 arg0, Vector3 arg1, Vector3 arg2) => - Matrix3.zero()..setColumns(arg0, arg1, arg2); - - /// Outer product of [u] and [v]. - factory Matrix3.outer(Vector3 u, Vector3 v) => Matrix3.zero()..setOuter(u, v); - - /// Rotation of [radians] around X axis. - factory Matrix3.rotationX(double radians) => - Matrix3.zero()..setRotationX(radians); - - /// Rotation of [radians] around Y axis. - factory Matrix3.rotationY(double radians) => - Matrix3.zero()..setRotationY(radians); - - /// Rotation of [radians] around Z axis. - factory Matrix3.rotationZ(double radians) => - Matrix3.zero()..setRotationZ(radians); - /// Sets the matrix with specified values. void setValues( double arg0, @@ -183,9 +187,9 @@ class Matrix3 { /// Sets the entire matrix to the column values. void setColumns(Vector3 arg0, Vector3 arg1, Vector3 arg2) { - final arg0Storage = arg0._v3storage; - final arg1Storage = arg1._v3storage; - final arg2Storage = arg2._v3storage; + final Float64List arg0Storage = arg0._v3storage; + final Float64List arg1Storage = arg1._v3storage; + final Float64List arg2Storage = arg2._v3storage; _m3storage[0] = arg0Storage[0]; _m3storage[1] = arg0Storage[1]; _m3storage[2] = arg0Storage[2]; @@ -199,7 +203,7 @@ class Matrix3 { /// Sets the entire matrix to the matrix in [arg]. void setFrom(Matrix3 arg) { - final argStorage = arg._m3storage; + final Float64List argStorage = arg._m3storage; _m3storage[8] = argStorage[8]; _m3storage[7] = argStorage[7]; _m3storage[6] = argStorage[6]; @@ -213,8 +217,8 @@ class Matrix3 { /// Set this to the outer product of [u] and [v]. void setOuter(Vector3 u, Vector3 v) { - final uStorage = u._v3storage; - final vStorage = v._v3storage; + final Float64List uStorage = u._v3storage; + final Float64List vStorage = v._v3storage; _m3storage[0] = uStorage[0] * vStorage[0]; _m3storage[1] = uStorage[0] * vStorage[1]; _m3storage[2] = uStorage[0] * vStorage[2]; @@ -242,7 +246,7 @@ class Matrix3 { /// Sets the upper 2x2 of the matrix to be [arg]. void setUpper2x2(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float64List argStorage = arg._m2storage; _m3storage[0] = argStorage[0]; _m3storage[1] = argStorage[1]; _m3storage[3] = argStorage[2]; @@ -266,6 +270,7 @@ class Matrix3 { /// Check if two matrices are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Matrix3) && (_m3storage[0] == other._m3storage[0]) && @@ -279,6 +284,7 @@ class Matrix3 { (_m3storage[8] == other._m3storage[8]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_m3storage); /// Returns row 0 @@ -301,7 +307,7 @@ class Matrix3 { /// Assigns the [row] of to [arg]. void setRow(int row, Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _m3storage[index(row, 0)] = argStorage[0]; _m3storage[index(row, 1)] = argStorage[1]; _m3storage[index(row, 2)] = argStorage[2]; @@ -310,7 +316,7 @@ class Matrix3 { /// Gets the [row] of the matrix Vector3 getRow(int row) { final r = Vector3.zero(); - final rStorage = r._v3storage; + final Float64List rStorage = r._v3storage; rStorage[0] = _m3storage[index(row, 0)]; rStorage[1] = _m3storage[index(row, 1)]; rStorage[2] = _m3storage[index(row, 2)]; @@ -319,8 +325,8 @@ class Matrix3 { /// Assigns the [column] of the matrix [arg] void setColumn(int column, Vector3 arg) { - final argStorage = arg._v3storage; - final entry = column * 3; + final Float64List argStorage = arg._v3storage; + final int entry = column * 3; _m3storage[entry + 2] = argStorage[2]; _m3storage[entry + 1] = argStorage[1]; _m3storage[entry + 0] = argStorage[0]; @@ -329,8 +335,8 @@ class Matrix3 { /// Gets the [column] of the matrix Vector3 getColumn(int column) { final r = Vector3.zero(); - final rStorage = r._v3storage; - final entry = column * 3; + final Float64List rStorage = r._v3storage; + final int entry = column * 3; rStorage[2] = _m3storage[entry + 2]; rStorage[1] = _m3storage[entry + 1]; rStorage[0] = _m3storage[entry + 0]; @@ -342,7 +348,7 @@ class Matrix3 { /// Copy this into [arg]. Matrix3 copyInto(Matrix3 arg) { - final argStorage = arg._m3storage; + final Float64List argStorage = arg._m3storage; argStorage[0] = _m3storage[0]; argStorage[1] = _m3storage[1]; argStorage[2] = _m3storage[2]; @@ -428,7 +434,7 @@ class Matrix3 { /// Returns the component wise absolute value of this. Matrix3 absolute() { final r = Matrix3.zero(); - final rStorage = r._m3storage; + final Float64List rStorage = r._m3storage; rStorage[0] = _m3storage[0].abs(); rStorage[1] = _m3storage[1].abs(); rStorage[2] = _m3storage[2].abs(); @@ -443,13 +449,13 @@ class Matrix3 { /// Returns the determinant of this matrix. double determinant() { - final x = + final double x = _m3storage[0] * ((_m3storage[4] * _m3storage[8]) - (_m3storage[5] * _m3storage[7])); - final y = + final double y = _m3storage[1] * ((_m3storage[3] * _m3storage[8]) - (_m3storage[5] * _m3storage[6])); - final z = + final double z = _m3storage[2] * ((_m3storage[3] * _m3storage[7]) - (_m3storage[4] * _m3storage[6])); return x - y + z; @@ -457,7 +463,7 @@ class Matrix3 { /// Returns the dot product of row [i] and [v]. double dotRow(int i, Vector3 v) { - final vStorage = v._v3storage; + final Float64List vStorage = v._v3storage; return _m3storage[i] * vStorage[0] + _m3storage[3 + i] * vStorage[1] + _m3storage[6 + i] * vStorage[2]; @@ -465,7 +471,7 @@ class Matrix3 { /// Returns the dot product of column [j] and [v]. double dotColumn(int j, Vector3 v) { - final vStorage = v._v3storage; + final Float64List vStorage = v._v3storage; return _m3storage[j * 3] * vStorage[0] + _m3storage[j * 3 + 1] * vStorage[1] + _m3storage[j * 3 + 2] * vStorage[2]; @@ -485,43 +491,43 @@ class Matrix3 { double infinityNorm() { var norm = 0.0; { - var row_norm = 0.0; - row_norm += _m3storage[0].abs(); - row_norm += _m3storage[1].abs(); - row_norm += _m3storage[2].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m3storage[0].abs(); + rowNorm += _m3storage[1].abs(); + rowNorm += _m3storage[2].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m3storage[3].abs(); - row_norm += _m3storage[4].abs(); - row_norm += _m3storage[5].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m3storage[3].abs(); + rowNorm += _m3storage[4].abs(); + rowNorm += _m3storage[5].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m3storage[6].abs(); - row_norm += _m3storage[7].abs(); - row_norm += _m3storage[8].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m3storage[6].abs(); + rowNorm += _m3storage[7].abs(); + rowNorm += _m3storage[8].abs(); + norm = rowNorm > norm ? rowNorm : norm; } return norm; } /// Returns relative error between this and [correct] double relativeError(Matrix3 correct) { - final diff = correct - this; - final correct_norm = correct.infinityNorm(); - final diff_norm = diff.infinityNorm(); - return diff_norm / correct_norm; + final Matrix3 diff = correct - this; + final double correctNorm = correct.infinityNorm(); + final double diffNorm = diff.infinityNorm(); + return diffNorm / correctNorm; } /// Returns absolute error between this and [correct] double absoluteError(Matrix3 correct) { - final this_norm = infinityNorm(); - final correct_norm = correct.infinityNorm(); - final diff_norm = (this_norm - correct_norm).abs(); - return diff_norm; + final double thisNorm = infinityNorm(); + final double correctNorm = correct.infinityNorm(); + final double diffNorm = (thisNorm - correctNorm).abs(); + return diffNorm; } /// Invert the matrix. Returns the determinant. @@ -529,38 +535,38 @@ class Matrix3 { /// Set this matrix to be the inverse of [arg] double copyInverse(Matrix3 arg) { - final det = arg.determinant(); + final double det = arg.determinant(); if (det == 0.0) { setFrom(arg); return 0.0; } - final invDet = 1.0 / det; - final argStorage = arg._m3storage; - final ix = + final double invDet = 1.0 / det; + final Float64List argStorage = arg._m3storage; + final double ix = invDet * (argStorage[4] * argStorage[8] - argStorage[5] * argStorage[7]); - final iy = + final double iy = invDet * (argStorage[2] * argStorage[7] - argStorage[1] * argStorage[8]); - final iz = + final double iz = invDet * (argStorage[1] * argStorage[5] - argStorage[2] * argStorage[4]); - final jx = + final double jx = invDet * (argStorage[5] * argStorage[6] - argStorage[3] * argStorage[8]); - final jy = + final double jy = invDet * (argStorage[0] * argStorage[8] - argStorage[2] * argStorage[6]); - final jz = + final double jz = invDet * (argStorage[2] * argStorage[3] - argStorage[0] * argStorage[5]); - final kx = + final double kx = invDet * (argStorage[3] * argStorage[7] - argStorage[4] * argStorage[6]); - final ky = + final double ky = invDet * (argStorage[1] * argStorage[6] - argStorage[0] * argStorage[7]); - final kz = + final double kz = invDet * (argStorage[0] * argStorage[4] - argStorage[1] * argStorage[3]); _m3storage[0] = ix; @@ -583,8 +589,8 @@ class Matrix3 { /// Turns the matrix into a rotation of [radians] around X void setRotationX(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m3storage[0] = 1.0; _m3storage[1] = 0.0; _m3storage[2] = 0.0; @@ -598,8 +604,8 @@ class Matrix3 { /// Turns the matrix into a rotation of [radians] around Y void setRotationY(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m3storage[0] = c; _m3storage[1] = 0.0; _m3storage[2] = -s; @@ -613,8 +619,8 @@ class Matrix3 { /// Turns the matrix into a rotation of [radians] around Z void setRotationZ(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m3storage[0] = c; _m3storage[1] = s; _m3storage[2] = 0.0; @@ -628,15 +634,15 @@ class Matrix3 { /// Converts into Adjugate matrix and scales by [scale] void scaleAdjoint(double scale) { - final m00 = _m3storage[0]; - final m01 = _m3storage[3]; - final m02 = _m3storage[6]; - final m10 = _m3storage[1]; - final m11 = _m3storage[4]; - final m12 = _m3storage[7]; - final m20 = _m3storage[2]; - final m21 = _m3storage[5]; - final m22 = _m3storage[8]; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[3]; + final double m02 = _m3storage[6]; + final double m10 = _m3storage[1]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[7]; + final double m20 = _m3storage[2]; + final double m21 = _m3storage[5]; + final double m22 = _m3storage[8]; _m3storage[0] = (m11 * m22 - m12 * m21) * scale; _m3storage[1] = (m12 * m20 - m10 * m22) * scale; _m3storage[2] = (m10 * m21 - m11 * m20) * scale; @@ -652,19 +658,19 @@ class Matrix3 { /// Returns [arg]. /// Primarily used by AABB transformation code. Vector3 absoluteRotate(Vector3 arg) { - final m00 = _m3storage[0].abs(); - final m01 = _m3storage[3].abs(); - final m02 = _m3storage[6].abs(); - final m10 = _m3storage[1].abs(); - final m11 = _m3storage[4].abs(); - final m12 = _m3storage[7].abs(); - final m20 = _m3storage[2].abs(); - final m21 = _m3storage[5].abs(); - final m22 = _m3storage[8].abs(); - final argStorage = arg._v3storage; - final x = argStorage[0]; - final y = argStorage[1]; - final z = argStorage[2]; + final double m00 = _m3storage[0].abs(); + final double m01 = _m3storage[3].abs(); + final double m02 = _m3storage[6].abs(); + final double m10 = _m3storage[1].abs(); + final double m11 = _m3storage[4].abs(); + final double m12 = _m3storage[7].abs(); + final double m20 = _m3storage[2].abs(); + final double m21 = _m3storage[5].abs(); + final double m22 = _m3storage[8].abs(); + final Float64List argStorage = arg._v3storage; + final double x = argStorage[0]; + final double y = argStorage[1]; + final double z = argStorage[2]; argStorage[0] = x * m00 + y * m01 + z * m02; argStorage[1] = x * m10 + y * m11 + z * m12; argStorage[2] = x * m20 + y * m21 + z * m22; @@ -675,13 +681,13 @@ class Matrix3 { /// Returns [arg]. /// Primarily used by AABB transformation code. Vector2 absoluteRotate2(Vector2 arg) { - final m00 = _m3storage[0].abs(); - final m01 = _m3storage[3].abs(); - final m10 = _m3storage[1].abs(); - final m11 = _m3storage[4].abs(); - final argStorage = arg._v2storage; - final x = argStorage[0]; - final y = argStorage[1]; + final double m00 = _m3storage[0].abs(); + final double m01 = _m3storage[3].abs(); + final double m10 = _m3storage[1].abs(); + final double m11 = _m3storage[4].abs(); + final Float64List argStorage = arg._v2storage; + final double x = argStorage[0]; + final double y = argStorage[1]; argStorage[0] = x * m00 + y * m01; argStorage[1] = x * m10 + y * m11; return arg; @@ -689,12 +695,12 @@ class Matrix3 { /// Transforms [arg] with this. Vector2 transform2(Vector2 arg) { - final argStorage = arg._v2storage; - final x_ = + final Float64List argStorage = arg._v2storage; + final double x_ = (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + _m3storage[6]; - final y_ = + final double y_ = (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + _m3storage[7]; @@ -721,7 +727,7 @@ class Matrix3 { /// Add [o] to this. void add(Matrix3 o) { - final oStorage = o._m3storage; + final Float64List oStorage = o._m3storage; _m3storage[0] = _m3storage[0] + oStorage[0]; _m3storage[1] = _m3storage[1] + oStorage[1]; _m3storage[2] = _m3storage[2] + oStorage[2]; @@ -735,7 +741,7 @@ class Matrix3 { /// Subtract [o] from this. void sub(Matrix3 o) { - final oStorage = o._m3storage; + final Float64List oStorage = o._m3storage; _m3storage[0] = _m3storage[0] - oStorage[0]; _m3storage[1] = _m3storage[1] - oStorage[1]; _m3storage[2] = _m3storage[2] - oStorage[2]; @@ -762,25 +768,25 @@ class Matrix3 { /// Multiply this by [arg]. void multiply(Matrix3 arg) { - final m00 = _m3storage[0]; - final m01 = _m3storage[3]; - final m02 = _m3storage[6]; - final m10 = _m3storage[1]; - final m11 = _m3storage[4]; - final m12 = _m3storage[7]; - final m20 = _m3storage[2]; - final m21 = _m3storage[5]; - final m22 = _m3storage[8]; - final argStorage = arg._m3storage; - final n00 = argStorage[0]; - final n01 = argStorage[3]; - final n02 = argStorage[6]; - final n10 = argStorage[1]; - final n11 = argStorage[4]; - final n12 = argStorage[7]; - final n20 = argStorage[2]; - final n21 = argStorage[5]; - final n22 = argStorage[8]; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[3]; + final double m02 = _m3storage[6]; + final double m10 = _m3storage[1]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[7]; + final double m20 = _m3storage[2]; + final double m21 = _m3storage[5]; + final double m22 = _m3storage[8]; + final Float64List argStorage = arg._m3storage; + final double n00 = argStorage[0]; + final double n01 = argStorage[3]; + final double n02 = argStorage[6]; + final double n10 = argStorage[1]; + final double n11 = argStorage[4]; + final double n12 = argStorage[7]; + final double n20 = argStorage[2]; + final double n21 = argStorage[5]; + final double n22 = argStorage[8]; _m3storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20); _m3storage[3] = (m00 * n01) + (m01 * n11) + (m02 * n21); _m3storage[6] = (m00 * n02) + (m01 * n12) + (m02 * n22); @@ -796,16 +802,16 @@ class Matrix3 { Matrix3 multiplied(Matrix3 arg) => clone()..multiply(arg); void transposeMultiply(Matrix3 arg) { - final m00 = _m3storage[0]; - final m01 = _m3storage[1]; - final m02 = _m3storage[2]; - final m10 = _m3storage[3]; - final m11 = _m3storage[4]; - final m12 = _m3storage[5]; - final m20 = _m3storage[6]; - final m21 = _m3storage[7]; - final m22 = _m3storage[8]; - final argStorage = arg._m3storage; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[1]; + final double m02 = _m3storage[2]; + final double m10 = _m3storage[3]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[5]; + final double m20 = _m3storage[6]; + final double m21 = _m3storage[7]; + final double m22 = _m3storage[8]; + final Float64List argStorage = arg._m3storage; _m3storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]) + (m02 * argStorage[2]); _m3storage[3] = @@ -827,16 +833,16 @@ class Matrix3 { } void multiplyTranspose(Matrix3 arg) { - final m00 = _m3storage[0]; - final m01 = _m3storage[3]; - final m02 = _m3storage[6]; - final m10 = _m3storage[1]; - final m11 = _m3storage[4]; - final m12 = _m3storage[7]; - final m20 = _m3storage[2]; - final m21 = _m3storage[5]; - final m22 = _m3storage[8]; - final argStorage = arg._m3storage; + final double m00 = _m3storage[0]; + final double m01 = _m3storage[3]; + final double m02 = _m3storage[6]; + final double m10 = _m3storage[1]; + final double m11 = _m3storage[4]; + final double m12 = _m3storage[7]; + final double m20 = _m3storage[2]; + final double m21 = _m3storage[5]; + final double m22 = _m3storage[8]; + final Float64List argStorage = arg._m3storage; _m3storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[3]) + (m02 * argStorage[6]); _m3storage[3] = @@ -860,16 +866,16 @@ class Matrix3 { /// Transform [arg] of type [Vector3] using the transformation defined by /// this. Vector3 transform(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float64List argStorage = arg._v3storage; + final double x_ = (_m3storage[0] * argStorage[0]) + (_m3storage[3] * argStorage[1]) + (_m3storage[6] * argStorage[2]); - final y_ = + final double y_ = (_m3storage[1] * argStorage[0]) + (_m3storage[4] * argStorage[1]) + (_m3storage[7] * argStorage[2]); - final z_ = + final double z_ = (_m3storage[2] * argStorage[0]) + (_m3storage[5] * argStorage[1]) + (_m3storage[8] * argStorage[2]); @@ -933,23 +939,23 @@ class Matrix3 { } Vector3 get right { - final x = _m3storage[0]; - final y = _m3storage[1]; - final z = _m3storage[2]; + final double x = _m3storage[0]; + final double y = _m3storage[1]; + final double z = _m3storage[2]; return Vector3(x, y, z); } Vector3 get up { - final x = _m3storage[3]; - final y = _m3storage[4]; - final z = _m3storage[5]; + final double x = _m3storage[3]; + final double y = _m3storage[4]; + final double z = _m3storage[5]; return Vector3(x, y, z); } Vector3 get forward { - final x = _m3storage[6]; - final y = _m3storage[7]; - final z = _m3storage[8]; + final double x = _m3storage[6]; + final double y = _m3storage[7]; + final double z = _m3storage[8]; return Vector3(x, y, z); } diff --git a/packages/vector_math/lib/src/vector_math_64/matrix4.dart b/packages/vector_math/lib/src/vector_math_64/matrix4.dart index 5b3d05f..b2fcd08 100644 --- a/packages/vector_math/lib/src/vector_math_64/matrix4.dart +++ b/packages/vector_math/lib/src/vector_math_64/matrix4.dart @@ -2,186 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; /// 4D Matrix. /// Values are stored in column major order. class Matrix4 { - final Float64List _m4storage; - - /// The components of the matrix. - Float64List get storage => _m4storage; - - /// Solve [A] * [x] = [b]. - static void solve2(Matrix4 A, Vector2 x, Vector2 b) { - final a11 = A.entry(0, 0); - final a12 = A.entry(0, 1); - final a21 = A.entry(1, 0); - final a22 = A.entry(1, 1); - final bx = b.x - A._m4storage[8]; - final by = b.y - A._m4storage[9]; - var det = a11 * a22 - a12 * a21; - - if (det != 0.0) { - det = 1.0 / det; - } - - x - ..x = det * (a22 * bx - a12 * by) - ..y = det * (a11 * by - a21 * bx); - } - - /// Solve [A] * [x] = [b]. - static void solve3(Matrix4 A, Vector3 x, Vector3 b) { - final A0x = A.entry(0, 0); - final A0y = A.entry(1, 0); - final A0z = A.entry(2, 0); - final A1x = A.entry(0, 1); - final A1y = A.entry(1, 1); - final A1z = A.entry(2, 1); - final A2x = A.entry(0, 2); - final A2y = A.entry(1, 2); - final A2z = A.entry(2, 2); - final bx = b.x - A._m4storage[12]; - final by = b.y - A._m4storage[13]; - final bz = b.z - A._m4storage[14]; - double rx, ry, rz; - double det; - - // Column1 cross Column 2 - rx = A1y * A2z - A1z * A2y; - ry = A1z * A2x - A1x * A2z; - rz = A1x * A2y - A1y * A2x; - - // A.getColumn(0).dot(x) - det = A0x * rx + A0y * ry + A0z * rz; - if (det != 0.0) { - det = 1.0 / det; - } - - // b dot [Column1 cross Column 2] - final x_ = det * (bx * rx + by * ry + bz * rz); - - // Column2 cross b - rx = -(A2y * bz - A2z * by); - ry = -(A2z * bx - A2x * bz); - rz = -(A2x * by - A2y * bx); - // Column0 dot -[Column2 cross b (Column3)] - final y_ = det * (A0x * rx + A0y * ry + A0z * rz); - - // b cross Column 1 - rx = -(by * A1z - bz * A1y); - ry = -(bz * A1x - bx * A1z); - rz = -(bx * A1y - by * A1x); - // Column0 dot -[b cross Column 1] - final z_ = det * (A0x * rx + A0y * ry + A0z * rz); - - x - ..x = x_ - ..y = y_ - ..z = z_; - } - - /// Solve [A] * [x] = [b]. - static void solve(Matrix4 A, Vector4 x, Vector4 b) { - final a00 = A._m4storage[0]; - final a01 = A._m4storage[1]; - final a02 = A._m4storage[2]; - final a03 = A._m4storage[3]; - final a10 = A._m4storage[4]; - final a11 = A._m4storage[5]; - final a12 = A._m4storage[6]; - final a13 = A._m4storage[7]; - final a20 = A._m4storage[8]; - final a21 = A._m4storage[9]; - final a22 = A._m4storage[10]; - final a23 = A._m4storage[11]; - final a30 = A._m4storage[12]; - final a31 = A._m4storage[13]; - final a32 = A._m4storage[14]; - final a33 = A._m4storage[15]; - final b00 = a00 * a11 - a01 * a10; - final b01 = a00 * a12 - a02 * a10; - final b02 = a00 * a13 - a03 * a10; - final b03 = a01 * a12 - a02 * a11; - final b04 = a01 * a13 - a03 * a11; - final b05 = a02 * a13 - a03 * a12; - final b06 = a20 * a31 - a21 * a30; - final b07 = a20 * a32 - a22 * a30; - final b08 = a20 * a33 - a23 * a30; - final b09 = a21 * a32 - a22 * a31; - final b10 = a21 * a33 - a23 * a31; - final b11 = a22 * a33 - a23 * a32; - - final bX = b.storage[0]; - final bY = b.storage[1]; - final bZ = b.storage[2]; - final bW = b.storage[3]; - - var det = - b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; - - if (det != 0.0) { - det = 1.0 / det; - } - - x - ..x = - det * - ((a11 * b11 - a12 * b10 + a13 * b09) * bX - - (a10 * b11 - a12 * b08 + a13 * b07) * bY + - (a10 * b10 - a11 * b08 + a13 * b06) * bZ - - (a10 * b09 - a11 * b07 + a12 * b06) * bW) - ..y = - det * - -((a01 * b11 - a02 * b10 + a03 * b09) * bX - - (a00 * b11 - a02 * b08 + a03 * b07) * bY + - (a00 * b10 - a01 * b08 + a03 * b06) * bZ - - (a00 * b09 - a01 * b07 + a02 * b06) * bW) - ..z = - det * - ((a31 * b05 - a32 * b04 + a33 * b03) * bX - - (a30 * b05 - a32 * b02 + a33 * b01) * bY + - (a30 * b04 - a31 * b02 + a33 * b00) * bZ - - (a30 * b03 - a31 * b01 + a32 * b00) * bW) - ..w = - det * - -((a21 * b05 - a22 * b04 + a23 * b03) * bX - - (a20 * b05 - a22 * b02 + a23 * b01) * bY + - (a20 * b04 - a21 * b02 + a23 * b00) * bZ - - (a20 * b03 - a21 * b01 + a22 * b00) * bW); - } - - /// Returns a matrix that is the inverse of [other] if [other] is invertible, - /// otherwise `null`. - static Matrix4? tryInvert(Matrix4 other) { - final r = Matrix4.zero(); - final determinant = r.copyInverse(other); - if (determinant == 0.0) { - return null; - } - return r; - } - - /// Return index in storage for [row], [col] value. - int index(int row, int col) => (col * 4) + row; - - /// Value at [row], [col]. - double entry(int row, int col) { - assert((row >= 0) && (row < dimension)); - assert((col >= 0) && (col < dimension)); - - return _m4storage[index(row, col)]; - } - - /// Set value at [row], [col] to be [v]. - void setEntry(int row, int col, double v) { - assert((row >= 0) && (row < dimension)); - assert((col >= 0) && (col < dimension)); - - _m4storage[index(row, col)] = v; - } - /// Constructs a new mat4. factory Matrix4( double arg0, @@ -200,56 +29,57 @@ 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 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 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 = Float64List(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); @@ -257,7 +87,7 @@ class Matrix4 { /// Constructs a matrix that is the inverse of [other]. factory Matrix4.inverted(Matrix4 other) { final r = Matrix4.zero(); - final determinant = r.copyInverse(other); + final double determinant = r.copyInverse(other); if (determinant == 0.0) { throw ArgumentError.value(other, 'other', 'Matrix cannot be inverted'); } @@ -276,24 +106,28 @@ 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) => @@ -304,8 +138,8 @@ class Matrix4 { /// Scale matrix. factory Matrix4.diagonal3(Vector3 scale) { final m = Matrix4.zero(); - final mStorage = m._m4storage; - final scaleStorage = scale._v3storage; + final Float64List mStorage = m._m4storage; + final Float64List scaleStorage = scale._v3storage; mStorage[15] = 1.0; mStorage[10] = scaleStorage[2]; mStorage[5] = scaleStorage[1]; @@ -359,6 +193,180 @@ class Matrix4 { ) => Matrix4.zero() ..setFromTranslationRotationScale(translation, rotation, scale); + final Float64List _m4storage; + + /// The components of the matrix. + Float64List get storage => _m4storage; + + /// Solve [A] * [x] = [b]. + static void solve2(Matrix4 A, Vector2 x, Vector2 b) { + final double a11 = A.entry(0, 0); + final double a12 = A.entry(0, 1); + final double a21 = A.entry(1, 0); + final double a22 = A.entry(1, 1); + final double bx = b.x - A._m4storage[8]; + final double by = b.y - A._m4storage[9]; + double det = a11 * a22 - a12 * a21; + + if (det != 0.0) { + det = 1.0 / det; + } + + x + ..x = det * (a22 * bx - a12 * by) + ..y = det * (a11 * by - a21 * bx); + } + + /// Solve [A] * [x] = [b]. + static void solve3(Matrix4 A, Vector3 x, Vector3 b) { + final double a0x = A.entry(0, 0); + final double a0y = A.entry(1, 0); + final double a0z = A.entry(2, 0); + final double a1x = A.entry(0, 1); + final double a1y = A.entry(1, 1); + final double a1z = A.entry(2, 1); + final double a2x = A.entry(0, 2); + final double a2y = A.entry(1, 2); + final double a2z = A.entry(2, 2); + final double bx = b.x - A._m4storage[12]; + final double by = b.y - A._m4storage[13]; + final double bz = b.z - A._m4storage[14]; + double rx, ry, rz; + double det; + + // Column1 cross Column 2 + rx = a1y * a2z - a1z * a2y; + ry = a1z * a2x - a1x * a2z; + rz = a1x * a2y - a1y * a2x; + + // A.getColumn(0).dot(x) + det = a0x * rx + a0y * ry + a0z * rz; + if (det != 0.0) { + det = 1.0 / det; + } + + // b dot [Column1 cross Column 2] + final double x_ = det * (bx * rx + by * ry + bz * rz); + + // Column2 cross b + rx = -(a2y * bz - a2z * by); + ry = -(a2z * bx - a2x * bz); + rz = -(a2x * by - a2y * bx); + // Column0 dot -[Column2 cross b (Column3)] + final double y_ = det * (a0x * rx + a0y * ry + a0z * rz); + + // b cross Column 1 + rx = -(by * a1z - bz * a1y); + ry = -(bz * a1x - bx * a1z); + rz = -(bx * a1y - by * a1x); + // Column0 dot -[b cross Column 1] + final double z_ = det * (a0x * rx + a0y * ry + a0z * rz); + + x + ..x = x_ + ..y = y_ + ..z = z_; + } + + /// Solve [A] * [x] = [b]. + static void solve(Matrix4 A, Vector4 x, Vector4 b) { + final double a00 = A._m4storage[0]; + final double a01 = A._m4storage[1]; + final double a02 = A._m4storage[2]; + final double a03 = A._m4storage[3]; + final double a10 = A._m4storage[4]; + final double a11 = A._m4storage[5]; + final double a12 = A._m4storage[6]; + final double a13 = A._m4storage[7]; + final double a20 = A._m4storage[8]; + final double a21 = A._m4storage[9]; + final double a22 = A._m4storage[10]; + final double a23 = A._m4storage[11]; + final double a30 = A._m4storage[12]; + final double a31 = A._m4storage[13]; + final double a32 = A._m4storage[14]; + final double a33 = A._m4storage[15]; + final double b00 = a00 * a11 - a01 * a10; + final double b01 = a00 * a12 - a02 * a10; + final double b02 = a00 * a13 - a03 * a10; + final double b03 = a01 * a12 - a02 * a11; + final double b04 = a01 * a13 - a03 * a11; + final double b05 = a02 * a13 - a03 * a12; + final double b06 = a20 * a31 - a21 * a30; + final double b07 = a20 * a32 - a22 * a30; + final double b08 = a20 * a33 - a23 * a30; + final double b09 = a21 * a32 - a22 * a31; + final double b10 = a21 * a33 - a23 * a31; + final double b11 = a22 * a33 - a23 * a32; + + final double bX = b.storage[0]; + final double bY = b.storage[1]; + final double bZ = b.storage[2]; + final double bW = b.storage[3]; + + double det = + b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (det != 0.0) { + det = 1.0 / det; + } + + x + ..x = + det * + ((a11 * b11 - a12 * b10 + a13 * b09) * bX - + (a10 * b11 - a12 * b08 + a13 * b07) * bY + + (a10 * b10 - a11 * b08 + a13 * b06) * bZ - + (a10 * b09 - a11 * b07 + a12 * b06) * bW) + ..y = + det * + -((a01 * b11 - a02 * b10 + a03 * b09) * bX - + (a00 * b11 - a02 * b08 + a03 * b07) * bY + + (a00 * b10 - a01 * b08 + a03 * b06) * bZ - + (a00 * b09 - a01 * b07 + a02 * b06) * bW) + ..z = + det * + ((a31 * b05 - a32 * b04 + a33 * b03) * bX - + (a30 * b05 - a32 * b02 + a33 * b01) * bY + + (a30 * b04 - a31 * b02 + a33 * b00) * bZ - + (a30 * b03 - a31 * b01 + a32 * b00) * bW) + ..w = + det * + -((a21 * b05 - a22 * b04 + a23 * b03) * bX - + (a20 * b05 - a22 * b02 + a23 * b01) * bY + + (a20 * b04 - a21 * b02 + a23 * b00) * bZ - + (a20 * b03 - a21 * b01 + a22 * b00) * bW); + } + + /// Returns a matrix that is the inverse of [other] if [other] is invertible, + /// otherwise `null`. + static Matrix4? tryInvert(Matrix4 other) { + final r = Matrix4.zero(); + final double determinant = r.copyInverse(other); + if (determinant == 0.0) { + return null; + } + return r; + } + + /// Return index in storage for [row], [col] value. + int index(int row, int col) => (col * 4) + row; + + /// Value at [row], [col]. + double entry(int row, int col) { + assert((row >= 0) && (row < dimension)); + assert((col >= 0) && (col < dimension)); + + return _m4storage[index(row, col)]; + } + + /// Set value at [row], [col] to be [v]. + void setEntry(int row, int col, double v) { + assert((row >= 0) && (row < dimension)); + assert((col >= 0) && (col < dimension)); + + _m4storage[index(row, col)] = v; + } /// Sets the diagonal to [arg]. void splatDiagonal(double arg) { @@ -407,10 +415,10 @@ class Matrix4 { /// Sets the entire matrix to the column values. void setColumns(Vector4 arg0, Vector4 arg1, Vector4 arg2, Vector4 arg3) { - final arg0Storage = arg0._v4storage; - final arg1Storage = arg1._v4storage; - final arg2Storage = arg2._v4storage; - final arg3Storage = arg3._v4storage; + final Float64List arg0Storage = arg0._v4storage; + final Float64List arg1Storage = arg1._v4storage; + final Float64List arg2Storage = arg2._v4storage; + final Float64List arg3Storage = arg3._v4storage; _m4storage[0] = arg0Storage[0]; _m4storage[1] = arg0Storage[1]; _m4storage[2] = arg0Storage[2]; @@ -431,7 +439,7 @@ class Matrix4 { /// Sets the entire matrix to the matrix in [arg]. void setFrom(Matrix4 arg) { - final argStorage = arg._m4storage; + final Float64List argStorage = arg._m4storage; _m4storage[15] = argStorage[15]; _m4storage[14] = argStorage[14]; _m4storage[13] = argStorage[13]; @@ -452,25 +460,25 @@ class Matrix4 { /// Sets the matrix from translation [arg0] and rotation [arg1]. void setFromTranslationRotation(Vector3 arg0, Quaternion arg1) { - final arg1Storage = arg1._qStorage; - final x = arg1Storage[0]; - final y = arg1Storage[1]; - final z = arg1Storage[2]; - final w = arg1Storage[3]; - final x2 = x + x; - final y2 = y + y; - final z2 = z + z; - final xx = x * x2; - final xy = x * y2; - final xz = x * z2; - final yy = y * y2; - final yz = y * z2; - final zz = z * z2; - final wx = w * x2; - final wy = w * y2; - final wz = w * z2; - - final arg0Storage = arg0._v3storage; + final Float64List arg1Storage = arg1._qStorage; + final double x = arg1Storage[0]; + final double y = arg1Storage[1]; + final double z = arg1Storage[2]; + final double w = arg1Storage[3]; + final double x2 = x + x; + final double y2 = y + y; + final double z2 = z + z; + final double xx = x * x2; + final double xy = x * y2; + final double xz = x * z2; + final double yy = y * y2; + final double yz = y * z2; + final double zz = z * z2; + final double wx = w * x2; + final double wy = w * y2; + final double wz = w * z2; + + final Float64List arg0Storage = arg0._v3storage; _m4storage[0] = 1.0 - (yy + zz); _m4storage[1] = xy + wz; _m4storage[2] = xz - wy; @@ -501,7 +509,7 @@ class Matrix4 { /// Sets the upper 2x2 of the matrix to be [arg]. void setUpper2x2(Matrix2 arg) { - final argStorage = arg._m2storage; + final Float64List argStorage = arg._m2storage; _m4storage[0] = argStorage[0]; _m4storage[1] = argStorage[1]; _m4storage[4] = argStorage[2]; @@ -510,7 +518,7 @@ class Matrix4 { /// Sets the diagonal of the matrix to be [arg]. void setDiagonal(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _m4storage[0] = argStorage[0]; _m4storage[5] = argStorage[1]; _m4storage[10] = argStorage[2]; @@ -518,8 +526,8 @@ class Matrix4 { } void setOuter(Vector4 u, Vector4 v) { - final uStorage = u._v4storage; - final vStorage = v._v4storage; + final Float64List uStorage = u._v4storage; + final Float64List vStorage = v._v4storage; _m4storage[0] = uStorage[0] * vStorage[0]; _m4storage[1] = uStorage[0] * vStorage[1]; _m4storage[2] = uStorage[0] * vStorage[2]; @@ -557,6 +565,7 @@ class Matrix4 { /// Check if two matrices are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Matrix4) && (_m4storage[0] == other._m4storage[0]) && @@ -577,6 +586,7 @@ class Matrix4 { (_m4storage[15] == other._m4storage[15]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_m4storage); /// Returns row 0 @@ -605,7 +615,7 @@ class Matrix4 { /// Assigns the [row] of the matrix [arg] void setRow(int row, Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _m4storage[index(row, 0)] = argStorage[0]; _m4storage[index(row, 1)] = argStorage[1]; _m4storage[index(row, 2)] = argStorage[2]; @@ -615,7 +625,7 @@ class Matrix4 { /// Gets the [row] of the matrix Vector4 getRow(int row) { final r = Vector4.zero(); - final rStorage = r._v4storage; + final Float64List rStorage = r._v4storage; rStorage[0] = _m4storage[index(row, 0)]; rStorage[1] = _m4storage[index(row, 1)]; rStorage[2] = _m4storage[index(row, 2)]; @@ -625,8 +635,8 @@ class Matrix4 { /// Assigns the [column] of the matrix [arg] void setColumn(int column, Vector4 arg) { - final entry = column * 4; - final argStorage = arg._v4storage; + final int entry = column * 4; + final Float64List argStorage = arg._v4storage; _m4storage[entry + 3] = argStorage[3]; _m4storage[entry + 2] = argStorage[2]; _m4storage[entry + 1] = argStorage[1]; @@ -636,8 +646,8 @@ class Matrix4 { /// Gets the [column] of the matrix Vector4 getColumn(int column) { final r = Vector4.zero(); - final rStorage = r._v4storage; - final entry = column * 4; + final Float64List rStorage = r._v4storage; + final int entry = column * 4; rStorage[3] = _m4storage[entry + 3]; rStorage[2] = _m4storage[entry + 2]; rStorage[1] = _m4storage[entry + 1]; @@ -650,7 +660,7 @@ class Matrix4 { /// Copy into [arg]. Matrix4 copyInto(Matrix4 arg) { - final argStorage = arg._m4storage; + final Float64List argStorage = arg._m4storage; argStorage[0] = _m4storage[0]; argStorage[1] = _m4storage[1]; argStorage[2] = _m4storage[2]; @@ -730,28 +740,28 @@ class Matrix4 { /// Translate this matrix by x, y, z, w. void translateByDouble(double tx, double ty, double tz, double tw) { - final t1 = + final double t1 = _m4storage[0] * tx + _m4storage[4] * ty + _m4storage[8] * tz + _m4storage[12] * tw; _m4storage[12] = t1; - final t2 = + final double t2 = _m4storage[1] * tx + _m4storage[5] * ty + _m4storage[9] * tz + _m4storage[13] * tw; _m4storage[13] = t2; - final t3 = + final double t3 = _m4storage[2] * tx + _m4storage[6] * ty + _m4storage[10] * tz + _m4storage[14] * tw; _m4storage[14] = t3; - final t4 = + final double t4 = _m4storage[3] * tx + _m4storage[7] * ty + _m4storage[11] * tz + @@ -810,28 +820,28 @@ class Matrix4 { /// Multiply this by a translation from the left. void leftTranslateByDouble(double tx, double ty, double tz, double tw) { // Column 1 - final r1 = _m4storage[3]; + final double r1 = _m4storage[3]; _m4storage[0] += tx * r1; _m4storage[1] += ty * r1; _m4storage[2] += tz * r1; _m4storage[3] = tw * r1; // Column 2 - final r2 = _m4storage[7]; + final double r2 = _m4storage[7]; _m4storage[4] += tx * r2; _m4storage[5] += ty * r2; _m4storage[6] += tz * r2; _m4storage[7] = tw * r2; // Column 3 - final r3 = _m4storage[11]; + final double r3 = _m4storage[11]; _m4storage[8] += tx * r3; _m4storage[9] += ty * r3; _m4storage[10] += tz * r3; _m4storage[11] = tw * r3; // Column 4 - final r4 = _m4storage[15]; + final double r4 = _m4storage[15]; _m4storage[12] += tx * r4; _m4storage[13] += ty * r4; _m4storage[14] += tz * r4; @@ -861,36 +871,46 @@ class Matrix4 { /// Rotate this [angle] radians around [axis] void rotate(Vector3 axis, double angle) { - final len = axis.length; - final axisStorage = axis._v3storage; - final x = axisStorage[0] / len; - final y = axisStorage[1] / len; - final z = axisStorage[2] / len; - final c = math.cos(angle); - final s = math.sin(angle); - final C = 1.0 - c; - final m11 = x * x * C + c; - final m12 = x * y * C - z * s; - final m13 = x * z * C + y * s; - final m21 = y * x * C + z * s; - final m22 = y * y * C + c; - final m23 = y * z * C - x * s; - final m31 = z * x * C - y * s; - final m32 = z * y * C + x * s; - final m33 = z * z * C + c; - final t1 = _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31; - final t2 = _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31; - final t3 = _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31; - final t4 = _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31; - final t5 = _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32; - final t6 = _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32; - final t7 = _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32; - final t8 = _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32; - final t9 = _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33; - final t10 = _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33; - final t11 = + final double len = axis.length; + final Float64List axisStorage = axis._v3storage; + final double x = axisStorage[0] / len; + final double y = axisStorage[1] / len; + final double z = axisStorage[2] / len; + final double c = math.cos(angle); + final double s = math.sin(angle); + final double C = 1.0 - c; + final double m11 = x * x * C + c; + final double m12 = x * y * C - z * s; + final double m13 = x * z * C + y * s; + final double m21 = y * x * C + z * s; + final double m22 = y * y * C + c; + final double m23 = y * z * C - x * s; + final double m31 = z * x * C - y * s; + final double m32 = z * y * C + x * s; + final double m33 = z * z * C + c; + final double t1 = + _m4storage[0] * m11 + _m4storage[4] * m21 + _m4storage[8] * m31; + final double t2 = + _m4storage[1] * m11 + _m4storage[5] * m21 + _m4storage[9] * m31; + final double t3 = + _m4storage[2] * m11 + _m4storage[6] * m21 + _m4storage[10] * m31; + final double t4 = + _m4storage[3] * m11 + _m4storage[7] * m21 + _m4storage[11] * m31; + final double t5 = + _m4storage[0] * m12 + _m4storage[4] * m22 + _m4storage[8] * m32; + final double t6 = + _m4storage[1] * m12 + _m4storage[5] * m22 + _m4storage[9] * m32; + final double t7 = + _m4storage[2] * m12 + _m4storage[6] * m22 + _m4storage[10] * m32; + final double t8 = + _m4storage[3] * m12 + _m4storage[7] * m22 + _m4storage[11] * m32; + final double t9 = + _m4storage[0] * m13 + _m4storage[4] * m23 + _m4storage[8] * m33; + final double t10 = + _m4storage[1] * m13 + _m4storage[5] * m23 + _m4storage[9] * m33; + final double t11 = _m4storage[2] * m13 + _m4storage[6] * m23 + _m4storage[10] * m33; - final t12 = + final double t12 = _m4storage[3] * m13 + _m4storage[7] * m23 + _m4storage[11] * m33; _m4storage[0] = t1; _m4storage[1] = t2; @@ -908,16 +928,16 @@ class Matrix4 { /// Rotate this [angle] radians around X void rotateX(double angle) { - final cosAngle = math.cos(angle); - final sinAngle = math.sin(angle); - final t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle; - final t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle; - final t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle; - final t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle; - final t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle; - final t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle; - final t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle; - final t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle; + final double cosAngle = math.cos(angle); + final double sinAngle = math.sin(angle); + final double t1 = _m4storage[4] * cosAngle + _m4storage[8] * sinAngle; + final double t2 = _m4storage[5] * cosAngle + _m4storage[9] * sinAngle; + final double t3 = _m4storage[6] * cosAngle + _m4storage[10] * sinAngle; + final double t4 = _m4storage[7] * cosAngle + _m4storage[11] * sinAngle; + final double t5 = _m4storage[4] * -sinAngle + _m4storage[8] * cosAngle; + final double t6 = _m4storage[5] * -sinAngle + _m4storage[9] * cosAngle; + final double t7 = _m4storage[6] * -sinAngle + _m4storage[10] * cosAngle; + final double t8 = _m4storage[7] * -sinAngle + _m4storage[11] * cosAngle; _m4storage[4] = t1; _m4storage[5] = t2; _m4storage[6] = t3; @@ -930,16 +950,16 @@ class Matrix4 { /// Rotate this matrix [angle] radians around Y void rotateY(double angle) { - final cosAngle = math.cos(angle); - final sinAngle = math.sin(angle); - final t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle; - final t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle; - final t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle; - final t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle; - final t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle; - final t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle; - final t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle; - final t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle; + final double cosAngle = math.cos(angle); + final double sinAngle = math.sin(angle); + final double t1 = _m4storage[0] * cosAngle + _m4storage[8] * -sinAngle; + final double t2 = _m4storage[1] * cosAngle + _m4storage[9] * -sinAngle; + final double t3 = _m4storage[2] * cosAngle + _m4storage[10] * -sinAngle; + final double t4 = _m4storage[3] * cosAngle + _m4storage[11] * -sinAngle; + final double t5 = _m4storage[0] * sinAngle + _m4storage[8] * cosAngle; + final double t6 = _m4storage[1] * sinAngle + _m4storage[9] * cosAngle; + final double t7 = _m4storage[2] * sinAngle + _m4storage[10] * cosAngle; + final double t8 = _m4storage[3] * sinAngle + _m4storage[11] * cosAngle; _m4storage[0] = t1; _m4storage[1] = t2; _m4storage[2] = t3; @@ -952,16 +972,16 @@ class Matrix4 { /// Rotate this matrix [angle] radians around Z void rotateZ(double angle) { - final cosAngle = math.cos(angle); - final sinAngle = math.sin(angle); - final t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle; - final t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle; - final t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle; - final t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle; - final t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle; - final t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle; - final t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle; - final t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle; + final double cosAngle = math.cos(angle); + final double sinAngle = math.sin(angle); + final double t1 = _m4storage[0] * cosAngle + _m4storage[4] * sinAngle; + final double t2 = _m4storage[1] * cosAngle + _m4storage[5] * sinAngle; + final double t3 = _m4storage[2] * cosAngle + _m4storage[6] * sinAngle; + final double t4 = _m4storage[3] * cosAngle + _m4storage[7] * sinAngle; + final double t5 = _m4storage[0] * -sinAngle + _m4storage[4] * cosAngle; + final double t6 = _m4storage[1] * -sinAngle + _m4storage[5] * cosAngle; + final double t7 = _m4storage[2] * -sinAngle + _m4storage[6] * cosAngle; + final double t8 = _m4storage[3] * -sinAngle + _m4storage[7] * cosAngle; _m4storage[0] = t1; _m4storage[1] = t2; _m4storage[2] = t3; @@ -1119,7 +1139,7 @@ class Matrix4 { /// Returns the component wise absolute value of this. Matrix4 absolute() { final r = Matrix4.zero(); - final rStorage = r._m4storage; + final Float64List rStorage = r._m4storage; rStorage[0] = _m4storage[0].abs(); rStorage[1] = _m4storage[1].abs(); rStorage[2] = _m4storage[2].abs(); @@ -1141,31 +1161,31 @@ class Matrix4 { /// Returns the determinant of this matrix. double determinant() { - final det2_01_01 = + final double det2_01_01 = _m4storage[0] * _m4storage[5] - _m4storage[1] * _m4storage[4]; - final det2_01_02 = + final double det2_01_02 = _m4storage[0] * _m4storage[6] - _m4storage[2] * _m4storage[4]; - final det2_01_03 = + final double det2_01_03 = _m4storage[0] * _m4storage[7] - _m4storage[3] * _m4storage[4]; - final det2_01_12 = + final double det2_01_12 = _m4storage[1] * _m4storage[6] - _m4storage[2] * _m4storage[5]; - final det2_01_13 = + final double det2_01_13 = _m4storage[1] * _m4storage[7] - _m4storage[3] * _m4storage[5]; - final det2_01_23 = + final double det2_01_23 = _m4storage[2] * _m4storage[7] - _m4storage[3] * _m4storage[6]; - final det3_201_012 = + final double det3_201_012 = _m4storage[8] * det2_01_12 - _m4storage[9] * det2_01_02 + _m4storage[10] * det2_01_01; - final det3_201_013 = + final double det3_201_013 = _m4storage[8] * det2_01_13 - _m4storage[9] * det2_01_03 + _m4storage[11] * det2_01_01; - final det3_201_023 = + final double det3_201_023 = _m4storage[8] * det2_01_23 - _m4storage[10] * det2_01_03 + _m4storage[11] * det2_01_02; - final det3_201_123 = + final double det3_201_123 = _m4storage[9] * det2_01_23 - _m4storage[10] * det2_01_13 + _m4storage[11] * det2_01_12; @@ -1177,7 +1197,7 @@ class Matrix4 { /// Returns the dot product of row [i] and [v]. double dotRow(int i, Vector4 v) { - final vStorage = v._v4storage; + final Float64List vStorage = v._v4storage; return _m4storage[i] * vStorage[0] + _m4storage[4 + i] * vStorage[1] + _m4storage[8 + i] * vStorage[2] + @@ -1186,7 +1206,7 @@ class Matrix4 { /// Returns the dot product of column [j] and [v]. double dotColumn(int j, Vector4 v) { - final vStorage = v._v4storage; + final Float64List vStorage = v._v4storage; return _m4storage[j * 4] * vStorage[0] + _m4storage[j * 4 + 1] * vStorage[1] + _m4storage[j * 4 + 2] * vStorage[2] + @@ -1208,71 +1228,71 @@ class Matrix4 { double infinityNorm() { var norm = 0.0; { - var row_norm = 0.0; - row_norm += _m4storage[0].abs(); - row_norm += _m4storage[1].abs(); - row_norm += _m4storage[2].abs(); - row_norm += _m4storage[3].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[0].abs(); + rowNorm += _m4storage[1].abs(); + rowNorm += _m4storage[2].abs(); + rowNorm += _m4storage[3].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m4storage[4].abs(); - row_norm += _m4storage[5].abs(); - row_norm += _m4storage[6].abs(); - row_norm += _m4storage[7].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[4].abs(); + rowNorm += _m4storage[5].abs(); + rowNorm += _m4storage[6].abs(); + rowNorm += _m4storage[7].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m4storage[8].abs(); - row_norm += _m4storage[9].abs(); - row_norm += _m4storage[10].abs(); - row_norm += _m4storage[11].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[8].abs(); + rowNorm += _m4storage[9].abs(); + rowNorm += _m4storage[10].abs(); + rowNorm += _m4storage[11].abs(); + norm = rowNorm > norm ? rowNorm : norm; } { - var row_norm = 0.0; - row_norm += _m4storage[12].abs(); - row_norm += _m4storage[13].abs(); - row_norm += _m4storage[14].abs(); - row_norm += _m4storage[15].abs(); - norm = row_norm > norm ? row_norm : norm; + var rowNorm = 0.0; + rowNorm += _m4storage[12].abs(); + rowNorm += _m4storage[13].abs(); + rowNorm += _m4storage[14].abs(); + rowNorm += _m4storage[15].abs(); + norm = rowNorm > norm ? rowNorm : norm; } return norm; } /// Returns relative error between this and [correct] double relativeError(Matrix4 correct) { - final diff = correct - this; - final correct_norm = correct.infinityNorm(); - final diff_norm = diff.infinityNorm(); - return diff_norm / correct_norm; + final Matrix4 diff = correct - this; + final double correctNorm = correct.infinityNorm(); + final double diffNorm = diff.infinityNorm(); + return diffNorm / correctNorm; } /// Returns absolute error between this and [correct] double absoluteError(Matrix4 correct) { - final this_norm = infinityNorm(); - final correct_norm = correct.infinityNorm(); - final diff_norm = (this_norm - correct_norm).abs(); - return diff_norm; + final double thisNorm = infinityNorm(); + final double correctNorm = correct.infinityNorm(); + final double diffNorm = (thisNorm - correctNorm).abs(); + return diffNorm; } /// Returns the translation vector from this homogeneous transformation /// matrix. Vector3 getTranslation() { - final z = _m4storage[14]; - final y = _m4storage[13]; - final x = _m4storage[12]; + final double z = _m4storage[14]; + final double y = _m4storage[13]; + final double x = _m4storage[12]; return Vector3(x, y, z); } /// Sets the translation vector in this homogeneous transformation matrix. void setTranslation(Vector3 t) { - final tStorage = t._v3storage; - final z = tStorage[2]; - final y = tStorage[1]; - final x = tStorage[0]; + final Float64List tStorage = t._v3storage; + final double z = tStorage[2]; + final double y = tStorage[1]; + final double x = tStorage[0]; _m4storage[14] = z; _m4storage[13] = y; _m4storage[12] = x; @@ -1295,7 +1315,7 @@ class Matrix4 { /// Copies the rotation matrix from this homogeneous transformation matrix /// into [rotation]. void copyRotation(Matrix3 rotation) { - final rStorage = rotation._m3storage; + final Float64List rStorage = rotation._m3storage; rStorage[0] = _m4storage[0]; rStorage[1] = _m4storage[1]; rStorage[2] = _m4storage[2]; @@ -1309,7 +1329,7 @@ class Matrix4 { /// Sets the rotation matrix in this homogeneous transformation matrix. void setRotation(Matrix3 r) { - final rStorage = r._m3storage; + final Float64List rStorage = r._m3storage; _m4storage[0] = rStorage[0]; _m4storage[1] = rStorage[1]; _m4storage[2] = rStorage[2]; @@ -1329,15 +1349,15 @@ class Matrix4 { /// Returns the max scale value of the 3 axes. double getMaxScaleOnAxis() { - final scaleXSq = + final double scaleXSq = _m4storage[0] * _m4storage[0] + _m4storage[1] * _m4storage[1] + _m4storage[2] * _m4storage[2]; - final scaleYSq = + final double scaleYSq = _m4storage[4] * _m4storage[4] + _m4storage[5] * _m4storage[5] + _m4storage[6] * _m4storage[6]; - final scaleZSq = + final double scaleZSq = _m4storage[8] * _m4storage[8] + _m4storage[9] * _m4storage[9] + _m4storage[10] * _m4storage[10]; @@ -1372,42 +1392,42 @@ class Matrix4 { /// Set this matrix to be the inverse of [arg] double copyInverse(Matrix4 arg) { - final argStorage = arg._m4storage; - final a00 = argStorage[0]; - final a01 = argStorage[1]; - final a02 = argStorage[2]; - final a03 = argStorage[3]; - final a10 = argStorage[4]; - final a11 = argStorage[5]; - final a12 = argStorage[6]; - final a13 = argStorage[7]; - final a20 = argStorage[8]; - final a21 = argStorage[9]; - final a22 = argStorage[10]; - final a23 = argStorage[11]; - final a30 = argStorage[12]; - final a31 = argStorage[13]; - final a32 = argStorage[14]; - final a33 = argStorage[15]; - final b00 = a00 * a11 - a01 * a10; - final b01 = a00 * a12 - a02 * a10; - final b02 = a00 * a13 - a03 * a10; - final b03 = a01 * a12 - a02 * a11; - final b04 = a01 * a13 - a03 * a11; - final b05 = a02 * a13 - a03 * a12; - final b06 = a20 * a31 - a21 * a30; - final b07 = a20 * a32 - a22 * a30; - final b08 = a20 * a33 - a23 * a30; - final b09 = a21 * a32 - a22 * a31; - final b10 = a21 * a33 - a23 * a31; - final b11 = a22 * a33 - a23 * a32; - final det = + final Float64List argStorage = arg._m4storage; + final double a00 = argStorage[0]; + final double a01 = argStorage[1]; + final double a02 = argStorage[2]; + final double a03 = argStorage[3]; + final double a10 = argStorage[4]; + final double a11 = argStorage[5]; + final double a12 = argStorage[6]; + final double a13 = argStorage[7]; + final double a20 = argStorage[8]; + final double a21 = argStorage[9]; + final double a22 = argStorage[10]; + final double a23 = argStorage[11]; + final double a30 = argStorage[12]; + final double a31 = argStorage[13]; + final double a32 = argStorage[14]; + final double a33 = argStorage[15]; + final double b00 = a00 * a11 - a01 * a10; + final double b01 = a00 * a12 - a02 * a10; + final double b02 = a00 * a13 - a03 * a10; + final double b03 = a01 * a12 - a02 * a11; + final double b04 = a01 * a13 - a03 * a11; + final double b05 = a02 * a13 - a03 * a12; + final double b06 = a20 * a31 - a21 * a30; + final double b07 = a20 * a32 - a22 * a30; + final double b08 = a20 * a33 - a23 * a30; + final double b09 = a21 * a32 - a22 * a31; + final double b10 = a21 * a33 - a23 * a31; + final double b11 = a22 * a33 - a23 * a32; + final double det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; if (det == 0.0) { setFrom(arg); return 0.0; } - final invDet = 1.0 / det; + final double invDet = 1.0 / det; _m4storage[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet; _m4storage[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet; _m4storage[2] = (a31 * b05 - a32 * b04 + a33 * b03) * invDet; @@ -1428,11 +1448,11 @@ class Matrix4 { } double invertRotation() { - final det = determinant(); + final double det = determinant(); if (det == 0.0) { return 0.0; } - final invDet = 1.0 / det; + final double invDet = 1.0 / det; double ix; double iy; double iz; @@ -1483,8 +1503,8 @@ class Matrix4 { /// Sets the upper 3x3 to a rotation of [radians] around X void setRotationX(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m4storage[0] = 1.0; _m4storage[1] = 0.0; _m4storage[2] = 0.0; @@ -1501,8 +1521,8 @@ class Matrix4 { /// Sets the upper 3x3 to a rotation of [radians] around Y void setRotationY(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m4storage[0] = c; _m4storage[1] = 0.0; _m4storage[2] = -s; @@ -1519,8 +1539,8 @@ class Matrix4 { /// Sets the upper 3x3 to a rotation of [radians] around Z void setRotationZ(double radians) { - final c = math.cos(radians); - final s = math.sin(radians); + final double c = math.cos(radians); + final double s = math.sin(radians); _m4storage[0] = c; _m4storage[1] = s; _m4storage[2] = 0.0; @@ -1538,22 +1558,22 @@ class Matrix4 { /// Converts into Adjugate matrix and scales by [scale] void scaleAdjoint(double scale) { // Adapted from code by Richard Carling. - final a1 = _m4storage[0]; - final b1 = _m4storage[4]; - final c1 = _m4storage[8]; - final d1 = _m4storage[12]; - final a2 = _m4storage[1]; - final b2 = _m4storage[5]; - final c2 = _m4storage[9]; - final d2 = _m4storage[13]; - final a3 = _m4storage[2]; - final b3 = _m4storage[6]; - final c3 = _m4storage[10]; - final d3 = _m4storage[14]; - final a4 = _m4storage[3]; - final b4 = _m4storage[7]; - final c4 = _m4storage[11]; - final d4 = _m4storage[15]; + final double a1 = _m4storage[0]; + final double b1 = _m4storage[4]; + final double c1 = _m4storage[8]; + final double d1 = _m4storage[12]; + final double a2 = _m4storage[1]; + final double b2 = _m4storage[5]; + final double c2 = _m4storage[9]; + final double d2 = _m4storage[13]; + final double a3 = _m4storage[2]; + final double b3 = _m4storage[6]; + final double c3 = _m4storage[10]; + final double d3 = _m4storage[14]; + final double a4 = _m4storage[3]; + final double b4 = _m4storage[7]; + final double c4 = _m4storage[11]; + final double d4 = _m4storage[15]; _m4storage[0] = (b2 * (c3 * d4 - c4 * d3) - c2 * (b3 * d4 - b4 * d3) + @@ -1640,19 +1660,19 @@ class Matrix4 { /// Returns [arg]. /// Primarily used by AABB transformation code. Vector3 absoluteRotate(Vector3 arg) { - final m00 = _m4storage[0].abs(); - final m01 = _m4storage[4].abs(); - final m02 = _m4storage[8].abs(); - final m10 = _m4storage[1].abs(); - final m11 = _m4storage[5].abs(); - final m12 = _m4storage[9].abs(); - final m20 = _m4storage[2].abs(); - final m21 = _m4storage[6].abs(); - final m22 = _m4storage[10].abs(); - final argStorage = arg._v3storage; - final x = argStorage[0]; - final y = argStorage[1]; - final z = argStorage[2]; + final double m00 = _m4storage[0].abs(); + final double m01 = _m4storage[4].abs(); + final double m02 = _m4storage[8].abs(); + final double m10 = _m4storage[1].abs(); + final double m11 = _m4storage[5].abs(); + final double m12 = _m4storage[9].abs(); + final double m20 = _m4storage[2].abs(); + final double m21 = _m4storage[6].abs(); + final double m22 = _m4storage[10].abs(); + final Float64List argStorage = arg._v3storage; + final double x = argStorage[0]; + final double y = argStorage[1]; + final double z = argStorage[2]; argStorage[0] = x * m00 + y * m01 + z * m02 + 0.0 * 0.0; argStorage[1] = x * m10 + y * m11 + z * m12 + 0.0 * 0.0; argStorage[2] = x * m20 + y * m21 + z * m22 + 0.0 * 0.0; @@ -1661,7 +1681,7 @@ class Matrix4 { /// Adds [o] to this. void add(Matrix4 o) { - final oStorage = o._m4storage; + final Float64List oStorage = o._m4storage; _m4storage[0] = _m4storage[0] + oStorage[0]; _m4storage[1] = _m4storage[1] + oStorage[1]; _m4storage[2] = _m4storage[2] + oStorage[2]; @@ -1682,7 +1702,7 @@ class Matrix4 { /// Subtracts [o] from this. void sub(Matrix4 o) { - final oStorage = o._m4storage; + final Float64List oStorage = o._m4storage; _m4storage[0] = _m4storage[0] - oStorage[0]; _m4storage[1] = _m4storage[1] - oStorage[1]; _m4storage[2] = _m4storage[2] - oStorage[2]; @@ -1723,39 +1743,39 @@ class Matrix4 { /// Multiply this by [arg]. void multiply(Matrix4 arg) { - final m00 = _m4storage[0]; - final m01 = _m4storage[4]; - final m02 = _m4storage[8]; - final m03 = _m4storage[12]; - final m10 = _m4storage[1]; - final m11 = _m4storage[5]; - final m12 = _m4storage[9]; - final m13 = _m4storage[13]; - final m20 = _m4storage[2]; - final m21 = _m4storage[6]; - final m22 = _m4storage[10]; - final m23 = _m4storage[14]; - final m30 = _m4storage[3]; - final m31 = _m4storage[7]; - final m32 = _m4storage[11]; - final m33 = _m4storage[15]; - final argStorage = arg._m4storage; - final n00 = argStorage[0]; - final n01 = argStorage[4]; - final n02 = argStorage[8]; - final n03 = argStorage[12]; - final n10 = argStorage[1]; - final n11 = argStorage[5]; - final n12 = argStorage[9]; - final n13 = argStorage[13]; - final n20 = argStorage[2]; - final n21 = argStorage[6]; - final n22 = argStorage[10]; - final n23 = argStorage[14]; - final n30 = argStorage[3]; - final n31 = argStorage[7]; - final n32 = argStorage[11]; - final n33 = argStorage[15]; + final double m00 = _m4storage[0]; + final double m01 = _m4storage[4]; + final double m02 = _m4storage[8]; + final double m03 = _m4storage[12]; + final double m10 = _m4storage[1]; + final double m11 = _m4storage[5]; + final double m12 = _m4storage[9]; + final double m13 = _m4storage[13]; + final double m20 = _m4storage[2]; + final double m21 = _m4storage[6]; + final double m22 = _m4storage[10]; + final double m23 = _m4storage[14]; + final double m30 = _m4storage[3]; + final double m31 = _m4storage[7]; + final double m32 = _m4storage[11]; + final double m33 = _m4storage[15]; + final Float64List argStorage = arg._m4storage; + final double n00 = argStorage[0]; + final double n01 = argStorage[4]; + final double n02 = argStorage[8]; + final double n03 = argStorage[12]; + final double n10 = argStorage[1]; + final double n11 = argStorage[5]; + final double n12 = argStorage[9]; + final double n13 = argStorage[13]; + final double n20 = argStorage[2]; + final double n21 = argStorage[6]; + final double n22 = argStorage[10]; + final double n23 = argStorage[14]; + final double n30 = argStorage[3]; + final double n31 = argStorage[7]; + final double n32 = argStorage[11]; + final double n33 = argStorage[15]; _m4storage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30); _m4storage[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31); _m4storage[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32); @@ -1779,40 +1799,40 @@ class Matrix4 { /// /// This method does not alter the [Matrix4] in [arg]. void leftMultiply(Matrix4 arg) { - final argStorage = arg._m4storage; - final m00 = argStorage[0]; - final m01 = argStorage[4]; - final m02 = argStorage[8]; - final m03 = argStorage[12]; - final m10 = argStorage[1]; - final m11 = argStorage[5]; - final m12 = argStorage[9]; - final m13 = argStorage[13]; - final m20 = argStorage[2]; - final m21 = argStorage[6]; - final m22 = argStorage[10]; - final m23 = argStorage[14]; - final m30 = argStorage[3]; - final m31 = argStorage[7]; - final m32 = argStorage[11]; - final m33 = argStorage[15]; - final bStorage = _m4storage; - final n00 = bStorage[0]; - final n01 = bStorage[4]; - final n02 = bStorage[8]; - final n03 = bStorage[12]; - final n10 = bStorage[1]; - final n11 = bStorage[5]; - final n12 = bStorage[9]; - final n13 = bStorage[13]; - final n20 = bStorage[2]; - final n21 = bStorage[6]; - final n22 = bStorage[10]; - final n23 = bStorage[14]; - final n30 = bStorage[3]; - final n31 = bStorage[7]; - final n32 = bStorage[11]; - final n33 = bStorage[15]; + final Float64List argStorage = arg._m4storage; + final double m00 = argStorage[0]; + final double m01 = argStorage[4]; + final double m02 = argStorage[8]; + final double m03 = argStorage[12]; + final double m10 = argStorage[1]; + final double m11 = argStorage[5]; + final double m12 = argStorage[9]; + final double m13 = argStorage[13]; + final double m20 = argStorage[2]; + final double m21 = argStorage[6]; + final double m22 = argStorage[10]; + final double m23 = argStorage[14]; + final double m30 = argStorage[3]; + final double m31 = argStorage[7]; + final double m32 = argStorage[11]; + final double m33 = argStorage[15]; + final Float64List bStorage = _m4storage; + final double n00 = bStorage[0]; + final double n01 = bStorage[4]; + final double n02 = bStorage[8]; + final double n03 = bStorage[12]; + final double n10 = bStorage[1]; + final double n11 = bStorage[5]; + final double n12 = bStorage[9]; + final double n13 = bStorage[13]; + final double n20 = bStorage[2]; + final double n21 = bStorage[6]; + final double n22 = bStorage[10]; + final double n23 = bStorage[14]; + final double n30 = bStorage[3]; + final double n31 = bStorage[7]; + final double n32 = bStorage[11]; + final double n33 = bStorage[15]; bStorage[0] = (m00 * n00) + (m01 * n10) + (m02 * n20) + (m03 * n30); bStorage[4] = (m00 * n01) + (m01 * n11) + (m02 * n21) + (m03 * n31); bStorage[8] = (m00 * n02) + (m01 * n12) + (m02 * n22) + (m03 * n32); @@ -1836,23 +1856,23 @@ class Matrix4 { /// Multiply a transposed this with [arg]. void transposeMultiply(Matrix4 arg) { - final m00 = _m4storage[0]; - final m01 = _m4storage[1]; - final m02 = _m4storage[2]; - final m03 = _m4storage[3]; - final m10 = _m4storage[4]; - final m11 = _m4storage[5]; - final m12 = _m4storage[6]; - final m13 = _m4storage[7]; - final m20 = _m4storage[8]; - final m21 = _m4storage[9]; - final m22 = _m4storage[10]; - final m23 = _m4storage[11]; - final m30 = _m4storage[12]; - final m31 = _m4storage[13]; - final m32 = _m4storage[14]; - final m33 = _m4storage[15]; - final argStorage = arg._m4storage; + final double m00 = _m4storage[0]; + final double m01 = _m4storage[1]; + final double m02 = _m4storage[2]; + final double m03 = _m4storage[3]; + final double m10 = _m4storage[4]; + final double m11 = _m4storage[5]; + final double m12 = _m4storage[6]; + final double m13 = _m4storage[7]; + final double m20 = _m4storage[8]; + final double m21 = _m4storage[9]; + final double m22 = _m4storage[10]; + final double m23 = _m4storage[11]; + final double m30 = _m4storage[12]; + final double m31 = _m4storage[13]; + final double m32 = _m4storage[14]; + final double m33 = _m4storage[15]; + final Float64List argStorage = arg._m4storage; _m4storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[1]) + @@ -1937,23 +1957,23 @@ class Matrix4 { /// Multiply this with a transposed [arg]. void multiplyTranspose(Matrix4 arg) { - final m00 = _m4storage[0]; - final m01 = _m4storage[4]; - final m02 = _m4storage[8]; - final m03 = _m4storage[12]; - final m10 = _m4storage[1]; - final m11 = _m4storage[5]; - final m12 = _m4storage[9]; - final m13 = _m4storage[13]; - final m20 = _m4storage[2]; - final m21 = _m4storage[6]; - final m22 = _m4storage[10]; - final m23 = _m4storage[14]; - final m30 = _m4storage[3]; - final m31 = _m4storage[7]; - final m32 = _m4storage[11]; - final m33 = _m4storage[15]; - final argStorage = arg._m4storage; + final double m00 = _m4storage[0]; + final double m01 = _m4storage[4]; + final double m02 = _m4storage[8]; + final double m03 = _m4storage[12]; + final double m10 = _m4storage[1]; + final double m11 = _m4storage[5]; + final double m12 = _m4storage[9]; + final double m13 = _m4storage[13]; + final double m20 = _m4storage[2]; + final double m21 = _m4storage[6]; + final double m22 = _m4storage[10]; + final double m23 = _m4storage[14]; + final double m30 = _m4storage[3]; + final double m31 = _m4storage[7]; + final double m32 = _m4storage[11]; + final double m33 = _m4storage[15]; + final Float64List argStorage = arg._m4storage; _m4storage[0] = (m00 * argStorage[0]) + (m01 * argStorage[4]) + @@ -2038,11 +2058,12 @@ class Matrix4 { /// Decomposes this into [translation], [rotation] and [scale] components. void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) { - final v = _decomposeV ??= Vector3.zero(); - var sx = (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length; - final sy = + final Vector3 v = _decomposeV ??= Vector3.zero(); + double sx = + (v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length; + final double sy = (v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length; - final sz = + final double sz = (v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length; if (determinant() < 0) { @@ -2053,11 +2074,11 @@ class Matrix4 { translation._v3storage[1] = _m4storage[13]; translation._v3storage[2] = _m4storage[14]; - final invSX = 1.0 / sx; - final invSY = 1.0 / sy; - final invSZ = 1.0 / sz; + final double invSX = 1.0 / sx; + final double invSY = 1.0 / sy; + final double invSZ = 1.0 / sz; - final m = _decomposeM ??= Matrix4.zero(); + final Matrix4 m = _decomposeM ??= Matrix4.zero(); m.setFrom(this); m._m4storage[0] *= invSX; m._m4storage[1] *= invSX; @@ -2069,7 +2090,7 @@ class Matrix4 { m._m4storage[9] *= invSZ; m._m4storage[10] *= invSZ; - final r = _decomposeR ??= Matrix3.zero(); + final Matrix3 r = _decomposeR ??= Matrix3.zero(); m.copyRotation(r); rotation.setFromRotation(r); @@ -2084,16 +2105,16 @@ class Matrix4 { /// Rotate [arg] of type [Vector3] using the rotation defined by this. Vector3 rotate3(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float64List argStorage = arg._v3storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]); - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]); - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]); @@ -2117,18 +2138,18 @@ class Matrix4 { /// Transform [arg] of type [Vector3] using the transformation defined by /// this. Vector3 transform3(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float64List argStorage = arg._v3storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + @@ -2154,23 +2175,23 @@ class Matrix4 { /// Transform [arg] of type [Vector4] using the transformation defined by /// this. Vector4 transform(Vector4 arg) { - final argStorage = arg._v4storage; - final x_ = + final Float64List argStorage = arg._v4storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + (_m4storage[12] * argStorage[3]); - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + (_m4storage[13] * argStorage[3]); - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + (_m4storage[14] * argStorage[3]); - final w_ = + final double w_ = (_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + (_m4storage[11] * argStorage[2]) + @@ -2185,23 +2206,23 @@ class Matrix4 { /// Transform [arg] of type [Vector3] using the perspective transformation /// defined by this. Vector3 perspectiveTransform(Vector3 arg) { - final argStorage = arg._v3storage; - final x_ = + final Float64List argStorage = arg._v3storage; + final double x_ = (_m4storage[0] * argStorage[0]) + (_m4storage[4] * argStorage[1]) + (_m4storage[8] * argStorage[2]) + _m4storage[12]; - final y_ = + final double y_ = (_m4storage[1] * argStorage[0]) + (_m4storage[5] * argStorage[1]) + (_m4storage[9] * argStorage[2]) + _m4storage[13]; - final z_ = + final double z_ = (_m4storage[2] * argStorage[0]) + (_m4storage[6] * argStorage[1]) + (_m4storage[10] * argStorage[2]) + _m4storage[14]; - final w_ = + final double w_ = 1.0 / ((_m4storage[3] * argStorage[0]) + (_m4storage[7] * argStorage[1]) + @@ -2280,23 +2301,23 @@ class Matrix4 { } Vector3 get right { - final x = _m4storage[0]; - final y = _m4storage[1]; - final z = _m4storage[2]; + final double x = _m4storage[0]; + final double y = _m4storage[1]; + final double z = _m4storage[2]; return Vector3(x, y, z); } Vector3 get up { - final x = _m4storage[4]; - final y = _m4storage[5]; - final z = _m4storage[6]; + final double x = _m4storage[4]; + final double y = _m4storage[5]; + final double z = _m4storage[6]; return Vector3(x, y, z); } Vector3 get forward { - final x = _m4storage[8]; - final y = _m4storage[9]; - final z = _m4storage[10]; + final double x = _m4storage[8]; + final double y = _m4storage[9]; + final double z = _m4storage[10]; return Vector3(x, y, z); } diff --git a/packages/vector_math/lib/src/vector_math_64/obb3.dart b/packages/vector_math/lib/src/vector_math_64/obb3.dart index 4df2896..1c23f45 100644 --- a/packages/vector_math/lib/src/vector_math_64/obb3.dart +++ b/packages/vector_math/lib/src/vector_math_64/obb3.dart @@ -6,27 +6,6 @@ part of '../../vector_math_64.dart'; /// Defines a 3-dimensional oriented bounding box defined with a [center], /// [halfExtents] and axes. class Obb3 { - final Vector3 _center; - final Vector3 _halfExtents; - final Vector3 _axis0; - final Vector3 _axis1; - final Vector3 _axis2; - - /// The center of the OBB. - Vector3 get center => _center; - - /// The half extends of the OBB. - Vector3 get halfExtents => _halfExtents; - - /// The first axis of the OBB. - Vector3 get axis0 => _axis0; - - /// The second axis of the OBB. - Vector3 get axis1 => _axis1; - - /// The third axis of the OBB. - Vector3 get axis2 => _axis2; - /// Create a new OBB with erverything set to zero. Obb3() : _center = Vector3.zero(), @@ -55,6 +34,26 @@ class Obb3 { _axis0 = Vector3.copy(axis0), _axis1 = Vector3.copy(axis1), _axis2 = Vector3.copy(axis2); + final Vector3 _center; + final Vector3 _halfExtents; + final Vector3 _axis0; + final Vector3 _axis1; + final Vector3 _axis2; + + /// The center of the OBB. + Vector3 get center => _center; + + /// The half extends of the OBB. + Vector3 get halfExtents => _halfExtents; + + /// The first axis of the OBB. + Vector3 get axis0 => _axis0; + + /// The second axis of the OBB. + Vector3 get axis1 => _axis1; + + /// The third axis of the OBB. + Vector3 get axis2 => _axis2; /// Copy from [other] into this. void copyFrom(Obb3 other) { @@ -125,69 +124,61 @@ class Obb3 { ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 1: corner ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; case 2: corner ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 3: corner ..addScaled(_axis0, -_halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; case 4: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 5: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, -_halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; case 6: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, -_halfExtents.z); - break; case 7: corner ..addScaled(_axis0, _halfExtents.x) ..addScaled(_axis1, _halfExtents.y) ..addScaled(_axis2, _halfExtents.z); - break; } } /// Find the closest point [q] on the OBB to the point [p] and store it in /// [q]. void closestPointTo(Vector3 p, Vector3 q) { - final d = p - _center; + final Vector3 d = p - _center; q.setFrom(_center); - var dist = d.dot(_axis0); - dist = dist.clamp(-_halfExtents.x, _halfExtents.x).toDouble(); + double dist = d.dot(_axis0); + dist = dist.clamp(-_halfExtents.x, _halfExtents.x); q.addScaled(_axis0, dist); dist = d.dot(_axis1); - dist = dist.clamp(-_halfExtents.y, _halfExtents.y).toDouble(); + dist = dist.clamp(-_halfExtents.y, _halfExtents.y); q.addScaled(_axis1, dist); dist = d.dot(_axis2); - dist = dist.clamp(-_halfExtents.z, _halfExtents.z).toDouble(); + dist = dist.clamp(-_halfExtents.z, _halfExtents.z); q.addScaled(_axis2, dist); } diff --git a/packages/vector_math/lib/src/vector_math_64/opengl.dart b/packages/vector_math/lib/src/vector_math_64/opengl.dart index db1d362..79f1295 100644 --- a/packages/vector_math/lib/src/vector_math_64/opengl.dart +++ b/packages/vector_math/lib/src/vector_math_64/opengl.dart @@ -65,10 +65,10 @@ void setModelMatrix( double ty, double tz, ) { - final right = forwardDirection.cross(upDirection)..normalize(); + final Vector3 right = forwardDirection.cross(upDirection)..normalize(); final c1 = right; final c2 = upDirection; - final c3 = -forwardDirection; + final Vector3 c3 = -forwardDirection; modelMatrix.setValues( c1[0], c1[1], @@ -103,13 +103,13 @@ void setViewMatrix( Vector3 cameraFocusPosition, Vector3 upDirection, ) { - final z = (cameraPosition - cameraFocusPosition)..normalize(); - final x = upDirection.cross(z)..normalize(); - final y = z.cross(x)..normalize(); + final Vector3 z = (cameraPosition - cameraFocusPosition)..normalize(); + final Vector3 x = upDirection.cross(z)..normalize(); + final Vector3 y = z.cross(x)..normalize(); - final rotatedEyeX = -x.dot(cameraPosition); - final rotatedEyeY = -y.dot(cameraPosition); - final rotatedEyeZ = -z.dot(cameraPosition); + final double rotatedEyeX = -x.dot(cameraPosition); + final double rotatedEyeY = -y.dot(cameraPosition); + final double rotatedEyeZ = -z.dot(cameraPosition); viewMatrix.setValues( x[0], @@ -163,17 +163,17 @@ void setPerspectiveMatrix( double zNear, double zFar, ) { - final height = math.tan(fovYRadians * 0.5); - final width = height * aspectRatio; - final near_minus_far = zNear - zFar; + final double height = math.tan(fovYRadians * 0.5); + final double width = height * aspectRatio; + final double nearMinusFar = zNear - zFar; perspectiveMatrix ..setZero() ..setEntry(0, 0, 1.0 / width) ..setEntry(1, 1, 1.0 / height) - ..setEntry(2, 2, (zFar + zNear) / near_minus_far) + ..setEntry(2, 2, (zFar + zNear) / nearMinusFar) ..setEntry(3, 2, -1.0) - ..setEntry(2, 3, (2.0 * zNear * zFar) / near_minus_far); + ..setEntry(2, 3, (2.0 * zNear * zFar) / nearMinusFar); } /// Constructs a new OpenGL perspective projection matrix. @@ -210,8 +210,8 @@ void setInfiniteMatrix( double aspectRatio, double zNear, ) { - final height = math.tan(fovYRadians * 0.5); - final width = height * aspectRatio; + final double height = math.tan(fovYRadians * 0.5); + final double width = height * aspectRatio; infiniteMatrix ..setZero() @@ -257,19 +257,19 @@ void setFrustumMatrix( double near, double far, ) { - final two_near = 2.0 * near; - final right_minus_left = right - left; - final top_minus_bottom = top - bottom; - final far_minus_near = far - near; + final double twoNear = 2.0 * near; + final double rightMinusLeft = right - left; + final double topMinusBottom = top - bottom; + final double farMinusNear = far - near; perspectiveMatrix ..setZero() - ..setEntry(0, 0, two_near / right_minus_left) - ..setEntry(1, 1, two_near / top_minus_bottom) - ..setEntry(0, 2, (right + left) / right_minus_left) - ..setEntry(1, 2, (top + bottom) / top_minus_bottom) - ..setEntry(2, 2, -(far + near) / far_minus_near) + ..setEntry(0, 0, twoNear / rightMinusLeft) + ..setEntry(1, 1, twoNear / topMinusBottom) + ..setEntry(0, 2, (right + left) / rightMinusLeft) + ..setEntry(1, 2, (top + bottom) / topMinusBottom) + ..setEntry(2, 2, -(far + near) / farMinusNear) ..setEntry(3, 2, -1.0) - ..setEntry(2, 3, -(two_near * far) / far_minus_near); + ..setEntry(2, 3, -(twoNear * far) / farMinusNear); } /// Constructs a new OpenGL perspective projection matrix. @@ -310,12 +310,12 @@ void setOrthographicMatrix( double near, double far, ) { - final rml = right - left; - final rpl = right + left; - final tmb = top - bottom; - final tpb = top + bottom; - final fmn = far - near; - final fpn = far + near; + final double rml = right - left; + final double rpl = right + left; + final double tmb = top - bottom; + final double tpb = top + bottom; + final double fmn = far - near; + final double fpn = far + near; orthographicMatrix ..setZero() ..setEntry(0, 0, 2.0 / rml) @@ -360,7 +360,9 @@ Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) { final outer = Matrix4.outer(v, v); var r = Matrix4.zero(); r = r - outer; - final scaledNormal = planeNormal.scaled(dot3(planePoint, planeNormal)); + final Vector3 scaledNormal = planeNormal.scaled( + dot3(planePoint, planeNormal), + ); final T = Vector4( scaledNormal.storage[0], scaledNormal.storage[1], @@ -383,8 +385,8 @@ Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) { final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0, 1.0); var r = Matrix4.zero(); r = r - outer; - final scale = 2.0 * planePoint.dot(planeNormal); - final scaledNormal = planeNormal.scaled(scale); + final double scale = 2.0 * planePoint.dot(planeNormal); + final Vector3 scaledNormal = planeNormal.scaled(scale); final T = Vector4( scaledNormal.storage[0], scaledNormal.storage[1], @@ -449,7 +451,7 @@ bool unproject( if (v.w == 0.0) { return false; } - final invW = 1.0 / v.w; + final double invW = 1.0 / v.w; pickWorld ..x = v.x * invW ..y = v.y * invW diff --git a/packages/vector_math/lib/src/vector_math_64/plane.dart b/packages/vector_math/lib/src/vector_math_64/plane.dart index e775eb8..4301c25 100644 --- a/packages/vector_math/lib/src/vector_math_64/plane.dart +++ b/packages/vector_math/lib/src/vector_math_64/plane.dart @@ -2,9 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; class Plane { + Plane() : _normal = Vector3.zero(), constant = 0.0; + + Plane.copy(Plane other) + : _normal = Vector3.copy(other._normal), + constant = other.constant; + + Plane.components(double x, double y, double z, this.constant) + : _normal = Vector3(x, y, z); + + Plane.normalconstant(Vector3 normal_, this.constant) + : _normal = Vector3.copy(normal_); final Vector3 _normal; double constant; @@ -15,17 +30,17 @@ class Plane { b.normal.crossInto(c.normal, cross); - final f = -a.normal.dot(cross); + final double f = -a.normal.dot(cross); - final v1 = cross.scaled(a.constant); + final Vector3 v1 = cross.scaled(a.constant); c.normal.crossInto(a.normal, cross); - final v2 = cross.scaled(b.constant); + final Vector3 v2 = cross.scaled(b.constant); a.normal.crossInto(b.normal, cross); - final v3 = cross.scaled(c.constant); + final Vector3 v3 = cross.scaled(c.constant); result ..x = (v1.x + v2.x + v3.x) / f @@ -35,18 +50,6 @@ class Plane { Vector3 get normal => _normal; - Plane() : _normal = Vector3.zero(), constant = 0.0; - - Plane.copy(Plane other) - : _normal = Vector3.copy(other._normal), - constant = other.constant; - - Plane.components(double x, double y, double z, this.constant) - : _normal = Vector3(x, y, z); - - Plane.normalconstant(Vector3 normal_, this.constant) - : _normal = Vector3.copy(normal_); - void copyFrom(Plane o) { _normal.setFrom(o._normal); constant = o.constant; @@ -58,7 +61,7 @@ class Plane { } void normalize() { - final inverseLength = 1.0 / normal.length; + final double inverseLength = 1.0 / normal.length; _normal.scale(inverseLength); constant *= inverseLength; } diff --git a/packages/vector_math/lib/src/vector_math_64/quad.dart b/packages/vector_math/lib/src/vector_math_64/quad.dart index ca9aa12..168a896 100644 --- a/packages/vector_math/lib/src/vector_math_64/quad.dart +++ b/packages/vector_math/lib/src/vector_math_64/quad.dart @@ -6,23 +6,6 @@ part of '../../vector_math_64.dart'; /// Defines a quad by four points. class Quad { - final Vector3 _point0; - final Vector3 _point1; - final Vector3 _point2; - final Vector3 _point3; - - /// The first point of the quad. - Vector3 get point0 => _point0; - - /// The second point of the quad. - Vector3 get point1 => _point1; - - /// The third point of the quad. - Vector3 get point2 => _point2; - - /// The fourth point of the quad. - Vector3 get point3 => _point3; - /// Create a new, uninitialized quad. Quad() : _point0 = Vector3.zero(), @@ -43,6 +26,22 @@ class Quad { _point1 = Vector3.copy(point1), _point2 = Vector3.copy(point2), _point3 = Vector3.copy(point3); + final Vector3 _point0; + final Vector3 _point1; + final Vector3 _point2; + final Vector3 _point3; + + /// The first point of the quad. + Vector3 get point0 => _point0; + + /// The second point of the quad. + Vector3 get point1 => _point1; + + /// The third point of the quad. + Vector3 get point2 => _point2; + + /// The fourth point of the quad. + Vector3 get point3 => _point3; /// Copy the quad from [other] into this. void copyFrom(Quad other) { @@ -54,7 +53,7 @@ class Quad { /// Copy the normal of this into [normal]. void copyNormalInto(Vector3 normal) { - final v0 = _point0.clone()..sub(_point1); + final Vector3 v0 = _point0.clone()..sub(_point1); normal ..setFrom(_point2) ..sub(_point1) @@ -97,6 +96,7 @@ class Quad { /// Check if two quad are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Quad) && (_point3 == other._point3) && @@ -105,5 +105,6 @@ class Quad { (_point0 == other._point0); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hash(_point0, _point1, _point2, _point3); } diff --git a/packages/vector_math/lib/src/vector_math_64/quaternion.dart b/packages/vector_math/lib/src/vector_math_64/quaternion.dart index c07fc3f..68ebf8f 100644 --- a/packages/vector_math/lib/src/vector_math_64/quaternion.dart +++ b/packages/vector_math/lib/src/vector_math_64/quaternion.dart @@ -11,41 +11,12 @@ part of '../../vector_math_64.dart'; /// [gimbal lock](http://de.wikipedia.org/wiki/Gimbal_Lock) problem compared to /// euler rotations. class Quaternion { - final Float64List _qStorage; - - /// Access the internal [storage] of the quaternions components. - Float64List get storage => _qStorage; - - /// Access the [x] component of the quaternion. - double get x => _qStorage[0]; - set x(double x) { - _qStorage[0] = x; - } - - /// Access the [y] component of the quaternion. - double get y => _qStorage[1]; - set y(double y) { - _qStorage[1] = y; - } - - /// Access the [z] component of the quaternion. - double get z => _qStorage[2]; - set z(double z) { - _qStorage[2] = z; - } - - /// Access the [w] component of the quaternion. - double get w => _qStorage[3]; - set w(double w) { - _qStorage[3] = w; - } - - Quaternion._() : _qStorage = Float64List(4); - /// Constructs a quaternion using the raw values [x], [y], [z], and [w]. factory Quaternion(double x, double y, double z, double w) => Quaternion._()..setValues(x, y, z, w); + Quaternion._() : _qStorage = Float64List(4); + /// Constructs a quaternion from a rotation matrix [rotationMatrix]. factory Quaternion.fromRotation(Matrix3 rotationMatrix) => Quaternion._()..setFromRotation(rotationMatrix); @@ -86,13 +57,41 @@ class Quaternion { /// [Float64List.bytesPerElement]. Quaternion.fromBuffer(ByteBuffer buffer, int offset) : _qStorage = Float64List.view(buffer, offset, 4); + final Float64List _qStorage; + + /// Access the internal [storage] of the quaternions components. + Float64List get storage => _qStorage; + + /// Access the [x] component of the quaternion. + double get x => _qStorage[0]; + set x(double x) { + _qStorage[0] = x; + } + + /// Access the [y] component of the quaternion. + double get y => _qStorage[1]; + set y(double y) { + _qStorage[1] = y; + } + + /// Access the [z] component of the quaternion. + double get z => _qStorage[2]; + set z(double z) { + _qStorage[2] = z; + } + + /// Access the [w] component of the quaternion. + double get w => _qStorage[3]; + set w(double w) { + _qStorage[3] = w; + } /// Returns a new copy of this. Quaternion clone() => Quaternion.copy(this); /// Copy [source] into this. void setFrom(Quaternion source) { - final sourceStorage = source._qStorage; + final Float64List sourceStorage = source._qStorage; _qStorage[0] = sourceStorage[0]; _qStorage[1] = sourceStorage[1]; _qStorage[2] = sourceStorage[2]; @@ -109,12 +108,12 @@ class Quaternion { /// Set the quaternion with rotation of [radians] around [axis]. void setAxisAngle(Vector3 axis, double radians) { - final len = axis.length; + final double len = axis.length; if (len == 0.0) { return; } - final halfSin = math.sin(radians * 0.5) / len; - final axisStorage = axis.storage; + final double halfSin = math.sin(radians * 0.5) / len; + final Float64List axisStorage = axis.storage; _qStorage[0] = axisStorage[0] * halfSin; _qStorage[1] = axisStorage[1] * halfSin; _qStorage[2] = axisStorage[2] * halfSin; @@ -123,22 +122,23 @@ class Quaternion { /// Set the quaternion with rotation from a rotation matrix [rotationMatrix]. void setFromRotation(Matrix3 rotationMatrix) { - final rotationMatrixStorage = rotationMatrix.storage; - final trace = rotationMatrix.trace(); + final Float64List rotationMatrixStorage = rotationMatrix.storage; + final double trace = rotationMatrix.trace(); if (trace > 0.0) { - var s = math.sqrt(trace + 1.0); + double s = math.sqrt(trace + 1.0); _qStorage[3] = s * 0.5; s = 0.5 / s; _qStorage[0] = (rotationMatrixStorage[5] - rotationMatrixStorage[7]) * s; _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 j = (i + 1) % 3; - final k = (i + 2) % 3; - var s = math.sqrt( + 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( rotationMatrixStorage[rotationMatrix.index(i, i)] - rotationMatrixStorage[rotationMatrix.index(j, j)] - rotationMatrixStorage[rotationMatrix.index(k, k)] + @@ -161,13 +161,16 @@ class Quaternion { } } + // TODO(stuartmorgan): Remove this and add the missing docs. + // https://github.com/flutter/flutter/issues/186827 + // ignore: public_member_api_docs void setFromTwoVectors(Vector3 a, Vector3 b) { - final v1 = a.normalized(); - final v2 = b.normalized(); + final Vector3 v1 = a.normalized(); + final Vector3 v2 = b.normalized(); - final c = v1.dot(v2); - var angle = math.acos(c); - var axis = v1.cross(v2); + final double c = v1.dot(v2); + double angle = math.acos(c); + Vector3 axis = v1.cross(v2); if ((1.0 + c).abs() < 0.0005) { // c \approx -1 indicates 180 degree rotation @@ -199,15 +202,15 @@ class Quaternion { void setRandom(math.Random rn) { // From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III, // pg. 124-132. - final x0 = rn.nextDouble(); - final r1 = math.sqrt(1.0 - x0); - final r2 = math.sqrt(x0); - final t1 = math.pi * 2.0 * rn.nextDouble(); - final t2 = math.pi * 2.0 * rn.nextDouble(); - final c1 = math.cos(t1); - final s1 = math.sin(t1); - final c2 = math.cos(t2); - final s2 = math.sin(t2); + final double x0 = rn.nextDouble(); + final double r1 = math.sqrt(1.0 - x0); + final double r2 = math.sqrt(x0); + final double t1 = math.pi * 2.0 * rn.nextDouble(); + final double t2 = math.pi * 2.0 * rn.nextDouble(); + final double c1 = math.cos(t1); + final double s1 = math.sin(t1); + final double c2 = math.cos(t2); + final double s2 = math.sin(t2); _qStorage[0] = s1 * r1; _qStorage[1] = c1 * r1; _qStorage[2] = s2 * r2; @@ -217,19 +220,19 @@ class Quaternion { /// Set the quaternion to the time derivative of [q] with angular velocity /// [omega]. void setDQ(Quaternion q, Vector3 omega) { - final qStorage = q._qStorage; - final omegaStorage = omega.storage; - final qx = qStorage[0]; - final qy = qStorage[1]; - final qz = qStorage[2]; - final qw = qStorage[3]; - final ox = omegaStorage[0]; - final oy = omegaStorage[1]; - final oz = omegaStorage[2]; - final x = ox * qw + oy * qz - oz * qy; - final y = oy * qw + oz * qx - ox * qz; - final z = oz * qw + ox * qy - oy * qx; - final w = -ox * qx - oy * qy - oz * qz; + final Float64List qStorage = q._qStorage; + final Float64List omegaStorage = omega.storage; + final double qx = qStorage[0]; + final double qy = qStorage[1]; + final double qz = qStorage[2]; + final double qw = qStorage[3]; + final double ox = omegaStorage[0]; + final double oy = omegaStorage[1]; + final double oz = omegaStorage[2]; + final double x = ox * qw + oy * qz - oz * qy; + final double y = oy * qw + oz * qx - ox * qz; + final double z = oz * qw + ox * qy - oy * qx; + final double w = -ox * qx - oy * qy - oz * qz; _qStorage[0] = x * 0.5; _qStorage[1] = y * 0.5; _qStorage[2] = z * 0.5; @@ -238,15 +241,15 @@ class Quaternion { /// Set quaternion with rotation of [yaw], [pitch] and [roll]. void setEuler(double yaw, double pitch, double roll) { - final halfYaw = yaw * 0.5; - final halfPitch = pitch * 0.5; - final halfRoll = roll * 0.5; - final cosYaw = math.cos(halfYaw); - final sinYaw = math.sin(halfYaw); - final cosPitch = math.cos(halfPitch); - final sinPitch = math.sin(halfPitch); - final cosRoll = math.cos(halfRoll); - final sinRoll = math.sin(halfRoll); + final double halfYaw = yaw * 0.5; + final double halfPitch = pitch * 0.5; + final double halfRoll = roll * 0.5; + final double cosYaw = math.cos(halfYaw); + final double sinYaw = math.sin(halfYaw); + final double cosPitch = math.cos(halfPitch); + final double sinPitch = math.sin(halfPitch); + final double cosRoll = math.cos(halfRoll); + final double sinRoll = math.sin(halfRoll); _qStorage[0] = cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw; _qStorage[1] = cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw; _qStorage[2] = sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw; @@ -255,11 +258,11 @@ class Quaternion { /// Normalize this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _qStorage[0] *= d; _qStorage[1] *= d; _qStorage[2] *= d; @@ -282,7 +285,7 @@ class Quaternion { /// Invert this. void inverse() { - final l = 1.0 / length2; + final double l = 1.0 / length2; _qStorage[3] = _qStorage[3] * l; _qStorage[2] = -_qStorage[2] * l; _qStorage[1] = -_qStorage[1] * l; @@ -306,13 +309,13 @@ class Quaternion { /// [axis] of rotation. Vector3 get axis { - final den = 1.0 - (_qStorage[3] * _qStorage[3]); + final double den = 1.0 - (_qStorage[3] * _qStorage[3]); if (den < 1e-9) { // 0-angle rotation, so axis does not matter return Vector3.zero(); } - final scale = 1.0 / math.sqrt(den); + final double scale = 1.0 / math.sqrt(den); return Vector3( _qStorage[0] * scale, _qStorage[1] * scale, @@ -322,10 +325,10 @@ class Quaternion { /// Length squared. double get length2 { - final x = _qStorage[0]; - final y = _qStorage[1]; - final z = _qStorage[2]; - final w = _qStorage[3]; + final double x = _qStorage[0]; + final double y = _qStorage[1]; + final double z = _qStorage[2]; + final double w = _qStorage[3]; return (x * x) + (y * y) + (z * z) + (w * w); } @@ -334,7 +337,7 @@ class Quaternion { /// Returns a copy of [v] rotated by quaternion. Vector3 rotated(Vector3 v) { - final out = v.clone(); + final Vector3 out = v.clone(); rotate(out); return out; } @@ -342,31 +345,31 @@ class Quaternion { /// Rotates [v] by this. Vector3 rotate(Vector3 v) { // conjugate(this) * [v,0] * this - final w = _qStorage[3]; - final z = _qStorage[2]; - final y = _qStorage[1]; - final x = _qStorage[0]; + final double w = _qStorage[3]; + final double z = _qStorage[2]; + final double y = _qStorage[1]; + final double x = _qStorage[0]; final tiw = w; - final tiz = -z; - final tiy = -y; - final tix = -x; - final tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y; - final ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z; - final tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x; - final tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z; - final result_x = tw * x + tx * w + ty * z - tz * y; - final result_y = tw * y + ty * w + tz * x - tx * z; - final result_z = tw * z + tz * w + tx * y - ty * x; - final vStorage = v.storage; - vStorage[2] = result_z; - vStorage[1] = result_y; - vStorage[0] = result_x; + final double tiz = -z; + final double tiy = -y; + final double tix = -x; + final double tx = tiw * v.x + tix * 0.0 + tiy * v.z - tiz * v.y; + final double ty = tiw * v.y + tiy * 0.0 + tiz * v.x - tix * v.z; + final double tz = tiw * v.z + tiz * 0.0 + tix * v.y - tiy * v.x; + final double tw = tiw * 0.0 - tix * v.x - tiy * v.y - tiz * v.z; + final double resultX = tw * x + tx * w + ty * z - tz * y; + final double resultY = tw * y + ty * w + tz * x - tx * z; + final double resultZ = tw * z + tz * w + tx * y - ty * x; + final Float64List vStorage = v.storage; + vStorage[2] = resultZ; + vStorage[1] = resultY; + vStorage[0] = resultX; return v; } /// Add [arg] to this. void add(Quaternion arg) { - final argStorage = arg._qStorage; + final Float64List argStorage = arg._qStorage; _qStorage[0] = _qStorage[0] + argStorage[0]; _qStorage[1] = _qStorage[1] + argStorage[1]; _qStorage[2] = _qStorage[2] + argStorage[2]; @@ -375,7 +378,7 @@ class Quaternion { /// Subtracts [arg] from this. void sub(Quaternion arg) { - final argStorage = arg._qStorage; + final Float64List argStorage = arg._qStorage; _qStorage[0] = _qStorage[0] - argStorage[0]; _qStorage[1] = _qStorage[1] - argStorage[1]; _qStorage[2] = _qStorage[2] - argStorage[2]; @@ -395,15 +398,15 @@ class Quaternion { /// this rotated by [other]. Quaternion operator *(Quaternion other) { - final w = _qStorage[3]; - final z = _qStorage[2]; - final y = _qStorage[1]; - final x = _qStorage[0]; - final otherStorage = other._qStorage; - final ow = otherStorage[3]; - final oz = otherStorage[2]; - final oy = otherStorage[1]; - final ox = otherStorage[0]; + final double w = _qStorage[3]; + final double z = _qStorage[2]; + final double y = _qStorage[1]; + final double x = _qStorage[0]; + final Float64List otherStorage = other._qStorage; + final double ow = otherStorage[3]; + final double oz = otherStorage[2]; + final double oy = otherStorage[1]; + final double ox = otherStorage[0]; return Quaternion( w * ox + x * ow + y * oz - z * oy, w * oy + y * ow + z * ox - x * oz, @@ -414,6 +417,7 @@ class Quaternion { /// Check if two quaternions are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Quaternion) && (_qStorage[3] == other._qStorage[3]) && @@ -422,6 +426,7 @@ class Quaternion { (_qStorage[0] == other._qStorage[0]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_qStorage); /// Returns copy of this + [other]. @@ -447,32 +452,32 @@ class Quaternion { /// Set [rotationMatrix] to a rotation matrix containing the same rotation as /// this. Matrix3 copyRotationInto(Matrix3 rotationMatrix) { - final d = length2; + final double d = length2; assert(d != 0.0); - final s = 2.0 / d; + final double s = 2.0 / d; - final x = _qStorage[0]; - final y = _qStorage[1]; - final z = _qStorage[2]; - final w = _qStorage[3]; + final double x = _qStorage[0]; + final double y = _qStorage[1]; + final double z = _qStorage[2]; + final double w = _qStorage[3]; - final xs = x * s; - final ys = y * s; - final zs = z * s; + final double xs = x * s; + final double ys = y * s; + final double zs = z * s; - final wx = w * xs; - final wy = w * ys; - final wz = w * zs; + final double wx = w * xs; + final double wy = w * ys; + final double wz = w * zs; - final xx = x * xs; - final xy = x * ys; - final xz = x * zs; + final double xx = x * xs; + final double xy = x * ys; + final double xz = x * zs; - final yy = y * ys; - final yz = y * zs; - final zz = z * zs; + final double yy = y * ys; + final double yz = y * zs; + final double zz = z * zs; - final rotationMatrixStorage = rotationMatrix.storage; + final Float64List rotationMatrixStorage = rotationMatrix.storage; rotationMatrixStorage[0] = 1.0 - (yy + zz); // column 0 rotationMatrixStorage[1] = xy + wz; rotationMatrixStorage[2] = xz - wy; @@ -493,17 +498,17 @@ class Quaternion { /// Relative error between this and [correct]. double relativeError(Quaternion correct) { - final diff = correct - this; - final norm_diff = diff.length; - final correct_norm = correct.length; - return norm_diff / correct_norm; + final Quaternion diff = correct - this; + final double normDiff = diff.length; + final double correctNorm = correct.length; + return normDiff / correctNorm; } /// Absolute error between this and [correct]. double absoluteError(Quaternion correct) { - final this_norm = length; - final correct_norm = correct.length; - final norm_diff = (this_norm - correct_norm).abs(); - return norm_diff; + final double thisNorm = length; + final double correctNorm = correct.length; + final double normDiff = (thisNorm - correctNorm).abs(); + return normDiff; } } diff --git a/packages/vector_math/lib/src/vector_math_64/ray.dart b/packages/vector_math/lib/src/vector_math_64/ray.dart index 84313da..2be9a31 100644 --- a/packages/vector_math/lib/src/vector_math_64/ray.dart +++ b/packages/vector_math/lib/src/vector_math_64/ray.dart @@ -6,15 +6,6 @@ part of '../../vector_math_64.dart'; /// Defines a [Ray] by an [origin] and a [direction]. class Ray { - final Vector3 _origin; - final Vector3 _direction; - - /// The [origin] of the ray. - Vector3 get origin => _origin; - - /// The [direction] of the ray. - Vector3 get direction => _direction; - /// Create a new, uninitialized ray. Ray() : _origin = Vector3.zero(), _direction = Vector3.zero(); @@ -27,6 +18,14 @@ class Ray { Ray.originDirection(Vector3 origin, Vector3 direction) : _origin = Vector3.copy(origin), _direction = Vector3.copy(direction); + final Vector3 _origin; + final Vector3 _direction; + + /// The [origin] of the ray. + Vector3 get origin => _origin; + + /// The [direction] of the ray. + Vector3 get direction => _direction; /// Copy the [origin] and [direction] from [other] into this. void copyFrom(Ray other) { @@ -49,19 +48,19 @@ class Ray { /// Return the distance from the origin of this to the intersection with /// [other] if this intersects with [other], or null if the don't intersect. double? intersectsWithSphere(Sphere other) { - final r = other.radius; - final r2 = r * r; - final l = other._center.clone()..sub(_origin); - final s = l.dot(_direction); - final l2 = l.dot(l); + final double r = other.radius; + final double r2 = r * r; + final Vector3 l = other._center.clone()..sub(_origin); + final double s = l.dot(_direction); + final double l2 = l.dot(l); if (s < 0 && l2 > r2) { return null; } - final m2 = l2 - s * s; + final double m2 = l2 - s * s; if (m2 > r2) { return null; } - final q = math.sqrt(r2 - m2); + final double q = math.sqrt(r2 - m2); return (l2 > r2) ? s - q : s + q; } @@ -80,9 +79,9 @@ class Ray { double? intersectsWithTriangle(Triangle other) { const epsilon = 10e-6; - final point0 = other._point0; - final point1 = other._point1; - final point2 = other._point2; + final Vector3 point0 = other._point0; + final Vector3 point1 = other._point1; + final Vector3 point2 = other._point2; _e1 ..setFrom(point1) @@ -92,30 +91,30 @@ class Ray { ..sub(point0); _direction.crossInto(_e2, _q); - final a = _e1.dot(_q); + final double a = _e1.dot(_q); if (a > -epsilon && a < epsilon) { return null; } - final f = 1 / a; + final double f = 1 / a; _s ..setFrom(_origin) ..sub(point0); - final u = f * (_s.dot(_q)); + final double u = f * (_s.dot(_q)); if (u < 0.0) { return null; } _s.crossInto(_e1, _r); - final v = f * (_direction.dot(_r)); + final double v = f * (_direction.dot(_r)); if (v < -epsilon || u + v > 1.0 + epsilon) { return null; } - final t = f * (_e2.dot(_r)); + final double t = f * (_e2.dot(_r)); return t; } @@ -126,9 +125,9 @@ class Ray { const epsilon = 10e-6; // First triangle - var point0 = other._point0; - var point1 = other._point1; - var point2 = other._point2; + Vector3 point0 = other._point0; + Vector3 point1 = other._point1; + Vector3 point2 = other._point2; _e1 ..setFrom(point1) @@ -138,21 +137,21 @@ class Ray { ..sub(point0); _direction.crossInto(_e2, _q); - final a0 = _e1.dot(_q); + final double a0 = _e1.dot(_q); if (!(a0 > -epsilon && a0 < epsilon)) { - final f = 1 / a0; + final double f = 1 / a0; _s ..setFrom(_origin) ..sub(point0); - final u = f * (_s.dot(_q)); + final double u = f * (_s.dot(_q)); if (u >= 0.0) { _s.crossInto(_e1, _r); - final v = f * (_direction.dot(_r)); + final double v = f * (_direction.dot(_r)); if (!(v < -epsilon || u + v > 1.0 + epsilon)) { - final t = f * (_e2.dot(_r)); + final double t = f * (_e2.dot(_r)); return t; } @@ -172,21 +171,21 @@ class Ray { ..sub(point0); _direction.crossInto(_e2, _q); - final a1 = _e1.dot(_q); + final double a1 = _e1.dot(_q); if (!(a1 > -epsilon && a1 < epsilon)) { - final f = 1 / a1; + final double f = 1 / a1; _s ..setFrom(_origin) ..sub(point0); - final u = f * (_s.dot(_q)); + final double u = f * (_s.dot(_q)); if (u >= 0.0) { _s.crossInto(_e1, _r); - final v = f * (_direction.dot(_r)); + final double v = f * (_direction.dot(_r)); if (!(v < -epsilon || u + v > 1.0 + epsilon)) { - final t = f * (_e2.dot(_r)); + final double t = f * (_e2.dot(_r)); return t; } @@ -199,11 +198,11 @@ class Ray { /// Return the distance from the origin of this to the intersection with /// [other] if this intersects with [other], or null if the don't intersect. double? intersectsWithAabb3(Aabb3 other) { - final otherMin = other.min; - final otherMax = other.max; + final Vector3 otherMin = other.min; + final Vector3 otherMax = other.max; - var tNear = -double.maxFinite; - var tFar = double.maxFinite; + double tNear = -double.maxFinite; + double tFar = double.maxFinite; for (var i = 0; i < 3; ++i) { if (_direction[i] == 0.0) { @@ -211,8 +210,8 @@ class Ray { return null; } } else { - var t1 = (otherMin[i] - _origin[i]) / _direction[i]; - var t2 = (otherMax[i] - _origin[i]) / _direction[i]; + double t1 = (otherMin[i] - _origin[i]) / _direction[i]; + double t2 = (otherMax[i] - _origin[i]) / _direction[i]; if (t1 > t2) { final temp = t1; diff --git a/packages/vector_math/lib/src/vector_math_64/sphere.dart b/packages/vector_math/lib/src/vector_math_64/sphere.dart index f5a4cd8..4cc157d 100644 --- a/packages/vector_math/lib/src/vector_math_64/sphere.dart +++ b/packages/vector_math/lib/src/vector_math_64/sphere.dart @@ -6,14 +6,6 @@ part of '../../vector_math_64.dart'; /// Defines a sphere with a [center] and a [radius]. class Sphere { - final Vector3 _center; - - /// The [radius] of the sphere. - double radius; - - /// The [center] of the sphere. - Vector3 get center => _center; - /// Create a new, uninitialized sphere. Sphere() : _center = Vector3.zero(), radius = 0.0; @@ -25,6 +17,13 @@ class Sphere { /// Create a sphere from a [center] and a [radius]. Sphere.centerRadius(Vector3 center, this.radius) : _center = Vector3.copy(center); + final Vector3 _center; + + /// The [radius] of the sphere. + double radius; + + /// The [center] of the sphere. + Vector3 get center => _center; /// Copy the sphere from [other] into this. void copyFrom(Sphere other) { @@ -42,7 +41,7 @@ class Sphere { /// Return if this intersects with [other]. bool intersectsWithSphere(Sphere other) { - final radiusSum = radius + other.radius; + final double radiusSum = radius + other.radius; return other.center.distanceToSquared(center) <= (radiusSum * radiusSum); } diff --git a/packages/vector_math/lib/src/vector_math_64/triangle.dart b/packages/vector_math/lib/src/vector_math_64/triangle.dart index 22dda1a..c92b1c6 100644 --- a/packages/vector_math/lib/src/vector_math_64/triangle.dart +++ b/packages/vector_math/lib/src/vector_math_64/triangle.dart @@ -6,19 +6,6 @@ part of '../../vector_math_64.dart'; /// Defines a triangle by three points. class Triangle { - final Vector3 _point0; - final Vector3 _point1; - final Vector3 _point2; - - /// The first point of the triangle. - Vector3 get point0 => _point0; - - /// The second point of the triangle. - Vector3 get point1 => _point1; - - /// The third point of the triangle. - Vector3 get point2 => _point2; - /// Create a new, uninitialized triangle. Triangle() : _point0 = Vector3.zero(), @@ -36,6 +23,18 @@ class Triangle { : _point0 = Vector3.copy(point0), _point1 = Vector3.copy(point1), _point2 = Vector3.copy(point2); + final Vector3 _point0; + final Vector3 _point1; + final Vector3 _point2; + + /// The first point of the triangle. + Vector3 get point0 => _point0; + + /// The second point of the triangle. + Vector3 get point1 => _point1; + + /// The third point of the triangle. + Vector3 get point2 => _point2; /// Copy the triangle from [other] into this. void copyFrom(Triangle other) { @@ -46,7 +45,7 @@ class Triangle { /// Copy the normal of this into [normal]. void copyNormalInto(Vector3 normal) { - final v0 = point0.clone()..sub(point1); + final Vector3 v0 = point0.clone()..sub(point1); normal ..setFrom(point2) ..sub(point1) diff --git a/packages/vector_math/lib/src/vector_math_64/utilities.dart b/packages/vector_math/lib/src/vector_math_64/utilities.dart index d2aa6e8..13b7b99 100644 --- a/packages/vector_math/lib/src/vector_math_64/utilities.dart +++ b/packages/vector_math/lib/src/vector_math_64/utilities.dart @@ -18,7 +18,7 @@ double mix(double min, double max, double a) => min + a * (max - min); /// [edge1] by [amount]. The computation is equivalent to the GLSL function /// smoothstep. double smoothStep(double edge0, double edge1, double amount) { - final t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0).toDouble(); + final double t = ((amount - edge0) / (edge1 - edge0)).clamp(0.0, 1.0); return t * t * (3.0 - 2.0 * t); } diff --git a/packages/vector_math/lib/src/vector_math_64/vector.dart b/packages/vector_math/lib/src/vector_math_64/vector.dart index c72dbe8..a709b5a 100644 --- a/packages/vector_math/lib/src/vector_math_64/vector.dart +++ b/packages/vector_math/lib/src/vector_math_64/vector.dart @@ -20,7 +20,7 @@ double cross2(Vector2 x, Vector2 y) => x.cross(y); /// 2D cross product. double x vec2. void cross2A(double x, Vector2 y, Vector2 out) { - final tempy = x * y.x; + final double tempy = x * y.x; out ..x = -x * y.y ..y = tempy; @@ -28,7 +28,7 @@ void cross2A(double x, Vector2 y, Vector2 out) { /// 2D cross product. vec2 x double. void cross2B(Vector2 x, double y, Vector2 out) { - final tempy = -y * x.x; + final double tempy = -y * x.x; out ..x = y * x.y ..y = tempy; @@ -39,8 +39,9 @@ void cross2B(Vector2 x, double y, Vector2 out) { void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) { if (planeNormal.z.abs() > math.sqrt1_2) { // choose u in y-z plane - final a = planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z; - final k = 1.0 / math.sqrt(a); + final double a = + planeNormal.y * planeNormal.y + planeNormal.z * planeNormal.z; + final double k = 1.0 / math.sqrt(a); u ..x = 0.0 ..y = -planeNormal.z * k @@ -52,8 +53,9 @@ void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) { ..z = planeNormal[0] * (-planeNormal[2] * k); } else { // choose u in x-y plane - final a = planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y; - final k = 1.0 / math.sqrt(a); + final double a = + planeNormal.x * planeNormal.x + planeNormal.y * planeNormal.y; + final double k = 1.0 / math.sqrt(a); u ..x = -planeNormal[1] * k ..y = planeNormal[0] * k @@ -68,5 +70,6 @@ void buildPlaneVectors(final Vector3 planeNormal, Vector3 u, Vector3 v) { /// Base class for vectors abstract class Vector { + /// The values in the vector. List get storage; } diff --git a/packages/vector_math/lib/src/vector_math_64/vector2.dart b/packages/vector_math/lib/src/vector_math_64/vector2.dart index 2ae6ade..a086016 100644 --- a/packages/vector_math/lib/src/vector_math_64/vector2.dart +++ b/packages/vector_math/lib/src/vector_math_64/vector2.dart @@ -2,38 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Too many vector accessors that don't benefit from comments. +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; /// 2D column vector. class Vector2 implements Vector { - final Float64List _v2storage; - - /// The components of the vector. - @override - Float64List get storage => _v2storage; - - /// Set the values of [result] to the minimum of [a] and [b] for each line. - static void min(Vector2 a, Vector2 b, Vector2 result) { - result - ..x = math.min(a.x, b.x) - ..y = math.min(a.y, b.y); - } - - /// Set the values of [result] to the maximum of [a] and [b] for each line. - static void max(Vector2 a, Vector2 b, Vector2 result) { - result - ..x = math.max(a.x, b.x) - ..y = math.max(a.y, b.y); - } - - /// Interpolate between [min] and [max] with the amount of [a] using a linear - /// interpolation and store the values in [result]. - static void mix(Vector2 min, Vector2 max, double a, Vector2 result) { - result - ..x = min.x + a * (max.x - min.x) - ..y = min.y + a * (max.y - min.y); - } - /// Construct a new vector with the specified values. factory Vector2(double x, double y) => Vector2.zero()..setValues(x, y); @@ -64,6 +39,33 @@ class Vector2 implements Vector { rng ??= math.Random(); return Vector2(rng.nextDouble(), rng.nextDouble()); } + final Float64List _v2storage; + + /// The components of the vector. + @override + Float64List get storage => _v2storage; + + /// Set the values of [result] to the minimum of [a] and [b] for each line. + static void min(Vector2 a, Vector2 b, Vector2 result) { + result + ..x = math.min(a.x, b.x) + ..y = math.min(a.y, b.y); + } + + /// Set the values of [result] to the maximum of [a] and [b] for each line. + static void max(Vector2 a, Vector2 b, Vector2 result) { + result + ..x = math.max(a.x, b.x) + ..y = math.max(a.y, b.y); + } + + /// Interpolate between [min] and [max] with the amount of [a] using a linear + /// interpolation and store the values in [result]. + static void mix(Vector2 min, Vector2 max, double a, Vector2 result) { + result + ..x = min.x + a * (max.x - min.x) + ..y = min.y + a * (max.y - min.y); + } /// Set the values of the vector. void setValues(double x_, double y_) { @@ -79,7 +81,7 @@ class Vector2 implements Vector { /// Set the values by copying them from [other]. void setFrom(Vector2 other) { - final otherStorage = other._v2storage; + final Float64List otherStorage = other._v2storage; _v2storage[1] = otherStorage[1]; _v2storage[0] = otherStorage[0]; } @@ -96,12 +98,14 @@ class Vector2 implements Vector { /// Check if two vectors are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => other is Vector2 && _v2storage[1] == other._v2storage[1] && _v2storage[0] == other._v2storage[0]; @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_v2storage); /// Negate. @@ -133,7 +137,7 @@ class Vector2 implements Vector { if (value == 0.0) { setZero(); } else { - var l = length; + double l = length; if (l == 0.0) { return; } @@ -152,11 +156,11 @@ class Vector2 implements Vector { /// Normalize this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _v2storage[1] *= d; _v2storage[0] *= d; return l; @@ -182,40 +186,40 @@ class Vector2 implements Vector { /// Squared distance from this to [arg] double distanceToSquared(Vector2 arg) { - final dx = x - arg.x; - final dy = y - arg.y; + final double dx = x - arg.x; + final double dy = y - arg.y; return dx * dx + dy * dy; } /// Returns the angle between this vector and [other] in radians. double angleTo(Vector2 other) { - final otherStorage = other._v2storage; + final Float64List otherStorage = other._v2storage; if (_v2storage[1] == otherStorage[1] && _v2storage[0] == otherStorage[0]) { return 0.0; } - final d = dot(other) / (length * other.length); + final double d = dot(other) / (length * other.length); return math.acos(d.clamp(-1.0, 1.0)); } /// Returns the signed angle between this and [other] in radians. double angleToSigned(Vector2 other) { - final otherStorage = other._v2storage; + final Float64List otherStorage = other._v2storage; if (_v2storage[1] == otherStorage[1] && _v2storage[0] == otherStorage[0]) { return 0.0; } - final s = cross(other); - final c = dot(other); + final double s = cross(other); + final double c = dot(other); return math.atan2(s, c); } /// Inner product. double dot(Vector2 other) { - final otherStorage = other._v2storage; + final Float64List otherStorage = other._v2storage; return _v2storage[1] * otherStorage[1] + _v2storage[0] * otherStorage[0]; } @@ -225,16 +229,16 @@ class Vector2 implements Vector { /// applying, the inverse of the transformation. /// void postmultiply(Matrix2 arg) { - final argStorage = arg.storage; - final v1 = _v2storage[1]; - final v0 = _v2storage[0]; + final Float64List argStorage = arg.storage; + final double v1 = _v2storage[1]; + final double v0 = _v2storage[0]; _v2storage[1] = v0 * argStorage[2] + v1 * argStorage[3]; _v2storage[0] = v0 * argStorage[0] + v1 * argStorage[1]; } /// Cross product. double cross(Vector2 other) { - final otherStorage = other._v2storage; + final Float64List otherStorage = other._v2storage; return _v2storage[0] * otherStorage[1] - _v2storage[1] * otherStorage[0]; } @@ -248,7 +252,7 @@ class Vector2 implements Vector { /// Reflect this. void reflect(Vector2 normal) { - final dotProduct = normal.dot(this) * 2; + final double dotProduct = normal.dot(this) * 2; _v2storage[1] -= normal._v2storage[1] * dotProduct; _v2storage[0] -= normal._v2storage[0] * dotProduct; } @@ -262,8 +266,8 @@ class Vector2 implements Vector { /// Absolute error between this and [correct] double absoluteError(Vector2 correct) { - final yDiff = _v2storage[1] - correct._v2storage[1]; - final xDiff = _v2storage[0] - correct._v2storage[0]; + final double yDiff = _v2storage[1] - correct._v2storage[1]; + final double xDiff = _v2storage[0] - correct._v2storage[0]; return math.sqrt(xDiff * xDiff + yDiff * yDiff); } @@ -275,35 +279,35 @@ class Vector2 implements Vector { /// Add [arg] to this. void add(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] += argStorage[1]; _v2storage[0] += argStorage[0]; } /// Add [arg] scaled by [factor] to this. void addScaled(Vector2 arg, double factor) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] += argStorage[1] * factor; _v2storage[0] += argStorage[0] * factor; } /// Subtract [arg] from this. void sub(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] -= argStorage[1]; _v2storage[0] -= argStorage[0]; } /// Multiply entries in this with entries in [arg]. void multiply(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] *= argStorage[1]; _v2storage[0] *= argStorage[0]; } /// Divide entries in this with entries in [arg]. void divide(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] /= argStorage[1]; _v2storage[0] /= argStorage[0]; } @@ -331,20 +335,16 @@ class Vector2 implements Vector { /// Clamp each entry `n` in this in the range `[min[n]]-[max[n]]`. void clamp(Vector2 min, Vector2 max) { - final minStorage = min._v2storage; - final maxStorage = max._v2storage; - _v2storage[1] = _v2storage[1] - .clamp(minStorage[1], maxStorage[1]) - .toDouble(); - _v2storage[0] = _v2storage[0] - .clamp(minStorage[0], maxStorage[0]) - .toDouble(); + final Float64List minStorage = min._v2storage; + final Float64List maxStorage = max._v2storage; + _v2storage[1] = _v2storage[1].clamp(minStorage[1], maxStorage[1]); + _v2storage[0] = _v2storage[0].clamp(minStorage[0], maxStorage[0]); } /// Clamp entries this in the range [min]-[max]. void clampScalar(double min, double max) { - _v2storage[1] = _v2storage[1].clamp(min, max).toDouble(); - _v2storage[0] = _v2storage[0].clamp(min, max).toDouble(); + _v2storage[1] = _v2storage[1].clamp(min, max); + _v2storage[0] = _v2storage[0].clamp(min, max); } /// Floor entries in this. @@ -367,12 +367,14 @@ 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. @@ -380,7 +382,7 @@ class Vector2 implements Vector { /// Copy this into [arg]. Returns [arg]. Vector2 copyInto(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; argStorage[1] = _v2storage[1]; argStorage[0] = _v2storage[0]; return arg; @@ -399,13 +401,13 @@ class Vector2 implements Vector { } set xy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] = argStorage[1]; _v2storage[0] = argStorage[0]; } set yx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v2storage[1] = argStorage[0]; _v2storage[0] = argStorage[1]; } diff --git a/packages/vector_math/lib/src/vector_math_64/vector3.dart b/packages/vector_math/lib/src/vector_math_64/vector3.dart index 83ef7fc..8735480 100644 --- a/packages/vector_math/lib/src/vector_math_64/vector3.dart +++ b/packages/vector_math/lib/src/vector_math_64/vector3.dart @@ -2,41 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Too many vector accessors that don't benefit from comments. +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; /// 3D column vector. class Vector3 implements Vector { - final Float64List _v3storage; - - /// The components of the vector. - @override - Float64List get storage => _v3storage; - - /// Set the values of [result] to the minimum of [a] and [b] for each line. - static void min(Vector3 a, Vector3 b, Vector3 result) { - result - ..x = math.min(a.x, b.x) - ..y = math.min(a.y, b.y) - ..z = math.min(a.z, b.z); - } - - /// Set the values of [result] to the maximum of [a] and [b] for each line. - static void max(Vector3 a, Vector3 b, Vector3 result) { - result - ..x = math.max(a.x, b.x) - ..y = math.max(a.y, b.y) - ..z = math.max(a.z, b.z); - } - - /// Interpolate between [min] and [max] with the amount of [a] using a linear - /// interpolation and store the values in [result]. - static void mix(Vector3 min, Vector3 max, double a, Vector3 result) { - result - ..x = min.x + a * (max.x - min.x) - ..y = min.y + a * (max.y - min.y) - ..z = min.z + a * (max.z - min.z); - } - /// Construct a new vector with the specified values. factory Vector3(double x, double y, double z) => Vector3.zero()..setValues(x, y, z); @@ -68,6 +40,36 @@ class Vector3 implements Vector { rng ??= math.Random(); return Vector3(rng.nextDouble(), rng.nextDouble(), rng.nextDouble()); } + final Float64List _v3storage; + + /// The components of the vector. + @override + Float64List get storage => _v3storage; + + /// Set the values of [result] to the minimum of [a] and [b] for each line. + static void min(Vector3 a, Vector3 b, Vector3 result) { + result + ..x = math.min(a.x, b.x) + ..y = math.min(a.y, b.y) + ..z = math.min(a.z, b.z); + } + + /// Set the values of [result] to the maximum of [a] and [b] for each line. + static void max(Vector3 a, Vector3 b, Vector3 result) { + result + ..x = math.max(a.x, b.x) + ..y = math.max(a.y, b.y) + ..z = math.max(a.z, b.z); + } + + /// Interpolate between [min] and [max] with the amount of [a] using a linear + /// interpolation and store the values in [result]. + static void mix(Vector3 min, Vector3 max, double a, Vector3 result) { + result + ..x = min.x + a * (max.x - min.x) + ..y = min.y + a * (max.y - min.y) + ..z = min.z + a * (max.z - min.z); + } /// Set the values of the vector. void setValues(double x, double y, double z) { @@ -85,7 +87,7 @@ class Vector3 implements Vector { /// Set the values by copying them from [other]. void setFrom(Vector3 other) { - final otherStorage = other._v3storage; + final Float64List otherStorage = other._v3storage; _v3storage[2] = otherStorage[2]; _v3storage[1] = otherStorage[1]; _v3storage[0] = otherStorage[0]; @@ -104,6 +106,7 @@ class Vector3 implements Vector { /// Check if two vectors are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Vector3) && (_v3storage[2] == other._v3storage[2]) && @@ -111,6 +114,7 @@ class Vector3 implements Vector { (_v3storage[0] == other._v3storage[0]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_v3storage); /// Negate @@ -142,7 +146,7 @@ class Vector3 implements Vector { if (value == 0.0) { setZero(); } else { - var l = length; + double l = length; if (l == 0.0) { return; } @@ -167,11 +171,11 @@ class Vector3 implements Vector { /// Normalizes this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _v3storage[2] *= d; _v3storage[1] *= d; _v3storage[0] *= d; @@ -198,24 +202,24 @@ class Vector3 implements Vector { /// Squared distance from this to [arg] double distanceToSquared(Vector3 arg) { - final argStorage = arg._v3storage; - final dz = _v3storage[2] - argStorage[2]; - final dy = _v3storage[1] - argStorage[1]; - final dx = _v3storage[0] - argStorage[0]; + final Float64List argStorage = arg._v3storage; + final double dz = _v3storage[2] - argStorage[2]; + final double dy = _v3storage[1] - argStorage[1]; + final double dx = _v3storage[0] - argStorage[0]; return dx * dx + dy * dy + dz * dz; } /// Returns the angle between this vector and [other] in radians. double angleTo(Vector3 other) { - final otherStorage = other._v3storage; + final Float64List otherStorage = other._v3storage; if (_v3storage[2] == otherStorage[2] && _v3storage[1] == otherStorage[1] && _v3storage[0] == otherStorage[0]) { return 0.0; } - final d = dot(other) / (length * other.length); + final double d = dot(other) / (length * other.length); return math.acos(d.clamp(-1.0, 1.0)); } @@ -223,16 +227,16 @@ class Vector3 implements Vector { /// Returns the signed angle between this and [other] around [normal] /// in radians. double angleToSigned(Vector3 other, Vector3 normal) { - final angle = angleTo(other); - final c = cross(other); - final d = c.dot(normal); + final double angle = angleTo(other); + final Vector3 c = cross(other); + final double d = c.dot(normal); return d < 0.0 ? -angle : angle; } /// Inner product. double dot(Vector3 other) { - final otherStorage = other._v3storage; + final Float64List otherStorage = other._v3storage; return _v3storage[2] * otherStorage[2] + _v3storage[1] * otherStorage[1] + _v3storage[0] * otherStorage[0]; @@ -244,10 +248,10 @@ class Vector3 implements Vector { /// If [arg] is a rotation matrix, this is a computational shortcut for /// applying, the inverse of the transformation. void postmultiply(Matrix3 arg) { - final argStorage = arg._m3storage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; + final Float64List argStorage = arg._m3storage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; _v3storage[2] = v0 * argStorage[6] + v1 * argStorage[7] + v2 * argStorage[8]; @@ -259,26 +263,26 @@ class Vector3 implements Vector { /// Cross product. Vector3 cross(Vector3 other) { - final z = _v3storage[2]; - final y = _v3storage[1]; - final x = _v3storage[0]; - final otherStorage = other._v3storage; - final oz = otherStorage[2]; - final oy = otherStorage[1]; - final ox = otherStorage[0]; + final double z = _v3storage[2]; + final double y = _v3storage[1]; + final double x = _v3storage[0]; + final Float64List otherStorage = other._v3storage; + final double oz = otherStorage[2]; + final double oy = otherStorage[1]; + final double ox = otherStorage[0]; return Vector3(y * oz - z * oy, z * ox - x * oz, x * oy - y * ox); } /// Cross product. Stores result in [out]. Vector3 crossInto(Vector3 other, Vector3 out) { - final z = _v3storage[2]; - final y = _v3storage[1]; - final x = _v3storage[0]; - final otherStorage = other._v3storage; - final oz = otherStorage[2]; - final oy = otherStorage[1]; - final ox = otherStorage[0]; - final outStorage = out._v3storage; + final double z = _v3storage[2]; + final double y = _v3storage[1]; + final double x = _v3storage[0]; + final Float64List otherStorage = other._v3storage; + final double oz = otherStorage[2]; + final double oy = otherStorage[1]; + final double ox = otherStorage[0]; + final Float64List outStorage = out._v3storage; outStorage[2] = x * oy - y * ox; outStorage[1] = z * ox - x * oz; outStorage[0] = y * oz - z * oy; @@ -287,7 +291,7 @@ class Vector3 implements Vector { /// Reflect this. void reflect(Vector3 normal) { - final dotProduct = 2.0 * normal.dot(this); + final double dotProduct = 2.0 * normal.dot(this); _v3storage[2] -= normal._v3storage[2] * dotProduct; _v3storage[1] -= normal._v3storage[1] * dotProduct; _v3storage[0] -= normal._v3storage[0] * dotProduct; @@ -298,11 +302,11 @@ class Vector3 implements Vector { /// Projects this using the projection matrix [arg] void applyProjection(Matrix4 arg) { - final argStorage = arg._m4storage; - final z = _v3storage[2]; - final y = _v3storage[1]; - final x = _v3storage[0]; - final d = + final Float64List argStorage = arg._m4storage; + final double z = _v3storage[2]; + final double y = _v3storage[1]; + final double x = _v3storage[0]; + final double d = 1.0 / (argStorage[15] + argStorage[11] * z + @@ -335,18 +339,18 @@ class Vector3 implements Vector { /// Applies a quaternion transform. void applyQuaternion(Quaternion arg) { - final argStorage = arg._qStorage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; - final qw = argStorage[3]; - final qz = argStorage[2]; - final qy = argStorage[1]; - final qx = argStorage[0]; - final ix = qw * v0 + qy * v2 - qz * v1; - final iy = qw * v1 + qz * v0 - qx * v2; - final iz = qw * v2 + qx * v1 - qy * v0; - final iw = -qx * v0 - qy * v1 - qz * v2; + final Float64List argStorage = arg._qStorage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; + final double qw = argStorage[3]; + final double qz = argStorage[2]; + final double qy = argStorage[1]; + final double qx = argStorage[0]; + final double ix = qw * v0 + qy * v2 - qz * v1; + final double iy = qw * v1 + qz * v0 - qx * v2; + final double iz = qw * v2 + qx * v1 - qy * v0; + final double iw = -qx * v0 - qy * v1 - qz * v2; _v3storage[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx; _v3storage[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz; _v3storage[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy; @@ -354,10 +358,10 @@ class Vector3 implements Vector { /// Multiplies this by [arg]. void applyMatrix3(Matrix3 arg) { - final argStorage = arg._m3storage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; + final Float64List argStorage = arg._m3storage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; _v3storage[2] = argStorage[2] * v0 + argStorage[5] * v1 + argStorage[8] * v2; _v3storage[1] = @@ -369,10 +373,10 @@ class Vector3 implements Vector { /// Multiplies this by a 4x3 subset of [arg]. Expects [arg] to be an affine /// transformation matrix. void applyMatrix4(Matrix4 arg) { - final argStorage = arg._m4storage; - final v2 = _v3storage[2]; - final v1 = _v3storage[1]; - final v0 = _v3storage[0]; + final Float64List argStorage = arg._m4storage; + final double v2 = _v3storage[2]; + final double v1 = _v3storage[1]; + final double v0 = _v3storage[0]; _v3storage[2] = argStorage[2] * v0 + argStorage[6] * v1 + @@ -396,9 +400,9 @@ class Vector3 implements Vector { /// Absolute error between this and [correct] double absoluteError(Vector3 correct) { - final zDiff = _v3storage[2] - correct._v3storage[2]; - final yDiff = _v3storage[1] - correct._v3storage[1]; - final xDiff = _v3storage[0] - correct._v3storage[0]; + final double zDiff = _v3storage[2] - correct._v3storage[2]; + final double yDiff = _v3storage[1] - correct._v3storage[1]; + final double xDiff = _v3storage[0] - correct._v3storage[0]; return math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff); } @@ -414,7 +418,7 @@ class Vector3 implements Vector { /// Add [arg] to this. void add(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] += argStorage[2]; _v3storage[1] += argStorage[1]; _v3storage[0] += argStorage[0]; @@ -422,7 +426,7 @@ class Vector3 implements Vector { /// Add [arg] scaled by [factor] to this. void addScaled(Vector3 arg, double factor) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] += argStorage[2] * factor; _v3storage[1] += argStorage[1] * factor; _v3storage[0] += argStorage[0] * factor; @@ -430,7 +434,7 @@ class Vector3 implements Vector { /// Subtract [arg] from this. void sub(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] -= argStorage[2]; _v3storage[1] -= argStorage[1]; _v3storage[0] -= argStorage[0]; @@ -438,7 +442,7 @@ class Vector3 implements Vector { /// Multiply entries in this with entries in [arg]. void multiply(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] *= argStorage[2]; _v3storage[1] *= argStorage[1]; _v3storage[0] *= argStorage[0]; @@ -446,7 +450,7 @@ class Vector3 implements Vector { /// Divide entries in this with entries in [arg]. void divide(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] /= argStorage[2]; _v3storage[1] /= argStorage[1]; _v3storage[0] /= argStorage[0]; @@ -478,24 +482,18 @@ class Vector3 implements Vector { /// Clamp each entry `n` in this in the range `[min[n]]-[max[n]]`. void clamp(Vector3 min, Vector3 max) { - final minStorage = min.storage; - final maxStorage = max.storage; - _v3storage[2] = _v3storage[2] - .clamp(minStorage[2], maxStorage[2]) - .toDouble(); - _v3storage[1] = _v3storage[1] - .clamp(minStorage[1], maxStorage[1]) - .toDouble(); - _v3storage[0] = _v3storage[0] - .clamp(minStorage[0], maxStorage[0]) - .toDouble(); + final Float64List minStorage = min.storage; + final Float64List maxStorage = max.storage; + _v3storage[2] = _v3storage[2].clamp(minStorage[2], maxStorage[2]); + _v3storage[1] = _v3storage[1].clamp(minStorage[1], maxStorage[1]); + _v3storage[0] = _v3storage[0].clamp(minStorage[0], maxStorage[0]); } /// Clamp entries in this in the range [min]-[max]. void clampScalar(double min, double max) { - _v3storage[2] = _v3storage[2].clamp(min, max).toDouble(); - _v3storage[1] = _v3storage[1].clamp(min, max).toDouble(); - _v3storage[0] = _v3storage[0].clamp(min, max).toDouble(); + _v3storage[2] = _v3storage[2].clamp(min, max); + _v3storage[1] = _v3storage[1].clamp(min, max); + _v3storage[0] = _v3storage[0].clamp(min, max); } /// Floor entries in this. @@ -521,15 +519,18 @@ 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. @@ -537,7 +538,7 @@ class Vector3 implements Vector { /// Copy this into [arg]. Vector3 copyInto(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; argStorage[2] = _v3storage[2]; argStorage[1] = _v3storage[1]; argStorage[0] = _v3storage[0]; @@ -559,78 +560,78 @@ class Vector3 implements Vector { } set xy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v3storage[1] = argStorage[1]; _v3storage[0] = argStorage[0]; } set xz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v3storage[2] = argStorage[1]; _v3storage[0] = argStorage[0]; } set yx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v3storage[1] = argStorage[0]; _v3storage[0] = argStorage[1]; } set yz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v3storage[2] = argStorage[1]; _v3storage[1] = argStorage[0]; } set zx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v3storage[2] = argStorage[0]; _v3storage[0] = argStorage[1]; } set zy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v3storage[2] = argStorage[0]; _v3storage[1] = argStorage[1]; } set xyz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] = argStorage[2]; _v3storage[1] = argStorage[1]; _v3storage[0] = argStorage[0]; } set xzy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[0] = argStorage[0]; _v3storage[2] = argStorage[1]; _v3storage[1] = argStorage[2]; } set yxz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] = argStorage[2]; _v3storage[1] = argStorage[0]; _v3storage[0] = argStorage[1]; } set yzx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] = argStorage[1]; _v3storage[1] = argStorage[0]; _v3storage[0] = argStorage[2]; } set zxy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] = argStorage[0]; _v3storage[0] = argStorage[1]; _v3storage[1] = argStorage[2]; } set zyx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v3storage[2] = argStorage[0]; _v3storage[1] = argStorage[1]; _v3storage[0] = argStorage[2]; diff --git a/packages/vector_math/lib/src/vector_math_64/vector4.dart b/packages/vector_math/lib/src/vector_math_64/vector4.dart index 006ce62..d30f8f9 100644 --- a/packages/vector_math/lib/src/vector_math_64/vector4.dart +++ b/packages/vector_math/lib/src/vector_math_64/vector4.dart @@ -2,44 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Too many vector accessors that don't benefit from comments. +// ignore_for_file: public_member_api_docs + part of '../../vector_math_64.dart'; /// 4D column vector. class Vector4 implements Vector { - final Float64List _v4storage; - - /// Set the values of [result] to the minimum of [a] and [b] for each line. - static void min(Vector4 a, Vector4 b, Vector4 result) { - result - ..x = math.min(a.x, b.x) - ..y = math.min(a.y, b.y) - ..z = math.min(a.z, b.z) - ..w = math.min(a.w, b.w); - } - - /// Set the values of [result] to the maximum of [a] and [b] for each line. - static void max(Vector4 a, Vector4 b, Vector4 result) { - result - ..x = math.max(a.x, b.x) - ..y = math.max(a.y, b.y) - ..z = math.max(a.z, b.z) - ..w = math.max(a.w, b.w); - } - - /// Interpolate between [min] and [max] with the amount of [a] using a linear - /// interpolation and store the values in [result]. - static void mix(Vector4 min, Vector4 max, double a, Vector4 result) { - result - ..x = min.x + a * (max.x - min.x) - ..y = min.y + a * (max.y - min.y) - ..z = min.z + a * (max.z - min.z) - ..w = min.w + a * (max.w - min.w); - } - - /// The components of the vector. - @override - Float64List get storage => _v4storage; - /// Construct a new vector with the specified values. factory Vector4(double x, double y, double z, double w) => Vector4.zero()..setValues(x, y, z, w); @@ -79,6 +48,39 @@ class Vector4 implements Vector { rng.nextDouble(), ); } + final Float64List _v4storage; + + /// Set the values of [result] to the minimum of [a] and [b] for each line. + static void min(Vector4 a, Vector4 b, Vector4 result) { + result + ..x = math.min(a.x, b.x) + ..y = math.min(a.y, b.y) + ..z = math.min(a.z, b.z) + ..w = math.min(a.w, b.w); + } + + /// Set the values of [result] to the maximum of [a] and [b] for each line. + static void max(Vector4 a, Vector4 b, Vector4 result) { + result + ..x = math.max(a.x, b.x) + ..y = math.max(a.y, b.y) + ..z = math.max(a.z, b.z) + ..w = math.max(a.w, b.w); + } + + /// Interpolate between [min] and [max] with the amount of [a] using a linear + /// interpolation and store the values in [result]. + static void mix(Vector4 min, Vector4 max, double a, Vector4 result) { + result + ..x = min.x + a * (max.x - min.x) + ..y = min.y + a * (max.y - min.y) + ..z = min.z + a * (max.z - min.z) + ..w = min.w + a * (max.w - min.w); + } + + /// The components of the vector. + @override + Float64List get storage => _v4storage; /// Set the values of the vector. void setValues(double x, double y, double z, double w) { @@ -106,7 +108,7 @@ class Vector4 implements Vector { /// Set the values by copying them from [other]. void setFrom(Vector4 other) { - final otherStorage = other._v4storage; + final Float64List otherStorage = other._v4storage; _v4storage[3] = otherStorage[3]; _v4storage[2] = otherStorage[2]; _v4storage[1] = otherStorage[1]; @@ -129,6 +131,7 @@ class Vector4 implements Vector { /// Check if two vectors are the same. @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes bool operator ==(Object other) => (other is Vector4) && (_v4storage[3] == other._v4storage[3]) && @@ -137,6 +140,7 @@ class Vector4 implements Vector { (_v4storage[0] == other._v4storage[0]); @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes int get hashCode => Object.hashAll(_v4storage); /// Negate. @@ -168,7 +172,7 @@ class Vector4 implements Vector { if (value == 0.0) { setZero(); } else { - var l = length; + double l = length; if (l == 0.0) { return; } @@ -192,11 +196,11 @@ class Vector4 implements Vector { /// Normalizes this. double normalize() { - final l = length; + final double l = length; if (l == 0.0) { return 0.0; } - final d = 1.0 / l; + final double d = 1.0 / l; _v4storage[3] *= d; _v4storage[2] *= d; _v4storage[1] *= d; @@ -224,18 +228,18 @@ class Vector4 implements Vector { /// Squared distance from this to [arg] double distanceToSquared(Vector4 arg) { - final argStorage = arg._v4storage; - final dw = _v4storage[3] - argStorage[3]; - final dz = _v4storage[2] - argStorage[2]; - final dy = _v4storage[1] - argStorage[1]; - final dx = _v4storage[0] - argStorage[0]; + final Float64List argStorage = arg._v4storage; + final double dw = _v4storage[3] - argStorage[3]; + final double dz = _v4storage[2] - argStorage[2]; + final double dy = _v4storage[1] - argStorage[1]; + final double dx = _v4storage[0] - argStorage[0]; return dx * dx + dy * dy + dz * dz + dw * dw; } /// Inner product. double dot(Vector4 other) { - final otherStorage = other._v4storage; + final Float64List otherStorage = other._v4storage; return _v4storage[3] * otherStorage[3] + _v4storage[2] * otherStorage[2] + _v4storage[1] * otherStorage[1] + @@ -244,11 +248,11 @@ class Vector4 implements Vector { /// Multiplies this by [arg]. void applyMatrix4(Matrix4 arg) { - final v4 = _v4storage[3]; - final v3 = _v4storage[2]; - final v2 = _v4storage[1]; - final v1 = _v4storage[0]; - final argStorage = arg._m4storage; + final double v4 = _v4storage[3]; + final double v3 = _v4storage[2]; + final double v2 = _v4storage[1]; + final double v1 = _v4storage[0]; + final Float64List argStorage = arg._m4storage; _v4storage[3] = argStorage[3] * v1 + argStorage[7] * v2 + @@ -277,10 +281,10 @@ class Vector4 implements Vector { /// Absolute error between this and [correct] double absoluteError(Vector4 correct) { - final wDiff = _v4storage[3] - correct._v4storage[3]; - final zDiff = _v4storage[2] - correct._v4storage[2]; - final yDiff = _v4storage[1] - correct._v4storage[1]; - final xDiff = _v4storage[0] - correct._v4storage[0]; + final double wDiff = _v4storage[3] - correct._v4storage[3]; + final double zDiff = _v4storage[2] - correct._v4storage[2]; + final double yDiff = _v4storage[1] - correct._v4storage[1]; + final double xDiff = _v4storage[0] - correct._v4storage[0]; return math.sqrt( xDiff * xDiff + yDiff * yDiff + zDiff * zDiff + wDiff * wDiff, ); @@ -301,7 +305,7 @@ class Vector4 implements Vector { _v4storage[0].isNaN; void add(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] += argStorage[3]; _v4storage[2] += argStorage[2]; _v4storage[1] += argStorage[1]; @@ -310,7 +314,7 @@ class Vector4 implements Vector { /// Add [arg] scaled by [factor] to this. void addScaled(Vector4 arg, double factor) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] += argStorage[3] * factor; _v4storage[2] += argStorage[2] * factor; _v4storage[1] += argStorage[1] * factor; @@ -319,7 +323,7 @@ class Vector4 implements Vector { /// Subtract [arg] from this. void sub(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] -= argStorage[3]; _v4storage[2] -= argStorage[2]; _v4storage[1] -= argStorage[1]; @@ -328,7 +332,7 @@ class Vector4 implements Vector { /// Multiply this by [arg]. void multiply(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] *= argStorage[3]; _v4storage[2] *= argStorage[2]; _v4storage[1] *= argStorage[1]; @@ -337,7 +341,7 @@ class Vector4 implements Vector { /// Divide this by [arg]. void div(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] /= argStorage[3]; _v4storage[2] /= argStorage[2]; _v4storage[1] /= argStorage[1]; @@ -373,28 +377,20 @@ class Vector4 implements Vector { /// Clamp each entry `n` in this in the range `[min[n]]-[max[n]]`. void clamp(Vector4 min, Vector4 max) { - final minStorage = min.storage; - final maxStorage = max.storage; - _v4storage[3] = _v4storage[3] - .clamp(minStorage[3], maxStorage[3]) - .toDouble(); - _v4storage[2] = _v4storage[2] - .clamp(minStorage[2], maxStorage[2]) - .toDouble(); - _v4storage[1] = _v4storage[1] - .clamp(minStorage[1], maxStorage[1]) - .toDouble(); - _v4storage[0] = _v4storage[0] - .clamp(minStorage[0], maxStorage[0]) - .toDouble(); + final Float64List minStorage = min.storage; + final Float64List maxStorage = max.storage; + _v4storage[3] = _v4storage[3].clamp(minStorage[3], maxStorage[3]); + _v4storage[2] = _v4storage[2].clamp(minStorage[2], maxStorage[2]); + _v4storage[1] = _v4storage[1].clamp(minStorage[1], maxStorage[1]); + _v4storage[0] = _v4storage[0].clamp(minStorage[0], maxStorage[0]); } /// Clamp entries in this in the range [min]-[max]. void clampScalar(double min, double max) { - _v4storage[3] = _v4storage[3].clamp(min, max).toDouble(); - _v4storage[2] = _v4storage[2].clamp(min, max).toDouble(); - _v4storage[1] = _v4storage[1].clamp(min, max).toDouble(); - _v4storage[0] = _v4storage[0].clamp(min, max).toDouble(); + _v4storage[3] = _v4storage[3].clamp(min, max); + _v4storage[2] = _v4storage[2].clamp(min, max); + _v4storage[1] = _v4storage[1].clamp(min, max); + _v4storage[0] = _v4storage[0].clamp(min, max); } /// Floor entries in this. @@ -423,18 +419,22 @@ 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. @@ -442,7 +442,7 @@ class Vector4 implements Vector { /// Copy this Vector4 copyInto(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; argStorage[3] = _v4storage[3]; argStorage[2] = _v4storage[2]; argStorage[1] = _v4storage[1]; @@ -467,247 +467,247 @@ class Vector4 implements Vector { } set xy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[2] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xw(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[3] = argStorage[1]; _v4storage[0] = argStorage[0]; } set yx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[1]; } set yz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; } set yw(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[0]; } set zx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[1]; } set zy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; } set zw(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[2] = argStorage[0]; _v4storage[3] = argStorage[1]; } set wx(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[1]; } set wy(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[1]; } set wz(Vector2 arg) { - final argStorage = arg._v2storage; + final Float64List argStorage = arg._v2storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[1]; } set xyz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xyw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xzy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[2]; _v4storage[0] = argStorage[0]; } set xzw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[0] = argStorage[0]; } set xwy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[2]; _v4storage[0] = argStorage[0]; } set xwz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[2]; _v4storage[0] = argStorage[0]; } set yxz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[1]; } set yxw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[1]; } set yzx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[1] = argStorage[0]; _v4storage[2] = argStorage[1]; _v4storage[0] = argStorage[2]; } set yzw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; } set ywx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[0]; _v4storage[0] = argStorage[2]; } set ywz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[0]; } set zxy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[1]; _v4storage[1] = argStorage[2]; } set zxw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[1]; } set zyx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; _v4storage[0] = argStorage[2]; } set zyw(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; } set zwx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[0]; _v4storage[0] = argStorage[2]; } set zwy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[2]; } set wxy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[2]; _v4storage[0] = argStorage[1]; } set wxz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[2]; _v4storage[0] = argStorage[1]; } set wyx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[2]; _v4storage[1] = argStorage[1]; } set wyz(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[1]; } set wzx(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[2]; _v4storage[2] = argStorage[1]; } set wzy(Vector3 arg) { - final argStorage = arg._v3storage; + final Float64List argStorage = arg._v3storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[2]; _v4storage[2] = argStorage[1]; } set xyzw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[1]; @@ -715,7 +715,7 @@ class Vector4 implements Vector { } set xywz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[1]; @@ -723,7 +723,7 @@ class Vector4 implements Vector { } set xzyw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[2]; @@ -731,7 +731,7 @@ class Vector4 implements Vector { } set xzwy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[3]; @@ -739,7 +739,7 @@ class Vector4 implements Vector { } set xwyz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[2]; @@ -747,7 +747,7 @@ class Vector4 implements Vector { } set xwzy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[3]; @@ -755,7 +755,7 @@ class Vector4 implements Vector { } set yxzw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[2]; _v4storage[1] = argStorage[0]; @@ -763,7 +763,7 @@ class Vector4 implements Vector { } set yxwz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[0]; @@ -771,7 +771,7 @@ class Vector4 implements Vector { } set yzxw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; @@ -779,7 +779,7 @@ class Vector4 implements Vector { } set yzwx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[2] = argStorage[1]; _v4storage[1] = argStorage[0]; @@ -787,7 +787,7 @@ class Vector4 implements Vector { } set ywxz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[0]; @@ -795,7 +795,7 @@ class Vector4 implements Vector { } set ywzx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[2]; @@ -803,7 +803,7 @@ class Vector4 implements Vector { } set zxyw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[2]; @@ -811,7 +811,7 @@ class Vector4 implements Vector { } set zxwy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -819,7 +819,7 @@ class Vector4 implements Vector { } set zyxw(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[3]; _v4storage[2] = argStorage[0]; _v4storage[1] = argStorage[1]; @@ -827,7 +827,7 @@ class Vector4 implements Vector { } set zywx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[2]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -835,7 +835,7 @@ class Vector4 implements Vector { } set zwxy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -843,7 +843,7 @@ class Vector4 implements Vector { } set zwyx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[1]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[0]; @@ -851,7 +851,7 @@ class Vector4 implements Vector { } set wxyz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[2]; @@ -859,7 +859,7 @@ class Vector4 implements Vector { } set wxzy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[2]; @@ -867,7 +867,7 @@ class Vector4 implements Vector { } set wyxz(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[2] = argStorage[3]; _v4storage[1] = argStorage[1]; @@ -875,7 +875,7 @@ class Vector4 implements Vector { } set wyzx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[3]; _v4storage[2] = argStorage[2]; @@ -883,7 +883,7 @@ class Vector4 implements Vector { } set wzxy(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[1] = argStorage[3]; _v4storage[2] = argStorage[1]; @@ -891,7 +891,7 @@ class Vector4 implements Vector { } set wzyx(Vector4 arg) { - final argStorage = arg._v4storage; + final Float64List argStorage = arg._v4storage; _v4storage[3] = argStorage[0]; _v4storage[0] = argStorage[3]; _v4storage[1] = argStorage[2]; diff --git a/packages/vector_math/lib/src/vector_math_geometry/filters/barycentric_filter.dart b/packages/vector_math/lib/src/vector_math_geometry/filters/barycentric_filter.dart index f9a2e77..c2f1fe6 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/filters/barycentric_filter.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/filters/barycentric_filter.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class BarycentricFilter extends GeometryFilter { @@ -21,7 +25,7 @@ class BarycentricFilter extends GeometryFilter { final output = MeshGeometry(mesh.triangleVertexCount, newAttribs); Vector3List barycentricCoords; - final view = output.getViewForAttrib('BARYCENTRIC'); + final VectorList? view = output.getViewForAttrib('BARYCENTRIC'); if (view is Vector3List) { barycentricCoords = view; } else { @@ -30,7 +34,7 @@ class BarycentricFilter extends GeometryFilter { final srcAttribs = >[]; final destAttribs = >[]; - for (var attrib in mesh.attribs) { + for (final VertexAttrib attrib in mesh.attribs) { if (attrib.name == 'BARYCENTRIC') { continue; } diff --git a/packages/vector_math/lib/src/vector_math_geometry/filters/color_filter.dart b/packages/vector_math/lib/src/vector_math_geometry/filters/color_filter.dart index 9a76ddb..1de0da4 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/filters/color_filter.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/filters/color_filter.dart @@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class ColorFilter extends GeometryFilter { - Vector4 color; - ColorFilter(this.color); + Vector4 color; @override List get generates => [ @@ -27,7 +30,7 @@ class ColorFilter extends GeometryFilter { output = MeshGeometry.copy(mesh); } - final colors = output.getViewForAttrib('COLOR'); + final VectorList? colors = output.getViewForAttrib('COLOR'); if (colors is Vector4List) { for (var i = 0; i < colors.length; ++i) { colors[i] = color; diff --git a/packages/vector_math/lib/src/vector_math_geometry/filters/flat_shade_filter.dart b/packages/vector_math/lib/src/vector_math_geometry/filters/flat_shade_filter.dart index ec5f37e..c21478b 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/filters/flat_shade_filter.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/filters/flat_shade_filter.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class FlatShadeFilter extends GeometryFilter { @@ -27,9 +31,11 @@ class FlatShadeFilter extends GeometryFilter { final p0 = Vector3.zero(), p1 = Vector3.zero(), p2 = Vector3.zero(); - final srcPosition = mesh.getViewForAttrib('POSITION'); - final destPosition = output.getViewForAttrib('POSITION'); - final normals = output.getViewForAttrib('NORMAL'); + final VectorList? srcPosition = mesh.getViewForAttrib('POSITION'); + final VectorList? destPosition = output.getViewForAttrib( + 'POSITION', + ); + final VectorList? normals = output.getViewForAttrib('NORMAL'); if (srcPosition is! Vector3List || destPosition is! Vector3List || @@ -39,7 +45,7 @@ class FlatShadeFilter extends GeometryFilter { final srcAttribs = >[]; final destAttribs = >[]; - for (var attrib in mesh.attribs) { + for (final VertexAttrib attrib in mesh.attribs) { if (attrib.name == 'POSITION' || attrib.name == 'NORMAL') { continue; } @@ -49,9 +55,9 @@ class FlatShadeFilter extends GeometryFilter { } for (var i = 0; i < output.length; i += 3) { - final i0 = mesh.indices![i]; - final i1 = mesh.indices![i + 1]; - final i2 = mesh.indices![i + 2]; + final int i0 = mesh.indices![i]; + final int i1 = mesh.indices![i + 1]; + final int i2 = mesh.indices![i + 2]; srcPosition ..load(i0, p0) diff --git a/packages/vector_math/lib/src/vector_math_geometry/filters/geometry_filter.dart b/packages/vector_math/lib/src/vector_math_geometry/filters/geometry_filter.dart index b36fd6e..b9a6030 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/filters/geometry_filter.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/filters/geometry_filter.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; abstract class GeometryFilter { diff --git a/packages/vector_math/lib/src/vector_math_geometry/filters/invert_filter.dart b/packages/vector_math/lib/src/vector_math_geometry/filters/invert_filter.dart index 9b6a2e7..8237fbf 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/filters/invert_filter.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/filters/invert_filter.dart @@ -2,25 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class InvertFilter extends InplaceGeometryFilter { @override void filterInplace(MeshGeometry mesh) { - // TODO: Do the tangents need to be inverted? Maybe just the W component? - // TODO: Should modify in-place be allowed, or should it be required + // TODO(toji): Do the tangents need to be inverted? Maybe just the W component? + // TODO(toji): Should modify in-place be allowed, or should it be required // to return a new geometry? // Swap all the triangle indices - final indicies = mesh.indices!; + final Uint16List indicies = mesh.indices!; for (var i = 0; i < indicies.length; i += 3) { - final tmp = indicies[i]; + final int tmp = indicies[i]; indicies[i] = indicies[i + 2]; indicies[i + 2] = tmp; } - final normals = mesh.getViewForAttrib('NORMAL'); + final VectorList? normals = mesh.getViewForAttrib('NORMAL'); if (normals is Vector3List) { for (var i = 0; i < normals.length; ++i) { normals[i] = -normals[i]; diff --git a/packages/vector_math/lib/src/vector_math_geometry/filters/transform_filter.dart b/packages/vector_math/lib/src/vector_math_geometry/filters/transform_filter.dart index fb59ac4..5535f55 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/filters/transform_filter.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/filters/transform_filter.dart @@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class TransformFilter extends InplaceGeometryFilter { - Matrix4 transform; - TransformFilter(this.transform); + Matrix4 transform; @override List get requires => [ @@ -16,7 +19,7 @@ class TransformFilter extends InplaceGeometryFilter { @override void filterInplace(MeshGeometry mesh) { - final position = mesh.getViewForAttrib('POSITION'); + final VectorList? position = mesh.getViewForAttrib('POSITION'); if (position is Vector3List) { for (var i = 0; i < position.length; ++i) { // multiplication always returns Vector3 here diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/attribute_generators.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/attribute_generators.dart index 0da8286..c43a263 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/attribute_generators.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/attribute_generators.dart @@ -20,7 +20,7 @@ void generateNormals( // Loop through every polygon, find it's normal, and add that to the vertex // normals. for (var i = 0; i < indices.length; i += 3) { - final i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2]; + final int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2]; positions ..load(i0, p0) ..load(i1, p1) @@ -84,7 +84,7 @@ void generateTangents( tan1 = Vector3List(positions.length); for (var i = 0; i < indices.length; i += 3) { - final i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2]; + final int i0 = indices[i], i1 = indices[i + 1], i2 = indices[i + 2]; positions ..load(i0, p0) ..load(i1, p1) @@ -101,7 +101,7 @@ void generateTangents( uv1.sub(uv0); uv2.sub(uv0); - final r = 1.0 / (uv1.x * uv2.y - uv2.x * uv1.y); + final double r = 1.0 / (uv1.x * uv2.y - uv2.x * uv1.y); udir.setValues( (uv2.y * p1.x - uv1.y * p2.x) * r, diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/circle_generator.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/circle_generator.dart index 427983d..11dae4a 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/circle_generator.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/circle_generator.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class CircleGenerator extends GeometryGenerator { @@ -37,7 +41,7 @@ class CircleGenerator extends GeometryGenerator { positions[0] = v; var index = 1; for (var i = 0; i <= _segments; i++) { - final percent = i / _segments; + final double percent = i / _segments; v ..x = _radius * math.cos(_thetaStart + percent * _thetaLength) ..z = _radius * math.sin(_thetaStart + percent * _thetaLength); @@ -57,9 +61,9 @@ class CircleGenerator extends GeometryGenerator { texCoords[0] = v; var index = 1; for (var i = 0; i <= _segments; i++) { - final position = positions[index]; - final x = (position.x / (_radius + 1.0)) * 0.5; - final y = (position.z / (_radius + 1.0)) * 0.5; + final Vector3 position = positions[index]; + final double x = (position.x / (_radius + 1.0)) * 0.5; + final double y = (position.z / (_radius + 1.0)) * 0.5; v ..x = x + 0.5 ..y = y + 0.5; diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/cube_generator.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/cube_generator.dart index dee9b4d..e99a602 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/cube_generator.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/cube_generator.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class CubeGenerator extends GeometryGenerator { diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/cylinder_generator.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/cylinder_generator.dart index 39a61b7..0088b6e 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/cylinder_generator.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/cylinder_generator.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class CylinderGenerator extends GeometryGenerator { @@ -38,7 +42,7 @@ class CylinderGenerator extends GeometryGenerator { // Sides var base1 = 0; - final base2 = _segments + 1; + final int base2 = _segments + 1; for (var x = 0; x < _segments; ++x) { indices[i++] = base1 + x; indices[i++] = base1 + x + 1; @@ -72,7 +76,7 @@ class CylinderGenerator extends GeometryGenerator { // Top for (var x = 0; x <= _segments; ++x) { - final u = x / _segments; + final double u = x / _segments; positions[i++] = Vector3( _topRadius * math.cos(u * math.pi * 2.0), @@ -83,7 +87,7 @@ class CylinderGenerator extends GeometryGenerator { // Bottom for (var x = 0; x <= _segments; ++x) { - final u = x / _segments; + final double u = x / _segments; positions[i++] = Vector3( _bottomRadius * math.cos(u * math.pi * 2.0), @@ -94,7 +98,7 @@ class CylinderGenerator extends GeometryGenerator { // Top cap for (var x = 0; x < _segments; ++x) { - final u = x / _segments; + final double u = x / _segments; positions[i++] = Vector3( _topRadius * math.cos(u * math.pi * 2.0), @@ -105,7 +109,7 @@ class CylinderGenerator extends GeometryGenerator { // Bottom cap for (var x = 0; x < _segments; ++x) { - final u = x / _segments; + final double u = x / _segments; positions[i++] = Vector3( _bottomRadius * math.cos(u * math.pi * 2.0), @@ -125,19 +129,19 @@ class CylinderGenerator extends GeometryGenerator { // Cylinder top for (var x = 0; x <= _segments; ++x) { - final u = 1.0 - (x / _segments); + final double u = 1.0 - (x / _segments); texCoords[i++] = Vector2(u, 0.0); } // Cylinder bottom for (var x = 0; x <= _segments; ++x) { - final u = 1.0 - (x / _segments); + final double u = 1.0 - (x / _segments); texCoords[i++] = Vector2(u, 1.0); } // Top cap for (var x = 0; x < _segments; ++x) { - final r = (x / _segments) * math.pi * 2.0; + final double r = (x / _segments) * math.pi * 2.0; texCoords[i++] = Vector2( math.cos(r) * 0.5 + 0.5, math.sin(r) * 0.5 + 0.5, @@ -146,7 +150,7 @@ class CylinderGenerator extends GeometryGenerator { // Bottom cap for (var x = 0; x < _segments; ++x) { - final r = (x / _segments) * math.pi * 2.0; + final double r = (x / _segments) * math.pi * 2.0; texCoords[i++] = Vector2( math.cos(r) * 0.5 + 0.5, math.sin(r) * 0.5 + 0.5, diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/geometry_generator.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/geometry_generator.dart index 7bd8963..397c5cb 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/geometry_generator.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/geometry_generator.dart @@ -2,18 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class GeometryGeneratorFlags { - final bool texCoords; - final bool normals; - final bool tangents; - GeometryGeneratorFlags({ this.texCoords = true, this.normals = true, this.tangents = true, }); + final bool texCoords; + final bool normals; + final bool tangents; } abstract class GeometryGenerator { @@ -60,7 +63,7 @@ abstract class GeometryGenerator { ..indices = Uint16List(indexCount); generateIndices(mesh.indices!); - var view = mesh.getViewForAttrib('POSITION'); + VectorList? view = mesh.getViewForAttrib('POSITION'); if (view is Vector3List) { positionView = view; generateVertexPositions(positionView, mesh.indices!); @@ -97,7 +100,7 @@ abstract class GeometryGenerator { } if (filters != null) { - for (var filter in filters) { + for (final GeometryFilter filter in filters) { if (filter.inplace && filter is InplaceGeometryFilter) { filter.filterInplace(mesh); } else { @@ -119,7 +122,7 @@ abstract class GeometryGenerator { Uint16List indices, ) { for (var i = 0; i < positions.length; ++i) { - final p = positions[i]; + final Vector3 p = positions[i]; // These are TERRIBLE texture coords, but it's better than nothing. // Override this function and put better ones in place! diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/ring_generator.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/ring_generator.dart index 442957b..6211e3d 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/ring_generator.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/ring_generator.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class RingGenerator extends GeometryGenerator { @@ -42,7 +46,7 @@ class RingGenerator extends GeometryGenerator { final v = Vector3.zero(); var index = 0; for (var i = 0; i <= _segments; i++) { - final percent = i / _segments; + final double percent = i / _segments; v ..x = _innerRadius * math.cos(_thetaStart + percent * _thetaLength) ..z = _innerRadius * math.sin(_thetaStart + percent * _thetaLength); @@ -67,7 +71,7 @@ class RingGenerator extends GeometryGenerator { final v = Vector2.zero(); var index = 0; for (var i = 0; i <= _segments; i++) { - final percent = i / _segments; + final double percent = i / _segments; v ..x = 0.0 ..y = percent; @@ -83,9 +87,9 @@ class RingGenerator extends GeometryGenerator { final v = Vector2.zero(); var index = 0; for (var i = 0; i <= _segments; i++) { - var position = positions[index]; - var x = (position.x / (_outerRadius + 1.0)) * 0.5; - var y = (position.z / (_outerRadius + 1.0)) * 0.5; + Vector3 position = positions[index]; + double x = (position.x / (_outerRadius + 1.0)) * 0.5; + double y = (position.z / (_outerRadius + 1.0)) * 0.5; v ..x = x + 0.5 ..y = y + 0.5; @@ -107,7 +111,7 @@ class RingGenerator extends GeometryGenerator { @override void generateIndices(Uint16List indices) { var index = 0; - final length = _segments * 2; + final int length = _segments * 2; for (var i = 0; i < length; i += 2) { indices[index + 0] = i + 0; indices[index + 1] = i + 1; diff --git a/packages/vector_math/lib/src/vector_math_geometry/generators/sphere_generator.dart b/packages/vector_math/lib/src/vector_math_geometry/generators/sphere_generator.dart index 61ad85f..3f3bc01 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/generators/sphere_generator.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/generators/sphere_generator.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../../vector_math_geometry.dart'; class SphereGenerator extends GeometryGenerator { @@ -33,8 +37,8 @@ class SphereGenerator extends GeometryGenerator { void generateIndices(Uint16List indices) { var i = 0; for (var y = 0; y < _latSegments; ++y) { - final base1 = (_lonSegments + 1) * y; - final base2 = (_lonSegments + 1) * (y + 1); + final int base1 = (_lonSegments + 1) * y; + final int base2 = (_lonSegments + 1) * (y + 1); for (var x = 0; x < _lonSegments; ++x) { indices[i++] = base1 + x; @@ -52,12 +56,12 @@ class SphereGenerator extends GeometryGenerator { void generateVertexPositions(Vector3List positions, Uint16List indices) { var i = 0; for (var y = 0; y <= _latSegments; ++y) { - final v = y / _latSegments; - final sv = math.sin(v * math.pi); - final cv = math.cos(v * math.pi); + final double v = y / _latSegments; + final double sv = math.sin(v * math.pi); + final double cv = math.cos(v * math.pi); for (var x = 0; x <= _lonSegments; ++x) { - final u = x / _lonSegments; + final double u = x / _lonSegments; positions[i++] = Vector3( _radius * math.cos(u * math.pi * 2.0) * sv, @@ -76,10 +80,10 @@ class SphereGenerator extends GeometryGenerator { ) { var i = 0; for (var y = 0; y <= _latSegments; ++y) { - final v = y / _latSegments; + final double v = y / _latSegments; for (var x = 0; x <= _lonSegments; ++x) { - final u = x / _lonSegments; + final double u = x / _lonSegments; texCoords[i++] = Vector2(u, v); } } @@ -93,12 +97,12 @@ class SphereGenerator extends GeometryGenerator { ) { var i = 0; for (var y = 0; y <= _latSegments; ++y) { - final v = y / _latSegments; - final sv = math.sin(v * math.pi); - final cv = math.cos(v * math.pi); + final double v = y / _latSegments; + final double sv = math.sin(v * math.pi); + final double cv = math.cos(v * math.pi); for (var x = 0; x <= _lonSegments; ++x) { - final u = x / _lonSegments; + final double u = x / _lonSegments; normals[i++] = Vector3( math.cos(u * math.pi * 2.0) * sv, diff --git a/packages/vector_math/lib/src/vector_math_geometry/mesh_geometry.dart b/packages/vector_math/lib/src/vector_math_geometry/mesh_geometry.dart index 2519085..69588ee 100644 --- a/packages/vector_math/lib/src/vector_math_geometry/mesh_geometry.dart +++ b/packages/vector_math/lib/src/vector_math_geometry/mesh_geometry.dart @@ -2,15 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math_geometry.dart'; class VertexAttrib { - final String name; - final String type; - final int size; - final int stride; - final int offset; - VertexAttrib(this.name, this.size, this.type) : stride = 0, offset = 0; VertexAttrib.copy(VertexAttrib attrib) @@ -32,10 +30,15 @@ class VertexAttrib { : name = attrib.name, size = attrib.size, type = attrib.type; + final String name; + final String type; + final int size; + final int stride; + final int offset; VectorList getView(Float32List buffer) { - final viewOffset = offset ~/ buffer.elementSizeInBytes; - final viewStride = stride ~/ buffer.elementSizeInBytes; + final int viewOffset = offset ~/ buffer.elementSizeInBytes; + final int viewStride = stride ~/ buffer.elementSizeInBytes; switch (size) { case 2: return Vector2List.view(buffer, viewOffset, viewStride); @@ -75,20 +78,14 @@ class VertexAttrib { } class MeshGeometry { - late final Float32List buffer; - Uint16List? indices; - final List attribs; - final int length; - final int stride; - factory MeshGeometry(int length, List attributes) { var stride = 0; - for (var a in attributes) { + for (final a in attributes) { stride += a.elementSize * a.size; } var offset = 0; final attribs = []; - for (var a in attributes) { + for (final a in attributes) { attribs.add(VertexAttrib._resetStrideOffset(a, stride, offset)); offset += a.elementSize * a.size; } @@ -123,7 +120,7 @@ class MeshGeometry { factory MeshGeometry.fromJson(Map json) { Float32List buffer; - final jsonBuffer = json['buffer']; + final Object? jsonBuffer = json['buffer']; if (jsonBuffer is List) { buffer = Float32List.fromList(jsonBuffer); } else { @@ -134,7 +131,7 @@ class MeshGeometry { ); } - final jsonAttribs = json['attribs']; + final Object? jsonAttribs = json['attribs']; Map jsonAttribsMap; if (jsonAttribs is Map) { jsonAttribsMap = jsonAttribs; @@ -147,9 +144,9 @@ class MeshGeometry { } final attribs = []; var stride = 0; - for (var key in jsonAttribsMap.keys) { + for (final String key in jsonAttribsMap.keys) { VertexAttrib attrib; - final jsonAttrib = jsonAttribsMap[key]; + final Object? jsonAttrib = jsonAttribsMap[key]; if (jsonAttrib is Map) { attrib = attribFromJson(key, jsonAttrib); attribs.add(attrib); @@ -166,7 +163,7 @@ class MeshGeometry { buffer, ); - final jsonIndices = json['indices']; + final Object? jsonIndices = json['indices']; if (jsonIndices is List) { mesh.indices = Uint16List.fromList(jsonIndices); } @@ -182,8 +179,8 @@ class MeshGeometry { ..indices = inputMesh.indices; // Copy over the attributes that were specified - for (var attrib in mesh.attribs) { - final inputAttrib = inputMesh.getAttrib(attrib.name); + for (final VertexAttrib attrib in mesh.attribs) { + final VertexAttrib? inputAttrib = inputMesh.getAttrib(attrib.name); if (inputAttrib != null) { if (inputAttrib.size != attrib.size || inputAttrib.type != attrib.type) { @@ -192,7 +189,9 @@ class MeshGeometry { ); } - final inputView = inputAttrib.getView(inputMesh.buffer); + final VectorList inputView = inputAttrib.getView( + inputMesh.buffer, + ); // Copy [inputView] to a view from attrib attrib.getView(mesh.buffer).copy(inputView); @@ -210,13 +209,12 @@ class MeshGeometry { } // When combining meshes they must all have a matching set of VertexAttribs - final firstMesh = meshes[0]; - var totalVerts = firstMesh.length; - var totalIndices = firstMesh.indices != null - ? firstMesh.indices!.length - : 0; + final MeshGeometry firstMesh = meshes[0]; + int totalVerts = firstMesh.length; + int totalIndices = + firstMesh.indices != null ? firstMesh.indices!.length : 0; for (var i = 1; i < meshes.length; ++i) { - final srcMesh = meshes[i]; + final MeshGeometry srcMesh = meshes[i]; if (!firstMesh.attribsAreCompatible(srcMesh)) { throw Exception( 'All meshes must have identical attributes to combine.', @@ -241,7 +239,7 @@ class MeshGeometry { var indexOffset = 0; var vertexOffset = 0; for (var i = 0; i < meshes.length; ++i) { - final srcMesh = meshes[i]; + final MeshGeometry srcMesh = meshes[i]; mesh.buffer.setAll(bufferOffset, srcMesh.buffer); if (totalIndices > 0) { @@ -257,6 +255,11 @@ class MeshGeometry { return mesh; } + late final Float32List buffer; + Uint16List? indices; + final List attribs; + final int length; + final int stride; int get triangleVertexCount => indices != null ? indices!.length : length; @@ -269,10 +272,10 @@ class MeshGeometry { } static VertexAttrib attribFromJson(String name, Map json) { - final jsonSize = json['size']; - final jsonType = json['type']; - final jsonStride = json['stride']; - final jsonOffset = json['offset']; + final Object? jsonSize = json['size']; + final Object? jsonType = json['type']; + final Object? jsonStride = json['stride']; + final Object? jsonOffset = json['offset']; if (jsonSize is int && jsonType is String && jsonStride is int && @@ -290,7 +293,7 @@ class MeshGeometry { } VertexAttrib? getAttrib(String name) { - for (var attrib in attribs) { + for (final VertexAttrib attrib in attribs) { if (attrib.name == name) { return attrib; } @@ -299,7 +302,7 @@ class MeshGeometry { } VectorList? getViewForAttrib(String name) { - for (var attrib in attribs) { + for (final VertexAttrib attrib in attribs) { if (attrib.name == name) { return attrib.getView(buffer); } @@ -312,8 +315,8 @@ class MeshGeometry { return false; } - for (var attrib in attribs) { - final otherAttrib = mesh.getAttrib(attrib.name); + for (final VertexAttrib attrib in attribs) { + final VertexAttrib? otherAttrib = mesh.getAttrib(attrib.name); if (otherAttrib == null) { return false; } diff --git a/packages/vector_math/lib/src/vector_math_lists/scalar_list_view.dart b/packages/vector_math/lib/src/vector_math_lists/scalar_list_view.dart index b33662e..ff3f1b3 100644 --- a/packages/vector_math/lib/src/vector_math_lists/scalar_list_view.dart +++ b/packages/vector_math/lib/src/vector_math_lists/scalar_list_view.dart @@ -7,22 +7,6 @@ part of '../../vector_math_lists.dart'; /// Defines a view of scalar values over a [Float32List] that allows for a /// custom offset and stride. class ScalarListView { - final int _offset; - final int _stride; - final int _length; - final Float32List _buffer; - - /// The count of vectors in this list. - int get length => _length; - - /// The internal storage buffer of this list. - Float32List get buffer => _buffer; - - static int _listLength(int offset, int stride, int length) { - final width = stride == 0 ? 1 : stride; - return offset + width * length; - } - /// Create a new vector list with [length] elements. /// /// Optionally it is possible to specify an [offset] in the @@ -56,6 +40,21 @@ class ScalarListView { (buffer.length - math.max(0, offset - stride)) ~/ (stride == 0 ? 1 : stride), _buffer = buffer; + final int _offset; + final int _stride; + final int _length; + final Float32List _buffer; + + /// The count of vectors in this list. + int get length => _length; + + /// The internal storage buffer of this list. + Float32List get buffer => _buffer; + + static int _listLength(int offset, int stride, int length) { + final width = stride == 0 ? 1 : stride; + return offset + width * length; + } int _elementIndexToBufferIndex(int index) => _offset + _stride * index; @@ -69,7 +68,7 @@ class ScalarListView { /// Store [value] in the list at [index]. void store(int index, double value) { - final i = _elementIndexToBufferIndex(index); + final int i = _elementIndexToBufferIndex(index); _buffer[i] = value; } diff --git a/packages/vector_math/lib/src/vector_math_lists/vector2_list.dart b/packages/vector_math/lib/src/vector_math_lists/vector2_list.dart index d219b8c..1189e12 100644 --- a/packages/vector_math/lib/src/vector_math_lists/vector2_list.dart +++ b/packages/vector_math/lib/src/vector_math_lists/vector2_list.dart @@ -27,7 +27,7 @@ class Vector2List extends VectorList { /// Retrieves the vector at [index] and stores it in [vector]. @override void load(int index, Vector2 vector) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); vector.storage[0] = _buffer[i + 0]; vector.storage[1] = _buffer[i + 1]; } @@ -35,8 +35,8 @@ class Vector2List extends VectorList { /// Store [vector] in the list at [index]. @override void store(int index, Vector2 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; _buffer[i + 0] = storage[0]; _buffer[i + 1] = storage[1]; } @@ -46,46 +46,46 @@ class Vector2List extends VectorList { /// Set the vector at [index] to [x] and [y]. void setValues(int index, double x, double y) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); buffer[i + 0] = x; buffer[i + 1] = y; } /// Add [vector] to the vector at [index]. void add(int index, Vector2 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] += storage[0]; buffer[i + 1] += storage[1]; } /// Add [vector] scaled by [factor] to the vector at [index]. void addScaled(int index, Vector2 vector, double factor) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] += storage[0] * factor; buffer[i + 1] += storage[1] * factor; } /// Substract [vector] from the vector at [index]. void sub(int index, Vector2 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] -= storage[0]; buffer[i + 1] -= storage[1]; } /// Multiply the vector at [index] by [vector]. void multiply(int index, Vector2 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] *= storage[0]; buffer[i + 1] *= storage[1]; } /// Scale the vector at [index] by [factor]. void scale(int index, double factor) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); buffer[i + 0] *= factor; buffer[i + 1] *= factor; } diff --git a/packages/vector_math/lib/src/vector_math_lists/vector3_list.dart b/packages/vector_math/lib/src/vector_math_lists/vector3_list.dart index 5bc0467..3db0e7a 100644 --- a/packages/vector_math/lib/src/vector_math_lists/vector3_list.dart +++ b/packages/vector_math/lib/src/vector_math_lists/vector3_list.dart @@ -27,7 +27,7 @@ class Vector3List extends VectorList { /// Retrieves the vector at [index] and stores it in [vector]. @override void load(int index, Vector3 vector) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); vector.storage[0] = _buffer[i + 0]; vector.storage[1] = _buffer[i + 1]; vector.storage[2] = _buffer[i + 2]; @@ -36,8 +36,8 @@ class Vector3List extends VectorList { /// Store [vector] in the list at [index]. @override void store(int index, Vector3 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; _buffer[i + 0] = storage[0]; _buffer[i + 1] = storage[1]; _buffer[i + 2] = storage[2]; @@ -48,7 +48,7 @@ class Vector3List extends VectorList { /// Set the vector at [index] to [x], [y], and [z]. void setValues(int index, double x, double y, double z) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); buffer[i + 0] = x; buffer[i + 1] = y; buffer[i + 2] = z; @@ -56,8 +56,8 @@ class Vector3List extends VectorList { /// Add [vector] to the vector at [index]. void add(int index, Vector3 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] += storage[0]; buffer[i + 1] += storage[1]; buffer[i + 2] += storage[2]; @@ -65,8 +65,8 @@ class Vector3List extends VectorList { /// Add [vector] scaled by [factor] to the vector at [index]. void addScaled(int index, Vector3 vector, double factor) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] += storage[0] * factor; buffer[i + 1] += storage[1] * factor; buffer[i + 2] += storage[2] * factor; @@ -74,8 +74,8 @@ class Vector3List extends VectorList { /// Substract [vector] from the vector at [index]. void sub(int index, Vector3 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] -= storage[0]; buffer[i + 1] -= storage[1]; buffer[i + 2] -= storage[2]; @@ -83,8 +83,8 @@ class Vector3List extends VectorList { /// Multiply the vector at [index] by [vector]. void multiply(int index, Vector3 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] *= storage[0]; buffer[i + 1] *= storage[1]; buffer[i + 2] *= storage[2]; @@ -92,7 +92,7 @@ class Vector3List extends VectorList { /// Scale the vector at [index] by [factor]. void scale(int index, double factor) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); buffer[i + 0] *= factor; buffer[i + 1] *= factor; buffer[i + 2] *= factor; diff --git a/packages/vector_math/lib/src/vector_math_lists/vector4_list.dart b/packages/vector_math/lib/src/vector_math_lists/vector4_list.dart index fd4e55d..5772b58 100644 --- a/packages/vector_math/lib/src/vector_math_lists/vector4_list.dart +++ b/packages/vector_math/lib/src/vector_math_lists/vector4_list.dart @@ -27,7 +27,7 @@ class Vector4List extends VectorList { /// Retrieves the vector at [index] and stores it in [vector]. @override void load(int index, Vector4 vector) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); vector.storage[0] = _buffer[i + 0]; vector.storage[1] = _buffer[i + 1]; vector.storage[2] = _buffer[i + 2]; @@ -37,8 +37,8 @@ class Vector4List extends VectorList { /// Store [vector] in the list at [index]. @override void store(int index, Vector4 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; _buffer[i + 0] = storage[0]; _buffer[i + 1] = storage[1]; _buffer[i + 2] = storage[2]; @@ -50,7 +50,7 @@ class Vector4List extends VectorList { /// Set the vector at [index] to [x], [y], [z], and [w]. void setValues(int index, double x, double y, double z, double w) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); buffer[i + 0] = x; buffer[i + 1] = y; buffer[i + 2] = z; @@ -59,8 +59,8 @@ class Vector4List extends VectorList { /// Add [vector] to the vector at [index]. void add(int index, Vector4 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] += storage[0]; buffer[i + 1] += storage[1]; buffer[i + 2] += storage[2]; @@ -69,8 +69,8 @@ class Vector4List extends VectorList { /// Add [vector] scaled by [factor] to the vector at [index]. void addScaled(int index, Vector4 vector, double factor) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] += storage[0] * factor; buffer[i + 1] += storage[1] * factor; buffer[i + 2] += storage[2] * factor; @@ -79,8 +79,8 @@ class Vector4List extends VectorList { /// Substract [vector] from the vector at [index]. void sub(int index, Vector4 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] -= storage[0]; buffer[i + 1] -= storage[1]; buffer[i + 2] -= storage[2]; @@ -89,8 +89,8 @@ class Vector4List extends VectorList { /// Multiply the vector at [index] by [vector]. void multiply(int index, Vector4 vector) { - final i = _vectorIndexToBufferIndex(index); - final storage = vector.storage; + final int i = _vectorIndexToBufferIndex(index); + final Float32List storage = vector.storage; buffer[i + 0] *= storage[0]; buffer[i + 1] *= storage[1]; buffer[i + 2] *= storage[2]; @@ -99,7 +99,7 @@ class Vector4List extends VectorList { /// Scale the vector at [index] by [factor]. void scale(int index, double factor) { - final i = _vectorIndexToBufferIndex(index); + final int i = _vectorIndexToBufferIndex(index); buffer[i + 0] *= factor; buffer[i + 1] *= factor; buffer[i + 2] *= factor; diff --git a/packages/vector_math/lib/src/vector_math_lists/vector_list.dart b/packages/vector_math/lib/src/vector_math_lists/vector_list.dart index 080e58f..53dc816 100644 --- a/packages/vector_math/lib/src/vector_math_lists/vector_list.dart +++ b/packages/vector_math/lib/src/vector_math_lists/vector_list.dart @@ -7,23 +7,6 @@ part of '../../vector_math_lists.dart'; /// Abstract base class for vector lists. See [Vector2List], [Vector3List], and /// [Vector4List] for implementations of this class. abstract class VectorList { - final int _vectorLength; - final int _offset; - final int _stride; - final int _length; - final Float32List _buffer; - - /// The count of vectors in this list. - int get length => _length; - - /// The internal storage buffer of this list. - Float32List get buffer => _buffer; - - static int _listLength(int offset, int stride, int vectorLength, int length) { - final width = stride == 0 ? vectorLength : stride; - return offset + width * length; - } - /// Create a new vector list with [length] elements that have a size of /// [vectorLength]. Optionally it is possible to specify an [offset] in the /// [buffer] and a [stride] between each vector. @@ -82,6 +65,22 @@ abstract class VectorList { throw ArgumentError('Stride cannot be smaller than the vector size.'); } } + final int _vectorLength; + final int _offset; + final int _stride; + final int _length; + final Float32List _buffer; + + /// The count of vectors in this list. + int get length => _length; + + /// The internal storage buffer of this list. + Float32List get buffer => _buffer; + + static int _listLength(int offset, int stride, int vectorLength, int length) { + final width = stride == 0 ? vectorLength : stride; + return offset + width * length; + } int _vectorIndexToBufferIndex(int index) => _offset + _stride * index; @@ -105,10 +104,10 @@ abstract class VectorList { if (count == 0) { count = math.min(length - offset, src.length - srcOffset); } - final minVectorLength = math.min(_vectorLength, src._vectorLength); + final int minVectorLength = math.min(_vectorLength, src._vectorLength); for (var i = 0; i < count; i++) { - var index = _vectorIndexToBufferIndex(i + offset); - var srcIndex = src._vectorIndexToBufferIndex(i + srcOffset); + int index = _vectorIndexToBufferIndex(i + offset); + int srcIndex = src._vectorIndexToBufferIndex(i + srcOffset); for (var j = 0; j < minVectorLength; j++) { _buffer[index++] = src._buffer[srcIndex++]; } @@ -117,7 +116,7 @@ abstract class VectorList { /// Retrieves the vector at [index]. T operator [](int index) { - final r = newVector(); + final T r = newVector(); load(index, r); return r; } diff --git a/packages/vector_math/lib/src/vector_math_operations/matrix.dart b/packages/vector_math/lib/src/vector_math_operations/matrix.dart index 83f0684..bb16878 100644 --- a/packages/vector_math/lib/src/vector_math_operations/matrix.dart +++ b/packages/vector_math/lib/src/vector_math_operations/matrix.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(stuartmorgan): Remove this and fix violations. See +// https://github.com/flutter/flutter/issues/186827 +// ignore_for_file: public_member_api_docs + part of '../../vector_math_operations.dart'; /// Static methods operating on 4x4 matrices packed column major into a @@ -10,36 +14,40 @@ part of '../../vector_math_operations.dart'; class Matrix44Operations { /// Compute the determinant of the 4x4 [matrix] starting at [offset]. static double determinant(Float32List matrix, int offset) { - final m0 = matrix[0 + offset]; - final m1 = matrix[1 + offset]; - final m2 = matrix[2 + offset]; - final m3 = matrix[3 + offset]; - final m4 = matrix[4 + offset]; - final m5 = matrix[5 + offset]; - final m6 = matrix[6 + offset]; - final m7 = matrix[7 + offset]; - - final det2_01_01 = m0 * m5 - m1 * m4; - final det2_01_02 = m0 * m6 - m2 * m4; - final det2_01_03 = m0 * m7 - m3 * m4; - final det2_01_12 = m1 * m6 - m2 * m5; - final det2_01_13 = m1 * m7 - m3 * m5; - final det2_01_23 = m2 * m7 - m3 * m6; - - final m8 = matrix[8 + offset]; - final m9 = matrix[9 + offset]; - final m10 = matrix[10 + offset]; - final m11 = matrix[11 + offset]; - - final det3_201_012 = m8 * det2_01_12 - m9 * det2_01_02 + m10 * det2_01_01; - final det3_201_013 = m8 * det2_01_13 - m9 * det2_01_03 + m11 * det2_01_01; - final det3_201_023 = m8 * det2_01_23 - m10 * det2_01_03 + m11 * det2_01_02; - final det3_201_123 = m9 * det2_01_23 - m10 * det2_01_13 + m11 * det2_01_12; - - final m12 = matrix[12 + offset]; - final m13 = matrix[13 + offset]; - final m14 = matrix[14 + offset]; - final m15 = matrix[15 + offset]; + final double m0 = matrix[0 + offset]; + final double m1 = matrix[1 + offset]; + final double m2 = matrix[2 + offset]; + final double m3 = matrix[3 + offset]; + final double m4 = matrix[4 + offset]; + final double m5 = matrix[5 + offset]; + final double m6 = matrix[6 + offset]; + final double m7 = matrix[7 + offset]; + + final double det2_01_01 = m0 * m5 - m1 * m4; + final double det2_01_02 = m0 * m6 - m2 * m4; + final double det2_01_03 = m0 * m7 - m3 * m4; + final double det2_01_12 = m1 * m6 - m2 * m5; + final double det2_01_13 = m1 * m7 - m3 * m5; + final double det2_01_23 = m2 * m7 - m3 * m6; + + final double m8 = matrix[8 + offset]; + final double m9 = matrix[9 + offset]; + final double m10 = matrix[10 + offset]; + final double m11 = matrix[11 + offset]; + + final double det3_201_012 = + m8 * det2_01_12 - m9 * det2_01_02 + m10 * det2_01_01; + final double det3_201_013 = + m8 * det2_01_13 - m9 * det2_01_03 + m11 * det2_01_01; + final double det3_201_023 = + m8 * det2_01_23 - m10 * det2_01_03 + m11 * det2_01_02; + final double det3_201_123 = + m9 * det2_01_23 - m10 * det2_01_13 + m11 * det2_01_12; + + final double m12 = matrix[12 + offset]; + final double m13 = matrix[13 + offset]; + final double m14 = matrix[14 + offset]; + final double m15 = matrix[15 + offset]; return -det3_201_123 * m12 + det3_201_023 * m13 - @@ -50,59 +58,59 @@ class Matrix44Operations { /// Compute the determinant of the upper 3x3 of the 4x4 [matrix] starting at /// [offset]. static double determinant33(Float32List matrix, int offset) { - final m0 = matrix[0 + offset]; - final m1 = matrix[1 + offset]; - final m2 = matrix[2 + offset]; - final m4 = matrix[4 + offset]; - final m5 = matrix[5 + offset]; - final m6 = matrix[6 + offset]; - final m8 = matrix[8 + offset]; - final m9 = matrix[9 + offset]; - final m10 = matrix[10 + offset]; - final x = m0 * ((m5 * m10) - (m6 * m8)); - final y = m1 * ((m4 * m10) - (m6 * m8)); - final z = m2 * ((m4 * m9) - (m5 * m8)); + final double m0 = matrix[0 + offset]; + final double m1 = matrix[1 + offset]; + final double m2 = matrix[2 + offset]; + final double m4 = matrix[4 + offset]; + final double m5 = matrix[5 + offset]; + final double m6 = matrix[6 + offset]; + final double m8 = matrix[8 + offset]; + final double m9 = matrix[9 + offset]; + final double m10 = matrix[10 + offset]; + final double x = m0 * ((m5 * m10) - (m6 * m8)); + final double y = m1 * ((m4 * m10) - (m6 * m8)); + final double z = m2 * ((m4 * m9) - (m5 * m8)); return x - y + z; } /// Compute the inverse of the 4x4 [matrix] starting at [offset]. static double inverse(Float32List matrix, int offset) { - final a00 = matrix[0]; - final a01 = matrix[1]; - final a02 = matrix[2]; - final a03 = matrix[3]; - final a10 = matrix[4]; - final a11 = matrix[5]; - final a12 = matrix[6]; - final a13 = matrix[7]; - final a20 = matrix[8]; - final a21 = matrix[9]; - final a22 = matrix[10]; - final a23 = matrix[11]; - final a30 = matrix[12]; - final a31 = matrix[13]; - final a32 = matrix[14]; - final a33 = matrix[15]; - final b00 = a00 * a11 - a01 * a10; - final b01 = a00 * a12 - a02 * a10; - final b02 = a00 * a13 - a03 * a10; - final b03 = a01 * a12 - a02 * a11; - final b04 = a01 * a13 - a03 * a11; - final b05 = a02 * a13 - a03 * a12; - final b06 = a20 * a31 - a21 * a30; - final b07 = a20 * a32 - a22 * a30; - final b08 = a20 * a33 - a23 * a30; - final b09 = a21 * a32 - a22 * a31; - final b10 = a21 * a33 - a23 * a31; - final b11 = a22 * a33 - a23 * a32; - final det = + final double a00 = matrix[0]; + final double a01 = matrix[1]; + final double a02 = matrix[2]; + final double a03 = matrix[3]; + final double a10 = matrix[4]; + final double a11 = matrix[5]; + final double a12 = matrix[6]; + final double a13 = matrix[7]; + final double a20 = matrix[8]; + final double a21 = matrix[9]; + final double a22 = matrix[10]; + final double a23 = matrix[11]; + final double a30 = matrix[12]; + final double a31 = matrix[13]; + final double a32 = matrix[14]; + final double a33 = matrix[15]; + final double b00 = a00 * a11 - a01 * a10; + final double b01 = a00 * a12 - a02 * a10; + final double b02 = a00 * a13 - a03 * a10; + final double b03 = a01 * a12 - a02 * a11; + final double b04 = a01 * a13 - a03 * a11; + final double b05 = a02 * a13 - a03 * a12; + final double b06 = a20 * a31 - a21 * a30; + final double b07 = a20 * a32 - a22 * a30; + final double b08 = a20 * a33 - a23 * a30; + final double b09 = a21 * a32 - a22 * a31; + final double b10 = a21 * a33 - a23 * a31; + final double b11 = a22 * a33 - a23 * a32; + final double det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; if (det == 0.0) { return det; } - final invDet = 1.0 / det; + final double invDet = 1.0 / det; matrix[0] = (a11 * b11 - a12 * b10 + a13 * b09) * invDet; matrix[1] = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet; @@ -138,27 +146,27 @@ class Matrix44Operations { Float32List b, int bOffset, ) { - final a00 = a[aOffset++]; - final a01 = a[aOffset++]; - final a02 = a[aOffset++]; - final a03 = a[aOffset++]; - final a10 = a[aOffset++]; - final a11 = a[aOffset++]; - final a12 = a[aOffset++]; - final a13 = a[aOffset++]; - final a20 = a[aOffset++]; - final a21 = a[aOffset++]; - final a22 = a[aOffset++]; - final a23 = a[aOffset++]; - final a30 = a[aOffset++]; - final a31 = a[aOffset++]; - final a32 = a[aOffset++]; - final a33 = a[aOffset++]; - - var b0 = b[bOffset++]; - var b1 = b[bOffset++]; - var b2 = b[bOffset++]; - var b3 = b[bOffset++]; + final double a00 = a[aOffset++]; + final double a01 = a[aOffset++]; + final double a02 = a[aOffset++]; + final double a03 = a[aOffset++]; + final double a10 = a[aOffset++]; + final double a11 = a[aOffset++]; + final double a12 = a[aOffset++]; + final double a13 = a[aOffset++]; + final double a20 = a[aOffset++]; + final double a21 = a[aOffset++]; + final double a22 = a[aOffset++]; + final double a23 = a[aOffset++]; + final double a30 = a[aOffset++]; + final double a31 = a[aOffset++]; + final double a32 = a[aOffset++]; + final double a33 = a[aOffset++]; + + double b0 = b[bOffset++]; + double b1 = b[bOffset++]; + double b2 = b[bOffset++]; + double b3 = b[bOffset++]; out[outOffset++] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30; out[outOffset++] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31; out[outOffset++] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32; @@ -209,29 +217,29 @@ class Matrix44Operations { Float32List vector, int vectorOffset, ) { - final x = vector[vectorOffset++]; - final y = vector[vectorOffset++]; - final z = vector[vectorOffset++]; - final w = vector[vectorOffset++]; - final m0 = matrix[matrixOffset]; - final m4 = matrix[4 + matrixOffset]; - final m8 = matrix[8 + matrixOffset]; - final m12 = matrix[12 + matrixOffset]; + final double x = vector[vectorOffset++]; + final double y = vector[vectorOffset++]; + final double z = vector[vectorOffset++]; + final double w = vector[vectorOffset++]; + final double m0 = matrix[matrixOffset]; + final double m4 = matrix[4 + matrixOffset]; + final double m8 = matrix[8 + matrixOffset]; + final double m12 = matrix[12 + matrixOffset]; out[outOffset++] = m0 * x + m4 * y + m8 * z + m12 * w; - final m1 = matrix[1 + matrixOffset]; - final m5 = matrix[5 + matrixOffset]; - final m9 = matrix[9 + matrixOffset]; - final m13 = matrix[13 + matrixOffset]; + final double m1 = matrix[1 + matrixOffset]; + final double m5 = matrix[5 + matrixOffset]; + final double m9 = matrix[9 + matrixOffset]; + final double m13 = matrix[13 + matrixOffset]; out[outOffset++] = m1 * x + m5 * y + m9 * z + m13 * w; - final m2 = matrix[2 + matrixOffset]; - final m6 = matrix[6 + matrixOffset]; - final m10 = matrix[10 + matrixOffset]; - final m14 = matrix[14 + matrixOffset]; + final double m2 = matrix[2 + matrixOffset]; + final double m6 = matrix[6 + matrixOffset]; + final double m10 = matrix[10 + matrixOffset]; + final double m14 = matrix[14 + matrixOffset]; out[outOffset++] = m2 * x + m6 * y + m10 * z + m14 * w; - final m3 = matrix[3 + matrixOffset]; - final m7 = matrix[7 + matrixOffset]; - final m11 = matrix[11 + matrixOffset]; - final m15 = matrix[15 + matrixOffset]; + final double m3 = matrix[3 + matrixOffset]; + final double m7 = matrix[7 + matrixOffset]; + final double m11 = matrix[11 + matrixOffset]; + final double m15 = matrix[15 + matrixOffset]; out[outOffset++] = m3 * x + m7 * y + m11 * z + m15 * w; } @@ -288,29 +296,29 @@ class Matrix44SIMDOperations { Float32x4List B, int bOffset, ) { - final a0 = A[aOffset++]; - final a1 = A[aOffset++]; - final a2 = A[aOffset++]; - final a3 = A[aOffset++]; - final b0 = B[bOffset++]; + final Float32x4 a0 = A[aOffset++]; + final Float32x4 a1 = A[aOffset++]; + final Float32x4 a2 = A[aOffset++]; + final Float32x4 a3 = A[aOffset++]; + final Float32x4 b0 = B[bOffset++]; out[outOffset++] = b0.shuffle(Float32x4.xxxx) * a0 + b0.shuffle(Float32x4.yyyy) * a1 + b0.shuffle(Float32x4.zzzz) * a2 + b0.shuffle(Float32x4.wwww) * a3; - final b1 = B[bOffset++]; + final Float32x4 b1 = B[bOffset++]; out[outOffset++] = b1.shuffle(Float32x4.xxxx) * a0 + b1.shuffle(Float32x4.yyyy) * a1 + b1.shuffle(Float32x4.zzzz) * a2 + b1.shuffle(Float32x4.wwww) * a3; - final b2 = B[bOffset++]; + final Float32x4 b2 = B[bOffset++]; out[outOffset++] = b2.shuffle(Float32x4.xxxx) * a0 + b2.shuffle(Float32x4.yyyy) * a1 + b2.shuffle(Float32x4.zzzz) * a2 + b2.shuffle(Float32x4.wwww) * a3; - final b3 = B[bOffset++]; + final Float32x4 b3 = B[bOffset++]; out[outOffset++] = b3.shuffle(Float32x4.xxxx) * a0 + b3.shuffle(Float32x4.yyyy) * a1 + @@ -328,13 +336,13 @@ class Matrix44SIMDOperations { Float32x4List vector, int vectorOffset, ) { - final v = vector[vectorOffset]; - final xxxx = v.shuffle(Float32x4.xxxx); + final Float32x4 v = vector[vectorOffset]; + final Float32x4 xxxx = v.shuffle(Float32x4.xxxx); var z = Float32x4.zero(); z += xxxx * matrix[0 + matrixOffset]; - final yyyy = v.shuffle(Float32x4.yyyy); + final Float32x4 yyyy = v.shuffle(Float32x4.yyyy); z += yyyy * matrix[1 + matrixOffset]; - final zzzz = v.shuffle(Float32x4.zzzz); + final Float32x4 zzzz = v.shuffle(Float32x4.zzzz); z += zzzz * matrix[2 + matrixOffset]; z += matrix[3 + matrixOffset]; out[0 + outOffset] = z; diff --git a/packages/vector_math/pubspec.yaml b/packages/vector_math/pubspec.yaml index 181599b..81daa64 100644 --- a/packages/vector_math/pubspec.yaml +++ b/packages/vector_math/pubspec.yaml @@ -14,6 +14,5 @@ dev_dependencies: build_runner: ^2.5.0 build_test: ^3.0.0 build_web_compilers: ^4.1.1 - dart_flutter_team_lints: ^3.0.0 path: ^1.9.0 test: ^1.25.9 diff --git a/packages/vector_math/test/aabb2_test.dart b/packages/vector_math/test/aabb2_test.dart index 4a86081..e1c1734 100644 --- a/packages/vector_math/test/aabb2_test.dart +++ b/packages/vector_math/test/aabb2_test.dart @@ -12,7 +12,7 @@ import 'test_utils.dart'; void testAabb2Center() { final aabb = Aabb2.minMax($v2(1.0, 2.0), $v2(8.0, 16.0)); - final center = aabb.center; + final Vector2 center = aabb.center; expect(center.x, equals(4.5)); expect(center.y, equals(9.0)); @@ -78,9 +78,9 @@ void testAabb2ContainsAabb2() { void testAabb2ContainsVector2() { final parent = Aabb2.minMax($v2(1.0, 1.0), $v2(8.0, 8.0)); - final child = $v2(2.0, 2.0); - final cutting = $v2(1.0, 8.0); - final outside = $v2(-1.0, 0.0); + final Vector2 child = $v2(2.0, 2.0); + final Vector2 cutting = $v2(1.0, 8.0); + final Vector2 outside = $v2(-1.0, 0.0); expect(parent.containsVector2(child), isTrue); expect(parent.containsVector2(cutting), isFalse); @@ -126,9 +126,9 @@ void testAabb2IntersectionAabb2() { void testAabb2IntersectionVector2() { final parent = Aabb2.minMax($v2(1.0, 1.0), $v2(8.0, 8.0)); - final child = $v2(2.0, 2.0); - final cutting = $v2(1.0, 8.0); - final outside = $v2(-1.0, 0.0); + final Vector2 child = $v2(2.0, 2.0); + final Vector2 cutting = $v2(1.0, 8.0); + final Vector2 outside = $v2(-1.0, 0.0); expect(parent.intersectsWithVector2(child), isTrue); expect(parent.intersectsWithVector2(cutting), isTrue); @@ -149,7 +149,7 @@ void testAabb2Hull() { void testAabb2HullPoint() { final a = Aabb2.minMax($v2(1.0, 1.0), $v2(3.0, 4.0)); - final b = $v2(6.0, 2.0); + final Vector2 b = $v2(6.0, 2.0); a.hullPoint(b); @@ -158,7 +158,7 @@ void testAabb2HullPoint() { expect(a.max.x, equals(6.0)); expect(a.max.y, equals(4.0)); - final c = $v2(0.0, 1.0); + final Vector2 c = $v2(0.0, 1.0); a.hullPoint(c); @@ -187,7 +187,7 @@ void testAabb2Transform() { final input = Aabb2.minMax($v2(1.0, 1.0), $v2(3.0, 3.0)); final result = input..transform(rotation); - final newCenterY = math.sqrt(8); + final double newCenterY = math.sqrt(8); relativeTest(result.min.x, -math.sqrt(2)); relativeTest(result.min.y, newCenterY - math.sqrt(2)); diff --git a/packages/vector_math/test/aabb3_test.dart b/packages/vector_math/test/aabb3_test.dart index 69dbf7b..aa4e4d5 100644 --- a/packages/vector_math/test/aabb3_test.dart +++ b/packages/vector_math/test/aabb3_test.dart @@ -11,15 +11,8 @@ import 'package:vector_math/vector_math.dart'; import 'test_utils.dart'; void testAabb3ByteBufferInstanciation() { - final buffer = Float32List.fromList([ - 1.0, - 2.0, - 3.0, - 4.0, - 5.0, - 6.0, - 7.0, - ]).buffer; + final ByteBuffer buffer = + Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]).buffer; final aabb = Aabb3.fromBuffer(buffer, 0); final aabbOffest = Aabb3.fromBuffer(buffer, Float32List.bytesPerElement); @@ -40,7 +33,7 @@ void testAabb3ByteBufferInstanciation() { void testAabb3Center() { final aabb = Aabb3.minMax($v3(1.0, 2.0, 4.0), $v3(8.0, 16.0, 32.0)); - final center = aabb.center; + final Vector3 center = aabb.center; expect(center.x, equals(4.5)); expect(center.y, equals(9.0)); @@ -156,9 +149,9 @@ void testAabb3ContainsSphere() { void testAabb3ContainsVector3() { final parent = Aabb3.minMax($v3(1.0, 1.0, 1.0), $v3(8.0, 8.0, 8.0)); - final child = $v3(7.0, 7.0, 7.0); - final cutting = $v3(1.0, 2.0, 1.0); - final outside = $v3(-10.0, 10.0, 10.0); + final Vector3 child = $v3(7.0, 7.0, 7.0); + final Vector3 cutting = $v3(1.0, 2.0, 1.0); + final Vector3 outside = $v3(-10.0, 10.0, 10.0); expect(parent.containsVector3(child), isTrue); expect(parent.containsVector3(cutting), isFalse); @@ -333,9 +326,9 @@ void testIntersectionPlane() { void testAabb3IntersectionVector3() { final parent = Aabb3.minMax($v3(1.0, 1.0, 1.0), $v3(8.0, 8.0, 8.0)); - final child = $v3(7.0, 7.0, 7.0); - final cutting = $v3(1.0, 2.0, 1.0); - final outside = $v3(-10.0, 10.0, 10.0); + final Vector3 child = $v3(7.0, 7.0, 7.0); + final Vector3 cutting = $v3(1.0, 2.0, 1.0); + final Vector3 outside = $v3(-10.0, 10.0, 10.0); expect(parent.intersectsWithVector3(child), isTrue); expect(parent.intersectsWithVector3(cutting), isTrue); @@ -358,7 +351,7 @@ void testAabb3Hull() { void testAabb3HullPoint() { final a = Aabb3.minMax($v3(1.0, 1.0, 4.0), $v3(3.0, 4.0, 10.0)); - final b = $v3(6.0, 2.0, 8.0); + final Vector3 b = $v3(6.0, 2.0, 8.0); a.hullPoint(b); @@ -369,7 +362,7 @@ void testAabb3HullPoint() { expect(a.max.y, equals(4.0)); expect(a.max.z, equals(10.0)); - final c = $v3(6.0, 0.0, 2.0); + final Vector3 c = $v3(6.0, 0.0, 2.0); a.hullPoint(c); diff --git a/packages/vector_math/test/colors_test.dart b/packages/vector_math/test/colors_test.dart index 989f33e..81af22c 100644 --- a/packages/vector_math/test/colors_test.dart +++ b/packages/vector_math/test/colors_test.dart @@ -10,7 +10,7 @@ import 'test_utils.dart'; void testToGrayscale() { final input = Vector4(0.0, 1.0, 0.5, 1.0); - final output = input.clone(); + final Vector4 output = input.clone(); Colors.toGrayscale(output, output); @@ -221,7 +221,7 @@ void testRgbHsl() { expect(rgb.a, equals(input.a)); void testRoundtrip(Vector4 input) { - final result = input.clone(); + final Vector4 result = input.clone(); Colors.rgbToHsl(result, result); Colors.hslToRgb(result, result); @@ -264,7 +264,7 @@ void testRgbHsv() { expect(rgb.a, equals(input.a)); void testRoundtrip(Vector4 input) { - final result = input.clone(); + final Vector4 result = input.clone(); Colors.rgbToHsv(result, result); Colors.hsvToRgb(result, result); diff --git a/packages/vector_math/test/geometry_test.dart b/packages/vector_math/test/geometry_test.dart index 06695ee..aa63244 100644 --- a/packages/vector_math/test/geometry_test.dart +++ b/packages/vector_math/test/geometry_test.dart @@ -74,12 +74,12 @@ void testTransformFilter() { final scaleMat = Matrix4.identity(); scaleMat.scale(2.0, 2.0, 2.0); final filter = TransformFilter(scaleMat); - final cube = filterUnitCube(filter); + final MeshGeometry cube = filterUnitCube(filter); // Check to ensure all the vertices were properly scaled - final positions = cube.getViewForAttrib('POSITION') as Vector3List; + final positions = cube.getViewForAttrib('POSITION')! as Vector3List; for (var i = 0; i < positions.length; ++i) { - final position = positions[i]; + final Vector3 position = positions[i]; expect(position.storage[0].abs(), equals(2.0)); expect(position.storage[1].abs(), equals(2.0)); expect(position.storage[2].abs(), equals(2.0)); @@ -88,7 +88,7 @@ void testTransformFilter() { void testFlatShadeFilter() { final filter = FlatShadeFilter(); - final cube = filterUnitCube(filter); + final MeshGeometry cube = filterUnitCube(filter); // Flat shading removes indices and duplicates vertices expect(cube.indices, equals(null)); @@ -97,7 +97,7 @@ void testFlatShadeFilter() { void testBarycentricFilter() { final filter = BarycentricFilter(); - final cube = filterUnitCube(filter); + final MeshGeometry cube = filterUnitCube(filter); // Generating barycentric coords removes indices and duplicates vertices expect(cube.indices, equals(null)); @@ -109,12 +109,12 @@ void testBarycentricFilter() { void testColorFilter() { final filterColor = Vector4(1.0, 0.0, 0.0, 1.0); final filter = ColorFilter(filterColor); - final cube = filterUnitCube(filter); + final MeshGeometry cube = filterUnitCube(filter); // Ensure that the same color was applied to all vertices - final colors = cube.getViewForAttrib('COLOR') as Vector4List; + final colors = cube.getViewForAttrib('COLOR')! as Vector4List; for (var i = 0; i < colors.length; ++i) { - final color = colors[i]; + final Vector4 color = colors[i]; relativeTest(color, filterColor); } } @@ -123,12 +123,12 @@ void testCombineIndices() { // Combining two meshes should generate indices that are not out of range. final sphereGenerator = SphereGenerator(); - final sphere0 = sphereGenerator.createSphere( + final MeshGeometry sphere0 = sphereGenerator.createSphere( 10.0, latSegments: 8, lonSegments: 8, ); - final sphere1 = sphereGenerator.createSphere( + final MeshGeometry sphere1 = sphereGenerator.createSphere( 10.0, latSegments: 8, lonSegments: 8, diff --git a/packages/vector_math/test/matrix2_test.dart b/packages/vector_math/test/matrix2_test.dart index 977338e..3a17944 100644 --- a/packages/vector_math/test/matrix2_test.dart +++ b/packages/vector_math/test/matrix2_test.dart @@ -15,26 +15,30 @@ void testMatrix2Adjoint() { final expectedOutput = []; input.add( - parseMatrix('''0.830828627896291 0.549723608291140 + parseMatrix(''' +0.830828627896291 0.549723608291140 0.585264091152724 0.917193663829810'''), ); expectedOutput.add( - parseMatrix(''' 0.917193663829810 -0.549723608291140 + parseMatrix(''' + 0.917193663829810 -0.549723608291140 -0.585264091152724 0.830828627896291'''), ); input.add( - parseMatrix(''' 1 0 + parseMatrix(''' + 1 0 0 1'''), ); expectedOutput.add( - parseMatrix(''' 1 0 + parseMatrix(''' + 1 0 0 1'''), ); assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output = input[i].clone(); + final Matrix2 output = input[i].clone(); output.scaleAdjoint(1.0); relativeTest(output, expectedOutput[i]); } @@ -45,7 +49,8 @@ void testMatrix2Determinant() { final expectedOutput = []; input.add( - parseMatrix('''0.830828627896291 0.549723608291140 + parseMatrix(''' +0.830828627896291 0.549723608291140 0.585264091152724 0.917193663829810'''), ); expectedOutput.add(0.440297265243183); @@ -53,7 +58,7 @@ void testMatrix2Determinant() { assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output = input[i].determinant(); + final double output = input[i].determinant(); //print('${input[i].cols}x${input[i].rows} = $output'); relativeTest(output, expectedOutput[i]); } @@ -80,7 +85,7 @@ void testMatrix2Transform() { void testMatrix2Inversion() { final m = Matrix2(4.0, 3.0, 3.0, 2.0); final result = Matrix2.zero(); - final det = result.copyInverse(m); + final double det = result.copyInverse(m); expect(det, -1.0); expect(result.entry(0, 0), -2.0); expect(result.entry(1, 0), 3.0); @@ -101,7 +106,7 @@ void testMatrix2Dot() { void testMatrix2Scale() { final m = Matrix2(1.0, 2.0, 3.0, 4.0); - final n = m.scaled(2.0); + final Matrix2 n = m.scaled(2.0); expect(n.storage[0], equals(2.0)); expect(n.storage[1], equals(4.0)); @@ -110,15 +115,15 @@ void testMatrix2Scale() { } void testMatrix2Solving() { - final A = Matrix2(2.0, 2.0, 8.0, 20.0); - final AA = Matrix2.fromList([2.0, 2.0, 8.0, 20.0]); - expect(A, equals(AA)); + final a = Matrix2(2.0, 2.0, 8.0, 20.0); + final aa = Matrix2.fromList([2.0, 2.0, 8.0, 20.0]); + expect(a, equals(aa)); final b = Vector2(20.0, 64.0); final result = Vector2.zero(); - Matrix2.solve(A, result, b); + Matrix2.solve(a, result, b); - final backwards = A.transform(Vector2.copy(result)); + final Vector2 backwards = a.transform(Vector2.copy(result)); expect(backwards.x, equals(b.x)); expect(backwards.y, equals(b.y)); diff --git a/packages/vector_math/test/matrix3_test.dart b/packages/vector_math/test/matrix3_test.dart index 37f1de6..8cb3cb4 100644 --- a/packages/vector_math/test/matrix3_test.dart +++ b/packages/vector_math/test/matrix3_test.dart @@ -14,37 +14,39 @@ void testMatrix3Adjoint() { final expectedOutput = []; input.add( - parseMatrix( - ''' 0.285839018820374 0.380445846975357 0.053950118666607 + parseMatrix(''' + 0.285839018820374 0.380445846975357 0.053950118666607 0.757200229110721 0.567821640725221 0.530797553008973 - 0.753729094278495 0.075854289563064 0.779167230102011''', - ), + 0.753729094278495 0.075854289563064 0.779167230102011'''), ); expectedOutput.add( - parseMatrix( - ''' 0.402164743710542 -0.292338588868304 0.171305679728352 + parseMatrix(''' + 0.402164743710542 -0.292338588868304 0.171305679728352 -0.189908046274114 0.182052622470548 -0.110871609529434 - -0.370546805539367 0.265070987960728 -0.125768101844091''', - ), + -0.370546805539367 0.265070987960728 -0.125768101844091'''), ); input.add( - parseMatrix('''1 0 0 + parseMatrix(''' +1 0 0 0 1 0 0 0 1'''), ); expectedOutput.add( - parseMatrix('''1 0 0 + parseMatrix(''' +1 0 0 0 1 0 0 0 1'''), ); input.add( - parseMatrix('''1 0 0 0 + parseMatrix(''' +1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'''), ); expectedOutput.add( - parseMatrix('''1 0 0 0 + parseMatrix(''' +1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'''), @@ -66,18 +68,17 @@ void testMatrix3Determinant() { final expectedOutput = []; input.add( - parseMatrix( - '''0.285839018820374 0.380445846975357 0.053950118666607 + parseMatrix(''' +0.285839018820374 0.380445846975357 0.053950118666607 0.757200229110721 0.567821640725221 0.530797553008973 - 0.753729094278495 0.075854289563064 0.779167230102011''', - ), + 0.753729094278495 0.075854289563064 0.779167230102011'''), ); expectedOutput.add(0.022713604103796); assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output = input[i].determinant(); + final double output = input[i].determinant(); //print('${input[i].cols}x${input[i].rows} = $output'); relativeTest(output, expectedOutput[i]); } @@ -89,53 +90,47 @@ void testMatrix3SelfTransposeMultiply() { final expectedOutput = []; inputA.add( - parseMatrix( - '''0.084435845510910 0.800068480224308 0.181847028302852 + parseMatrix(''' +0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''', - ), + 0.259870402850654 0.910647594429523 0.145538980384717'''), ); inputB.add( - parseMatrix( - '''0.136068558708664 0.549860201836332 0.622055131485066 + parseMatrix(''' +0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''', - ), + 0.579704587365570 0.853031117721894 0.513249539867053'''), ); expectedOutput.add( - parseMatrix( - '''0.509665070066463 0.326055864494860 0.326206788210183 + parseMatrix(''' +0.509665070066463 0.326055864494860 0.326206788210183 1.011795431418814 1.279272055656899 1.116481872383158 - 0.338435097301446 0.262379221330899 0.280398953455993''', - ), + 0.338435097301446 0.262379221330899 0.280398953455993'''), ); inputA.add( - parseMatrix( - '''0.136068558708664 0.549860201836332 0.622055131485066 + parseMatrix(''' +0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''', - ), + 0.579704587365570 0.853031117721894 0.513249539867053'''), ); inputB.add( - parseMatrix( - '''0.084435845510910 0.800068480224308 0.181847028302852 + parseMatrix(''' +0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''', - ), + 0.259870402850654 0.910647594429523 0.145538980384717'''), ); expectedOutput.add( - parseMatrix( - '''0.509665070066463 1.011795431418814 0.338435097301446 + parseMatrix(''' +0.509665070066463 1.011795431418814 0.338435097301446 0.326055864494860 1.279272055656899 0.262379221330899 - 0.326206788210183 1.116481872383158 0.280398953455993''', - ), + 0.326206788210183 1.116481872383158 0.280398953455993'''), ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].clone(); + final Matrix3 output = inputA[i].clone(); output.transposeMultiply(inputB[i]); relativeTest(output, expectedOutput[i]); } @@ -147,53 +142,47 @@ void testMatrix3SelfMultiply() { final expectedOutput = []; inputA.add( - parseMatrix( - '''0.084435845510910 0.800068480224308 0.181847028302852 + parseMatrix(''' +0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''', - ), + 0.259870402850654 0.910647594429523 0.145538980384717'''), ); inputB.add( - parseMatrix( - '''0.136068558708664 0.549860201836332 0.622055131485066 + parseMatrix(''' +0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''', - ), + 0.579704587365570 0.853031117721894 0.513249539867053'''), ); expectedOutput.add( - parseMatrix( - '''0.812399915745417 0.317522849978516 0.426642592595554 + parseMatrix(''' +0.812399915745417 0.317522849978516 0.426642592595554 0.582350288210078 0.507392169174135 0.535489283769338 - 0.911348663480233 0.399044409575883 0.555945473748377''', - ), + 0.911348663480233 0.399044409575883 0.555945473748377'''), ); inputA.add( - parseMatrix( - '''0.136068558708664 0.549860201836332 0.622055131485066 + parseMatrix(''' +0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''', - ), + 0.579704587365570 0.853031117721894 0.513249539867053'''), ); inputB.add( - parseMatrix( - '''0.084435845510910 0.800068480224308 0.181847028302852 + parseMatrix(''' +0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''', - ), + 0.259870402850654 0.910647594429523 0.145538980384717'''), ); expectedOutput.add( - parseMatrix( - '''0.392967349540540 0.912554468305858 0.260331657549835 + parseMatrix(''' +0.392967349540540 0.912554468305858 0.260331657549835 0.222551972385485 1.077622741167203 0.247394954900102 - 0.523353251675581 1.299202246456530 0.405147467960185''', - ), + 0.523353251675581 1.299202246456530 0.405147467960185'''), ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].clone(); + final Matrix3 output = inputA[i].clone(); output.multiply(inputB[i]); relativeTest(output, expectedOutput[i]); } @@ -205,53 +194,47 @@ void testMatrix3SelfMultiplyTranspose() { final expectedOutput = []; inputA.add( - parseMatrix( - '''0.084435845510910 0.800068480224308 0.181847028302852 + parseMatrix(''' +0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''', - ), + 0.259870402850654 0.910647594429523 0.145538980384717'''), ); inputB.add( - parseMatrix( - '''0.136068558708664 0.549860201836332 0.622055131485066 + parseMatrix(''' +0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''', - ), + 0.579704587365570 0.853031117721894 0.513249539867053'''), ); expectedOutput.add( - parseMatrix( - '''0.564533756922142 0.253192835205285 0.824764060523193 + parseMatrix(''' +0.564533756922142 0.253192835205285 0.824764060523193 0.455715101026938 0.502645707562004 0.735161980594196 - 0.626622330821134 0.408983306176468 1.002156614695209''', - ), + 0.626622330821134 0.408983306176468 1.002156614695209'''), ); inputA.add( - parseMatrix( - '''0.136068558708664 0.549860201836332 0.622055131485066 + parseMatrix(''' +0.136068558708664 0.549860201836332 0.622055131485066 0.869292207640089 0.144954798223727 0.350952380892271 - 0.579704587365570 0.853031117721894 0.513249539867053''', - ), + 0.579704587365570 0.853031117721894 0.513249539867053'''), ); inputB.add( - parseMatrix( - '''0.084435845510910 0.800068480224308 0.181847028302852 + parseMatrix(''' +0.084435845510910 0.800068480224308 0.181847028302852 0.399782649098896 0.431413827463545 0.263802916521990 - 0.259870402850654 0.910647594429523 0.145538980384717''', - ), + 0.259870402850654 0.910647594429523 0.145538980384717'''), ); expectedOutput.add( - parseMatrix( - '''0.564533756922142 0.455715101026938 0.626622330821134 + parseMatrix(''' +0.564533756922142 0.455715101026938 0.626622330821134 0.253192835205285 0.502645707562004 0.408983306176468 - 0.824764060523193 0.735161980594196 1.002156614695209''', - ), + 0.824764060523193 0.735161980594196 1.002156614695209'''), ); assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].clone(); + final Matrix3 output = inputA[i].clone(); output.multiplyTranspose(inputB[i]); relativeTest(output, expectedOutput[i]); } @@ -357,7 +340,7 @@ void testMatrix3ConstructorCopy() { void testMatrix3Inversion() { final m = Matrix3(1.0, 0.0, 5.0, 2.0, 1.0, 6.0, 3.0, 4.0, 0.0); final result = Matrix3.zero(); - final det = result.copyInverse(m); + final double det = result.copyInverse(m); expect(det, 1.0); expect(result.entry(0, 0), -24.0); expect(result.entry(1, 0), 20.0); @@ -385,7 +368,7 @@ void testMatrix3Dot() { void testMatrix3Scale() { final m = Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); - final n = m.scaled(2.0); + final Matrix3 n = m.scaled(2.0); expect(n.storage[0], equals(2.0)); expect(n.storage[1], equals(4.0)); @@ -410,8 +393,8 @@ void testMatrix3Solving() { Matrix3.solve(A, result, b); Matrix3.solve2(A, result2, b2); - final backwards = A.transform(Vector3.copy(result)); - final backwards2 = A.transform2(Vector2.copy(result2)); + final Vector3 backwards = A.transform(Vector3.copy(result)); + final Vector2 backwards2 = A.transform2(Vector2.copy(result2)); expect(backwards.x, equals(b.x)); expect(backwards.y, equals(b.y)); diff --git a/packages/vector_math/test/matrix4_test.dart b/packages/vector_math/test/matrix4_test.dart index 4519a99..ab200ff 100644 --- a/packages/vector_math/test/matrix4_test.dart +++ b/packages/vector_math/test/matrix4_test.dart @@ -74,7 +74,7 @@ void testMatrix4InstacingFromByteBuffer() { 16.0, 17.0, ]); - final buffer = float32List.buffer; + final ByteBuffer buffer = float32List.buffer; final zeroOffset = Matrix4.fromBuffer(buffer, 0); final offsetVector = Matrix4.fromBuffer(buffer, Float32List.bytesPerElement); @@ -118,7 +118,8 @@ void testMatrix4Transpose() { final expectedOutput = []; inputA.add( parseMatrix( - '''0.337719409821377 0.780252068321138 0.096454525168389 0.575208595078466 + ''' +0.337719409821377 0.780252068321138 0.096454525168389 0.575208595078466 0.900053846417662 0.389738836961253 0.131973292606335 0.059779542947156 0.369246781120215 0.241691285913833 0.942050590775485 0.234779913372406 0.111202755293787 0.403912145588115 0.956134540229802 0.353158571222071''', @@ -139,20 +140,23 @@ void testMatrix4VectorMultiplication() { inputA.add( parseMatrix( - '''0.337719409821377 0.780252068321138 0.096454525168389 0.575208595078466 + ''' +0.337719409821377 0.780252068321138 0.096454525168389 0.575208595078466 0.900053846417662 0.389738836961253 0.131973292606335 0.059779542947156 0.369246781120215 0.241691285913833 0.942050590775485 0.234779913372406 0.111202755293787 0.403912145588115 0.956134540229802 0.353158571222071''', ), ); inputB.add( - parseVector('''0.821194040197959 + parseVector(''' +0.821194040197959 0.015403437651555 0.043023801657808 0.168990029462704'''), ); expectedOutput.add( - parseVector('''0.390706088480722 + parseVector(''' +0.390706088480722 0.760902311900085 0.387152194918898 0.198357495624973'''), @@ -174,7 +178,8 @@ void testMatrix4Multiplication() { inputA.add( parseMatrix( - '''0.587044704531417 0.230488160211558 0.170708047147859 0.923379642103244 + ''' +0.587044704531417 0.230488160211558 0.170708047147859 0.923379642103244 0.207742292733028 0.844308792695389 0.227664297816554 0.430207391329584 0.301246330279491 0.194764289567049 0.435698684103899 0.184816320124136 0.470923348517591 0.225921780972399 0.311102286650413 0.904880968679893''', @@ -182,7 +187,8 @@ void testMatrix4Multiplication() { ); inputB.add( parseMatrix( - '''0.979748378356085 0.408719846112552 0.711215780433683 0.318778301925882 + ''' +0.979748378356085 0.408719846112552 0.711215780433683 0.318778301925882 0.438869973126103 0.594896074008614 0.221746734017240 0.424166759713807 0.111119223440599 0.262211747780845 0.117417650855806 0.507858284661118 0.258064695912067 0.602843089382083 0.296675873218327 0.085515797090044''', @@ -190,7 +196,8 @@ void testMatrix4Multiplication() { ); expectedOutput.add( parseMatrix( - '''0.933571062150012 0.978468014433530 0.762614053950618 0.450561572247979 + ''' +0.933571062150012 0.978468014433530 0.762614053950618 0.450561572247979 0.710396171182635 0.906228190244263 0.489336274658484 0.576762187862375 0.476730868989407 0.464650419830879 0.363428748133464 0.415721232510293 0.828623949506267 0.953951612073692 0.690010785130483 0.481326146122225''', @@ -212,7 +219,8 @@ void testMatrix4Adjoint() { input.add( parseMatrix( - '''0.934010684229183 0.011902069501241 0.311215042044805 0.262971284540144 + ''' +0.934010684229183 0.011902069501241 0.311215042044805 0.262971284540144 0.129906208473730 0.337122644398882 0.528533135506213 0.654079098476782 0.568823660872193 0.162182308193243 0.165648729499781 0.689214503140008 0.469390641058206 0.794284540683907 0.601981941401637 0.748151592823709''', @@ -220,20 +228,23 @@ void testMatrix4Adjoint() { ); expectedOutput.add( parseMatrix( - '''0.104914550911225 -0.120218628213523 0.026180662741638 0.044107217835411 + ''' +0.104914550911225 -0.120218628213523 0.026180662741638 0.044107217835411 -0.081375770192194 -0.233925009984709 -0.022194776259965 0.253560794325371 0.155967414263983 0.300399085119975 -0.261648453454468 -0.076412061081351 -0.104925204524921 0.082065846290507 0.217666653572481 -0.077704028180558''', ), ); input.add( - parseMatrix('''1 0 0 0 + parseMatrix(''' +1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'''), ); expectedOutput.add( - parseMatrix('''1 0 0 0 + parseMatrix(''' +1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'''), @@ -241,7 +252,8 @@ void testMatrix4Adjoint() { input.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -249,7 +261,8 @@ void testMatrix4Adjoint() { ); expectedOutput.add( parseMatrix( - '''-0.100386867815513 0.076681891597503 -0.049082198794982 -0.021689260610181 + ''' +-0.100386867815513 0.076681891597503 -0.049082198794982 -0.021689260610181 -0.279454715225440 -0.269081505356250 0.114433412778961 0.133858687769130 0.218879650360982 0.073892735462981 0.069073300555062 -0.132069899391626 0.183633794399577 0.146113141160308 -0.156100829983306 -0.064859465665816''', @@ -259,7 +272,7 @@ void testMatrix4Adjoint() { assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output = input[i].clone(); + final Matrix4 output = input[i].clone(); output.scaleAdjoint(1.0); relativeTest(output, expectedOutput[i]); } @@ -270,7 +283,8 @@ void testMatrix4Determinant() { final expectedOutput = []; input.add( parseMatrix( - '''0.046171390631154 0.317099480060861 0.381558457093008 0.489764395788231 + ''' +0.046171390631154 0.317099480060861 0.381558457093008 0.489764395788231 0.097131781235848 0.950222048838355 0.765516788149002 0.445586200710899 0.823457828327293 0.034446080502909 0.795199901137063 0.646313010111265 0.694828622975817 0.438744359656398 0.186872604554379 0.709364830858073''', @@ -280,7 +294,8 @@ void testMatrix4Determinant() { input.add( parseMatrix( - ''' -2.336158020850647 0.358791716162913 0.571930324052307 0.866477090273158 + ''' + -2.336158020850647 0.358791716162913 0.571930324052307 0.866477090273158 -1.190335868711951 1.132044609886021 -0.693048859451418 0.742195189800671 0.015919048685702 0.552417702663606 1.020805610524362 -1.288062497216858 3.020318574990609 -1.197139524685751 -0.400475005629390 0.441263145991252''', @@ -290,7 +305,8 @@ void testMatrix4Determinant() { input.add( parseMatrix( - '''0.934010684229183 0.011902069501241 0.311215042044805 0.262971284540144 + ''' +0.934010684229183 0.011902069501241 0.311215042044805 0.262971284540144 0.129906208473730 0.337122644398882 0.528533135506213 0.654079098476782 0.568823660872193 0.162182308193243 0.165648729499781 0.689214503140008 0.469390641058206 0.794284540683907 0.601981941401637 0.748151592823709''', @@ -300,7 +316,7 @@ void testMatrix4Determinant() { assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output = input[i].determinant(); + final double output = input[i].determinant(); //print('${input[i].cols}x${input[i].rows} = $output'); relativeTest(output, expectedOutput[i]); } @@ -313,7 +329,8 @@ void testMatrix4SelfTransposeMultiply() { inputA.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -321,7 +338,8 @@ void testMatrix4SelfTransposeMultiply() { ); inputB.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -329,7 +347,8 @@ void testMatrix4SelfTransposeMultiply() { ); expectedOutput.add( parseMatrix( - '''1.096629343508065 1.170948826011164 0.975285713492989 1.047596917860438 + ''' +1.096629343508065 1.170948826011164 0.975285713492989 1.047596917860438 1.170948826011164 1.987289692246011 1.393079247172284 1.945966332001094 0.975285713492989 1.393079247172284 1.138698195167051 1.266161729169725 1.047596917860438 1.945966332001094 1.266161729169725 2.023122749969790''', @@ -340,7 +359,7 @@ void testMatrix4SelfTransposeMultiply() { assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].clone(); + final Matrix4 output = inputA[i].clone(); output.transposeMultiply(inputB[i]); relativeTest(output, expectedOutput[i]); } @@ -353,7 +372,8 @@ void testMatrix4SelfMultiply() { inputA.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -361,7 +381,8 @@ void testMatrix4SelfMultiply() { ); inputB.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -369,7 +390,8 @@ void testMatrix4SelfMultiply() { ); expectedOutput.add( parseMatrix( - '''0.237893273152584 0.241190507375353 0.115471053480014 0.188086069635435 + ''' +0.237893273152584 0.241190507375353 0.115471053480014 0.188086069635435 0.916103942227480 1.704973929800637 1.164721763902784 1.675285658272358 0.919182849383279 1.351023203753565 1.053750106199745 1.215382950294249 1.508657696357159 2.344965008135463 1.450552688877760 2.316940716769603''', @@ -380,7 +402,7 @@ void testMatrix4SelfMultiply() { assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].clone(); + final Matrix4 output = inputA[i].clone(); output.multiply(inputB[i]); relativeTest(output, expectedOutput[i]); } @@ -393,7 +415,8 @@ void testMatrix4LeftMultiply() { inputA.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -401,7 +424,8 @@ void testMatrix4LeftMultiply() { ); inputB.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -409,7 +433,8 @@ void testMatrix4LeftMultiply() { ); expectedOutput.add( parseMatrix( - '''0.237893273152584 0.241190507375353 0.115471053480014 0.188086069635435 + ''' +0.237893273152584 0.241190507375353 0.115471053480014 0.188086069635435 0.916103942227480 1.704973929800637 1.164721763902784 1.675285658272358 0.919182849383279 1.351023203753565 1.053750106199745 1.215382950294249 1.508657696357159 2.344965008135463 1.450552688877760 2.316940716769603''', @@ -420,7 +445,7 @@ void testMatrix4LeftMultiply() { assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputB[i].clone(); + final Matrix4 output = inputB[i].clone(); output.leftMultiply(inputA[i]); relativeTest(output, expectedOutput[i]); } @@ -433,7 +458,8 @@ void testMatrix4SelfMultiplyTranspose() { inputA.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -441,7 +467,8 @@ void testMatrix4SelfMultiplyTranspose() { ); inputB.add( parseMatrix( - '''0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 + ''' +0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067 0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502 0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433 0.913337361501670 0.996134716626885 0.961898080855054 0.868694705363510''', @@ -449,7 +476,8 @@ void testMatrix4SelfMultiplyTranspose() { ); expectedOutput.add( parseMatrix( - '''0.232339681975335 0.201799089276976 0.197320406329789 0.642508126615338 + ''' +0.232339681975335 0.201799089276976 0.197320406329789 0.642508126615338 0.201799089276976 1.485449982570056 1.144315170085286 1.998154153033270 0.197320406329789 1.144315170085286 1.021602397682138 1.557970885061235 0.642508126615338 1.998154153033270 1.557970885061235 3.506347918663387''', @@ -460,7 +488,7 @@ void testMatrix4SelfMultiplyTranspose() { assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].clone(); + final Matrix4 output = inputA[i].clone(); output.multiplyTranspose(inputB[i]); relativeTest(output, expectedOutput[i]); } @@ -490,14 +518,14 @@ void testMatrix4Translation() { 3, 7, 11, 15, // 4, 8, 12, 16, // ]); - final output2 = input.clone(); + final Matrix4 output2 = input.clone(); output2[12] = input.dotRow(0, Vector4(4, 8, 0, 1)); output2[13] = input.dotRow(1, Vector4(4, 8, 0, 1)); output2[14] = input.dotRow(2, Vector4(4, 8, 0, 1)); output2[15] = input.dotRow(3, Vector4(4, 8, 0, 1)); relativeTest(input.clone()..translateByVector2(Vector2(4.0, 8.0)), output2); - final output3 = input.clone(); + final Matrix4 output3 = input.clone(); output3[12] = input.dotRow(0, Vector4(4, 8, 12, 1)); output3[13] = input.dotRow(1, Vector4(4, 8, 12, 1)); output3[14] = input.dotRow(2, Vector4(4, 8, 12, 1)); @@ -508,7 +536,7 @@ void testMatrix4Translation() { output3, ); - final output4 = input.clone(); + final Matrix4 output4 = input.clone(); output4[12] = input.dotRow(0, Vector4(4, 8, 12, 16)); output4[13] = input.dotRow(1, Vector4(4, 8, 12, 16)); output4[14] = input.dotRow(2, Vector4(4, 8, 12, 16)); @@ -550,10 +578,10 @@ void testMatrix4Rotate() { { final axis = Vector3(1.1, 1.1, 1.1); axis.normalize(); - final angle = 1.5; + const angle = 1.5; final q = Quaternion.axisAngle(axis, angle); - final R = q.asRotationMatrix(); + final Matrix3 R = q.asRotationMatrix(); final T = Matrix4.identity(); T.setRotation(R); output1.add(T); @@ -576,7 +604,7 @@ void testMatrix4GetRotation() { (Matrix3.rotationX(math.pi) * Matrix3.rotationY(-math.pi) as Matrix3) * Matrix3.rotationZ(math.pi) as Matrix3; - final matRot = mat4.getRotation(); + final Matrix3 matRot = mat4.getRotation(); relativeTest(mat3, matRot); } @@ -612,7 +640,7 @@ void testMatrix4Inversion() { 4.0, ); final result = Matrix4.zero(); - final det = result.copyInverse(m); + final double det = result.copyInverse(m); expect(det, 2.0); expect(result.entry(0, 0), -2.0); expect(result.entry(1, 0), 1.0); @@ -663,7 +691,7 @@ void testMatrix4Dot() { } void testMatrix4PerspectiveTransform() { - final matrix = makePerspectiveMatrix(math.pi, 1.0, 1.0, 100.0); + final Matrix4 matrix = makePerspectiveMatrix(math.pi, 1.0, 1.0, 100.0); final vec = Vector3(10.0, 20.0, 30.0); matrix.perspectiveTransform(vec); @@ -691,7 +719,7 @@ void testMatrix4Solving() { 64.0, ); - final A_small = Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0); + final aSmall = Matrix3(2.0, 12.0, 8.0, 20.0, 24.0, 26.0, 8.0, 4.0, 60.0); final b = Vector4(32.0, 64.0, 72.0, 8.0); final result = Vector4.zero(); @@ -706,9 +734,9 @@ void testMatrix4Solving() { Matrix4.solve3(A, result3, b3); Matrix4.solve2(A, result2, b2); - final backwards = A.transform(Vector4.copy(result)); - final backwards3 = A.transform3(Vector3.copy(result3)); - final backwards2 = A_small.transform2(Vector2.copy(result2)); + final Vector4 backwards = A.transform(Vector4.copy(result)); + final Vector3 backwards3 = A.transform3(Vector3.copy(result3)); + final Vector2 backwards2 = aSmall.transform2(Vector2.copy(result2)); expect(backwards2.x, equals(b.x)); expect(backwards2.y, equals(b.y)); @@ -768,9 +796,9 @@ void testMatrix4Compose() { for (var ti = 0; ti < tValues.length; ti++) { for (var si = 0; si < sValues.length; si++) { for (var ri = 0; ri < rValues.length; ri++) { - final t = tValues[ti]; - final s = sValues[si]; - final r = rValues[ri]; + final Vector3 t = tValues[ti]; + final Vector3 s = sValues[si]; + final Quaternion r = rValues[ri]; final m = Matrix4.compose(t, r, s); @@ -843,7 +871,7 @@ void testLeftTranslate() { // Apply the transformation to p. This will move (0.5, 0, 0) to (2.0, 0, 0). // Scale: 0.5 -> 1.0. // Translate: 1.0 -> 2.0 - var result = m.transformed3(p); + Vector3 result = m.transformed3(p); expect(result.x, equals(2.0)); expect(result.y, equals(0.0)); expect(result.z, equals(0.0)); diff --git a/packages/vector_math/test/obb3_test.dart b/packages/vector_math/test/obb3_test.dart index 186853e..a7cd8c3 100644 --- a/packages/vector_math/test/obb3_test.dart +++ b/packages/vector_math/test/obb3_test.dart @@ -11,9 +11,10 @@ import 'package:vector_math/vector_math.dart'; import 'test_utils.dart'; void testCorners() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); a.copyCorner(0, corner); @@ -42,9 +43,10 @@ void testCorners() { } void testTranslate() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); a.translate(Vector3(-1.0, 2.0, 3.0)); @@ -75,9 +77,10 @@ void testTranslate() { } void testRotate() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); final matrix = Matrix3.rotationY(radians(-45.0)); @@ -109,9 +112,10 @@ void testRotate() { } void testTransform() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(5.0, 5.0, 5.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(5.0, 5.0, 5.0); final corner = Vector3.zero(); final matrix = Matrix4.diagonal3Values(3.0, 3.0, 3.0); @@ -143,9 +147,10 @@ void testTransform() { } void testClosestPointTo() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(2.0, 2.0, 2.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(2.0, 2.0, 2.0); final b = Vector3(3.0, 3.0, 3.0); final c = Vector3(3.0, 3.0, -3.0); final closestPoint = Vector3.zero(); @@ -170,45 +175,55 @@ void testClosestPointTo() { } void testIntersectionObb3() { - final a = Obb3() - ..center.setValues(0.0, 0.0, 0.0) - ..halfExtents.setValues(2.0, 2.0, 2.0); - - final b = Obb3() - ..center.setValues(3.0, 0.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final c = Obb3() - ..center.setValues(0.0, 3.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final d = Obb3() - ..center.setValues(0.0, 0.0, 3.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final e = Obb3() - ..center.setValues(-3.0, 0.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final f = Obb3() - ..center.setValues(0.0, -3.0, 0.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final g = Obb3() - ..center.setValues(0.0, 0.0, -3.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final u = Obb3() - ..center.setValues(1.0, 1.0, 1.0) - ..halfExtents.setValues(0.5, 0.5, 0.5); - - final v = Obb3() - ..center.setValues(10.0, 10.0, -10.0) - ..halfExtents.setValues(2.0, 2.0, 2.0); - - final w = Obb3() - ..center.setValues(10.0, 0.0, 0.0) - ..halfExtents.setValues(1.0, 1.0, 1.0); + final a = + Obb3() + ..center.setValues(0.0, 0.0, 0.0) + ..halfExtents.setValues(2.0, 2.0, 2.0); + + final b = + Obb3() + ..center.setValues(3.0, 0.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final c = + Obb3() + ..center.setValues(0.0, 3.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final d = + Obb3() + ..center.setValues(0.0, 0.0, 3.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final e = + Obb3() + ..center.setValues(-3.0, 0.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final f = + Obb3() + ..center.setValues(0.0, -3.0, 0.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final g = + Obb3() + ..center.setValues(0.0, 0.0, -3.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final u = + Obb3() + ..center.setValues(1.0, 1.0, 1.0) + ..halfExtents.setValues(0.5, 0.5, 0.5); + + final v = + Obb3() + ..center.setValues(10.0, 10.0, -10.0) + ..halfExtents.setValues(2.0, 2.0, 2.0); + + final w = + Obb3() + ..center.setValues(10.0, 0.0, 0.0) + ..halfExtents.setValues(1.0, 1.0, 1.0); // a - b expect(a.intersectsWithObb3(b), isFalse); @@ -302,13 +317,14 @@ void testIntersectionObb3() { void testIntersectionVector3() { //final parent = new Aabb3.minMax(_v(1.0,1.0,1.0), _v(8.0,8.0,8.0)); - final parent = Obb3() - ..center.setValues(4.5, 4.5, 4.5) - ..halfExtents.setValues(3.5, 3.5, 3.5); - final child = $v3(7.0, 7.0, 7.0); - final cutting = $v3(1.0, 2.0, 1.0); - final outside1 = $v3(-10.0, 10.0, 10.0); - final outside2 = $v3(4.5, 4.5, 9.0); + final parent = + Obb3() + ..center.setValues(4.5, 4.5, 4.5) + ..halfExtents.setValues(3.5, 3.5, 3.5); + final Vector3 child = $v3(7.0, 7.0, 7.0); + final Vector3 cutting = $v3(1.0, 2.0, 1.0); + final Vector3 outside1 = $v3(-10.0, 10.0, 10.0); + final Vector3 outside2 = $v3(4.5, 4.5, 9.0); expect(parent.intersectsWithVector3(child), isTrue); expect(parent.intersectsWithVector3(cutting), isTrue); diff --git a/packages/vector_math/test/opengl_matrix_test.dart b/packages/vector_math/test/opengl_matrix_test.dart index 3926c43..bafbd09 100644 --- a/packages/vector_math/test/opengl_matrix_test.dart +++ b/packages/vector_math/test/opengl_matrix_test.dart @@ -13,14 +13,14 @@ void testUnproject() { final position = Vector3(0.0, 0.0, 0.0); final focusPosition = Vector3(0.0, 0.0, -1.0); final upDirection = Vector3(0.0, 1.0, 0.0); - final lookat = makeViewMatrix(position, focusPosition, upDirection); - final n = 0.1; - final f = 1000.0; - final l = -10.0; - final r = 10.0; - final b = -10.0; - final t = 10.0; - final frustum = makeFrustumMatrix(l, r, b, t, n, f); + final Matrix4 lookat = makeViewMatrix(position, focusPosition, upDirection); + const n = 0.1; + const f = 1000.0; + const l = -10.0; + const r = 10.0; + const b = -10.0; + const t = 10.0; + final Matrix4 frustum = makeFrustumMatrix(l, r, b, t, n, f); final C = frustum * lookat as Matrix4; final re = Vector3.zero(); unproject(C, 0.0, 100.0, 0.0, 100.0, 50.0, 50.0, 1.0, re); @@ -31,7 +31,11 @@ void testLookAt() { final lookAtPosition = Vector3(0.0, 0.0, -1.0); final upDirection = Vector3(0.0, 1.0, 0.0); - final lookat = makeViewMatrix(eyePosition, lookAtPosition, upDirection); + final Matrix4 lookat = makeViewMatrix( + eyePosition, + lookAtPosition, + upDirection, + ); assert(lookat.getColumn(0).w == 0.0); assert(lookat.getColumn(1).w == 0.0); assert(lookat.getColumn(2).w == 0.0); @@ -43,13 +47,13 @@ void testLookAt() { } void testFrustumMatrix() { - final n = 0.1; - final f = 1000.0; - final l = -1.0; - final r = 1.0; - final b = -1.0; - final t = 1.0; - final frustum = makeFrustumMatrix(l, r, b, t, n, f); + const n = 0.1; + const f = 1000.0; + const l = -1.0; + const r = 1.0; + const b = -1.0; + const t = 1.0; + final Matrix4 frustum = makeFrustumMatrix(l, r, b, t, n, f); relativeTest(frustum.getColumn(0), Vector4(2 * n / (r - l), 0.0, 0.0, 0.0)); relativeTest(frustum.getColumn(1), Vector4(0.0, 2 * n / (t - b), 0.0, 0.0)); relativeTest( @@ -63,12 +67,17 @@ void testFrustumMatrix() { } void testPerspectiveMatrix() { - final fov = pi / 2; - final aspectRatio = 2.0; - final zNear = 1.0; - final zFar = 100.0; - - final perspective = makePerspectiveMatrix(fov, aspectRatio, zNear, zFar); + const double fov = pi / 2; + const aspectRatio = 2.0; + const zNear = 1.0; + const zFar = 100.0; + + final Matrix4 perspective = makePerspectiveMatrix( + fov, + aspectRatio, + zNear, + zFar, + ); relativeTest(perspective.getColumn(0), Vector4(0.5, 0.0, 0.0, 0.0)); relativeTest(perspective.getColumn(1), Vector4(0.0, 1.0, 0.0, 0.0)); relativeTest( @@ -79,11 +88,11 @@ void testPerspectiveMatrix() { } void testInfiniteMatrix() { - final fov = pi / 2; - final aspectRatio = 2.0; - final zNear = 1.0; + const double fov = pi / 2; + const aspectRatio = 2.0; + const zNear = 1.0; - final infinite = makeInfiniteMatrix(fov, aspectRatio, zNear); + final Matrix4 infinite = makeInfiniteMatrix(fov, aspectRatio, zNear); relativeTest(infinite.getColumn(0), Vector4(0.5, 0.0, 0.0, 0.0)); relativeTest(infinite.getColumn(1), Vector4(0.0, 1.0, 0.0, 0.0)); relativeTest(infinite.getColumn(2), Vector4(0.0, 0.0, -1.0, -1.0)); @@ -91,13 +100,13 @@ void testInfiniteMatrix() { } void testOrthographicMatrix() { - final n = 0.1; - final f = 1000.0; - final l = -1.0; - final r = 1.0; - final b = -1.0; - final t = 1.0; - final ortho = makeOrthographicMatrix(l, r, b, t, n, f); + const n = 0.1; + const f = 1000.0; + const l = -1.0; + const r = 1.0; + const b = -1.0; + const t = 1.0; + final Matrix4 ortho = makeOrthographicMatrix(l, r, b, t, n, f); relativeTest(ortho.getColumn(0), Vector4(2 / (r - l), 0.0, 0.0, 0.0)); relativeTest(ortho.getColumn(1), Vector4(0.0, 2 / (t - b), 0.0, 0.0)); relativeTest(ortho.getColumn(2), Vector4(0.0, 0.0, -2 / (f - n), 0.0)); @@ -117,16 +126,16 @@ void testModelMatrix() { final model = Matrix4.zero(); - final forward = focus.clone(); + final Vector3 forward = focus.clone(); forward.sub(position); forward.normalize(); - final right = forward.cross(up).normalized(); - final u = right.cross(forward).normalized(); + final Vector3 right = forward.cross(up).normalized(); + final Vector3 u = right.cross(forward).normalized(); setModelMatrix(model, forward, u, position.x, position.y, position.z); - final result1 = view.clone(); + final Matrix4 result1 = view.clone(); result1.multiply(model); relativeTest(result1, Matrix4.identity()); diff --git a/packages/vector_math/test/quaternion_test.dart b/packages/vector_math/test/quaternion_test.dart index 900cbc2..e086d5e 100644 --- a/packages/vector_math/test/quaternion_test.dart +++ b/packages/vector_math/test/quaternion_test.dart @@ -23,7 +23,7 @@ void testQuaternionInstacinfFromFloat32List() { void testQuaternionInstacingFromByteBuffer() { final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0]); - final buffer = float32List.buffer; + final ByteBuffer buffer = float32List.buffer; final zeroOffset = Quaternion.fromBuffer(buffer, 0); final offsetVector = Quaternion.fromBuffer( buffer, @@ -44,8 +44,8 @@ void testQuaternionInstacingFromByteBuffer() { void testNegate(List input, List expectedOutput) { assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output1 = -input[i]; - final output2 = input[i]..negate(); + final Quaternion output1 = -input[i]; + final Quaternion output2 = input[i]..negate(); relativeTest(output1, expectedOutput[i]); relativeTest(output2, expectedOutput[i]); } @@ -54,14 +54,14 @@ void testNegate(List input, List expectedOutput) { void testConjugate(List input, List expectedOutput) { assert(input.length == expectedOutput.length); for (var i = 0; i < input.length; i++) { - final output = input[i]..conjugate(); + final Quaternion output = input[i]..conjugate(); relativeTest(output, expectedOutput[i]); } } void testQuaternionMatrixRoundTrip(List input) { for (var i = 0; i < input.length; i++) { - final R = input[i].asRotationMatrix(); + final Matrix3 R = input[i].asRotationMatrix(); final output = Quaternion.fromRotation(R); relativeTest(output, input[i]); } @@ -73,7 +73,7 @@ void testQuaternionMultiply( List expectedOutput, ) { for (var i = 0; i < inputA.length; i++) { - final output = inputA[i] * inputB[i]; + final Quaternion output = inputA[i] * inputB[i]; relativeTest(output, expectedOutput[i]); } } @@ -88,7 +88,7 @@ void testQuaternionVectorRotate( (inputB.length == expectedOutput.length), ); for (var i = 0; i < inputA.length; i++) { - final output = inputA[i].rotate(inputB[i]); + final Vector3 output = inputA[i].rotate(inputB[i]); relativeTest(output, expectedOutput[i]); } } diff --git a/packages/vector_math/test/ray_test.dart b/packages/vector_math/test/ray_test.dart index 3e76555..3ba419d 100644 --- a/packages/vector_math/test/ray_test.dart +++ b/packages/vector_math/test/ray_test.dart @@ -13,9 +13,9 @@ import 'test_utils.dart'; void testRayAt() { final parent = Ray.originDirection($v3(1.0, 1.0, 1.0), $v3(-1.0, 1.0, 1.0)); - final atOrigin = parent.at(0.0); - final atPositive = parent.at(1.0); - final atNegative = parent.at(-2.0); + final Vector3 atOrigin = parent.at(0.0); + final Vector3 atPositive = parent.at(1.0); + final Vector3 atNegative = parent.at(-2.0); expect(atOrigin.x, equals(1.0)); expect(atOrigin.y, equals(1.0)); diff --git a/packages/vector_math/test/sphere_test.dart b/packages/vector_math/test/sphere_test.dart index 1cb9b07..c735b27 100644 --- a/packages/vector_math/test/sphere_test.dart +++ b/packages/vector_math/test/sphere_test.dart @@ -10,9 +10,9 @@ import 'test_utils.dart'; void testSphereContainsVector3() { final parent = Sphere.centerRadius($v3(1.0, 1.0, 1.0), 2.0); - final child = $v3(1.0, 1.0, 2.0); - final cutting = $v3(1.0, 3.0, 1.0); - final outside = $v3(-10.0, 10.0, 10.0); + final Vector3 child = $v3(1.0, 1.0, 2.0); + final Vector3 cutting = $v3(1.0, 3.0, 1.0); + final Vector3 outside = $v3(-10.0, 10.0, 10.0); expect(parent.containsVector3(child), isTrue); expect(parent.containsVector3(cutting), isFalse); @@ -21,9 +21,9 @@ void testSphereContainsVector3() { void testSphereIntersectionVector3() { final parent = Sphere.centerRadius($v3(1.0, 1.0, 1.0), 2.0); - final child = $v3(1.0, 1.0, 2.0); - final cutting = $v3(1.0, 3.0, 1.0); - final outside = $v3(-10.0, 10.0, 10.0); + final Vector3 child = $v3(1.0, 1.0, 2.0); + final Vector3 cutting = $v3(1.0, 3.0, 1.0); + final Vector3 outside = $v3(-10.0, 10.0, 10.0); expect(parent.intersectsWithVector3(child), isTrue); expect(parent.intersectsWithVector3(cutting), isTrue); diff --git a/packages/vector_math/test/test_utils.dart b/packages/vector_math/test/test_utils.dart index 0c4c349..fc436d7 100644 --- a/packages/vector_math/test/test_utils.dart +++ b/packages/vector_math/test/test_utils.dart @@ -12,7 +12,7 @@ Vector3 $v3(double x, double y, double z) => Vector3(x, y, z); Vector4 $v4(double x, double y, double z, double w) => Vector4(x, y, z, w); void relativeTest(dynamic output, dynamic expectedOutput) { - final errorThreshold = 0.0005; + const errorThreshold = 0.0005; final num error = relativeError(output, expectedOutput).abs(); expect( error >= errorThreshold, @@ -22,7 +22,7 @@ void relativeTest(dynamic output, dynamic expectedOutput) { } void absoluteTest(dynamic output, dynamic expectedOutput) { - final errorThreshold = 0.0005; + const errorThreshold = 0.0005; final num error = absoluteError(output, expectedOutput).abs(); expect( error >= errorThreshold, @@ -51,12 +51,12 @@ dynamic makeMatrix(int rows, int cols) { T parseMatrix(String input) { input = input.trim(); - final rows = input.split('\n'); + final List rows = input.split('\n'); final values = []; - var col_count = 0; + var colCount = 0; for (var i = 0; i < rows.length; i++) { rows[i] = rows[i].trim(); - final cols = rows[i].split(' '); + final List cols = rows[i].split(' '); for (var j = 0; j < cols.length; j++) { cols[j] = cols[j].trim(); } @@ -66,17 +66,17 @@ T parseMatrix(String input) { continue; } if (i == 0) { - col_count++; + colCount++; } values.add(double.parse(cols[j])); } } - final dynamic m = makeMatrix(rows.length, col_count); + final dynamic m = makeMatrix(rows.length, colCount); for (var j = 0; j < rows.length; j++) { - for (var i = 0; i < col_count; i++) { + for (var i = 0; i < colCount; i++) { // ignore: avoid_dynamic_calls - m[m.index(j, i)] = values[j * col_count + i]; + m[m.index(j, i)] = values[j * colCount + i]; } } @@ -86,11 +86,11 @@ T parseMatrix(String input) { T parseVector(String v) { v = v.trim(); final Pattern pattern = RegExp( - '[\\s]+', + r'[\s]+', multiLine: true, caseSensitive: false, ); - final rows = v.split(pattern); + final List rows = v.split(pattern); final values = []; for (var i = 0; i < rows.length; i++) { rows[i] = rows[i].trim(); diff --git a/packages/vector_math/test/vector2_test.dart b/packages/vector_math/test/vector2_test.dart index 988ea02..e68816f 100644 --- a/packages/vector_math/test/vector2_test.dart +++ b/packages/vector_math/test/vector2_test.dart @@ -20,7 +20,7 @@ void testVector2InstacinfFromFloat32List() { void testVector2InstacingFromByteBuffer() { final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0]); - final buffer = float32List.buffer; + final ByteBuffer buffer = float32List.buffer; final zeroOffset = Vector2.fromBuffer(buffer, 0); final offsetVector = Vector2.fromBuffer(buffer, Float32List.bytesPerElement); @@ -81,7 +81,7 @@ void testVector2Mix() { void testVector2DotProduct() { final inputA = Vector2(0.417267069084370, 0.049654430325742); final inputB = Vector2(0.944787189721646, 0.490864092468080); - final expectedOutput = 0.418602158442475; + const expectedOutput = 0.418602158442475; relativeTest(dot2(inputA, inputB), expectedOutput); relativeTest(dot2(inputB, inputA), expectedOutput); } @@ -105,7 +105,7 @@ void testVector2Postmultiplication() { void testVector2CrossProduct() { final inputA = Vector2(0.417267069084370, 0.049654430325742); final inputB = Vector2(0.944787189721646, 0.490864092468080); - final expectedOutputCross = inputA.x * inputB.y - inputA.y * inputB.x; + final double expectedOutputCross = inputA.x * inputB.y - inputA.y * inputB.x; dynamic result; result = cross2(inputA, inputB); relativeTest(result, expectedOutputCross); @@ -252,8 +252,8 @@ void testVector2AngleTo() { final v0 = Vector2(1.0, 0.0); final v1 = Vector2(0.0, 1.0); final v2 = Vector2(1.0, 1.0); - final v3 = v2.normalized(); - final tol = 1e-8; + final Vector2 v3 = v2.normalized(); + const tol = 1e-8; expect(v0.angleTo(v0), equals(0.0)); expect(v0.angleTo(v1), equals(math.pi / 2.0)); @@ -273,7 +273,7 @@ void testVector2AngleToSigned() { } void testVector2Clamp() { - final x = 2.0, y = 3.0; + const x = 2.0, y = 3.0; final v0 = Vector2(x, y); final v1 = Vector2(-x, -y); final v2 = Vector2(-2.0 * x, 2.0 * y)..clamp(v1, v0); @@ -282,7 +282,7 @@ void testVector2Clamp() { } void testVector2ClampScalar() { - final x = 2.0; + const x = 2.0; final v0 = Vector2(-2.0 * x, 2.0 * x)..clampScalar(-x, x); expect(v0.storage, orderedEquals([-x, x])); } diff --git a/packages/vector_math/test/vector3_test.dart b/packages/vector_math/test/vector3_test.dart index d26d0c2..c29d944 100644 --- a/packages/vector_math/test/vector3_test.dart +++ b/packages/vector_math/test/vector3_test.dart @@ -21,7 +21,7 @@ void testVector3InstacinfFromFloat32List() { void testVector3InstacingFromByteBuffer() { final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0]); - final buffer = float32List.buffer; + final ByteBuffer buffer = float32List.buffer; final zeroOffset = Vector3.fromBuffer(buffer, 0); final offsetVector = Vector3.fromBuffer(buffer, Float32List.bytesPerElement); @@ -93,12 +93,14 @@ void testVector3DotProduct() { final inputB = []; final expectedOutput = []; inputA.add( - parseVector('''0.417267069084370 + parseVector(''' +0.417267069084370 0.049654430325742 0.902716109915281'''), ); inputB.add( - parseVector('''0.944787189721646 + parseVector(''' +0.944787189721646 0.490864092468080 0.489252638400019'''), ); @@ -106,8 +108,8 @@ void testVector3DotProduct() { assert(inputA.length == inputB.length); assert(inputB.length == expectedOutput.length); for (var i = 0; i < inputA.length; i++) { - final output1 = dot3(inputA[i], inputB[i]); - final output2 = dot3(inputB[i], inputA[i]); + final double output1 = dot3(inputA[i], inputB[i]); + final double output2 = dot3(inputB[i], inputA[i]); relativeTest(output1, expectedOutput[i]); relativeTest(output2, expectedOutput[i]); } @@ -137,33 +139,39 @@ void testVector3CrossProduct() { final expectedOutput = []; inputA.add( - parseVector('''0.417267069084370 + parseVector(''' +0.417267069084370 0.049654430325742 0.902716109915281'''), ); inputB.add( - parseVector('''0.944787189721646 + parseVector(''' +0.944787189721646 0.490864092468080 0.489252638400019'''), ); expectedOutput.add( - parseVector(''' -0.418817363004761 + parseVector(''' + -0.418817363004761 0.648725602136344 0.157908551498227'''), ); inputA.add( - parseVector('''0.944787189721646 + parseVector(''' +0.944787189721646 0.490864092468080 0.489252638400019'''), ); inputB.add( - parseVector('''0.417267069084370 + parseVector(''' +0.417267069084370 0.049654430325742 0.902716109915281'''), ); expectedOutput.add( - parseVector(''' 0.418817363004761 + parseVector(''' + 0.418817363004761 -0.648725602136344 -0.157908551498227'''), ); @@ -340,8 +348,8 @@ void testVector3Reflect() { void testVector3Projection() { final v = Vector3(1.0, 1.0, 1.0); - final a = 2.0 / 3.0; - final b = 1.0 / 3.0; + const double a = 2.0 / 3.0; + const double b = 1.0 / 3.0; final m = Matrix4( a, b, @@ -389,8 +397,8 @@ void testVector3AngleTo() { final v0 = Vector3(1.0, 0.0, 0.0); final v1 = Vector3(0.0, 1.0, 0.0); final v2 = Vector3(1.0, 1.0, 0.0); - final v3 = v2.normalized(); - final tol = 1e-8; + final Vector3 v3 = v2.normalized(); + const tol = 1e-8; expect(v0.angleTo(v0), equals(0.0)); expect(v0.angleTo(v1), equals(math.pi / 2.0)); @@ -409,7 +417,7 @@ void testVector3AngleToSigned() { } void testVector3Clamp() { - final x = 2.0, y = 3.0, z = 4.0; + const x = 2.0, y = 3.0, z = 4.0; final v0 = Vector3(x, y, z); final v1 = Vector3(-x, -y, -z); final v2 = Vector3(-2.0 * x, 2.0 * y, -2.0 * z)..clamp(v1, v0); @@ -418,7 +426,7 @@ void testVector3Clamp() { } void testVector3ClampScalar() { - final x = 2.0; + const x = 2.0; final v0 = Vector3(-2.0 * x, 2.0 * x, -2.0 * x)..clampScalar(-x, x); expect(v0.storage, orderedEquals([-x, x, -x])); diff --git a/packages/vector_math/test/vector4_test.dart b/packages/vector_math/test/vector4_test.dart index 275d89f..652a19a 100644 --- a/packages/vector_math/test/vector4_test.dart +++ b/packages/vector_math/test/vector4_test.dart @@ -22,7 +22,7 @@ void testVector4InstacinfFromFloat32List() { void testVector4InstacingFromByteBuffer() { final float32List = Float32List.fromList([1.0, 2.0, 3.0, 4.0, 5.0]); - final buffer = float32List.buffer; + final ByteBuffer buffer = float32List.buffer; final zeroOffset = Vector4.fromBuffer(buffer, 0); final offsetVector = Vector4.fromBuffer(buffer, Float32List.bytesPerElement); @@ -215,7 +215,7 @@ void testVector4DistanceToSquared() { } void testVector4Clamp() { - final x = 2.0, y = 3.0, z = 4.0, w = 5.0; + const x = 2.0, y = 3.0, z = 4.0, w = 5.0; final v0 = Vector4(x, y, z, w); final v1 = Vector4(-x, -y, -z, -w); final v2 = Vector4(-2.0 * x, 2.0 * y, -2.0 * z, 2.0 * w)..clamp(v1, v0); @@ -224,7 +224,7 @@ void testVector4Clamp() { } void testVector4ClampScalar() { - final x = 2.0; + const x = 2.0; final v0 = Vector4(-2.0 * x, 2.0 * x, -2.0 * x, 2.0 * x)..clampScalar(-x, x); expect(v0.storage, orderedEquals([-x, x, -x, x])); diff --git a/packages/vector_math/tool/generate_vector_math_64.dart b/packages/vector_math/tool/generate_vector_math_64.dart index d337027..4a4e788 100644 --- a/packages/vector_math/tool/generate_vector_math_64.dart +++ b/packages/vector_math/tool/generate_vector_math_64.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: avoid_print + import 'dart:async'; import 'dart:io'; @@ -17,7 +19,7 @@ Future generateVectorMath64() async { final directory = Directory('lib/src/vector_math_64/'); final libraryFile = File('lib/vector_math_64.dart'); - if (await directory.exists()) { + if (directory.existsSync()) { await directory.delete(recursive: true); } @@ -28,7 +30,7 @@ Future generateVectorMath64() async { await directory.create(recursive: true); await _processFile('lib/vector_math.dart'); - await for (FileSystemEntity f in Directory( + await for (final FileSystemEntity f in Directory( 'lib/src/vector_math/', ).list(recursive: true)) { if (f is File) { @@ -40,10 +42,10 @@ Future generateVectorMath64() async { Future _processFile(String inputFileName) async { final inputFile = File(inputFileName); - final input = await inputFile.readAsString(); - final output = _convertToVectorMath64(input); + final String input = await inputFile.readAsString(); + final String output = _convertToVectorMath64(input); - final outputFileName = inputFileName.replaceAll( + final String outputFileName = inputFileName.replaceAll( 'vector_math', 'vector_math_64', );