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

패키지 상세v0.0.4

sweepline_intersections

다각형과/또는 다선을 교차 검사하는 데 사용되는 스위프라인 알고리즘을 사용하는 작고 빠른 모듈입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
16.2만
좋아요
7
Pub 점수
150

패키지 설치

flutter pub add sweepline_intersections

패키지 개요

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

다각형과 다선을 효율적으로 교차 검사하는 스위플라인 알고리즘을 사용하는 가볍고 고성능의 Dart 패키지입니다. 2차원 공간에서의 기하 계산을 위해 설계되었으며, 실시간 또는 복잡한 형태의 배치 처리가 필요한 응용 프로그램에 적합한 빠른 교차 검출을 제공합니다. 플랫폼 독립적이며 모든 주요 플러터 플랫폼을 지원합니다. 정확성과 속도에 최적화되어 있어 지리정보시스템(GIS), CAD 및 시각화 도구에 적합합니다.

사용 사례

  • 실시간 다각형 충돌 감지
  • GIS 공간 분석
  • CAD 도면 검증
  • 인터랙티브 지도 기능
  • 렌더링을 위한 기하학 전처리
  • 게임에서의 충돌 감지

주요 기능

  • 고속 교차 검출
  • 스위프라인 알고리즘 구현
  • 다각형과 다각선을 지원합니다
  • 크로스 플랫폼 호환성
  • 최소 메모리 사용량
  • 정확한 기하학적 결과

적합한 대상

  • 인터랙티브 지도를 구축하는 개발자
  • 기하학적 형상 분석이 필요한 응용 프로그램
  • CAD 또는 디자인 소프트웨어용 도구
  • 복잡한 충돌 시스템을 갖춘 게임
  • 성능 중심의 기하 연산

고려 사항

  • 2차원 기하학에 가장 적합
  • 정확한 결과를 얻으려면 올바르게 닫힌 다각형이 필요합니다
  • 배치 처리 없이 초대규모 데이터 세트에 최적화되지 않음
  • 선분 및 다각형의 교차에 한정

원본 README

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

Ported from: rowanwins/sweepline-intersections

sweepline-intersections

A small and fast module using a sweepline algorithm to detect intersections between polygons and/or polylines.

Documentation

Install
dart pub add sweepline_intersections
Basic Use

Valid inputs: Geojson Feature or Geometry including Polygon, LineString, MultiPolygon, MultiLineString, as well as FeatureCollection.

Returns a List of intersection Points eg, [Point(coordinates:Position(lng:x1, lat:y1)), Point(coordinates:Position(lng:x2, lat:y2)]

    var box = Feature(geometry: Polygon(coordinates: [[Position.of([0, 0]), Position.of([1, 0]), Position.of([1, 1]), Position.of([0, 1]), Position.of([0, 0])]]));
    var intersections = sweeplineIntersections(box);
    // returns a List of self-intersection Points

Also accepts an optional boolean argument second which when set to true means the module won't detect self-intersections and will only report intersections between different features. This defaults to false. eg

    var intersectionsBetweenFeature = sweeplineIntersections(featureCollection, true);
    // returns a List of intersection Points between Features
Complex Use

This library also provide a class-based approach which is helpful if you want to check multiple geometries against a single geometry. This allows you to save the state of the initial event queue with the primary geometry.

    import 'package:sweepline_intersections/sweepline_intersections.dart';
    main(){
    // create the base instance
    var sl = SweeplineIntersections();
    sl.addData(aGeom);
    // clone the event queue in the original state so you can reuse it
    var origQueue = sl.cloneEventQueue();
    List<Position> positions = [
    Position.of([21.93869948387146, 49.99897434944081]),
    Position.of([21.93869948387100, 49.99897434944032]),
    ];
    var f = FeatureCollection(
    features: [
      Feature(
        geometry: LineString(coordinates: positions),
      ),
    ],
    );    // now you can iterate through some other set of features saving
    // the overhead of having to populate the complete queue multiple times
    for (var feature in f.features) {
    // add another feature to test against your original data
    sl.addData(feature, alternateEventQueue: origQueue);
    // check if those two features intersect
    // add an optional boolean argument to ignore self-intersections
    }
    var intersectionPoints = sl.getIntersections(true);
    }
API

SweeplineIntersectionsClass() - creates a new instance

.addData(geojson, existingQueue) - adds geojson to the event queue. The second argument for an existingQueue is optional, and takes a queue generated from .cloneEventQueue()

.cloneEventQueue() - clones the state of the existing event queue that's been populated with geojson. Returns a queue that you can pass to the addData method

.getIntersections(ignoreSelfIntersections) - Checks for segment intersections. Accepts an optional boolean argument to ignore self intersections are only report intersections between features.

Contributing

Algorithm notes

The basic concept of this algorithm is based on a sweepline. Where this algorithm differs from the bentley-ottmann algorithm is that there is no use of a tree data structure to store the segments. The reason for the modification is because if you are dealing with polygons or polylines (rather than a random group of line segments) there is a reasonable assumption that there are going to be very few segments that lie on the same x plane.

Removing the tree structure greatly simplifies the code. The tree structure is replaced with a priority queue of segments which is sorted by the x vertex of the right endpoint of the segments. A priority queue is already used to sort the vertices which means only 1 data structure is required.

Algorithm Steps
  • Vertices are entered into a priority queue sorted from left to right
  • An empty priority queue is created to store segments encountered
  • An item is removed from the priority queue
    • If the vertex is the left endpoint of a segment, we test it against every other segment in the segment queue for intersections with any intersection recorded. We then add the vertex (and it's associated right endpoint) to the segment queue.
    • When we encounter a right endpoint we remove the first item from the segment queue.

Each pair of segments are only tested once. And only segments that overlap on the x plane are tested against each other.

카테고리

의존성

의존성 목록 4 개

소스 저장소

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