Skip to content

Commit

Permalink
Release: 0.8.0 (#33)
Browse files Browse the repository at this point in the history
* FILES & FEATURES (#32)
 * Implemented #28 Calculating Polygon Area With Hole
 * Implemented Vincenty Formula for Geodesic Distance Calculation
 * Added CODE_OF_CONDUCT.md
 * Revised LICENSE

---------

Co-authored-by: wingkwong <wingkwong.code@gmail.com>

* refactor: comments
* docs: 0.8.0 CHANGELOG
* chore: bump to 0.8.0
* refactor: revise comments

---------

Co-authored-by: Ayoub Ali <ayoubzulfiqar3@gmail.com>
  • Loading branch information
wingkwong and ayoubzulfiqar authored Aug 28, 2023
1 parent bdbf0a3 commit 6af10d5
Show file tree
Hide file tree
Showing 17 changed files with 406 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ build/
test/.test_coverage.dart
coverage/
coverage_badge.svg
!coverage/lcov.info
!coverage/lcov.info
TODO.md
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 0.8.0

- Implement Calculating Polygon Area With Hole
- Implement Vincenty Formula for Geodesic Distance Calculation
- Add CODE_OF_CONDUCT.md
- Revise LICENSE

## 0.7.0

- Refactor geodesy
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019
Copyright (c) 2023 աɨռɢӄաօռɢ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Please check out [here](example/main.dart) for more.
```dart
import 'package:geodesy/geodesy.dart';
void main(){
void main() {
final Geodesy geodesy = Geodesy();
// Calculate Bounding Box
// Example central position (San Francisco)
Expand Down Expand Up @@ -102,6 +102,26 @@ void main(){
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}
}
// Calculate Area
final outerPolygon = [
const LatLng(0.0, 0.0),
const LatLng(0.0, 1.0),
const LatLng(1.0, 1.0),
const LatLng(1.0, 0.0),
];
// Define a hole within the outer polygon
final hole1 = [
const LatLng(0.25, 0.25),
const LatLng(0.25, 0.75),
const LatLng(0.75, 0.75),
const LatLng(0.75, 0.25),
];
final holes = [hole1];
final calculatedArea =
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
```

## Example Static Methods
Expand Down Expand Up @@ -158,4 +178,29 @@ void main() {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}
}
// Static Method
final outerPolygon = [
const LatLng(0.0, 0.0),
const LatLng(0.0, 1.0),
const LatLng(1.0, 1.0),
const LatLng(1.0, 0.0),
];
final hole1 = [
const LatLng(0.25, 0.25),
const LatLng(0.25, 0.75),
const LatLng(0.75, 0.75),
const LatLng(0.75, 0.25),
];
final holes = [hole1];
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
```

## Code of Conduct

See [here](doc/CODE_OF_CONDUCT.md).

## License

See [here](./LICENSE).
26 changes: 20 additions & 6 deletions doc/CLASS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool isGeoPointInPolygon(LatLng point, List<LatLng> polygon)
```

- `point` (LatLng): The point to check (latitude, longitude).
- `polygon` (List<LatLng>): A list of vertices defining the polygon.
- `polygon` (List`<LatLng>`): A list of vertices defining the polygon.

Returns `true` if the point is within the polygon, otherwise `false`.

Expand All @@ -154,7 +154,7 @@ List<LatLng> pointsInRange(LatLng point, List<LatLng> pointsToCheck, num distanc
```

- `point` (LatLng): The center point (latitude, longitude).
- `pointsToCheck` (List<LatLng>): List of points to check against.
- `pointsToCheck` (List`<LatLng>`): List of points to check against.
- `distance` (num): The maximum distance in meters.

Returns a list of `LatLng` points within the specified distance from the center point.
Expand Down Expand Up @@ -184,7 +184,7 @@ Get the bounding rectangle for a polygon defined by its vertices.
List<LatLng> getRectangleBounds(List<LatLng> polygonCoords)
```

- `polygonCoords` (List<LatLng>): List of vertices defining the polygon.
- `polygonCoords` (List`<LatLng>`): List of vertices defining the polygon.

Returns a list of `LatLng` points representing the bounding rectangle's corners.

Expand All @@ -209,7 +209,7 @@ Find the centroid of a polygon defined by its vertices.
LatLng findPolygonCentroid(List<LatLng> polygon)
```

- `polygon` (List<LatLng>): List of vertices defining the polygon.
- `polygon` (List`<LatLng>`): List of vertices defining the polygon.

Returns a `LatLng` object representing the centroid of the polygon.

Expand All @@ -223,11 +223,25 @@ Calculate the intersection of
List<LatLng> getPolygonIntersection(List<LatLng> polygon1, List<LatLng> polygon2)
```

- `polygon1` (List<LatLng>): List of vertices defining the first polygon.
- `polygon2` (List<LatLng>): List of vertices defining the second polygon.
- `polygon1` (List`<LatLng>`): List of vertices defining the first polygon.
- `polygon2` (List`<LatLng>`): List of vertices defining the second polygon.

Returns a list of `LatLng` points representing the intersection polygon.

### Vincenty formula for Geodesic Distance Calculation

```dart
final double calculatedDistance = geodesy.vincentyDistance(
point1.latitude, point1.longitude, point2.latitude, point2.longitude);
```

### Calculate Area of Polygon with Hole

```dart
final calculatedArea =
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
```

---

This `Geodesy` class provides a comprehensive set of methods for performing various geodetic calculations and operations. You can use these methods to calculate distances, bearings, intersections, and more based on geographical coordinates.
44 changes: 44 additions & 0 deletions doc/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Code of Conduct

## Introduction

This Code of Conduct outlines the expectations for behavior in the geodesy Dart library community. We are committed to providing a welcoming and inclusive environment for everyone, regardless of their background or beliefs.

## Responsibilities

All members of the geodesy Dart library community are expected to:

* Be respectful of others.
* Be welcoming and inclusive.
* Be open to feedback.
* Be constructive in their criticism.
* Be mindful of their language and avoid using discriminatory or offensive language.
* Report any instances of unacceptable behavior to the repository maintainers.

## Unacceptable Behavior

The following behaviors are considered unacceptable in the geodesy Dart library community:

* Harassment of any kind, including but not limited to:
* Verbal abuse
* Sexual harassment
* Threats or intimidation
* Stalking or following
* Unwanted physical contact
* Discrimination based on race, gender, sexual orientation, disability, or other personal characteristics
* Spamming or trolling
* Publishing private information about others without their consent
* Disrupting or interfering with the work of others

## Reporting Unacceptable Behavior

If you witness or experience unacceptable behavior, please report it to the repository maintainers immediately. You can do this by sending an email to wingkwong.code@gmail.com or opening an issue on the GitHub repository.

## Enforcement

The repository maintainers will investigate all reports of unacceptable behavior and take appropriate action. This may include warning the offender, suspending their access to the repository, or banning them from the community.

## Contact Information

If you have any questions about this Code of Conduct, please contact the repository maintainers at wingkwong.code@gmail.com.
24 changes: 18 additions & 6 deletions doc/METHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ GeoPoints.isGeoPointInPolygon(l, polygon);
```

- `l` (LatLng): The point to check (latitude, longitude).
- `polygon` (List<LatLng>): A list of vertices defining the polygon.
- `polygon` (List`<LatLng>`): A list of vertices defining the polygon.

Returns `true` if the point is within the polygon, otherwise `false`.

Expand All @@ -135,7 +135,7 @@ PointRange.pointInRange(point, pointsToCheck, distance);
```

- `point` (LatLng): The center point (latitude, longitude).
- `pointsToCheck` (List<LatLng>): List of points to check against.
- `pointsToCheck` (List`<LatLng>`): List of points to check against.
- `distance` (num): The maximum distance in meters.

Returns a list of `LatLng` points within the specified distance from the center point.
Expand Down Expand Up @@ -163,7 +163,7 @@ Get the bounding rectangle for a polygon defined by its vertices.
RectangleBounds.getRectangleBounds(polygonCoords);
```

- `polygonCoords` (List<LatLng>): List of vertices defining the polygon.
- `polygonCoords` (List`<LatLng>`): List of vertices defining the polygon.

Returns a list of `LatLng` points representing the bounding rectangle's corners.

Expand All @@ -188,7 +188,7 @@ Find the centroid of a polygon defined by its vertices.
PolygonCentroid.findPolygonCentroid(polygons);
```

- `polygon` (List<LatLng>): List of vertices defining the polygon.
- `polygon` (List`<LatLng>`): List of vertices defining the polygon.

Returns a `LatLng` object representing the centroid of the polygon.

Expand All @@ -202,11 +202,23 @@ Calculate the intersection of
PolygonIntersection.getPolygonIntersection(polygon1, polygon2);
```

- `polygon1` (List<LatLng>): List of vertices defining the first polygon.
- `polygon2` (List<LatLng>): List of vertices defining the second polygon.
- `polygon1` (List`<LatLng>`): List of vertices defining the first polygon.
- `polygon2` (List`<LatLng>`): List of vertices defining the second polygon.

Returns a list of `LatLng` points representing the intersection polygon.

### Vincenty formula for Geodesic Distance Calculation

```dart
VincentyDistance.vincentyDistance(lat1, lon1, lat2, lon2);
```

### Calculate Area of Polygon with Hole

```dart
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
```

---

This `Geodesy` provides a comprehensive set of methods for performing various geodetic calculations and operations. You can use these methods to calculate distances, bearings, intersections, and more based on geographical coordinates.
37 changes: 37 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:geodesy/geodesy.dart';
import 'package:geodesy/src/core/polygon_with_hole.dart';

void main() {
// Calculate Bounding Box
Expand Down Expand Up @@ -48,4 +49,40 @@ void main() {
for (final point in intersectionPoints) {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}

// Vincenty formula for Geodesic Distance Calculation
final LatLng point1 = const LatLng(37.7749, -122.4194); // San Francisco
final LatLng point2 = const LatLng(34.0522, -118.2437); // Los Angeles

final double calculatedDistance = VincentyDistance.vincentyDistance(
point1.latitude,
point1.longitude,
point2.latitude,
point2.longitude,
);

print(
'''Distance between San Francisco and Los Angeles: $calculatedDistance meters''',
);

// Define the outer polygon
final outerPolygon = [
const LatLng(0.0, 0.0),
const LatLng(0.0, 1.0),
const LatLng(1.0, 1.0),
const LatLng(1.0, 0.0),
];

// Define a hole within the outer polygon
final hole1 = [
const LatLng(0.25, 0.25),
const LatLng(0.25, 0.75),
const LatLng(0.75, 0.75),
const LatLng(0.75, 0.25),
];

final holes = [hole1];

final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
print("Area of polygon with holes: $area");
}
34 changes: 33 additions & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:latlong2/latlong.dart';

import 'package:geodesy/geodesy.dart' show Geodesy;

void main() {
Expand Down Expand Up @@ -130,4 +129,37 @@ void main() {
for (final point in intersectionPoints) {
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
}

// Vincenty formula for Geodesic Distance Calculation
final LatLng point1 = const LatLng(37.7749, -122.4194); // San Francisco
final LatLng point2 = const LatLng(34.0522, -118.2437); // Los Angeles

final double calculatedDistance = geodesy.vincentyDistance(
point1.latitude, point1.longitude, point2.latitude, point2.longitude);

print(
'''Distance between San Francisco and Los Angeles:
$calculatedDistance meters''',
);

// Define the outer polygon
final outerPolygon = [
const LatLng(0.0, 0.0),
const LatLng(0.0, 1.0),
const LatLng(1.0, 1.0),
const LatLng(1.0, 0.0),
];

// Define a hole within the outer polygon
final hole1 = [
const LatLng(0.25, 0.25),
const LatLng(0.25, 0.75),
const LatLng(0.75, 0.75),
const LatLng(0.75, 0.25),
];

final holes = [hole1];

final area = geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
print("Area of polygon with holes: $area");
}
2 changes: 2 additions & 0 deletions lib/src/core/core.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export 'package:geodesy/src/math/to_radian.dart';
export 'package:geodesy/src/core/bearing_between_two_geo_points.dart';
export 'package:geodesy/src/core/bounding_box.dart';
export 'package:geodesy/src/core/points_in_range.dart';
export 'package:geodesy/src/core/get_rectangle_bounds.dart';
export 'package:geodesy/src/core/get_polygon_intersection.dart';
export 'package:geodesy/src/core/find_polygon_centroid.dart';
export 'package:geodesy/src/core/geo_points.dart';
export 'package:geodesy/src/core/vincenty_distance_calculation.dart';
export 'package:geodesy/src/core/destination_point_by_distance_and_bearing.dart';
export 'package:geodesy/src/core/cross_track_distance_to.dart';
export 'package:latlong2/latlong.dart' hide pi;
Expand Down
12 changes: 6 additions & 6 deletions lib/src/core/destination_point_by_distance_and_bearing.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'core.dart';

///
/// DestinationPointByDistanceAndBearing
class DistanceAndBearing {
/// DestinationPointByDistanceAndBearing:-
/// This code takes a starting point, a distance, a direction (bearing), and
///optionally a radius, and calculates the coordinates of a new point based
///on these inputs, using trigonometric calculations and the Haversine formula
///for spherical geometry.
/// This code takes a starting point, a distance,
/// a direction (bearing), and optionally a radius, and
/// calculates the coordinates of a new point
/// based on these inputs, using trigonometric calculations and
/// the Haversine formula for spherical geometry.
static LatLng destinationPointByDistanceAndBearing(
LatLng l, num distance, num bearing,
[num? radius]) {
Expand Down
Loading

0 comments on commit 6af10d5

Please sign in to comment.