Skip to content

Commit 6af10d5

Browse files
Release: 0.8.0 (#33)
* 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 <[email protected]> * refactor: comments * docs: 0.8.0 CHANGELOG * chore: bump to 0.8.0 * refactor: revise comments --------- Co-authored-by: Ayoub Ali <[email protected]>
1 parent bdbf0a3 commit 6af10d5

17 files changed

+406
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ build/
7474
test/.test_coverage.dart
7575
coverage/
7676
coverage_badge.svg
77-
!coverage/lcov.info
77+
!coverage/lcov.info
78+
TODO.md

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 0.8.0
4+
5+
- Implement Calculating Polygon Area With Hole
6+
- Implement Vincenty Formula for Geodesic Distance Calculation
7+
- Add CODE_OF_CONDUCT.md
8+
- Revise LICENSE
9+
310
## 0.7.0
411

512
- Refactor geodesy

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019
3+
Copyright (c) 2023 աɨռɢӄաօռɢ
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Please check out [here](example/main.dart) for more.
5353
```dart
5454
import 'package:geodesy/geodesy.dart';
5555
56-
void main(){
56+
void main() {
5757
final Geodesy geodesy = Geodesy();
5858
// Calculate Bounding Box
5959
// Example central position (San Francisco)
@@ -102,6 +102,26 @@ void main(){
102102
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
103103
}
104104
}
105+
106+
// Calculate Area
107+
final outerPolygon = [
108+
const LatLng(0.0, 0.0),
109+
const LatLng(0.0, 1.0),
110+
const LatLng(1.0, 1.0),
111+
const LatLng(1.0, 0.0),
112+
];
113+
114+
// Define a hole within the outer polygon
115+
final hole1 = [
116+
const LatLng(0.25, 0.25),
117+
const LatLng(0.25, 0.75),
118+
const LatLng(0.75, 0.75),
119+
const LatLng(0.75, 0.25),
120+
];
121+
122+
final holes = [hole1];
123+
final calculatedArea =
124+
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
105125
```
106126

107127
## Example Static Methods
@@ -158,4 +178,29 @@ void main() {
158178
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
159179
}
160180
}
181+
// Static Method
182+
final outerPolygon = [
183+
const LatLng(0.0, 0.0),
184+
const LatLng(0.0, 1.0),
185+
const LatLng(1.0, 1.0),
186+
const LatLng(1.0, 0.0),
187+
];
188+
189+
final hole1 = [
190+
const LatLng(0.25, 0.25),
191+
const LatLng(0.25, 0.75),
192+
const LatLng(0.75, 0.75),
193+
const LatLng(0.75, 0.25),
194+
];
195+
196+
final holes = [hole1];
197+
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
161198
```
199+
200+
## Code of Conduct
201+
202+
See [here](doc/CODE_OF_CONDUCT.md).
203+
204+
## License
205+
206+
See [here](./LICENSE).

doc/CLASS.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ bool isGeoPointInPolygon(LatLng point, List<LatLng> polygon)
141141
```
142142

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

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

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

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

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

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

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

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

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

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

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

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

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

231+
### Vincenty formula for Geodesic Distance Calculation
232+
233+
```dart
234+
final double calculatedDistance = geodesy.vincentyDistance(
235+
point1.latitude, point1.longitude, point2.latitude, point2.longitude);
236+
```
237+
238+
### Calculate Area of Polygon with Hole
239+
240+
```dart
241+
final calculatedArea =
242+
geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
243+
```
244+
231245
---
232246

233247
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.

doc/CODE_OF_CONDUCT.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
# Code of Conduct
3+
4+
## Introduction
5+
6+
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.
7+
8+
## Responsibilities
9+
10+
All members of the geodesy Dart library community are expected to:
11+
12+
* Be respectful of others.
13+
* Be welcoming and inclusive.
14+
* Be open to feedback.
15+
* Be constructive in their criticism.
16+
* Be mindful of their language and avoid using discriminatory or offensive language.
17+
* Report any instances of unacceptable behavior to the repository maintainers.
18+
19+
## Unacceptable Behavior
20+
21+
The following behaviors are considered unacceptable in the geodesy Dart library community:
22+
23+
* Harassment of any kind, including but not limited to:
24+
* Verbal abuse
25+
* Sexual harassment
26+
* Threats or intimidation
27+
* Stalking or following
28+
* Unwanted physical contact
29+
* Discrimination based on race, gender, sexual orientation, disability, or other personal characteristics
30+
* Spamming or trolling
31+
* Publishing private information about others without their consent
32+
* Disrupting or interfering with the work of others
33+
34+
## Reporting Unacceptable Behavior
35+
36+
If you witness or experience unacceptable behavior, please report it to the repository maintainers immediately. You can do this by sending an email to [email protected] or opening an issue on the GitHub repository.
37+
38+
## Enforcement
39+
40+
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.
41+
42+
## Contact Information
43+
44+
If you have any questions about this Code of Conduct, please contact the repository maintainers at [email protected].

