패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.7+2

poly

지정된 점이 다각형 내부에 있는지 확인하기 위한 라이브러리입니다.

30일 다운로드
12
좋아요
29
Pub 점수
30

패키지 설치

flutter pub add poly

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Poly는 하나 이상의 점이 다각형 내부에 있는지 여부를 판단하기 위해 설계된 Dart 라이브러리입니다. 공간 데이터 분석, 지도 애플리케이션 및 인터랙티브 그래픽에서 유용한 점-다각형 테스트를 위한 효율적인 기하학적 계산을 제공합니다. 이 라이브러리는 구멍이 있는 복잡한 다각형을 포함하여 단순하고 복잡한 다각형 모두를 지원합니다. 가볍고 Flutter 패키지 매니저를 통해 쉽게 통합할 수 있으며, 실시간 공간 쿼리가 필요한 앱에 적합합니다. 소스 코드는 GitHub에 공개되어 있어 투명성과 사용자 맞춤화를 보장합니다.

사용 사례

  • 지리공간 응용 프로그램
  • 인터랙티브 지도 기능
  • 게임 개발
  • 충돌 감지
  • 데이터 시각화

주요 기능

  • 점-다각형 테스트
  • 복잡한 다각형 지원
  • 경량이고 빠름
  • Flutter와의 간편한 통합
  • GitHub에서 오픈소스

적합한 대상

  • 지도를 사용하는 Flutter 개발자
  • 공간 논리를 필요로 하는 응용 프로그램
  • 충돌 감지 기능이 있는 게임
  • 지리 데이터 처리 도구

고려 사항

  • 3D 다각형을 지원하지 않습니다
  • 내장된 다각형 생성 유틸리티 없음
  • 2차원 평면 기하학에 국한
  • 수동 다각형 정의 필요

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

poly

Pub build status License

A library for checking if given point(s) is present inside Polygon or not.

Contents

Installation

To install poly for your Dart project, simply add poly to your pub dependencies.

dependencies:
    poly^ 1.0.5

Examples

1. A very simple usage example
  1. Creates 2 Polygons from List<Point>
  2. Checks if 2 Polygon have same vertices i.e. points : using hasSamePoint()
  3. Prints if given Points are inside Polygon
  4. Prints if all points in list are inside Polygon or not
  5. 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> & other
  1. Example of toPoint() & pointToList()
    • toPoint() converts List<num> to Point<num>
    • pointToList() converts Point<num> to List<num>
  2. Example of toListOfPoint() & pointsToList()
    • toListOfPoint() converts List<List<num>> to List<Point<num>>
    • pointsToList() converts List<Point<num>> to List<List<num>>
  3. Example of toPolyFromListOfList() & listOfList()
    • toPolyFromListOfList() converts List<List<num>> to Polygon
    • listOfList() returns Polygon.points as List<List<num>>
    • toPolyFromListOfList() gives Polygon & backToListC2() gives back List<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
3. Examples of List<dynamic> => List<num> and List<List<dynamic>> => List<List<num>>
  • toListNum() returns List<num> from a List<dynamic>
  • toListListNum() returns List<List<num>> from a List<List<dynamic>>
  1. Examples of toListNum()
    • without any optional parameters
    • with replaceWithZero: true and sizeTwo: false
    • with sizeTwo: false
  2. Examples of toListListNum()
    • without any optional parameters
    • with swapXAndY: true
    • with replaceWithZero: true
    • with replaceWithZero: true and swapXAndY: true
