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

GitHub 저장소dartclub/turf_pip

turf_pip

점이 다각형 내부에 있는지 감지하는 작은 라이브러리입니다.

turf_pip 프로젝트 이미지
스타
3
포크
2
최근 푸시(UTC)
2024. 12. 30.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

turf_pip

A small library for detecting if a point lies inside a polygon.

A port of: point-in-polygon-hao NPM package.

Point in polygon library based on the paper "Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons" by Hao.

Features

  • Works on polygons with holes
  • Works with degenerate/self-intersecting polyons
  • Returns PointInPolygonResult.isOnEdge if on the edge, PointInPolygonResult.isInside if inside and PointInPolygonResult.isOutside if outside
  • Not effected by floating point errors
Usage

Install via dart pub add turf_pip

import 'package:turf_pip/turf_pip.dart';

const polygon = Polygon(coordinates:[
  [
    Position.of([1, 1]),
    Position.of([1, 2]),
    Position.of([2, 2]),
    Position.of([2, 1]),
    Position.of([1, 1])
  ]
]);

pointInPolygon(Point(coordinates: Position.of([ 1.5, 1.5 ]), polygon)
// => PointInPolygonResult.isInside

pointInPolygon(Point(coordinates: Position.of([ 4.9, 1.2 ]), polygon)
// => PointInPolygonResult.isOutside

pointInPolygon(Point(coordinates: Position.of([1, 2]), polygon)
// => PointInPolygonResult.isOnEdge

Note: The input polygon format aligns with the GeoJson specification for polygons. This means that the first and last coordinate in a polygon must be repeated, if not this library will throw an error.

var polygonWithHole = Polygon(coordinates:([
  [
    Position.of([0, 0]),
    Position.of([1, 0]),
    Position.of([1, 1]),
    Position.of([0, 1]),
    Position.of([0, 0]),
  ],
  [
    Position.of([0.1, 0.1]),
    Position.of([0.1, 0.9]),
    Position.of([0.9, 0.9]),
    Position.of([0.9, 0.1]),
    Position.of([0.1, 0.1]),
  ]
]);

The library does not support multi-polygons.

Comparisons

Some rough comparisons to similar libraries. While point-in-polygon is slightly faster in most cases it does not support polygons with holes or degenerate polygons.

// For a point in a much larger geometry (700+ vertices)
point-in-poly-hao x 474,180 ops/sec ±0.55% (93 runs sampled)
point-in-polygon x 489,649 ops/sec ±0.75% (91 runs sampled)
robust-point-in-polygon x 376,268 ops/sec ±0.79% (89 runs sampled)
// For a point in bounding box check
point-in-poly-hao x 29,365,704 ops/sec ±1.30% (90 runs sampled)
point-in-polygon x 42,339,450 ops/sec ±0.78% (95 runs sampled)
robust-point-in-polygon x 20,675,569 ops/sec ±0.65% (95 runs sampled)
Algorithm

This library is based on the paper Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons

Other notes
  • Works irrespective of winding order of polygon
  • Does not appear to be effected by floating point errors compared to point-in-polygon or robust-point-in-polygon
Dart Club GitHub avatar
GitHub 작성자

Dart Club ↗

Dart Language rocks! Flutter too btw. – Dart Club ~ Established 2018 –

Germany
언어Dart

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 7 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