doc/METHODS.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ GeoPoints.isGeoPointInPolygon(l, polygon);
122122
```
123123

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

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

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

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

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

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

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

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

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

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

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

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

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

210+
### Vincenty formula for Geodesic Distance Calculation
211+
212+
```dart
213+
VincentyDistance.vincentyDistance(lat1, lon1, lat2, lon2);
214+
```
215+
216+
### Calculate Area of Polygon with Hole
217+
218+
```dart
219+
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
220+
```
221+
210222
---
211223

212224
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.

example/example.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:geodesy/geodesy.dart';
2+
import 'package:geodesy/src/core/polygon_with_hole.dart';
23

34
void main() {
45
// Calculate Bounding Box
@@ -48,4 +49,40 @@ void main() {
4849
for (final point in intersectionPoints) {
4950
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
5051
}
52+
53+
// Vincenty formula for Geodesic Distance Calculation
54+
final LatLng point1 = const LatLng(37.7749, -122.4194); // San Francisco
55+
final LatLng point2 = const LatLng(34.0522, -118.2437); // Los Angeles
56+
57+
final double calculatedDistance = VincentyDistance.vincentyDistance(
58+
point1.latitude,
59+
point1.longitude,
60+
point2.latitude,
61+
point2.longitude,
62+
);
63+
64+
print(
65+
'''Distance between San Francisco and Los Angeles: $calculatedDistance meters''',
66+
);
67+
68+
// Define the outer polygon
69+
final outerPolygon = [
70+
const LatLng(0.0, 0.0),
71+
const LatLng(0.0, 1.0),
72+
const LatLng(1.0, 1.0),
73+
const LatLng(1.0, 0.0),
74+
];
75+
76+
// Define a hole within the outer polygon
77+
final hole1 = [
78+
const LatLng(0.25, 0.25),
79+
const LatLng(0.25, 0.75),
80+
const LatLng(0.75, 0.75),
81+
const LatLng(0.75, 0.25),
82+
];
83+
84+
final holes = [hole1];
85+
86+
final area = Polygon.calculatePolygonWithHolesArea(outerPolygon, holes);
87+
print("Area of polygon with holes: $area");
5188
}

example/main.dart

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:latlong2/latlong.dart';
2-
32
import 'package:geodesy/geodesy.dart' show Geodesy;
43

54
void main() {
@@ -130,4 +129,37 @@ void main() {
130129
for (final point in intersectionPoints) {
131130
print('Latitude: ${point.latitude}, Longitude: ${point.longitude}');
132131
}
132+
133+
// Vincenty formula for Geodesic Distance Calculation
134+
final LatLng point1 = const LatLng(37.7749, -122.4194); // San Francisco
135+
final LatLng point2 = const LatLng(34.0522, -118.2437); // Los Angeles
136+
137+
final double calculatedDistance = geodesy.vincentyDistance(
138+
point1.latitude, point1.longitude, point2.latitude, point2.longitude);
139+
140+
print(
141+
'''Distance between San Francisco and Los Angeles:
142+
$calculatedDistance meters''',
143+
);
144+
145+
// Define the outer polygon
146+
final outerPolygon = [
147+
const LatLng(0.0, 0.0),
148+
const LatLng(0.0, 1.0),
149+
const LatLng(1.0, 1.0),
150+
const LatLng(1.0, 0.0),
151+
];
152+
153+
// Define a hole within the outer polygon
154+
final hole1 = [
155+
const LatLng(0.25, 0.25),
156+
const LatLng(0.25, 0.75),
157+
const LatLng(0.75, 0.75),
158+
const LatLng(0.75, 0.25),
159+
];
160+
161+
final holes = [hole1];
162+
163+
final area = geodesy.calculatePolygonWithHolesArea(outerPolygon, holes);
164+
print("Area of polygon with holes: $area");
133165
}

lib/src/core/core.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
export 'package:geodesy/src/math/to_radian.dart';
12
export 'package:geodesy/src/core/bearing_between_two_geo_points.dart';
23
export 'package:geodesy/src/core/bounding_box.dart';
34
export 'package:geodesy/src/core/points_in_range.dart';
45
export 'package:geodesy/src/core/get_rectangle_bounds.dart';
56
export 'package:geodesy/src/core/get_polygon_intersection.dart';
67
export 'package:geodesy/src/core/find_polygon_centroid.dart';
78
export 'package:geodesy/src/core/geo_points.dart';
9+
export 'package:geodesy/src/core/vincenty_distance_calculation.dart';
810
export 'package:geodesy/src/core/destination_point_by_distance_and_bearing.dart';
911
export 'package:geodesy/src/core/cross_track_distance_to.dart';
1012
export 'package:latlong2/latlong.dart' hide pi;

0 commit comments

Comments
 (0)