4. Simple CSV example
  • It contains examples of following functions -
  1. Example of IsInsideResultWithXY_ToCSVString

    • Saving ArePointsInside Results to "IsInside.csv"
      • Headers row will be added, as includeHeader isnt passed as false`
      • And as diffNameThanIsInside:"Example String" is passed,
      • Header row will be latitude,longitude,Example String
  2. Example of toCSVString

    • Saving Polygon.points to "Polygon.csv"
      • Headers row will be added, as includeHeader isnt passed as false`
      • And as useXY is passed as true
      • Header row will be x,y
  3. Example of csvToResult

    • Display 1st row : 2nd element & 3rd element of "IsInside.csv"
      • e.g. here "longitude" and "Example String"
      • As, previously xY_IsInside_ToCSVString returned String with header
      • because optional parameter header was not set to false
  4. Example of csvToPoly

    • Check if Point(18.507305, 73.806131) is inside Polygon readPolygon (Polygon from Polygon.csv)
5. Exception Handling Example
  • It contains examples of following exceptions & errors -
  1. NeedsAtLeastThreePoints is thrown if Polygon.points contains less than 3 points
  2. WrongSizeForPoint is thrown if toPoint() has more or less than 2 element. Point has only x and y.
  3. TypeError is thrown if List<dynamic> is passed instead of List<num>
    • Here, casting can be used to cast List<dynamic> to List<num>
    • e.g. print(toPoint([1,2]));
      • Here, [1,2] has a type List<dynamic>
      • So, use [1,2].cast<num>()
  4. CastError example - wrongly casting List<num> to List<List<num>
6. Easy Casting Example
  • Without casting List<dynamic> to List<num> TypeErroris thrown
  1. Correct casting

    • casting List<dynamic> to List<num>
    • casting List<dynamic> to List<List<num>>
  2. Passing List instead of List<List>

  • Passing List instead of List<List> & casting it : throws CastError as shown below :

    type int is not a subtype of type List<num> in type cast

  • Passing List instead of List<List> but, without casting it : throws TypeError as shown below :

    type List<dynamic> is not a subtype of type List<List<num>>

  • Note: currently casting List<List<dynamic>> to List<List<num>> gives following CastError exception:
    • without as List<List<num>> -

    type List<dynamic> is not a subtype of type List<num> in type cast

    • with as List<List<num>> -

    type List<List<dynamic>> is not a subtype of type List<List<num>> in type cast

Note: Instead of casting, use toListNum() & toListListNum()

  • Use toListNum() for List<dynamic> => List<num>
  • Use toListListNum() forList<List<dynamic>> => List<List<num>>

Function List

Conversion Type
List<num> to Point(x,y) : use toPoint()
  • i.e. [x,y] -> Point(x,y)
  • Point can be created passing List<num> toPoint().
  • List must have exact 2 elements, else will throw WrongSizeForPoint exception
Point(x,y) to List<num> : use pointToList()
  • i.e. Point(x,y) -> [x,y]
  • List can be created passing Point(x,y) pointToList().
List<List<num>> to List<Point<num>> : use toListOfPoint()
  • 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 to toListOfPoint()
List<Point<num>> to List<List<num>> : use pointsToList()
  • i.e. [ Point(x1,y1), Point(x2,y2),... ] -> [ [x1,y1],[x2,y2],... ]
  • List can be created passing List<Point<num>> pointsToList().
List<List<num>> to Polygon : use toPolyFromListOfList()
  • i.e. [ [x1,y1],[x2,y2],... ] -> Polygon( Point(x1,y1), Point(x2,y2),... )
  • Polygon can be returned from List<List<num>> by passing it to toPolyFromListOfList()
List<List<num>> to Polygon : use listOfList()
  • i.e. [ [x1,y1],[x2,y2],... ] from Polygon( Point(x1,y1), Point(x2,y2),... )
  • List<List<num>> can be returned from Polygon by passing it to listOfList()
List<dynamic> to List<num> : use toListNum()
  • Returns List<num> from a List<dynamic>
  • Can be used with [toPoly] as it accepts List<num>
  • Optional Parameters -
    • sizeTwo
      • Default value true
      • When set false, Output List can have more than 2 elements
    • replaceWithZero
      • Default value false
      • When set true, elements with type String or bool will be replaced with 0, rather than being removed
    • reverseIt
      • Default value false
      • When set true, List will be reversed
