diff --git a/.gitignore b/.gitignore index f7ccd98..80cb434 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ build/ # Directory created by dartdoc doc/api/ +/.vs diff --git a/example/conversion.dart b/example/conversion.dart index e52c2dd..12ff14f 100644 --- a/example/conversion.dart +++ b/example/conversion.dart @@ -1,20 +1,16 @@ import 'package:poly/poly.dart'; main() { - int correct_count = 0; + var correct_count = 0; // Because of Error that List isn't subtype of List : // Either use List or cast it to List while passing to respective function - List c1 = [1, 2]; - List> c2 = [ + var c1 = [1, 2]; + var c2 = >[ [1, 2], [3, 4], [5, 6] ]; - List> c3 = [] - ..addAll(c2) - ..addAll([ - [7, 8] - ]); + var c3 = >[...c2, [7, 8]]; // Or use - // List> c3 = [ // c2, @@ -26,30 +22,25 @@ main() { //Example of `toPoint()` & `pointToList()` //* `toPoint()` converts `List` to `Point` // * `pointToList()` converts `Point` to `List` - Point pointFromC1 = toPoint(c1); - List listFromPoint = pointToList(pointFromC1); - print( - "${++correct_count}. toPoint(c1 = [1,2])= ${pointFromC1} with type:${pointFromC1.runtimeType} & pointToList() gives us ${listFromPoint} with type:${listFromPoint.runtimeType}"); + var pointFromC1 = toPoint(c1); + var listFromPoint = pointToList(pointFromC1); + print('${++correct_count}. toPoint(c1 = [1,2])= $pointFromC1 with type:${pointFromC1.runtimeType} & pointToList() gives us $listFromPoint with type:${listFromPoint.runtimeType}'); //Example of `toListOfPoint()` & `pointsToList()` //* `toListOfPoint()` converts `List>` to `List>` //* `pointsToList()` converts `List>` to `List>` - List pointsFromC2 = toListOfPoint(c2); - List> listFromPoints = pointsToList(pointsFromC2); - print( - "${++correct_count}. toListOfPoint(c2 = [ [1,2], [3,4], [5,6] ])= ${pointsFromC2} with type:${pointsFromC2.runtimeType} & pointsToList() gives us ${listFromPoints} with type:${listFromPoints.runtimeType}"); + var pointsFromC2 = toListOfPoint(c2); + var listFromPoints = pointsToList(pointsFromC2); + print('${++correct_count}. toListOfPoint(c2 = [ [1,2], [3,4], [5,6] ])= $pointsFromC2 with type:${pointsFromC2.runtimeType} & pointsToList() gives us $listFromPoints with type:${listFromPoints.runtimeType}'); //Example of `toPolyFromListOfList()` & `listOfList()` //* `toPolyFromListOfList()` converts `List>` to `Polygon` // * `listOfList()` returns `Polygon.points` as `List>` //* Print status of List of List if they are inside our Polygon using `getList_IsListOfListInside` //* Print if All points in List of List inside Polygon using - Polygon polygonC2 = toPolyFromListOfList(c2); - List> backToListC2 = polygonC2.listOfList(); - print( - "${++correct_count}. toPolyFromListOfList() gives ${polygonC2.runtimeType} & backToListC2() gives back ${backToListC2.runtimeType}"); - print( - "${++correct_count}. Is C3= [ C2, [7,8] ] inside Polygon C2 = ${polygonC2.getList_IsListOfListInside(c3)}"); - print( - "${++correct_count}. Are All Points in C3= [ C2, [7,8] ] present inside C2 = ${polygonC2.areAllPointsInsidePolygon_List(c3)}"); + var polygonC2 = toPolyFromListOfList(c2); + var backToListC2 = polygonC2.listOfList(); + print('${++correct_count}. toPolyFromListOfList() gives ${polygonC2.runtimeType} & backToListC2() gives back ${backToListC2.runtimeType}'); + print('${++correct_count}. Is C3= [ C2, [7,8] ] inside Polygon C2 = ${polygonC2.getList_IsListOfListInside(c3)}'); + print('${++correct_count}. Are All Points in C3= [ C2, [7,8] ] present inside C2 = ${polygonC2.areAllPointsInsidePolygon_List(c3)}'); } diff --git a/example/easy_casting.dart b/example/easy_casting.dart index bf2bd9f..321f650 100644 --- a/example/easy_casting.dart +++ b/example/easy_casting.dart @@ -1,96 +1,93 @@ import 'package:poly/poly.dart'; main() { - int correct_count = 0; - int exception_count = 0; + var correct_count = 0; + var exception_count = 0; //1. Correct casting // * casting `List to `List` - List correctDynamicList = [1, 2]; - Point correctPointFromDynamicList = toPoint(correctDynamicList.cast()); + var correctDynamicList = [1, 2]; + var correctPointFromDynamicList = toPoint(correctDynamicList.cast()); print( - "${++correct_count}. Type of correctPointFromDynamicList is ${correctPointFromDynamicList.runtimeType}, while correctDynamicList was ${correctDynamicList.runtimeType} \t //See casting worked as desired"); + '${++correct_count}. Type of correctPointFromDynamicList is ${correctPointFromDynamicList.runtimeType}, while correctDynamicList was ${correctDynamicList.runtimeType} \t //See casting worked as desired'); // * casting `List` to `List>` - List correctDynamicListOfList = [ + var correctDynamicListOfList = [ [1, 2], [3, 4] ]; - List listPointFromDynamicList = + var listPointFromDynamicList = toListOfPoint(correctDynamicListOfList.cast>()); print( - "${++correct_count}. Type of listPointFromDynamicList is ${listPointFromDynamicList.runtimeType}, while correctDynamicListOfList was ${correctDynamicListOfList.runtimeType} \t //See casting worked as desired"); + '${++correct_count}. Type of listPointFromDynamicList is ${listPointFromDynamicList.runtimeType}, while correctDynamicListOfList was ${correctDynamicListOfList.runtimeType} \t //See casting worked as desired'); // * Using `toListListNum` - List> l = toListListNum([correctDynamicList]); + List> l = toListListNum([correctDynamicList]); print( - "${++correct_count}. ${l} has type:${l.runtimeType} & has length:${l.length}"); + '${++correct_count}. $l has type:${l.runtimeType} & has length:${l.length}'); // Without casting `List` to `List` `TypeError`is thrown as shown below : try { - List wrongDynamicList = [1, 2]; + var wrongDynamicList = [1, 2]; var wrongPoint = toPoint(wrongDynamicList); print(wrongPoint.runtimeType); } on TypeError catch (e) { print( - "\n${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '\n${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } // 2. Passing `List` instead of `List` // * Passing `List` instead of `List` & casting it : throws `CastError` as shown below : // * type `int` is not a subtype of type `List` in type cast try { - List wrongDynamicList = [1, 2]; - var wrongPoint = toListOfPoint(wrongDynamicList); + var wrongDynamicList = [1, 2]; + var wrongPoint = toListOfPoint(wrongDynamicList as List>); print(wrongPoint.runtimeType); } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } // * Passing `List` instead of `List` but, without casting it : throws `TypeError` as shown below : // * type `List` is not a subtype of type `List>` try { - List wrongDynamicList = [1, 2]; + var wrongDynamicList = [1, 2]; var wrongPoint = toListOfPoint(wrongDynamicList.cast()); print(wrongPoint.runtimeType); - } on CastError catch (e) { + } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } // type `List` is not a subtype of type `List` in type cast try { var l = [correctDynamicList]; - print("${l.runtimeType}"); - List wrongListOfList = toListOfPoint(l.cast()); - } on CastError catch (e) { + print('${l.runtimeType}'); + var wrongListOfList = toListOfPoint(l.cast()); + } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } //type `List>` is not a subtype of type `List>` in type cast try { - var l = [correctDynamicList] as List>; - print("${l.runtimeType}"); - List wrongListOfList = toListOfPoint(l.cast()); - } on CastError catch (e) { + var l = [correctDynamicList]; + print('${l.runtimeType}'); + var wrongListOfList = toListOfPoint(l.cast()); + } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } // * Using from // > type `List` is not a subtype of type `List` try { var l = - List>.from([correctDynamicList].toList() as List>) + List>.from([correctDynamicList].toList()) .cast() .toList(); - print("${l.runtimeType}"); - List wrongListOfList = toListOfPoint(l.cast()); + print('${l.runtimeType}'); + var wrongListOfList = toListOfPoint(l.cast()); } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); - } on CastError catch (e) { - print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } } diff --git a/example/exception_handling.dart b/example/exception_handling.dart index ab7deb4..f4c6070 100644 --- a/example/exception_handling.dart +++ b/example/exception_handling.dart @@ -1,15 +1,15 @@ import 'package:poly/poly.dart'; main() { - int exception_count = 0; + var exception_count = 0; // Because of Error that List isn't subtype of List // So, List a can't be used without casting - List w1 = [1, 2, 3]; - List> w2 = [ + var w1 = [1, 2, 3]; + var w2 = >[ [1, 2], [3, 4] ]; - List> c2 = [ + var c2 = >[ [1, 2], [3, 4], [5, 6] @@ -18,43 +18,43 @@ main() { // Exception - 1 /// NeedsAtLeastThreePoints is thrown if Polygon.points contains less than 3 points try { - Polygon less_than_3 = toPolyFromListOfList(w2); + var less_than_3 = toPolyFromListOfList(w2); } on NeedsAtLeastThreePoints catch (e) { - print("\n"); + print('\n'); print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 Please provide three or more points. Current number of Points: ${e.currentPointsInPolygon()}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 Please provide three or more points. Current number of Points: ${e.currentPointsInPolygon()}'); } // Exception - 2 ///WrongSizeForPoint is thrown if to_Point has more or less than 2 element. Point has only x and y. try { - Point pointWithMoreThanXY = toPoint(w1); + var pointWithMoreThanXY = toPoint(w1); } on WrongSizeForPoint catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 Wrong size, List must have 2 element. Current Size: ${e.inputListLength()}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 Wrong size, List must have 2 element. Current Size: ${e.inputListLength()}'); } // Exception - 3 /// `TypeError` is thrown if `List` is passed instead of `List` /// e.g. type 'List' is not a subtype of type 'List' try { - List dy = [1, 2]; - var ttemp = toPoint(dy); + var dy = [1, 2]; + var ttemp = toPoint(dy as List); print(ttemp.runtimeType); } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } // Exception - 4 /// `CastError` example - List to List> try { - Polygon wrongPoly = toPolyFromListOfList(w1.cast()); + var wrongPoly = toPolyFromListOfList(w1.cast()); } on TypeError catch (e) { print( - "${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 ${e}"); + '${++exception_count}. ${e.runtimeType} Exception handled : \n \t \u2022 $e'); } catch (e) { print( - "${++exception_count}. ${e.runtimeType} handled : \n \t \u2022 ${e} || "); + '${++exception_count}. ${e.runtimeType} handled : \n \t \u2022 $e || '); } // Correct Error 1 // Error: The argument type 'List' can't be assigned to the parameter type 'List>'. diff --git a/example/poly_example.dart b/example/poly_example.dart index 3a841a9..dd57829 100644 --- a/example/poly_example.dart +++ b/example/poly_example.dart @@ -1,8 +1,8 @@ import 'package:poly/poly.dart'; main() { - int example_count = 0; - List> l = [ + var example_count = 0; + var l = >[ Point(18.4851825, 73.8498851), Point(18.4849214, 73.8498675), Point(18.4855965, 73.8520493), @@ -12,9 +12,9 @@ main() { ]; /// List of Points can be passed as parameter to constructor Polygon() - Polygon testPolygon = Polygon(l); + var testPolygon = Polygon(l); // Or Just Pass List inside constructor - Polygon copyOfFirstPolygon = Polygon([ + var copyOfFirstPolygon = Polygon([ Point(18.4851825, 73.8498851), Point(18.4849214, 73.8498675), Point(18.4855965, 73.8520493), @@ -22,38 +22,38 @@ main() { Point(18.4857828, 73.8500299), Point(18.4851825, 73.8498851) ]); - Point in1 = Point(18.48569, 73.85067); + var in1 = Point(18.48569, 73.85067); /// Example of `hasSamePoint()` /// *Checks if 2 `Polygon` have same vertices i.e. `points` // * Should print `true` print( - "${++example_count}. `testPolygon` and `copyOfFirstPolygon` are same : ${testPolygon.hasSamePoints(copyOfFirstPolygon)}"); + '${++example_count}. `testPolygon` and `copyOfFirstPolygon` are same : ${testPolygon.hasSamePoints(copyOfFirstPolygon)}'); /// A Point can be checked if it's present inside the Polygon by passing [Point i] to isPointInside function // Should Print true print( - "${++example_count}. in1=(18.48569, 73.85067) is inside testWyse - ${testPolygon.isPointInside(in1)}"); + '${++example_count}. in1=(18.48569, 73.85067) is inside testWyse - ${testPolygon.isPointInside(in1)}'); /// X,Y can be checked if they are present inside polygon by passing [x,y] to contains function // Should Print true print( - "${++example_count}. Polygon a contains :(18.48569, 73.85067) - ${copyOfFirstPolygon.contains(18.48569, 73.85067)}"); + '${++example_count}. Polygon a contains :(18.48569, 73.85067) - ${copyOfFirstPolygon.contains(18.48569, 73.85067)}'); /// Multiple Points inside a List can be tested by passing it to areAllPointsInsidePolygon_ListPoint // Should Print true print( - "${++example_count}. All points in l are within testWyse - ${testPolygon.areAllPointsInsidePolygon_ListPoint(l)}"); + '${++example_count}. All points in l are within testWyse - ${testPolygon.areAllPointsInsidePolygon_ListPoint(l)}'); ///areAllPointsInsidePolygon_ListPoint returns true if all Point are inside Polygon // Should Print false - List> notInsidePoints = []..addAll(l)..addAll([Point(75, 90)]); + var notInsidePoints = >[...l]..addAll([Point(75, 90)]); print( - "${++example_count}. All points in notInsidePoints are within testWyse - ${testPolygon.areAllPointsInsidePolygon_ListPoint(notInsidePoints)}"); + '${++example_count}. All points in notInsidePoints are within testWyse - ${testPolygon.areAllPointsInsidePolygon_ListPoint(notInsidePoints)}'); // print("${notInsidePoints}, ${notInsidePoints.runtimeType}"); /// getList_IsListOfPointInside returns List as List if List are inside Polygon // Should Print: [true, true, true, true, true, true, false] print( - "${++example_count}. Status of notInsidePoints - ${testPolygon.getList_IsListOfPointInside(notInsidePoints)}"); + '${++example_count}. Status of notInsidePoints - ${testPolygon.getList_IsListOfPointInside(notInsidePoints)}'); } diff --git a/example/prabhag11.dart b/example/prabhag11.dart index 3a8a383..d029ab5 100644 --- a/example/prabhag11.dart +++ b/example/prabhag11.dart @@ -4,13 +4,13 @@ import 'dart:io'; void main(){ - Polygon location_eleven = Polygon([ Point(18.507305, 73.806131), Point(18.508689, 73.806131), Point(18.509299, 73.805916), Point(18.509848, 73.805981), Point(18.512941, 73.806024), Point(18.512941, 73.803492), Point(18.512453, 73.802032), Point(18.512283, 73.800424), Point(18.511964, 73.798943), Point(18.511822, 73.798749), Point(18.513429, 73.79817), Point(18.514813, 73.797483), Point(18.514854, 73.796818), Point(18.515342, 73.796067), Point(18.515688, 73.795896), Point(18.516115, 73.795788), Point(18.517377, 73.79581), Point(18.518394, 73.794222), Point(18.519696, 73.795595), Point(18.520551, 73.796153), Point(18.523155, 73.799028), Point(18.523643, 73.800831), Point(18.523888, 73.802118), Point(18.524172, 73.80259), Point(18.524091, 73.80362), Point(18.524539, 73.804607), Point(18.524591, 73.808944), Point(18.524783, 73.809571), Point(18.524094, 73.811088), Point(18.524295, 73.81259), Point(18.525454, 73.814199), Point(18.526166, 73.814886), Point(18.524172, 73.817761), Point(18.523237, 73.818169), Point(18.5211, 73.822246), Point(18.520388, 73.823254), Point(18.520063, 73.824456), Point(18.519208, 73.827052), Point(18.517133, 73.826108), Point(18.516278, 73.824906), Point(18.514894, 73.824649), Point(18.514813, 73.824306), Point(18.513674, 73.824263), Point(18.513429, 73.824048), Point(18.511964, 73.824048), Point(18.511151, 73.824391), Point(18.51054, 73.824563), Point(18.509706, 73.825486), Point(18.507627, 73.826341), Point(18.507684, 73.827277), Point(18.506822, 73.827609), Point(18.506329, 73.826702), Point(18.505942, 73.825421), Point(18.506104, 73.82467), Point(18.507395, 73.823462), Point(18.508282, 73.822739), Point(18.509584, 73.821495), Point(18.510377, 73.820529), Point(18.510479, 73.820035), Point(18.510479, 73.819048), Point(18.510418, 73.818233), Point(18.50995, 73.815637), Point(18.509665, 73.814692), Point(18.509563, 73.813834), Point(18.50934, 73.811817), Point(18.508404, 73.810508), Point(18.508119, 73.809135), Point(18.507346, 73.807611), Point(18.507305, 73.806131), ]); - Point in1 = Point(18.507305, 73.806131); + var location_eleven = Polygon([ Point(18.507305, 73.806131), Point(18.508689, 73.806131), Point(18.509299, 73.805916), Point(18.509848, 73.805981), Point(18.512941, 73.806024), Point(18.512941, 73.803492), Point(18.512453, 73.802032), Point(18.512283, 73.800424), Point(18.511964, 73.798943), Point(18.511822, 73.798749), Point(18.513429, 73.79817), Point(18.514813, 73.797483), Point(18.514854, 73.796818), Point(18.515342, 73.796067), Point(18.515688, 73.795896), Point(18.516115, 73.795788), Point(18.517377, 73.79581), Point(18.518394, 73.794222), Point(18.519696, 73.795595), Point(18.520551, 73.796153), Point(18.523155, 73.799028), Point(18.523643, 73.800831), Point(18.523888, 73.802118), Point(18.524172, 73.80259), Point(18.524091, 73.80362), Point(18.524539, 73.804607), Point(18.524591, 73.808944), Point(18.524783, 73.809571), Point(18.524094, 73.811088), Point(18.524295, 73.81259), Point(18.525454, 73.814199), Point(18.526166, 73.814886), Point(18.524172, 73.817761), Point(18.523237, 73.818169), Point(18.5211, 73.822246), Point(18.520388, 73.823254), Point(18.520063, 73.824456), Point(18.519208, 73.827052), Point(18.517133, 73.826108), Point(18.516278, 73.824906), Point(18.514894, 73.824649), Point(18.514813, 73.824306), Point(18.513674, 73.824263), Point(18.513429, 73.824048), Point(18.511964, 73.824048), Point(18.511151, 73.824391), Point(18.51054, 73.824563), Point(18.509706, 73.825486), Point(18.507627, 73.826341), Point(18.507684, 73.827277), Point(18.506822, 73.827609), Point(18.506329, 73.826702), Point(18.505942, 73.825421), Point(18.506104, 73.82467), Point(18.507395, 73.823462), Point(18.508282, 73.822739), Point(18.509584, 73.821495), Point(18.510377, 73.820529), Point(18.510479, 73.820035), Point(18.510479, 73.819048), Point(18.510418, 73.818233), Point(18.50995, 73.815637), Point(18.509665, 73.814692), Point(18.509563, 73.813834), Point(18.50934, 73.811817), Point(18.508404, 73.810508), Point(18.508119, 73.809135), Point(18.507346, 73.807611), Point(18.507305, 73.806131), ]); + var in1 = Point(18.507305, 73.806131); - List checkPunches =[ Point(18.5124785, 73.8206602), Point(18.5112654, 73.8172661), Point(18.5016256, 73.8094801), Point(18.5115046, 73.8171069), Point(18.5109839, 73.8154427), Point(18.5112721, 73.8162126), Point(18.5163667, 73.8075354), Point(18.5124489, 73.8207613), Point(18.5127482, 73.8189808), Point(18.5060939, 73.8259163), Point(18.5114909, 73.8164503), Point(18.508175, 73.822866), Point(18.5128381, 73.8112762), Point(18.5017223, 73.8094366), Point(18.5150109, 73.8159275), Point(18.5163667, 73.8075354), Point(18.5014018, 73.80952), Point(18.5112285, 73.8171876), Point(18.5078999, 73.8229854), Point(18.5135063, 73.8159908), Point(18.5110897, 73.8176941), Point(18.5107774, 73.8157407), Point(18.5011049, 73.8096167), Point(18.5128833, 73.8181274), Point(18.514984, 73.8159425), Point(18.5082853, 73.8229171), Point(18.5109213, 73.8172806), Point(18.5019752, 73.8094272), Point(18.5036271, 73.8557149), Point(18.5112384, 73.8171174), Point(18.5112384, 73.8171174), Point(18.5112384, 73.8171174), Point(18.5114182, 73.8170969), Point(18.5019349, 73.8096291), Point(18.5149707, 73.8154424), Point(18.5111738, 73.8171607), Point(18.5111634, 73.8171551), Point(18.5120293, 73.8113572), Point(18.5012618, 73.8095137), Point(18.5124395, 73.8207164), Point(18.503084, 73.8088517), Point(18.5124448, 73.8207177), Point(18.5112947, 73.8198235), Point(18.5117293, 73.8167963), Point(18.5142932, 73.8169554), Point(18.5123237, 73.8170578), Point(18.515029, 73.8159474), Point(18.5125214, 73.8086799), Point(18.5112435, 73.817181), Point(18.5124343, 73.8206081), Point(18.5079338, 73.8228738), Point(18.5117969, 73.8117694), Point(18.5112558, 73.817308), Point(18.5115868, 73.8169698), Point(18.5115922, 73.8169871), Point(18.5615843, 73.8141527), Point(18.5035994, 73.8557277), Point(18.56675, 73.8075583), Point(18.5542636, 73.8051996), Point(18.5024549, 73.8781556), Point(18.5541433, 73.805365), Point(18.5542963, 73.8053572), Point(18.5072059, 73.8262839), Point(18.5746887, 73.76487), Point(18.5543487, 73.8055963), Point(18.5542637, 73.8053565), Point(18.5542578, 73.8054209), Point(18.5611495, 73.8149408), Point(18.5555028, 73.8057247), Point(18.554192, 73.8054267), Point(18.507693, 73.796015), Point(18.5612433, 73.8145167), Point(18.5542637, 73.8053565), Point(18.5542637, 73.8053565), Point(18.5542637, 73.8053565), Point(18.5542637, 73.8053565), Point(18.5619854, 73.7928126), Point(18.5280783, 73.8303274), Point(18.5035991, 73.8557274), Point(18.5542247, 73.8053859), Point(18.5542579, 73.8052151), Point(18.5036077, 73.8557219), Point(18.5542637, 73.8053565), Point(18.5542735, 73.805281), Point(18.5552057, 73.8160962), Point(18.5036221, 73.8557353), Point(18.5542557, 73.8051856), Point(18.5036307, 73.8557221), Point(18.5606828, 73.8148879), Point(18.5542889, 73.8054483), Point(18.5542979, 73.8055085), Point(18.5542557, 73.8051856), Point(18.5035764, 73.8557534), Point(18.5542557, 73.8051856), ]; - List out = []; - List x = []; - List y = []; + var checkPunches =[ Point(18.5124785, 73.8206602), Point(18.5112654, 73.8172661), Point(18.5016256, 73.8094801), Point(18.5115046, 73.8171069), Point(18.5109839, 73.8154427), Point(18.5112721, 73.8162126), Point(18.5163667, 73.8075354), Point(18.5124489, 73.8207613), Point(18.5127482, 73.8189808), Point(18.5060939, 73.8259163), Point(18.5114909, 73.8164503), Point(18.508175, 73.822866), Point(18.5128381, 73.8112762), Point(18.5017223, 73.8094366), Point(18.5150109, 73.8159275), Point(18.5163667, 73.8075354), Point(18.5014018, 73.80952), Point(18.5112285, 73.8171876), Point(18.5078999, 73.8229854), Point(18.5135063, 73.8159908), Point(18.5110897, 73.8176941), Point(18.5107774, 73.8157407), Point(18.5011049, 73.8096167), Point(18.5128833, 73.8181274), Point(18.514984, 73.8159425), Point(18.5082853, 73.8229171), Point(18.5109213, 73.8172806), Point(18.5019752, 73.8094272), Point(18.5036271, 73.8557149), Point(18.5112384, 73.8171174), Point(18.5112384, 73.8171174), Point(18.5112384, 73.8171174), Point(18.5114182, 73.8170969), Point(18.5019349, 73.8096291), Point(18.5149707, 73.8154424), Point(18.5111738, 73.8171607), Point(18.5111634, 73.8171551), Point(18.5120293, 73.8113572), Point(18.5012618, 73.8095137), Point(18.5124395, 73.8207164), Point(18.503084, 73.8088517), Point(18.5124448, 73.8207177), Point(18.5112947, 73.8198235), Point(18.5117293, 73.8167963), Point(18.5142932, 73.8169554), Point(18.5123237, 73.8170578), Point(18.515029, 73.8159474), Point(18.5125214, 73.8086799), Point(18.5112435, 73.817181), Point(18.5124343, 73.8206081), Point(18.5079338, 73.8228738), Point(18.5117969, 73.8117694), Point(18.5112558, 73.817308), Point(18.5115868, 73.8169698), Point(18.5115922, 73.8169871), Point(18.5615843, 73.8141527), Point(18.5035994, 73.8557277), Point(18.56675, 73.8075583), Point(18.5542636, 73.8051996), Point(18.5024549, 73.8781556), Point(18.5541433, 73.805365), Point(18.5542963, 73.8053572), Point(18.5072059, 73.8262839), Point(18.5746887, 73.76487), Point(18.5543487, 73.8055963), Point(18.5542637, 73.8053565), Point(18.5542578, 73.8054209), Point(18.5611495, 73.8149408), Point(18.5555028, 73.8057247), Point(18.554192, 73.8054267), Point(18.507693, 73.796015), Point(18.5612433, 73.8145167), Point(18.5542637, 73.8053565), Point(18.5542637, 73.8053565), Point(18.5542637, 73.8053565), Point(18.5542637, 73.8053565), Point(18.5619854, 73.7928126), Point(18.5280783, 73.8303274), Point(18.5035991, 73.8557274), Point(18.5542247, 73.8053859), Point(18.5542579, 73.8052151), Point(18.5036077, 73.8557219), Point(18.5542637, 73.8053565), Point(18.5542735, 73.805281), Point(18.5552057, 73.8160962), Point(18.5036221, 73.8557353), Point(18.5542557, 73.8051856), Point(18.5036307, 73.8557221), Point(18.5606828, 73.8148879), Point(18.5542889, 73.8054483), Point(18.5542979, 73.8055085), Point(18.5542557, 73.8051856), Point(18.5035764, 73.8557534), Point(18.5542557, 73.8051856), ]; + var out = []; + var x = []; + var y = []; /// A Point can be checked if it's present inside the Polygon by passing [Point i] to contains_p function print(location_eleven.isPointInside(in1)); @@ -22,10 +22,10 @@ void main(){ print(out); var out_l = out.length; - print("\n\n $out_l"); - List fe = []; + print('\n\n $out_l'); + var fe = []; // List Temp = []; - for(int i =0; i< out_l; i++){ + for(var i =0; i< out_l; i++){ // x[i] = e[i].x; // y[i] = e[i].y; var Temp = [x[i],y[i],out[i]]; @@ -33,13 +33,13 @@ void main(){ } // e.forEach(f) // fe = [e, out]; - String csv = const ListToCsvConverter().convert(fe); + var csv = const ListToCsvConverter().convert(fe); // var fil = File('out1.csv').createSync(recursive: true); var file = File('out1.csv'); // var sink = file.openSync(); var a = file.readAsStringSync(); if(a.isEmpty){ - print("Will write"); + print('Will write'); file.writeAsStringSync(csv); } else{ diff --git a/example/simple_csv.dart b/example/simple_csv.dart index 7ec50ce..187a59c 100644 --- a/example/simple_csv.dart +++ b/example/simple_csv.dart @@ -2,8 +2,8 @@ import 'package:poly/poly.dart'; import 'dart:io'; main() async { - int countCSV = 0; - Polygon location_eleven = Polygon([ + var countCSV = 0; + var location_eleven = Polygon([ Point(18.507305, 73.806131), Point(18.508689, 73.806131), Point(18.509299, 73.805916), @@ -74,7 +74,7 @@ main() async { Point(18.507346, 73.807611), Point(18.507305, 73.806131), ]); - List> checkPoints = [ + var checkPoints = >[ Point(18.5124785, 73.8206602), Point(18.5112654, 73.8172661), Point(18.5016256, 73.8094801), @@ -171,8 +171,8 @@ main() async { Point(18.5542557, 73.8051856), ]; - String nameOfIsInsideResult = "IsInside.csv"; - String nameOfPolygon = "Polygon.csv"; + var nameOfIsInsideResult = 'IsInside.csv'; + var nameOfPolygon = 'Polygon.csv'; // Example of `IsInsideResultWithXY_ToCSVString` //* Saving `ArePointsInside Results` to "IsInside.csv" @@ -180,9 +180,9 @@ main() async { // * And as `diffNameThanIsInside:"Example String"` is passed, // * Header row will be `latitude,longitude,Example String` // Get `ArePointsInside` as CSV String - `csvOfIsInsideResult` - String csvOfIsInsideResult = location_eleven.IsInsideResultWithXY_ToCSVString( + var csvOfIsInsideResult = location_eleven.IsInsideResultWithXY_ToCSVString( checkPoints, - diffNameThanIsInside: "Example String"); + diffNameThanIsInside: 'Example String'); // Write `String csvOfIsInsideResult` to "IsInside.csv" File(nameOfIsInsideResult).writeAsStringSync(csvOfIsInsideResult); print('${++countCSV}. ArePointsInside Results saved to IsInside.csv '); @@ -192,7 +192,7 @@ main() async { // * Headers row will be added, as `includeHeader` isn't passed as `false` // * And as `useXY` is passed as `true` // * Header row will be `x,y` - String csvOfPolygon = location_eleven.toCSVString(useXY: true); + var csvOfPolygon = location_eleven.toCSVString(useXY: true); // Write `String csvOfIsInsideResult` to "Polygon.csv" File(nameOfPolygon).writeAsStringSync(csvOfPolygon); print('${++countCSV}. `Polygon.points` saved to Polygon.csv '); @@ -203,13 +203,13 @@ main() async { //* As, previously `xY_IsInside_ToCSVString` returned String with header //* because optional parameter `header` was not set to false final IsInsideList = File(nameOfIsInsideResult).openRead(); - final l = await csvToListOfList(IsInsideList); - print("${++countCSV}. e.g. here ${l[0][1]} and ${l[0][2]}"); + final l = await (csvToListOfList(IsInsideList) as Future>>); + print('${++countCSV}. e.g. here ${l[0][1]} and ${l[0][2]}'); // Example of `csvToPoly` //* Check if Point(18.507305, 73.806131) is inside Polygon readPolygon (Polygon from Polygon.csv) final readPolygon = File(nameOfPolygon).openRead(); - Polygon newPolygon = await csvToPoly(readPolygon); + var newPolygon = await csvToPoly(readPolygon); print( - "${++countCSV}. Is Point(18.507305, 73.806131) inside Polygon (saved in Polygon.csv) : ${newPolygon.contains(18.507305, 73.806131)}"); + '${++countCSV}. Is Point(18.507305, 73.806131) inside Polygon (saved in Polygon.csv) : ${newPolygon.contains(18.507305, 73.806131)}'); } diff --git a/example/spreadsheet_example.dart b/example/spreadsheet_example.dart index 8aab008..f9154ef 100644 --- a/example/spreadsheet_example.dart +++ b/example/spreadsheet_example.dart @@ -49,7 +49,7 @@ ////void updatecell(){ //// var file = "poly1.xlsx"; //// //createFileRecursively(file); -//// var bytes = new File(file).readAsBytesSync(); +//// var bytes = File(file).readAsBytesSync(); //// var decoder = SpreadsheetDecoder.decodeBytes(bytes, update: true); //// var table = decoder.tables['Sheet1']; //// var values = table.rows[0]; @@ -64,7 +64,7 @@ // // unexpected behaviour - add new column with value c instated of adding/updating cell - A3 with value c // var file = "poly1.xlsx"; // String workSheet = 'Sheet1'; -// var bytes = new File(file).readAsBytesSync(); +// var bytes = File(file).readAsBytesSync(); // var decoder = SpreadsheetDecoder.decodeBytes(bytes, update: true); // //1 // // print(numberOfWorksheet(decoder)); diff --git a/example/using_to.dart b/example/using_to.dart index eb6ab88..27db5ea 100644 --- a/example/using_to.dart +++ b/example/using_to.dart @@ -1,11 +1,11 @@ import 'package:poly/poly.dart'; main() { - int correct_count = 0; - int exception_count = 0; - List correctDynamicList = [1, 2, 'a', 3]; + var correct_count = 0; + var exception_count = 0; + var correctDynamicList = [1, 2, 'a', 3]; // listOf is `List - List listOf = [ + var listOf = [ [1, true], [2, 'Remove me'], [3, 4], @@ -14,45 +14,45 @@ main() { ]; print( - "\u2022 Old List:${correctDynamicList} has type:${correctDynamicList.runtimeType} & has length:${correctDynamicList.length}"); + '\u2022 Old List:$correctDynamicList has type:${correctDynamicList.runtimeType} & has length:${correctDynamicList.length}'); // * Example of `toListNum` without any optional parameters - List l = toListNum(correctDynamicList); + var l = toListNum(correctDynamicList); print( - "${++correct_count}. Using `toListNum`,${l} has type:${l.runtimeType} & has length:${l.length}"); + '${++correct_count}. Using `toListNum`,$l has type:${l.runtimeType} & has length:${l.length}'); // * Example of `toListNum` with `replaceWithZero: true` and `sizeTwo: false` - List lSizeNotTwo_Zero = + var lSizeNotTwo_Zero = toListNum(correctDynamicList, replaceWithZero: true, sizeTwo: false); print( - "${++correct_count}. Using `toListNum` with `replaceWithZero: true` and `sizeTwo: false`,${lSizeNotTwo_Zero} has type:${lSizeNotTwo_Zero.runtimeType} & has length:${lSizeNotTwo_Zero.length}"); + '${++correct_count}. Using `toListNum` with `replaceWithZero: true` and `sizeTwo: false`,$lSizeNotTwo_Zero has type:${lSizeNotTwo_Zero.runtimeType} & has length:${lSizeNotTwo_Zero.length}'); // * Example of `toListNum` with `sizeTwo: false` - List lSizeNotTwo = toListNum(correctDynamicList, sizeTwo: false); + var lSizeNotTwo = toListNum(correctDynamicList, sizeTwo: false); print( - "${++correct_count}. Using `toListNum` with `sizeTwo: false`,${lSizeNotTwo} has type:${lSizeNotTwo.runtimeType} & has length:${lSizeNotTwo.length}"); + '${++correct_count}. Using `toListNum` with `sizeTwo: false`,$lSizeNotTwo has type:${lSizeNotTwo.runtimeType} & has length:${lSizeNotTwo.length}'); // * Example of `toListListNum` without any optional parameters print( - "\n\u2022 Old List:${listOf} has type:${listOf.runtimeType} & has length:${listOf.length}"); + '\n\u2022 Old List:$listOf has type:${listOf.runtimeType} & has length:${listOf.length}'); - List> m = toListListNum(listOf); + List> m = toListListNum(listOf); print( - "${++correct_count}. Using `toListListNum`,${m} has type:${m.runtimeType} & has length:${m.length}"); + '${++correct_count}. Using `toListListNum`,$m has type:${m.runtimeType} & has length:${m.length}'); // * Example of `toListListNum` with `swapXAndY: true` - List> mSwap = toListListNum(listOf, swapXAndY: true); + List> mSwap = toListListNum(listOf, swapXAndY: true); print( - "${++correct_count}. Using `toListListNum` with `swapXAndY: true`,${mSwap} has type:${mSwap.runtimeType} & has length:${mSwap.length}"); + '${++correct_count}. Using `toListListNum` with `swapXAndY: true`,$mSwap has type:${mSwap.runtimeType} & has length:${mSwap.length}'); // * Example of `toListListNum` with `replaceWithZero: true` - List> mZero = toListListNum(listOf, replaceWithZero: true); + List> mZero = toListListNum(listOf, replaceWithZero: true); print( - "${++correct_count}. Using `toListListNum` with `replaceWithZero: true`,${mZero} has type:${mZero.runtimeType} & has length:${mZero.length}"); + '${++correct_count}. Using `toListListNum` with `replaceWithZero: true`,$mZero has type:${mZero.runtimeType} & has length:${mZero.length}'); // * Example of `toListListNum` with `replaceWithZero: true` and `swapXAndY: true` - List> mZeroSwap = + List> mZeroSwap = toListListNum(listOf, replaceWithZero: true, swapXAndY: true); print( - "${++correct_count}. Using `toListListNum` with `replaceWithZero: true` and `swapXAndY: true`,${mZeroSwap} has type:${mZeroSwap.runtimeType} & has length:${mZeroSwap.length}"); + '${++correct_count}. Using `toListListNum` with `replaceWithZero: true` and `swapXAndY: true`,$mZeroSwap has type:${mZeroSwap.runtimeType} & has length:${mZeroSwap.length}'); } diff --git a/lib/poly.dart b/lib/poly.dart index 93f3c36..dbee588 100644 --- a/lib/poly.dart +++ b/lib/poly.dart @@ -22,7 +22,7 @@ import 'package:collection/collection.dart' as check_list //#1 _startIsolate. (dart:isolate/runtime/libisolate_patch.dart:300:19) //#2 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12) List listAppend(List one, List two) { - return []..addAll(one)..addAll(two); + return [...one, ...two]; } //List> new_w = append(l,[Point(74,99)].cast>()); //print("\n\n ${new_w}"); @@ -39,11 +39,13 @@ List listAppend(List one, List two) { //TODO - kml support ///* `NeedsAtLeastThreePoints` is thrown if `Polygon.points` contains less than 3 points class NeedsAtLeastThreePoints implements Exception { - int _number_of_point; + final int _number_of_point; NeedsAtLeastThreePoints(this._number_of_point); + + @override String toString() => - "Please provide three or more points. Current number of Points: $_number_of_point"; - int currentPointsInPolygon() => this._number_of_point; + 'Please provide three or more points. Current number of Points: $_number_of_point'; + int currentPointsInPolygon() => _number_of_point; } //TO DO - Check length of dart identifier - Not found @@ -52,23 +54,25 @@ class NeedsAtLeastThreePoints implements Exception { // NotJustTwoElementsForPoint ///* `WrongSizeForPoint` is thrown if `to_Point()` has more or less than 2 element. Point has only x and y. class WrongSizeForPoint implements Exception { - int _length_of_list; + final int _length_of_list; WrongSizeForPoint(this._length_of_list); + + @override String toString() => - "Wrong size, List must have 2 element. Current Size: $_length_of_list"; - int inputListLength() => this._length_of_list; + 'Wrong size, List must have 2 element. Current Size: $_length_of_list'; + int inputListLength() => _length_of_list; } //TO DO - Casting ?? // can we check if List is List ?? Replace List with List ///* returns `true` if `String` contains Space bool containsSpace(String inputString) { - return inputString.contains(" "); + return inputString.contains(' '); } /// `List` to `Point` Point toPoint(List list_of_xy) { - int _length_of_list_xy = list_of_xy.length; + var _length_of_list_xy = list_of_xy.length; if (_length_of_list_xy == 2) { return Point(list_of_xy[0], list_of_xy[1]); } else { @@ -79,14 +83,14 @@ Point toPoint(List list_of_xy) { /// `Point` to `List` List pointToList(Point inPoint) { - List output = [inPoint.x, inPoint.y]; + final output = [inPoint.x, inPoint.y]; return output; } //TODO - Add a check to see if it's List> or just List if it's casted ? /// `List` to `List` List> toListOfPoint(List> list_of_list) { - List> _out_list_of_point = []; + var _out_list_of_point = >[]; list_of_list.forEach((_element_in_list_of_list) { _out_list_of_point.add(toPoint(_element_in_list_of_list)); }); @@ -95,8 +99,8 @@ List> toListOfPoint(List> list_of_list) { /// `List` to `List` List> pointsToList(List> inputListOfPoint) { - List> _out = []; - for (int _i = 0; _i < inputListOfPoint.length; _i++) { + var _out = >[]; + for (var _i = 0; _i < inputListOfPoint.length; _i++) { _out.add(pointToList(inputListOfPoint[_i])); } return _out; @@ -108,7 +112,7 @@ Polygon toPolyFromListOfList(List> list_of_list) { if (_length_of_poly < 3) { throw NeedsAtLeastThreePoints(_length_of_poly); } - List> _list_of_point = []; + var _list_of_point = >[]; list_of_list.forEach((_element_in_list_of_list) { _list_of_point.add(toPoint(_element_in_list_of_list)); }); @@ -133,8 +137,8 @@ List toListNum(List _inputList, {bool reverseIt = false, bool replaceWithZero = false, bool sizeTwo = true}) { - var _list = []..addAll(_inputList); - int lengthOfPoints = _list.length; + var _list = [..._inputList]; + var lengthOfPoints = _list.length; if (replaceWithZero) { //print("${lengthOfPoints}"); if (sizeTwo) { @@ -153,7 +157,7 @@ List toListNum(List _inputList, _list = [x, 0]; } } else { - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { var element = _list[_i]; if ((element.runtimeType == String) || (element.runtimeType == bool)) { _list[_i] = 0; @@ -168,15 +172,15 @@ List toListNum(List _inputList, lengthOfPoints = sizeTwo ? 2 : _list.length; //print("${lengthOfPoints}"); - List numList = []; + var numList = []; if (reverseIt) { - for (int _i = lengthOfPoints - 1; _i >= 0; _i--) { + for (var _i = lengthOfPoints - 1; _i >= 0; _i--) { var x = _list[_i]; //print(x.runtimeType); numList.add(x); } } else { - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { var x = _list[_i]; //print(x.runtimeType); numList.add(x); @@ -197,20 +201,20 @@ List toListNum(List _inputList, /// - i.e. `[ [x1,y1], [x2,y2], ...]` -> `[ [y1,x1], [y2,x2], ...]` List> toListListNum(List _inputListOfList, {bool swapXAndY = false, bool replaceWithZero = false}) { - var _listOfList = []..addAll(_inputListOfList); + var _listOfList = [..._inputListOfList]; if (_listOfList[0][0].runtimeType == String) { swapXAndY = swapXAndY ? swapXAndY - : ((_listOfList[0][0] == "longitude" || _listOfList[0][0] == "y") + : ((_listOfList[0][0] == 'longitude' || _listOfList[0][0] == 'y') ? true : false); //_listOfList.removeAt(0); } - int lengthOfPoints = _listOfList.length; + var lengthOfPoints = _listOfList.length; //print("Before: ${lengthOfPoints}"); if (replaceWithZero) { //print("${lengthOfPoints}"); - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { var x = _listOfList[_i][0]; var y = _listOfList[_i][1]; //print(x.runtimeType); @@ -230,10 +234,10 @@ List> toListListNum(List _inputListOfList, ((_i[1].runtimeType == String) || (_i[1].runtimeType == bool)))); } lengthOfPoints = _listOfList.length; - List> numList = []; + var numList = >[]; if (swapXAndY) { - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { var x = _listOfList[_i][0]; var y = _listOfList[_i][1]; numList.add([y, x]); @@ -248,7 +252,7 @@ List> toListListNum(List _inputListOfList, } } else { //print("lengthOfPoints:${lengthOfPoints}"); - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { // print("_i:${_i}"); var y = _listOfList[_i][1]; var x = _listOfList[_i][0]; @@ -273,7 +277,7 @@ List> toListListNum(List _inputListOfList, /// A class for representing two-dimensional Polygon defined with `List> points`. class Polygon { final List> points; - String name; + String name = ''; // double version; ///Create a `Polygon` with vertices at `points`. @@ -282,7 +286,7 @@ class Polygon { var _number_of_point = this.points.length; if (_number_of_point < 3) { throw NeedsAtLeastThreePoints(_number_of_point); - // throw new ArgumentError("Please provide three or more points."); + // throw ArgumentError("Please provide three or more points."); } // name = tname; } @@ -296,11 +300,11 @@ class Polygon { bool contains(num px, num py) { num ax = 0; num ay = 0; - num bx = points[points.length - 1].x - px; - num by = points[points.length - 1].y - py; - int depth = 0; + var bx = points[points.length - 1].x - px; + var by = points[points.length - 1].y - py; + var depth = 0; - for (int i = 0; i < points.length; i++) { + for (var i = 0; i < points.length; i++) { ax = bx; ay = by; bx = points[i].x - px; @@ -342,10 +346,10 @@ class Polygon { if (isPointInside(i)) { return true; } else { - double dis = 0, dd = 0; - dis = distanceInMeter(i.x, i.y, points[0].x, points[0].y); - for (int j = 1; j < points.length; j++) { - dd = distanceInMeter(i.x, i.y, points[j].x, points[j].y); + var dis = 0.0, dd = 0.0; + dis = distanceInMeter(i.x as double, i.y as double, points[0].x as double, points[0].y as double); + for (var j = 1; j < points.length; j++) { + dd = distanceInMeter(i.x as double, i.y as double, points[j].x as double, points[j].y as double); dis = dd < dis ? dd : dis; } return dis > T ? false : true; @@ -354,7 +358,7 @@ class Polygon { /// Checks if 2 `Polygon` have same vertices i.e. `points` bool hasSamePoints(Polygon anotherPolygon) { - bool same = (points.length == anotherPolygon.points.length); + var same = (points.length == anotherPolygon.points.length); if (!same) { return false; } else { @@ -372,7 +376,7 @@ class Polygon { /// returns `List` from `List>` based on if `Point` is present or not List getList_IsListOfPointInside(List> inputListOfPoint) { - List _out = []; + var _out = []; for (var _currentPoint in inputListOfPoint) { _out.add(isPointInside(_currentPoint)); } @@ -381,7 +385,7 @@ class Polygon { /// returns `List` from `List>` based on if `Point` is present or not List getList_IsListOfListInside(List> inputListOfList) { - List _out = []; + var _out = []; var _inputListOfPoint = toListOfPoint(inputListOfList); _inputListOfPoint.forEach((_currentPoint) { _out.add(isPointInside(_currentPoint)); @@ -398,7 +402,7 @@ class Polygon { /// returns `true` if all List are inside `Polygon` bool areAllPointsInsidePolygon_List(List> inputListOfList) { - List> inputListOfPoint = toListOfPoint(inputListOfList); + var inputListOfPoint = toListOfPoint(inputListOfList); return getList_IsListOfPointInside(inputListOfPoint).contains(false) ? false : true; @@ -406,9 +410,9 @@ class Polygon { /// returns `List indexes` from `List>` based on which `Point` are present inside List listIndexOfInsidePoint(List> inputListOfPoint) { - List _out = []; + var _out = []; Point _pointInList; - for (int index = 0; index < inputListOfPoint.length; index++) { + for (var index = 0; index < inputListOfPoint.length; index++) { _pointInList = inputListOfPoint[index]; if (isPointInside(_pointInList)) { _out.add(index); @@ -428,33 +432,33 @@ class Polygon { /// * Different name than Default name(`isInside`) will be used by passing optional parameter: `diffNameThanIsInside` String IsInsideResultWithXY_ToCSVString(List> inputListOfPoint, {bool includeHeader = true, - String diffNameThanIsInside, + String diffNameThanIsInside = '', bool useXY = false}) { - List xYOut = []; + var xYOut = []; if (includeHeader) { - String headerX = useXY ? "x" : "latitude"; - String headerY = useXY ? "y" : "longitude"; + var headerX = useXY ? 'x' : 'latitude'; + var headerY = useXY ? 'y' : 'longitude'; // TODO - Remove three quotation marks """Example Name_with_space""" when '"x"' is used, instead of "x" diffNameThanIsInside = containsSpace(diffNameThanIsInside) - ? '${diffNameThanIsInside}' + ? '$diffNameThanIsInside' : diffNameThanIsInside; // print(diffNameThanIsInside); - String headerIs = (diffNameThanIsInside?.isNotEmpty ?? false) + var headerIs = diffNameThanIsInside.isNotEmpty ? diffNameThanIsInside - : "isInside"; + : 'isInside'; var headerL = [headerX, headerY, headerIs]; xYOut.add(headerL); } for (var _currentPoint in inputListOfPoint) { - bool c_out = isPointInside(_currentPoint); + var c_out = isPointInside(_currentPoint); // _out.add(c_out); // x.add(_currentPoint.x); // y.add(_currentPoint.y); var Temp = [_currentPoint.x, _currentPoint.y, c_out]; xYOut.add(Temp); } - String csv = const ListToCsvConverter().convert(xYOut); + var csv = const ListToCsvConverter().convert(xYOut); return csv; } @@ -466,10 +470,10 @@ class Polygon { /// * Optional Named parameter: `String includeHeader` /// * if optional parameter - `includeHeader` is is passed as `false`, returning String will not contain header row String toCSVString({bool includeHeader = true, bool useXY = false}) { - List _xY = []; + var _xY = []; if (includeHeader) { - String _headerX = useXY ? "x" : "latitude"; - String _headerY = useXY ? "y" : "longitude"; + var _headerX = useXY ? 'x' : 'latitude'; + var _headerY = useXY ? 'y' : 'longitude'; var _headerL = [_headerX, _headerY]; _xY.add(_headerL); } @@ -477,7 +481,7 @@ class Polygon { var _currentXY = [_currentPoint.x, _currentPoint.y]; _xY.add(_currentXY); } - String csv = const ListToCsvConverter().convert(_xY); + var csv = const ListToCsvConverter().convert(_xY); return csv; } } // class Polygon @@ -516,37 +520,37 @@ Future csvToPoly(var csvString, {bool isReversed = false}) async { if (_listOfList[0][0].runtimeType == String) { isReversed = isReversed ? isReversed - : ((_listOfList[0][0] == "longitude" || _listOfList[0][0] == "y") + : ((_listOfList[0][0] == 'longitude' || _listOfList[0][0] == 'y') ? true : false); _listOfList.removeAt(0); } - List> numList = []; - int lengthOfPoints = _listOfList.length; + var numList = >[]; + var lengthOfPoints = _listOfList.length; if (isReversed) { - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { var x = _listOfList[_i][0]; var y = _listOfList[_i][1]; //print(x.runtimeType); numList.add([y, x]); } } else { - for (int _i = 0; _i < lengthOfPoints; _i++) { + for (var _i = 0; _i < lengthOfPoints; _i++) { var y = _listOfList[_i][1]; var x = _listOfList[_i][0]; //print(x.runtimeType); numList.add([x, y]); } } - Polygon _out = toPolyFromListOfList(numList); + var _out = toPolyFromListOfList(numList); return _out; } //Future csvToPoly_casting_issue(var input, {bool isReversed = false}) async { // List> fields = await input // .transform(utf8.decoder) -// .transform(new CsvToListConverter()) +// .transform(CsvToListConverter()) // .toList(); // if (fields[0][0].runtimeType == String) { // fields.removeAt(0); @@ -565,7 +569,7 @@ Future csvToPoly(var csvString, {bool isReversed = false}) async { //Future csvToTemp(var input, {bool isReversed = false}) async { // List fields = await input // .transform(utf8.decoder) -// .transform(new CsvToListConverter()) +// .transform(CsvToListConverter()) // .toList(); // if (fields[0][0].runtimeType == String) { // fields.removeAt(0); diff --git a/pubspec.yaml b/pubspec.yaml index 7671c5b..a5127dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,20 +1,20 @@ name: poly description: A library for checking if given point(s) is present inside Polygon or not. -version: 1.0.7+2 +version: 1.0.8 homepage: https://github.com/Sacchid/poly author: sacchi <22224760+Sacchid@users.noreply.github.com> environment: - sdk: '>=2.1.0 <3.0.0' + sdk: ">=2.12.0-0 <3.0.0" dependencies: - csv: ^4.0.3 - collection: ^1.14.11 + collection: ^1.15.0 + csv: ^5.0.0 # spreadsheet_decoder: ^1.0.1 # json_serializable: ^2.1.0y # path: ^1.4.1 dev_dependencies: - pedantic: ^1.0.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.16.8 # test_coverage: ^0.2.0 diff --git a/test/poly_test.dart b/test/poly_test.dart index 5b3bd25..11d630b 100644 --- a/test/poly_test.dart +++ b/test/poly_test.dart @@ -1,10 +1,10 @@ import 'package:poly/poly.dart'; -import "package:test/test.dart"; +import 'package:test/test.dart'; void main() { - group("Simple Poly test: ", (){ - List> l = [ + group('Simple Poly test: ', (){ + var l = >[ Point(18.4851825, 73.8498851), Point(18.4849214, 73.8498675), Point(18.4855965, 73.8520493), @@ -12,8 +12,8 @@ void main() { Point(18.4857828, 73.8500299), Point(18.4851825, 73.8498851) ]; - Polygon testPolygon = Polygon(l); - Polygon copyOfFirstPolygon = Polygon([ + var testPolygon = Polygon(l); + var copyOfFirstPolygon = Polygon([ Point(18.4851825, 73.8498851), Point(18.4849214, 73.8498675), Point(18.4855965, 73.8520493), @@ -21,165 +21,165 @@ void main() { Point(18.4857828, 73.8500299), Point(18.4851825, 73.8498851) ]); - Point in1 = Point(18.48569, 73.85067); - test("`hasSamePoint()`",(){ - bool areTwoSame = testPolygon.hasSamePoints(copyOfFirstPolygon); + var in1 = Point(18.48569, 73.85067); + test('`hasSamePoint()`',(){ + bool? areTwoSame = testPolygon.hasSamePoints(copyOfFirstPolygon); expect(areTwoSame,equals(true)); }); - test("`isPointInside` ",(){ - bool isIn1InsideTestPolygon = testPolygon.isPointInside(in1); + test('`isPointInside` ',(){ + var isIn1InsideTestPolygon = testPolygon.isPointInside(in1); expect(isIn1InsideTestPolygon,equals(true)); }); - test("`isPointInside` ",(){ - bool polygonContain = copyOfFirstPolygon.contains(18.48569, 73.85067); + test('`isPointInside` ',(){ + var polygonContain = copyOfFirstPolygon.contains(18.48569, 73.85067); expect(polygonContain,equals(true)); }); - test(" areAllPointsInsidePolygon_ListPoint : true ", () { - bool areAllInside = testPolygon.areAllPointsInsidePolygon_ListPoint(l); + test(' areAllPointsInsidePolygon_ListPoint : true ', () { + var areAllInside = testPolygon.areAllPointsInsidePolygon_ListPoint(l); expect(areAllInside,equals(true)); }); - test(" areAllPointsInsidePolygon_ListPoint : false ", () { - List> notInsidePoints = []..addAll(l)..addAll([Point(75, 90)]); - bool areAllInside = testPolygon.areAllPointsInsidePolygon_ListPoint(notInsidePoints); + test(' areAllPointsInsidePolygon_ListPoint : false ', () { + var notInsidePoints = >[...l, Point(75, 90)]; + var areAllInside = testPolygon.areAllPointsInsidePolygon_ListPoint(notInsidePoints); expect(areAllInside,equals(false)); }); - test(" getList_IsListOfPointInside ", () { - List> notInsidePoints = []..addAll(l)..addAll([Point(75, 90)]); - List statusOfPoints = testPolygon.getList_IsListOfPointInside(notInsidePoints); + test(' getList_IsListOfPointInside ', () { + var notInsidePoints = >[...l, Point(75, 90)]; + var statusOfPoints = testPolygon.getList_IsListOfPointInside(notInsidePoints); expect(statusOfPoints,equals([true, true, true, true, true, true, false])); }); }); - group("Dynamic to num: ", (){ - List correctDynamicList = [1, 2, 'a', 3]; - List listOf = [ + group('Dynamic to num: ', (){ + var correctDynamicList = [1, 2, 'a', 3]; + var listOf = [ [1, true], [2, 'Remove me'], [3, 4], [5, 6], [7, 8] ]; - group("toListNum: ",(){ - group("Old List: ",(){ - test("Type",(){ + group('toListNum: ',(){ + group('Old List: ',(){ + test('Type',(){ var oldType = correctDynamicList.runtimeType.toString(); - expect(oldType,equals("List")); + expect(oldType,equals('List')); }); - test("Length",(){ + test('Length',(){ var oldLength = correctDynamicList.length; expect(oldLength,equals(4)); }); }); - group("without any optional parameters:",() { - List lWithoutAnyOptional = toListNum(correctDynamicList); - test("Type", () { + group('without any optional parameters:',() { + var lWithoutAnyOptional = toListNum(correctDynamicList); + test('Type', () { var type = lWithoutAnyOptional.runtimeType.toString(); - expect(type, equals("List")); + expect(type, equals('List')); }); - test("Length", () { + test('Length', () { var length = lWithoutAnyOptional.length; expect(length, equals(2)); }); - test("Value", () { + test('Value', () { expect(lWithoutAnyOptional, equals([1, 2])); }); }); - group("with `replaceWithZero: true` and `sizeTwo: false`:",(){ - List lSizeNotTwo_Zero = + group('with `replaceWithZero: true` and `sizeTwo: false`:',(){ + var lSizeNotTwo_Zero = toListNum(correctDynamicList, replaceWithZero: true, sizeTwo: false); - test("Type",(){ + test('Type',(){ var type = lSizeNotTwo_Zero.runtimeType.toString(); - expect(type,equals("List")); + expect(type,equals('List')); }); - test("Length",(){ + test('Length',(){ var length = lSizeNotTwo_Zero.length; expect(length,equals(4)); }); - test("Value",(){ + test('Value',(){ expect(lSizeNotTwo_Zero,equals([1,2,0,3])); }); }); - group("with `sizeTwo: false`:",(){ - List lSizeNotTwo = toListNum(correctDynamicList, sizeTwo: false); - test("Type",(){ + group('with `sizeTwo: false`:',(){ + var lSizeNotTwo = toListNum(correctDynamicList, sizeTwo: false); + test('Type',(){ var type = lSizeNotTwo.runtimeType.toString(); - expect(type,equals("List")); + expect(type,equals('List')); }); - test("Length",(){ + test('Length',(){ var length = lSizeNotTwo.length; expect(length,equals(3)); }); - test("Value",(){ + test('Value',(){ expect(lSizeNotTwo,equals([1,2,3])); }); }); });//toListnum - group("toListListNum: ",(){ - group("Old List: ",(){ - test("Type",(){ + group('toListListNum: ',(){ + group('Old List: ',(){ + test('Type',(){ var oldType = listOf.runtimeType.toString(); - expect(oldType,equals("List")); + expect(oldType,equals('List')); }); - test("Length",(){ + test('Length',(){ var oldLength = listOf.length; expect(oldLength,equals(5)); }); }); - group("without any optional parameters: ",() { - List> m = toListListNum(listOf); - test("Type", () { + group('without any optional parameters: ',() { + List> m = toListListNum(listOf); + test('Type', () { var type = m.runtimeType.toString(); - expect(type, equals("List>")); + expect(type, equals('List>')); }); - test("Length", () { + test('Length', () { var length = m.length; expect(length, equals(3)); }); - test("Value", () { + test('Value', () { expect(m, equals([[3, 4], [5, 6], [7, 8]])); }); }); - group("with `swapXAndY: true`: ",(){ - List> mSwap = toListListNum(listOf, swapXAndY: true); - test("Type",(){ + group('with `swapXAndY: true`: ',(){ + List> mSwap = toListListNum(listOf, swapXAndY: true); + test('Type',(){ var type = mSwap.runtimeType.toString(); - expect(type,equals("List>")); + expect(type,equals('List>')); }); - test("Length",(){ + test('Length',(){ var length = mSwap.length; expect(length,equals(3)); }); - test("Value",(){ + test('Value',(){ expect(mSwap,equals([[4, 3], [6, 5], [8, 7]])); }); }); - group("with `replaceWithZero: true`:",(){ - List> mZero = toListListNum(listOf, replaceWithZero: true); - test("Type",(){ + group('with `replaceWithZero: true`:',(){ + List> mZero = toListListNum(listOf, replaceWithZero: true); + test('Type',(){ var type = mZero.runtimeType.toString(); - expect(type,equals("List>")); + expect(type,equals('List>')); }); - test("Length",(){ + test('Length',(){ var length = mZero.length; expect(length,equals(5)); }); - test("Value",(){ + test('Value',(){ expect(mZero,equals([[1, 0], [2, 0], [3, 4], [5, 6], [7, 8]])); }); }); - group("with `replaceWithZero: true` and `swapXAndY: true`: ",(){ - List> mZeroSwap = + group('with `replaceWithZero: true` and `swapXAndY: true`: ',(){ + List> mZeroSwap = toListListNum(listOf, replaceWithZero: true, swapXAndY: true); - test("Type",(){ + test('Type',(){ var type = mZeroSwap.runtimeType.toString(); - expect(type,equals("List>")); + expect(type,equals('List>')); }); - test("Length",(){ + test('Length',(){ var length = mZeroSwap.length; expect(length,equals(5)); }); - test("Value",(){ + test('Value',(){ expect(mZeroSwap,equals([[0, 1], [0, 2], [4, 3], [6, 5], [8, 7]])); }); });