-
Notifications
You must be signed in to change notification settings - Fork 0
feat(llc): Add location-based filtering support #22
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3be5480
feat(llc): Add location-based filtering support
xsahil03x 3c26318
chore: update CHANGELOG.md
xsahil03x ef46321
chore: minor update
xsahil03x f5190b1
chore: minor import improvement
xsahil03x 3e384d4
feat: Add equality comparison and hashCode for LocationCoordinate
xsahil03x a6d6e24
feat: Improve equality comparison for LocationCoordinate with near-eq…
xsahil03x 5b4c75e
Merge branch 'main' into feat/location-filtering
xsahil03x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| export 'query/filter.dart'; | ||
| export 'query/filter_operator.dart'; | ||
| export 'query/filter/filter.dart'; | ||
| export 'query/filter/filter_operator.dart'; | ||
| export 'query/filter/location/bounding_box.dart'; | ||
| export 'query/filter/location/circular_region.dart'; | ||
| export 'query/filter/location/distance.dart'; | ||
| export 'query/filter/location/location_coordinate.dart'; | ||
| export 'query/sort.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
64 changes: 64 additions & 0 deletions
64
packages/stream_core/lib/src/query/filter/location/bounding_box.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| import 'location_coordinate.dart'; | ||
|
|
||
| part 'bounding_box.g.dart'; | ||
|
|
||
| /// A rectangular geographic region for area-based location filtering. | ||
| /// | ||
| /// Defined by northeast and southwest corners. Used for rectangular | ||
| /// area queries such as map viewports or city boundaries. | ||
| /// | ||
| /// ```dart | ||
| /// final bbox = BoundingBox( | ||
| /// northEast: LocationCoordinate(latitude: 37.8324, longitude: -122.3482), | ||
| /// southWest: LocationCoordinate(latitude: 37.7079, longitude: -122.5161), | ||
| /// ); | ||
| /// | ||
| /// final isInside = bbox.contains(point); | ||
| /// ``` | ||
| @JsonSerializable(createFactory: false) | ||
| class BoundingBox { | ||
| const BoundingBox({ | ||
| required this.northEast, | ||
| required this.southWest, | ||
| }); | ||
|
|
||
| /// The northeast corner of this bounding box. | ||
| @JsonKey(includeToJson: false) | ||
| final LocationCoordinate northEast; | ||
|
|
||
| /// The southwest corner of this bounding box. | ||
| @JsonKey(includeToJson: false) | ||
| final LocationCoordinate southWest; | ||
|
|
||
| /// The latitude of the northeast corner. | ||
| @JsonKey(name: 'ne_lat') | ||
| double get neLat => northEast.latitude; | ||
|
|
||
| /// The longitude of the northeast corner. | ||
| @JsonKey(name: 'ne_lng') | ||
| double get neLng => northEast.longitude; | ||
|
|
||
| /// The latitude of the southwest corner. | ||
| @JsonKey(name: 'sw_lat') | ||
| double get swLat => southWest.latitude; | ||
|
|
||
| /// The longitude of the southwest corner. | ||
| @JsonKey(name: 'sw_lng') | ||
| double get swLng => southWest.longitude; | ||
|
|
||
| /// Whether [point] is within this bounding box. | ||
| bool contains(LocationCoordinate point) { | ||
| var withinLatitude = point.latitude <= northEast.latitude; | ||
| withinLatitude &= point.latitude >= southWest.latitude; | ||
|
|
||
| var withinLongitude = point.longitude <= northEast.longitude; | ||
| withinLongitude &= point.longitude >= southWest.longitude; | ||
xsahil03x marked this conversation as resolved.
Show resolved
Hide resolved
xsahil03x marked this conversation as resolved.
Show resolved
Hide resolved
xsahil03x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return withinLatitude && withinLongitude; | ||
| } | ||
|
|
||
| /// Converts this bounding box to JSON. | ||
| Map<String, dynamic> toJson() => _$BoundingBoxToJson(this); | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
packages/stream_core/lib/src/query/filter/location/bounding_box.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
packages/stream_core/lib/src/query/filter/location/circular_region.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| import 'distance.dart'; | ||
| import 'location_coordinate.dart'; | ||
|
|
||
| part 'circular_region.g.dart'; | ||
|
|
||
| /// A circular geographic region for proximity-based location filtering. | ||
| /// | ||
| /// Defined by a center point and radius. Used for geofencing and | ||
| /// "near" location queries. | ||
| /// | ||
| /// ```dart | ||
| /// final region = CircularRegion( | ||
| /// radius: 5.kilometers, | ||
| /// center: LocationCoordinate(latitude: 37.7749, longitude: -122.4194), | ||
| /// ); | ||
| /// | ||
| /// final isInside = region.contains(point); | ||
| /// ``` | ||
| @JsonSerializable(createFactory: false) | ||
| class CircularRegion { | ||
| const CircularRegion({ | ||
| required this.radius, | ||
| required this.center, | ||
| }); | ||
xsahil03x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// The radius of this circular region. | ||
| @JsonKey(includeToJson: false) | ||
| final Distance radius; | ||
|
|
||
| /// The center coordinate of this circular region. | ||
| @JsonKey(includeToJson: false) | ||
| final LocationCoordinate center; | ||
|
|
||
| /// The latitude of the center point. | ||
| @JsonKey(name: 'lat') | ||
| double get lat => center.latitude; | ||
|
|
||
| /// The longitude of the center point. | ||
| @JsonKey(name: 'lng') | ||
| double get lng => center.longitude; | ||
|
|
||
| /// The radius in kilometers. | ||
| @JsonKey(name: 'distance') | ||
| double get distance => radius.inKilometers; | ||
|
|
||
| /// Whether [point] is within this circular region. | ||
| bool contains(LocationCoordinate point) { | ||
| final distance = center.distanceTo(point); | ||
| return distance <= radius; | ||
| } | ||
|
|
||
| /// Converts this circular region to JSON. | ||
| Map<String, dynamic> toJson() => _$CircularRegionToJson(this); | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
packages/stream_core/lib/src/query/filter/location/circular_region.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
packages/stream_core/lib/src/query/filter/location/distance.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /// A distance value with convenient unit conversions. | ||
| /// | ||
| /// ```dart | ||
| /// final distance1 = 1000.meters; // 1000 meters | ||
| /// final distance2 = 5.kilometers; // 5000 meters | ||
| /// print(distance1.inKilometers); // 1.0 | ||
| /// ``` | ||
| extension type const Distance._(double meters) implements double { | ||
| /// Creates a [Distance] from [meters]. | ||
| const Distance.fromMeters(double meters) : this._(meters); | ||
|
|
||
| /// The distance in kilometers. | ||
| double get inKilometers => meters / 1000; | ||
| } | ||
|
|
||
| /// Extension methods on [num] for creating [Distance] values. | ||
| extension DistanceExtension on num { | ||
| /// This value as a [Distance] in meters. | ||
| Distance get meters => Distance.fromMeters(toDouble()); | ||
|
|
||
| /// This value as a [Distance] in kilometers. | ||
| Distance get kilometers => Distance.fromMeters(toDouble() * 1000); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.