poly 1.0.4
poly: ^1.0.4 copied to clipboard
A library for checking if given point(s) is present inside Polygon or not.
A library for checking if given point(s) is present inside Polygon or not.
Usage #
1. A very simple usage example #
- Creates 2 Polygons from
List<Point> - Checks if 2
Polygonhave same vertices i.e.points: usinghasSamePoint() - Prints if given Points are inside Polygon
- Prints if all points in list are inside Polygon or not
- Prints list of result for List of points if they are inside Polygon or not
- Here
hasSamePoint(),isPointInside(Point( )),contains(x,y),areAllPointsInsidePolygon_ListPoint()&getList_IsListOfPointInside()are used.
2. Example of Conversions List <=> Point, List<Point> <=> List<List> etc. #
- Example of
toPoint()toPoint()convertsList<num>toPoint<num>
- Example of
toListOfPoint()toListOfPoint()convertsList<List<num>>toList<Point<num>>
- Example of
toPolyFromListOfList()toPolyFromListOfList()convertsList<List<num>>toPolygon- 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
3. Exception Handling Example #
- It contains examples of following exceptions & errors -
NeedsAtLeastThreePointsis thrown ifPolygon.pointscontains less than 3 pointsWrongSizeForPointis thrown iftoPoint()has more or less than 2 element. Point has only x and y.TypeErroris thrown ifList<dynamic>is passed instead ofList<num>- Here, casting can be used to cast
List<dynamic>toList<num> - e.g.
print(toPoint([1,2]));- Here, [1,2] has a type
List<dynamic> - So, use
[1,2].cast<num>()
- Here, [1,2] has a type
- Here, casting can be used to cast
CastError example- wrongly castingList<num>toList<List<num>
4. Simple CSV example #
- It contains examples of following functions -
-
Example of
IsInsideResultWithXY_ToCSVString- Saving
ArePointsInside Resultsto "IsInside.csv"- Headers row will be added, as
includeHeaderisnt passed asfalse` - And as
diffNameThanIsInside:"Example String"is passed, - Header row will be
latitude,longitude,Example String
- Headers row will be added, as
- Saving
-
Example of
toCSVString- Saving
Polygon.pointsto "Polygon.csv"- Headers row will be added, as
includeHeaderisnt passed asfalse` - And as
useXYis passed astrue - Header row will be
x,y
- Headers row will be added, as
- Saving
-
Example of
csvToResult- Display 1st row : 2nd element & 3rd element of "IsInside.csv"
- e.g. here "longitude" and "Example String"
- As, previously
xY_IsInside_ToCSVStringreturned String with header - because optional parameter
headerwas not set to false
- Display 1st row : 2nd element & 3rd element of "IsInside.csv"
-
Example of
csvToPoly- Check if Point(18.507305, 73.806131) is inside Polygon readPolygon (Polygon from Polygon.csv)
5. Easy Casting Example #
- Without casting
List<dynamic>toList<num>TypeErroris thrown
-
Correct casting
- casting
List<dynamic>toList<num> - casting
List<dynamic>toList<List<num>>
- casting
-
Passing
Listinstead ofList<List>
- Passing
Listinstead ofList<List>& casting it : throwsCastErroras shown below :type
intis not a subtype of typeList<num>in type cast - Passing
Listinstead ofList<List>but, without casting it : throwsTypeErroras shown below :type
List<dynamic>is not a subtype of typeList<List<num>> - Note: currently casting
List<List<dynamic>>toList<List<num>>gives followingCastErrorexception:- without
as List<List<num>>-
type
List<dynamic>is not a subtype of typeList<num>in type cast- with
as List<List<num>>-
type
List<List<dynamic>>is not a subtype of typeList<List<num>>in type cast - without
Function List #
Conversion Type #
List<num> to Point(x,y)
- i.e.
[x,y]->Point(x,y) - Point can be created passing
List<num>toPoint(). - List must have exact 2 elements, else will throw
WrongSizeForPointexception
List<List<num>> to List<Point<num>>
- i.e.
[ [x1,y1],[x2,y2],... ]->[ Point(x1,y1), Point(x2,y2),... ] - List of Points can be created from
List<List<num>>by passing it totoListOfPoint()
List<List<num>> to Polygon
- i.e.
[ [x1,y1],[x2,y2],... ]->Polygon( Point(x1,y1), Point(x2,y2),... ) - Polygon can be returned from
List<List<num>>by passing it totoPolyFromListOfList
is Point(s) inside #
Check if Single Point is inside
Get Status by passing x and y to contains
- returns
trueif(x,y)is present insidePolygon
Get Status by passing Point(x,y) to isPointInside
- returns
trueifPointis present insidePolygon
Check if Multiple Points are inside given Polygon
Get Status of each Point
getList_IsListOfListInside(List<List<num>>)returnsList<bool>getList_IsListOfPointInside(List<Point<num>>)returnsList<bool>
Check if all given Points are inside given Polygon
areAllPointsInsidePolygon_List((List<List<num>>)returnstrueorfalseareAllPointsInsidePolygon_ListPoint(List<Point<num>>)returnstrueorfalse
Exceptions #
NeedsAtLeastThreePointsis thrown ifPolygon.pointscontains less than 3 pointsWrongSizeForPointis thrown iftoPoint()has more or less than 2 element. Point has only x and y._TypeErroris thrown ifList<dynamic>is passed instead ofList<num>- Here, casting can be used to cast
List<dynamic>toList<num> - e.g.
print(toPoint([1,2]));- Here, [1,2] has a type
List<dynamic> - So, use
[1,2].cast<num>()
- Here, [1,2] has a type
- Here, casting can be used to cast
_CastError example- castingList<num>toList<List<num>
CSV #
IsInsideResultWithXY_ToCSVString
- Returns result of
ArePointsInsideas CSV String which can be later saved or displayed - Output CSV String will by default contain a header row -
latitude,longitude,isInside - Optional parameter:
bool useXY- By passing, optional parameter:
useXYas true, header will bex,yinstead oflatitude,longitude - Default value of
useXYisfalse
- By passing, optional parameter:
- Optional parameter:
String includeHeader- if optional parameter -
includeHeaderis passed asfalse, returning String will not contain header row
- if optional parameter -
- Optional Named parameter:
String diffNameThanIsInside- Different name than Default name(
isInside) will be used by passing optional parameter:diffNameThanIsInside
- Different name than Default name(
toCSVString
- Returns
Polygonas CSV String which can be later saved or displayed - Output CSV String will by default contain a header row -
latitude,longitude - Optional Named parameter:
bool useXY- By passing, optional parameter:
useXYas true, header will bex,yinstead oflatitude,longitude - Default value of
useXYisfalse
- By passing, optional parameter:
- Optional Named parameter:
String includeHeader- if optional parameter -
includeHeaderis is passed asfalse, returning String will not contain header row
- if optional parameter -
csvToListOfList
- Returns
Future<List<List>>based oncsvString- which then can be used - convert that list into
Polygon
- which then can be used - convert that list into
- Optional parameter:
bool noHeader- By passing optional parameter:
noHeaderastrue, Resulting List will not contain header row - Default value
false
- By passing optional parameter:
csvToPoly
- Returns
Future<Polygon>based oncsvString csvStringmay or may not contain header row- This function checks if
latitude,longitudeorx,yare reversed- By checking Header row label
- i.e. By checking 1st row 1st element is neither "longitude" or "y"
- If they are reversed, Returned
Polygonwill bePolygon(latitude,longitude), instead ofPolygon(longitude,latitude) - This can be manually set by passing optional parameter:
isReversedastrue
- Optional parameter:
isReversedisReversedhas default value =false
Features and bugs #
Please file feature requests and bugs at the issue tracker.
Licence #
Implemented contains function logic from StageXL - A fast and universal 2D rendering engine for HTML5 and Dart
As, StageXL imports dart:html, it can not be used in console application or in aqueduct back-end.
Created from templates made available by Stagehand under a BSD-style license.