MIT License

项目介绍

mfogel/polygon-clipping 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 MIT License 许可证,目前获得 642 个 Star、66 次 Fork。

仓库全名
mfogel/polygon-clipping
开源许可证
MIT License
Star 数
642
Fork 数
66
未关闭 Issue
45

README 摘要

polygon-clipping Apply boolean Polygon clipping operations (intersection, union, difference, xor) to your Polygons & MultiPolygons. Quickstart API Input Each positional argument ( ) may be either a Polygon or a MultiPolygon. The GeoJSON spec is followed, with the following notes/modifications: MultiPolygons may contain touching or overlapping Polygons. rings are not required to be self-closing. rings may contain…

完整内容见 GitHub 原始 README 或本页 。

常见问题

polygon-clipping 用什么语言开发?

主要使用 JavaScript 编写,采用 MIT License 许可证,目前有 642 个 Star。

polygon-clipping 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 polygon-clipping 的源码?

可以直接克隆仓库:git clone https://github.com/mfogel/polygon-clipping.git,默认分支为 main;安装与运行步骤见仓库 README。

polygon-clipping 最近还在维护吗?

仓库最近一次更新为 2024年4月19日,当前有 45 个未关闭 Issue;Star 数为 642,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Apply boolean polygon clipping operations (union, intersection, difference, xor) to your Polygons & MultiPolygons.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
785
价值分
403
活跃状态
活跃

语言占比

JavaScript

README

polygon-clipping

Apply boolean Polygon clipping operations (intersection, union, difference, xor) to your Polygons & MultiPolygons.

CI codecov License: MIT npm

Quickstart

const polygonClipping = require('polygon-clipping')

const poly1 = [[[0,0],[2,0],[0,2],[0,0]]]
const poly2 = [[[-1,0],[1,0],[0,1],[-1,0]]]

polygonClipping.union       (poly1, poly2 /* , poly3, ... */)
polygonClipping.intersection(poly1, poly2 /* , poly3, ... */)
polygonClipping.xor         (poly1, poly2 /* , poly3, ... */)
polygonClipping.difference  (poly1, poly2 /* , poly3, ... */)

API

/* All functions take one or more [multi]polygon(s) as input */

polygonClipping.union       (<geom>, ...<geoms>)
polygonClipping.intersection(<geom>, ...<geoms>)
polygonClipping.xor         (<geom>, ...<geoms>)

/* The clipGeoms will be subtracted from the subjectGeom */
polygonClipping.difference(<subjectGeom>, ...<clipGeoms>)

Input

Each positional argument (<geom>) may be either a Polygon or a MultiPolygon. The GeoJSON spec is followed, with the following notes/modifications:

  • MultiPolygons may contain touching or overlapping Polygons.
  • rings are not required to be self-closing.
  • rings may contain repeated points, which are ignored.
  • rings may be self-touching and/or self-crossing. Self-crossing rings will be interpreted using the non-zero rule.
  • winding order of rings does not matter.
  • inner rings may extend outside their outer ring. The portion of inner rings outside their outer ring is dropped.
  • inner rings may touch or overlap each other.

Output

For non-empty results, output will always be a MultiPolygon containing one or more non-overlapping, non-edge-sharing Polygons. The GeoJSON spec is followed, with the following notes/modifications:

  • outer rings will be wound counter-clockwise, and inner rings clockwise.
  • inner rings will not extend outside their outer ring.
  • rings will not overlap, nor share an edge with each other.
  • rings will be self-closing.
  • rings will not contain repeated points.
  • rings will not contain superfluous points (intermediate points along a straight line).
  • rings will not be self-touching nor self-crossing.
  • rings may touch each other, but may not cross each other.

In the event that the result of the operation is the empty set, output will be a MultiPolygon with no Polygons: [].

Correctness

Run: npm test

The tests are broken up into unit tests and end-to-end tests. The end-to-end tests are organized as GeoJSON files, to make them easy to visualize thanks to GitHub’s helpful rendering of GeoJSON files. Browse those tests here.

Performance

The Martinez-Rueda-Feito polygon clipping algorithm is used to compute the result in O((n+k)*log(n)) time, where n is the total number of edges in all polygons involved and k is the number of intersections between edges.

Settings

Global settings are set via environment variables.

  • POLYGON_CLIPPING_MAX_QUEUE_SIZE and POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS: Aims to prevent infinite loops - usually caused by floating-point math round-off errors. Defaults are 1,000,000.

Changelog

This project adheres to Semantic Versioning.

The full changelog is available at CHANGELOG.md.

Authors

Sponsors

Please contact Mike Fogel if you or your company is interested in sponsoring work on specific bug fixes or feature requests.

Based on

评论

暂无评论