-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
example.dart
42 lines (36 loc) · 1.38 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'package:polybool/polybool.dart';
class LatLng {
final double latitude;
final double longitude;
const LatLng(this.latitude, this.longitude);
}
void example() {
final poly1 = Polygon(regions: [
[LatLng(50, 50), LatLng(150, 150), LatLng(190, 50)]
.map((c) => Coordinate(double.parse(c.longitude.toStringAsFixed(6)),
double.parse(c.latitude.toStringAsFixed(6))))
.toList(),
[LatLng(130, 50), LatLng(290, 150), LatLng(290, 50)]
.map((c) => Coordinate(double.parse(c.longitude.toStringAsFixed(6)),
double.parse(c.latitude.toStringAsFixed(6))))
.toList(),
]);
final poly2 = Polygon(regions: [
[LatLng(110, 20), LatLng(110, 110), LatLng(20, 20)]
.map((c) => Coordinate(double.parse(c.longitude.toStringAsFixed(6)),
double.parse(c.latitude.toStringAsFixed(6))))
.toList(),
[LatLng(130, 170), LatLng(130, 20), LatLng(260, 170)]
.map((c) => Coordinate(double.parse(c.longitude.toStringAsFixed(6)),
double.parse(c.latitude.toStringAsFixed(6))))
.toList(),
]);
print('union: ${poly1.union(poly2).regions}');
print('intersection: ${poly1.intersect(poly2).regions}');
print('difference: ${poly1.difference(poly2).regions}');
print('inverse difference: ${poly1.differenceRev(poly2).regions}');
print('xor: ${poly1.xor(poly2).regions}');
}
void main() {
example();
}