2d-polygon-self-intersections

中文文档
1.3.1发布于 2015/05/28MITCommonJS近 30 天下载 1万

This library may not be fast, but it is robust. Robust in the fact that it will find all of the self-intersections in a polygon - minus of course shared endpoints.

原始使用文档
文档目录4 节
  1. install
  2. use
  3. api
  4. license

2d-polygon-self-intersections

find self-intersections in a 2d polygon

This library may not be fast, but it is robust. Robust in the fact that it will find all of the self-intersections in a polygon - minus of course shared endpoints.

You can expect a time complexity of O(n^2)

Why wouldn't we use Bentley–Ottmann? We may in the future, but that is going to take some time and having a functional mechanism for detecting self-intersections is far superior to a non-existant one. The api won't have to change for this to happen.

install

npm install 2d-polygon-self-intersections

use

var isects = require('2d-polygon-self-intersections');

var poly = [
  [0, 0],
  [10, 0],
  [0, 10],
  [10, 10]
];

var r = isects(poly);
console.log(r);
// outputs: [ [ 5, 5 ] ]

api

isects(polygon[, filterFn])

  • polygon - an array of 2 component arrays (i.e. a triangle [[0, 0], [10, 0], [10, 10]]) or an array of objects: [{x:0, y:0}, {x:10, y:0}, {x:10, y:10}]
  • filterFn - a filter function called whenever an intersection is found: filterFn(isect, start0, end0, start1, end1, unique)
  • isect - current intersection (e.g. [5, 5]) - mutations in this array get collected
  • index0 - index of the segment (e.g 1)
  • start0 - start of the first segment (e.g [0, 5])
  • end0 - start of the first segment (e.g [10, 5])
  • index0 - index of the segment (e.g 3)
  • start1 - start of the first segment (e.g [5, 0])
  • end1 - start of the first segment (e.g [5, 10])
  • unique - boolean representing whether or not this intersection point has been seen before
  • return true to collect and false to discard

returns an empty array if no interesections or an array of 2 component arrays representing the intersection points.

NOTE: this library assumes the polygon is closed, so manually adding the start point as the end point has no effect.

Also note that there are 2 intersections per crossing, this library by default will only report one - all intersections will be unique. This behavior can be changed with the filterFn.

license

MIT

版本与发布记录

2d-polygon-self-intersections 共发布 9 个版本,首次发布于 2015/05/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.3.1latest2015/05/2811 年前
1.2.22015/05/2411 年前
1.2.12015/05/2311 年前
1.3.02015/05/2311 年前
1.2.02015/05/2311 年前
1.1.22015/05/2011 年前

关于 2d-polygon-self-intersections 的常见问题

2d-polygon-self-intersections 是什么?

This library may not be fast, but it is robust. Robust in the fact that it will find all of the self-intersections in a polygon - minus of course shared endpoints.

如何安装 2d-polygon-self-intersections?

在项目目录运行 npm install 2d-polygon-self-intersections,或使用 pnpm add / yarn add / bun add。

2d-polygon-self-intersections 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/2d-polygon-self-intersections 是否存在。

2d-polygon-self-intersections 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

2d-polygon-self-intersections 可以商用吗?

2d-polygon-self-intersections 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

2d-polygon-self-intersections 的下载量有多少?

根据 npm 官方下载统计,2d-polygon-self-intersections 在 2026/10/04 – 2026/11/02 这 30 天内被下载 10,327 次,日均约 344 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

2d-polygon-self-intersections 还在维护吗?

最新版本 1.3.1 发布于 2015/05/28(11 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/05/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。