List<List<dynamic>> to List<List<num>> : use toListListNum()
  • Returns List<List<num>> from a List<List<dynamic>>
  • Can be used with functions like [areAllPointsInsidePolygon_List] , [getList_IsListOfListInside] , [toPolyFromListOfList] , [toListOfPoint] which accepts List<List<num>>
  • Optional Parameters -
    • replaceWithZero
      • Default value false
      • When set true, elements with type String or bool will be replaced with 0, rather than being removed
    • swapXAndY
      • Default value false
      • When set true, xi will be swapped with yi
        • i.e. [ [x1,y1], [x2,y2], ...] -> [ [y1,x1], [y2,x2], ...]
is Point(s) inside
Check if Single Point is inside
Get Status by passing x and y to contains
  • returns true if (x,y) is present inside Polygon
Get Status by passing Point(x,y) to isPointInside
  • returns true if Point is present inside Polygon
Check if Single Point is inside Polygon with tolerance of T meter
Get Status by passing Point(x,y) and Tolerance T to isPointInside
Check if Multiple Points are inside given Polygon
Get Status of each Point
  • getList_IsListOfListInside(List<List<num>>) returns List<bool>
  • getList_IsListOfPointInside(List<Point<num>>) returns List<bool>
Check if all given Points are inside given Polygon
  • areAllPointsInsidePolygon_List((List<List<num>>) returns true or false
  • areAllPointsInsidePolygon_ListPoint(List<Point<num>>) returns true or false
Checks if 2 Polygon have same vertices i.e. points
  • use hasSamePoints()
CSV
Get result(s) along with lat, lang as a CSV String : IsInsideResultWithXY_ToCSVString()
  • Returns result of ArePointsInside as 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: useXY as true, header will be x,y instead of latitude,longitude
    • Default value of useXY is false
  • Optional parameter: String includeHeader
    • if optional parameter - includeHeader is passed as false, returning String will not contain header row
  • Optional Named parameter: String diffNameThanIsInside
    • Different name than Default name(isInside) will be used by passing optional parameter: diffNameThanIsInside
Get Polygon as CSV String : toCSVString()
  • Returns Polygon as 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: useXY as true, header will be x,y instead of latitude,longitude
    • Default value of useXY is false
  • Optional Named parameter: String includeHeader
    • if optional parameter - includeHeader is is passed as false, returning String will not contain header row
Get Futurebased oncsvString : csvToPoly()
  • Returns Future<Polygon> based on csvString
  • csvString may or may not contain header row
  • This function checks if latitude,longitude or x,y are reversed
    • By checking Header row label
    • i.e. By checking 1st row 1st element is neither "longitude" or "y"
    • If they are reversed, Returned Polygon will be Polygon(latitude,longitude), instead of Polygon(longitude,latitude)
    • This can be manually set by passing optional parameter: isReversed as true
  • Optional parameter: isReversed
    • isReversed has default value = false
csvToListOfList()
  • Returns Future<List<List>> based on csvString
    • which then can be used - convert that list into Polygon
  • Optional parameter: bool noHeader
    • By passing optional parameter: noHeader as true, Resulting List will not contain header row
    • Default value false
Exceptions
  1. NeedsAtLeastThreePoints is thrown if Polygon.points contains less than 3 points
  2. WrongSizeForPoint is thrown if toPoint() has more or less than 2 element. Point has only x and y.
  3. _TypeError is thrown if List<dynamic> is passed instead of List<num>
    • Here, casting can be used to cast List<dynamic> to List<num>
    • e.g. print(toPoint([1,2]));
      • Here, [1,2] has a type List<dynamic>
      • So, use [1,2].cast<num>()
  4. _CastError example - casting List<num> to List<List<num>
Index

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.

Also, function distanceInMeter is implemented by using formulas for Algorithm & it's NOAA online calculator

Created from templates made available by Stagehand under a BSD-style license.

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.