Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Marker remover #135

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/src/models/view/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class AutonomyModel with ChangeNotifier {
}

/// An empty grid of size [gridSize].
List<List<AutonomyCell>> get empty => [
List<List<(GpsCoordinates, AutonomyCell)>> get empty => [
for (int i = 0; i < gridSize; i++) [
for (int j = 0; j < gridSize; j++)
AutonomyCell.empty,
(GpsCoordinates(), AutonomyCell.empty),
],
];

Expand All @@ -105,7 +105,7 @@ class AutonomyModel with ChangeNotifier {
AutonomyData data = AutonomyData();

/// The grid of size [gridSize] with the rover in the center, ready to draw on the UI.
List<List<AutonomyCell>> get grid {
List<List<(GpsCoordinates, AutonomyCell)>> get grid {
final result = empty;
for (final obstacle in data.obstacles) {
markCell(result, obstacle, AutonomyCell.obstacle);
Expand All @@ -129,7 +129,7 @@ class AutonomyModel with ChangeNotifier {
/// Calculates a new position for [gps] based on [offset] and adds it to the [list].
///
/// This function filters out any coordinates that shouldn't be shown based on [gridSize].
void markCell(List<List<AutonomyCell>> list, GpsCoordinates gps, AutonomyCell value) {
void markCell(List<List<(GpsCoordinates, AutonomyCell)>> list, GpsCoordinates gps, AutonomyCell value) {
// Latitude is y-axis, longitude is x-axis
// The rover will occupy the center of the grid, so
// - rover.longitude => (gridSize - 1) / 2
Expand All @@ -139,7 +139,7 @@ class AutonomyModel with ChangeNotifier {
final y = gpsToBlock(gps.latitude) + offset.y;
if (x < 0 || x >= gridSize) return;
if (y < 0 || y >= gridSize) return;
list[y][x] = value;
list[y][x] = (gps, value);
}

/// Determines the new [offset] based on the current [roverPosition].
Expand Down Expand Up @@ -182,6 +182,15 @@ class AutonomyModel with ChangeNotifier {
notifyListeners();
}

/// Removes a marker in [gps]
void updateMarker(GpsCoordinates gps) {
if(markers.remove(gps)){
notifyListeners();
} else {
models.home.setMessage(severity: Severity.info, text: "Marker not found");
}
}

/// Deletes all the markers in [markers].
void clearMarkers() {
markers.clear();
Expand Down
21 changes: 11 additions & 10 deletions lib/src/pages/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class MapPage extends ReactiveWidget<AutonomyModel> {
title: const Text("Add a Marker"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
GpsEditor(model.markerBuilder),
],
children: [ GpsEditor(model.markerBuilder) ],
),
actions: [
TextButton(child: const Text("Cancel"), onPressed: () => Navigator.of(context).pop()),
Expand All @@ -51,13 +49,16 @@ class MapPage extends ReactiveWidget<AutonomyModel> {
for (final row in model.grid.reversed) Expanded(
child: Row(children: [
for (final cell in row) Expanded(
child: Container(
height: double.infinity,
width: 24,
decoration: BoxDecoration(color: getColor(cell), border: Border.all()),
child: cell != AutonomyCell.rover ? null : Transform.rotate(
angle: -model.roverHeading * pi / 180,
child: const Icon(Icons.arrow_upward, size: 24),
child: GestureDetector(
onTap: () => cell.$2 != AutonomyCell.marker ? () : model.updateMarker(cell.$1),
child: Container(
height: double.infinity,
width: 24,
decoration: BoxDecoration(color: getColor(cell.$2), border: Border.all()),
child: cell.$2 != AutonomyCell.rover ? null : Transform.rotate(
angle: -model.roverHeading * pi / 180,
child: const Icon(Icons.arrow_upward, size: 24),
),
),
),
),
Expand Down
36 changes: 18 additions & 18 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.0"
file_picker:
dependency: "direct main"
description:
Expand All @@ -166,10 +166,10 @@ packages:
dependency: "direct main"
description:
name: fl_chart
sha256: "00b74ae680df6b1135bdbea00a7d1fc072a9180b7c3f3702e4b19a9943f5ed7d"
sha256: b5e2b0f13d93f8c532b5a2786bfb44580de1f50b927bf95813fa1af617e9caf8
url: "https://pub.dev"
source: hosted
version: "0.66.2"
version: "0.66.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -203,10 +203,10 @@ packages:
dependency: "direct main"
description:
name: flutter_resizable_container
sha256: f7a9ba223df913956eef049a4381663b0a1a2f9514ced645d8d877d05cfcdf19
sha256: "58eabffc4ae3eccdb5090ec3c10e58c39993bf2c12b1b799f4449878cb0d4a51"
url: "https://pub.dev"
source: hosted
version: "0.4.0"
version: "0.4.1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -253,18 +253,18 @@ packages:
dependency: transitive
description:
name: image
sha256: "4c68bfd5ae83e700b5204c1e74451e7bf3cf750e6843c6e158289cf56bda018e"
sha256: "49a0d4b0c12402853d3f227fe7c315601b238d126aa4caa5dbb2dcf99421aa4a"
url: "https://pub.dev"
source: hosted
version: "4.1.7"
version: "4.1.6"
js:
dependency: transitive
description:
name: js
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
sha256: "4186c61b32f99e60f011f7160e32c89a758ae9b1d0c6d28e2c02ef0382300e2b"
url: "https://pub.dev"
source: hosted
version: "0.7.1"
version: "0.7.0"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -594,18 +594,18 @@ packages:
dependency: "direct main"
description:
name: url_launcher
sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e"
sha256: c512655380d241a337521703af62d2c122bf7b77a46ff7dd750092aa9433499c
url: "https://pub.dev"
source: hosted
version: "6.2.5"
version: "6.2.4"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745
sha256: "507dc655b1d9cb5ebc756032eb785f114e415f91557b73bf60b7e201dfedeb2f"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
version: "6.2.2"
url_launcher_ios:
dependency: transitive
description:
Expand Down Expand Up @@ -634,10 +634,10 @@ packages:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
sha256: a932c3a8082e118f80a475ce692fde89dc20fddb24c57360b96bc56f7035de1f
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.1"
url_launcher_web:
dependency: transitive
description:
Expand Down Expand Up @@ -690,10 +690,10 @@ packages:
dependency: transitive
description:
name: web
sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05"
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.4.2"
version: "0.3.0"
win32:
dependency: transitive
description:
Expand Down
Loading