From 396bfbd0876620870e6d68f06a03bea53c6fb857 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Sun, 26 Nov 2023 16:10:52 +0100 Subject: [PATCH] Improve helpers --- api/lib/butterfly_helpers.dart | 6 ++-- .../helpers/{asset_helper.dart => asset.dart} | 0 .../helpers/{point_helper.dart => point.dart} | 0 .../{search_helper.dart => search.dart} | 0 api/lib/src/models/asset.dart | 2 +- .../{element_helper.dart => element.dart} | 0 app/lib/helpers/num_helper.dart | 21 -------------- app/lib/helpers/offset_helper.dart | 28 ------------------- .../helpers/{point_helper.dart => point.dart} | 2 +- .../helpers/{rect_helper.dart => rect.dart} | 0 app/lib/helpers/{xml_helper.dart => xml.dart} | 0 app/lib/models/label.dart | 2 +- app/lib/renderers/renderer.dart | 6 ++-- app/lib/renderers/textures/texture.dart | 2 +- app/lib/services/asset.dart | 2 +- app/lib/services/export.dart | 2 +- app/lib/views/navigator/components.dart | 2 +- app/lib/views/toolbar/components.dart | 2 +- app/pubspec.lock | 8 +++--- app/pubspec.yaml | 4 +-- 20 files changed, 20 insertions(+), 69 deletions(-) rename api/lib/src/helpers/{asset_helper.dart => asset.dart} (100%) rename api/lib/src/helpers/{point_helper.dart => point.dart} (100%) rename api/lib/src/helpers/{search_helper.dart => search.dart} (100%) rename app/lib/helpers/{element_helper.dart => element.dart} (100%) delete mode 100644 app/lib/helpers/num_helper.dart delete mode 100644 app/lib/helpers/offset_helper.dart rename app/lib/helpers/{point_helper.dart => point.dart} (94%) rename app/lib/helpers/{rect_helper.dart => rect.dart} (100%) rename app/lib/helpers/{xml_helper.dart => xml.dart} (100%) diff --git a/api/lib/butterfly_helpers.dart b/api/lib/butterfly_helpers.dart index 3a6c03fab310..4618b16fb3f9 100644 --- a/api/lib/butterfly_helpers.dart +++ b/api/lib/butterfly_helpers.dart @@ -1,3 +1,3 @@ -export 'src/helpers/asset_helper.dart'; -export 'src/helpers/point_helper.dart'; -export 'src/helpers/search_helper.dart'; +export 'src/helpers/asset.dart'; +export 'src/helpers/point.dart'; +export 'src/helpers/search.dart'; diff --git a/api/lib/src/helpers/asset_helper.dart b/api/lib/src/helpers/asset.dart similarity index 100% rename from api/lib/src/helpers/asset_helper.dart rename to api/lib/src/helpers/asset.dart diff --git a/api/lib/src/helpers/point_helper.dart b/api/lib/src/helpers/point.dart similarity index 100% rename from api/lib/src/helpers/point_helper.dart rename to api/lib/src/helpers/point.dart diff --git a/api/lib/src/helpers/search_helper.dart b/api/lib/src/helpers/search.dart similarity index 100% rename from api/lib/src/helpers/search_helper.dart rename to api/lib/src/helpers/search.dart diff --git a/api/lib/src/models/asset.dart b/api/lib/src/models/asset.dart index 5cab7ddbcf7d..51ba4e9828cd 100644 --- a/api/lib/src/models/asset.dart +++ b/api/lib/src/models/asset.dart @@ -2,7 +2,7 @@ import 'dart:typed_data'; import 'package:freezed_annotation/freezed_annotation.dart'; -import '../helpers/asset_helper.dart'; +import '../helpers/asset.dart'; import 'data.dart'; import 'meta.dart'; diff --git a/app/lib/helpers/element_helper.dart b/app/lib/helpers/element.dart similarity index 100% rename from app/lib/helpers/element_helper.dart rename to app/lib/helpers/element.dart diff --git a/app/lib/helpers/num_helper.dart b/app/lib/helpers/num_helper.dart deleted file mode 100644 index b7660816d1c9..000000000000 --- a/app/lib/helpers/num_helper.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'dart:ui'; - -extension IntHelper on int? { - int? add(int? value) { - if (this == null || value == null) return null; - return this! + value; - } - - int? subtract(int? value) { - if (this == null || value == null) return null; - return this! - value; - } -} - -extension DoubleHelper on double { - double toPrecision(int n) => double.parse(toStringAsFixed(n)); -} - -int convertColor(int color, int alpha) => Color(color).withAlpha(alpha).value; -int convertOldColor(int color, int old) => - convertColor(color, Color(old).alpha); diff --git a/app/lib/helpers/offset_helper.dart b/app/lib/helpers/offset_helper.dart deleted file mode 100644 index 7274f437123e..000000000000 --- a/app/lib/helpers/offset_helper.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'dart:math'; -import 'dart:ui'; - -extension OffsetHelper on Offset { - Offset rotate(Offset pivot, double radians) { - final x = dx - pivot.dx; - final y = dy - pivot.dy; - final cosA = cos(radians); - final sinA = sin(radians); - return Offset( - x * cosA - y * sinA + pivot.dx, - x * sinA + y * cosA + pivot.dy, - ); - } - - Offset scaleFromCenter(double zoom, Offset center) => Offset( - (dx - center.dx) * zoom + center.dx, - (dy - center.dy) * zoom + center.dy, - ); - - double getRotation(Offset pivot) { - final x = dx - pivot.dx; - final y = dy - pivot.dy; - return atan2(y, x); - } - - Point toPoint() => Point(dx, dy); -} diff --git a/app/lib/helpers/point_helper.dart b/app/lib/helpers/point.dart similarity index 94% rename from app/lib/helpers/point_helper.dart rename to app/lib/helpers/point.dart index ed6694c39f7f..60cd586ae301 100644 --- a/app/lib/helpers/point_helper.dart +++ b/app/lib/helpers/point.dart @@ -1,8 +1,8 @@ import 'dart:math'; import 'dart:ui'; -import 'package:butterfly/helpers/offset_helper.dart'; import 'package:butterfly_api/butterfly_api.dart'; +import 'package:material_leap/material_leap.dart'; import 'package:perfect_freehand/perfect_freehand.dart' as freehand show Point; import 'package:vector_math/vector_math.dart' show Vector2; diff --git a/app/lib/helpers/rect_helper.dart b/app/lib/helpers/rect.dart similarity index 100% rename from app/lib/helpers/rect_helper.dart rename to app/lib/helpers/rect.dart diff --git a/app/lib/helpers/xml_helper.dart b/app/lib/helpers/xml.dart similarity index 100% rename from app/lib/helpers/xml_helper.dart rename to app/lib/helpers/xml.dart diff --git a/app/lib/models/label.dart b/app/lib/models/label.dart index 6df8f7558ab5..0af069040b91 100644 --- a/app/lib/models/label.dart +++ b/app/lib/models/label.dart @@ -1,6 +1,6 @@ import 'dart:math'; -import 'package:butterfly/helpers/rect_helper.dart'; +import 'package:butterfly/helpers/rect.dart'; import 'package:butterfly_api/butterfly_api.dart'; import 'package:butterfly_api/butterfly_text.dart'; import 'package:flutter/material.dart'; diff --git a/app/lib/renderers/renderer.dart b/app/lib/renderers/renderer.dart index c3bb18fb46b9..de790036b9e2 100644 --- a/app/lib/renderers/renderer.dart +++ b/app/lib/renderers/renderer.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'dart:math'; import 'dart:ui' as ui; -import 'package:butterfly/helpers/element_helper.dart'; +import 'package:butterfly/helpers/element.dart'; import 'package:butterfly/helpers/offset_helper.dart'; -import 'package:butterfly/helpers/rect_helper.dart'; +import 'package:butterfly/helpers/rect.dart'; import 'package:butterfly/helpers/point_helper.dart'; import 'package:butterfly/visualizer/element.dart'; import 'package:butterfly/visualizer/text.dart'; @@ -20,7 +20,7 @@ import 'package:xml/xml.dart'; import '../cubits/current_index.dart'; import '../cubits/transform.dart'; -import '../helpers/xml_helper.dart'; +import '../helpers/xml.dart'; import '../models/label.dart'; import '../services/asset.dart'; import 'textures/texture.dart'; diff --git a/app/lib/renderers/textures/texture.dart b/app/lib/renderers/textures/texture.dart index 1ca44620b96e..c8e60eb72396 100644 --- a/app/lib/renderers/textures/texture.dart +++ b/app/lib/renderers/textures/texture.dart @@ -1,6 +1,6 @@ import 'dart:ui'; -import 'package:butterfly/helpers/xml_helper.dart'; +import 'package:butterfly/helpers/xml.dart'; import 'package:butterfly_api/butterfly_api.dart'; import 'package:material_leap/material_leap.dart'; import 'package:xml/xml.dart'; diff --git a/app/lib/services/asset.dart b/app/lib/services/asset.dart index 3274366a6e21..a0036f95e687 100644 --- a/app/lib/services/asset.dart +++ b/app/lib/services/asset.dart @@ -2,7 +2,7 @@ import 'dart:ui' as ui; import 'package:butterfly_api/butterfly_api.dart'; -import '../helpers/element_helper.dart'; +import '../helpers/element.dart'; class AssetService { final NoteData document; diff --git a/app/lib/services/export.dart b/app/lib/services/export.dart index f2e70bc035a9..5d4787bb32e9 100644 --- a/app/lib/services/export.dart +++ b/app/lib/services/export.dart @@ -1,7 +1,7 @@ import 'package:butterfly/api/save_data.dart'; import 'package:butterfly/bloc/document_bloc.dart'; import 'package:butterfly/cubits/current_index.dart'; -import 'package:butterfly/helpers/element_helper.dart'; +import 'package:butterfly/helpers/element.dart'; import 'package:butterfly_api/butterfly_api.dart'; import 'package:flutter/material.dart'; diff --git a/app/lib/views/navigator/components.dart b/app/lib/views/navigator/components.dart index c78ab179b926..267010eb4077 100644 --- a/app/lib/views/navigator/components.dart +++ b/app/lib/views/navigator/components.dart @@ -10,7 +10,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:phosphor_flutter/phosphor_flutter.dart'; -import '../../helpers/element_helper.dart'; +import '../../helpers/element.dart'; class ComponentsView extends StatefulWidget { const ComponentsView({super.key}); diff --git a/app/lib/views/toolbar/components.dart b/app/lib/views/toolbar/components.dart index 1787dfecb6e7..6b481bee3c93 100644 --- a/app/lib/views/toolbar/components.dart +++ b/app/lib/views/toolbar/components.dart @@ -10,7 +10,7 @@ import 'package:material_leap/material_leap.dart'; import 'package:phosphor_flutter/phosphor_flutter.dart'; import '../../bloc/document_bloc.dart'; -import '../../helpers/element_helper.dart'; +import '../../helpers/element.dart'; class ComponentsToolbarView extends StatefulWidget implements PreferredSizeWidget { diff --git a/app/pubspec.lock b/app/pubspec.lock index c788401af2c8..8cfcf6eb5565 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -748,8 +748,8 @@ packages: dependency: "direct main" description: path: "packages/material_leap" - ref: "0fc0ed877e4cc91c30824cac5fcd3bb69d1c6276" - resolved-ref: "0fc0ed877e4cc91c30824cac5fcd3bb69d1c6276" + ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81" + resolved-ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81" url: "https://github.com/LinwoodDev/dart_pkgs.git" source: git version: "0.0.1" @@ -790,8 +790,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker_socket" - ref: c13172f924b7828b75f20b91c89b99b77771092f - resolved-ref: c13172f924b7828b75f20b91c89b99b77771092f + ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81" + resolved-ref: "75b5ec0e51096ae169df3cd4f02c9f6affe22a81" url: "https://github.com/LinwoodDev/dart_pkgs.git" source: git version: "1.0.0" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 1e70f42f86ea..b6e2429ee363 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -70,7 +70,7 @@ dependencies: material_leap: git: url: https://github.com/LinwoodDev/dart_pkgs.git - ref: 0fc0ed877e4cc91c30824cac5fcd3bb69d1c6276 + ref: 75b5ec0e51096ae169df3cd4f02c9f6affe22a81 path: packages/material_leap lw_sysinfo: git: @@ -85,7 +85,7 @@ dependencies: networker_socket: git: url: https://github.com/LinwoodDev/dart_pkgs.git - ref: c13172f924b7828b75f20b91c89b99b77771092f + ref: 75b5ec0e51096ae169df3cd4f02c9f6affe22a81 path: packages/networker/networker_socket flutter_localized_locales: ^2.0.5 dynamic_color: ^1.6.8