Handling winded polygons with modified poin-in-polygon test
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
调研方向
检查 pointToPolygonDist 的 JavaScript 实现,并将其 point-in-polygon 测试与 issue 中展示的 winding-number 版本进行比较。复现链接图片中报告的 winded-polygon 情况;当 polylabel 选择内部点而不是重复的 boundary,并且 repository 的相关测试中包含回归覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
In my case of applying polylabel code, I've found some strange spaces on floor plan imported from some external CAD software, which occurred to wind themselves around its boundary. I detected this by splitting duplicated vertices apart, as below.

Original algorithm regarded all points inside visible contour as laying "outside", and "interior" point has been calculated as somewhere on duplicated boundary edge.
To cover such case, I had to modify test if point lies inside polygon by checking its winding number algorithm.
I don't want to cover it in formal pull request, so below is the part of modified code with core taken from well-known geometry algorithms:
// signed distance from point to polygon outline (negative if point is outside)
// redesigned using winding number algorithm for point inside polygon test
// http://geomalgorithms.com/a03-_inclusion.html#wn_PnPoly()
function pointToPolygonDist(x, y, polygon) {
var wn = 0;
var minDistSq = Infinity;
for (var k = 0; k < 1; k++) {
var ring = polygon[k];
for (var i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
var a = ring[i];
var b = ring[j];
var xi = a[0], yi = a[1];
var xj = b[0], yj = b[1];
if (yj <= y) {
if (yi > y) {
if (isLeft([xj, yj], [xi, yi], [x,y]) > 0) {
wn++;
}
}
} else {
if (yi <= y) {
if (isLeft([xj, yj], [xi, yi], [x, y]) < 0) {
wn--;
}
}
}
minDistSq = Math.min(minDistSq, getSegDistSq(x, y, a, b));
}
}
return minDistSq === 0 ? 0 : (wn != 0 ? 1 : -1) * Math.sqrt(minDistSq);
}
function isLeft(P0, P1, P2)
{
var res = ( (P1[0] - P0[0]) * (P2[1] - P0[1])
- (P2[0] - P0[0]) * (P1[1] - P0[1]) );
return res;
}
- 主要语言
- JavaScript
- 星标
- 1.6k
- 派生
- 163
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mapbox/polylabel 的其他 Issue
-
bug
难度 3/5 1-2 天 新手友好度 55/100
-
question
难度 3/5 1-2 天 新手友好度 20/100
-
bug
难度 4/5 3-5 天 新手友好度 38/100
-
question
难度 2/5 1-3 小时 新手友好度 48/100
-
MultiPolygon未关闭question
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 76/100
melodic-software/claude-code-plugins#9619 ·
维护者通常 1 天内回复
-
bug Frontend P2-medium UI UX
难度 1/5 1 小时以内 新手友好度 76/100
Deepak3699/Ai_Mentor#427 ·
维护者通常 1 天内回复
-
area: core
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
venn: a name that starts with set-, union-, text- or style- followed by a letter is a parse error未关闭
难度 2/5 1-3 小时 新手友好度 82/100
obsidianmd/pele#65 ·
维护者通常 3 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
11ty/buildawesome#4407 · 1 个 reaction ·
维护者通常 1 天内回复