mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Refactor: extract math utilities
This commit is contained in:
parent
7236e033d9
commit
2186cac470
20 changed files with 52 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
|||
import 'dart:math' as math;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:nc_photos/int_extension.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
|
||||
extension ListExtension<T> on List<T> {
|
||||
Iterable<T> takeIndex(List<int> indexes) => indexes.map((e) => this[e]);
|
||||
|
|
|
@ -4,10 +4,10 @@ import 'package:collection/collection.dart';
|
|||
import 'package:kdtree/kdtree.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/math_util.dart' as math_util;
|
||||
import 'package:nc_photos/mobile/platform.dart'
|
||||
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
import 'package:sqlite3/common.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
|
@ -58,10 +58,10 @@ class ReverseGeocoder {
|
|||
_log.info("[call] Nearest point, (lat: $nearestLatF, lng: $nearestLngF)");
|
||||
try {
|
||||
final distance = _distanceInKm(
|
||||
math_util.degToRad(latitude),
|
||||
math_util.degToRad(longitude),
|
||||
math_util.degToRad(nearestLatF),
|
||||
math_util.degToRad(nearestLngF),
|
||||
degToRad(latitude),
|
||||
degToRad(longitude),
|
||||
degToRad(nearestLatF),
|
||||
degToRad(nearestLngF),
|
||||
);
|
||||
_log.info(
|
||||
"[call] (lat: ${latitude.toStringAsFixed(3)}, lng: ${longitude.toStringAsFixed(3)}) <-> (lat: $nearestLatF, lng: $nearestLngF) = ${distance.toStringAsFixed(3)}km");
|
||||
|
|
|
@ -2,8 +2,8 @@ import 'dart:async';
|
|||
import 'dart:math' as math;
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/int_util.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
|
||||
part 'throttler.g.dart';
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/num_extension.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
|
||||
part 'photo_date_time_edit_dialog.g.dart';
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/num_extension.dart';
|
||||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
|
|
|
@ -983,6 +983,13 @@ packages:
|
|||
relative: true
|
||||
source: path
|
||||
version: "1.0.0"
|
||||
np_math:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../np_math"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0"
|
||||
np_ui:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
@ -105,6 +105,8 @@ dependencies:
|
|||
path: ../np_common
|
||||
np_log:
|
||||
path: ../np_log
|
||||
np_math:
|
||||
path: ../np_math
|
||||
np_ui:
|
||||
path: ../np_ui
|
||||
octo_image: any
|
||||
|
|
|
@ -3,9 +3,9 @@ import 'package:nc_photos/entity/file.dart';
|
|||
import 'package:nc_photos/entity/file/data_source.dart';
|
||||
import 'package:nc_photos/entity/file/file_cache_manager.dart';
|
||||
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
|
||||
import 'package:nc_photos/int_extension.dart';
|
||||
import 'package:nc_photos/list_extension.dart';
|
||||
import 'package:np_common/or_null.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../mock_type.dart';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:nc_photos/int_extension.dart';
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:np_math/np_math.dart';
|
||||
import 'package:quiver/core.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
|
7
np_math/.gitignore
vendored
Normal file
7
np_math/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
# https://dart.dev/guides/libraries/private-files
|
||||
# Created by `dart pub`
|
||||
.dart_tool/
|
||||
|
||||
# Avoid committing pubspec.lock for library packages; see
|
||||
# https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
pubspec.lock
|
1
np_math/analysis_options.yaml
Normal file
1
np_math/analysis_options.yaml
Normal file
|
@ -0,0 +1 @@
|
|||
include: package:np_lints/np.yaml
|
6
np_math/lib/np_math.dart
Normal file
6
np_math/lib/np_math.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
library np_math;
|
||||
|
||||
export 'src/int_extension.dart';
|
||||
export 'src/int_util.dart';
|
||||
export 'src/math_util.dart';
|
||||
export 'src/num_extension.dart';
|
13
np_math/pubspec.yaml
Normal file
13
np_math/pubspec.yaml
Normal file
|
@ -0,0 +1,13 @@
|
|||
name: np_math
|
||||
description: A starting point for Dart libraries or applications.
|
||||
version: 1.0.0
|
||||
# repository: https://github.com/my_org/my_repo
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: '>=2.19.6 <3.0.0'
|
||||
|
||||
dev_dependencies:
|
||||
np_lints:
|
||||
path: ../np_lints
|
||||
test: ^1.21.0
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:nc_photos/int_extension.dart';
|
||||
import 'package:np_math/src/int_extension.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
|
@ -1,15 +1,15 @@
|
|||
import 'dart:math' as math;
|
||||
|
||||
import 'package:nc_photos/math_util.dart' as math_util;
|
||||
import 'package:np_math/src/math_util.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group("math_util", () {
|
||||
test("degToRad", () {
|
||||
expect(math_util.degToRad(90), closeTo(1.570796, 1e-6));
|
||||
expect(degToRad(90), closeTo(1.570796, 1e-6));
|
||||
});
|
||||
test("radToDeg", () {
|
||||
expect(math_util.radToDeg(math.pi), 180);
|
||||
expect(radToDeg(math.pi), 180);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:nc_photos/num_extension.dart';
|
||||
import 'package:np_math/src/num_extension.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
Loading…
Reference in a new issue