gpt4 book ai didi

javascript - Clipper.js 不适用于坐标集

转载 作者:行者123 更新时间:2023-11-30 20:40:47 25 4
gpt4 key购买 nike

我正在尝试调整 clipper.js 库中的“简化多边形”功能。我不确定我是否理解以下脚本有什么问题:

   var five_pointed_star = [{
"X": 114.11152626295,
"Y": 22.213863709855
}, {
"X": 114.11262775355,
"Y": 22.214272283475
}, {
"X": 114.1133008867,
"Y": 22.214885143905
}, {
"X": 114.1133008867,
"Y": 22.21619257949
}, {
"X": 114.11164865079,
"Y": 22.216233436852
}, {
"X": 114.11152626295,
"Y": 22.213863709855
}];

var ten_pointed_star = ClipperLib.Clipper.SimplifyPolygon(five_pointed_star, ClipperLib.PolyFillType.pftNonZero);
console.log(ten_pointed_star);

但是,如果我将 five_pointed_star 更改为以下代码,代码将按预期工作:

var five_pointed_star = [{
"X": 147,
"Y": 313
}, {
"X": 247,
"Y": 34
}, {
"X": 338,
"Y": 312
}, {
"X": 86,
"Y": 123
}, {
"X": 404,
"Y": 124
}];

知道我做错了什么吗?

最佳答案

多边形使用路径作为参数,路径在文档中有如下定义:

This structure contains a sequence of IntPoint vertices defining a single contour (see also terminology). Paths may be open and represent a series of line segments bounded by 2 or more vertices, or they may be closed and represent polygons. Whether or not a path is open depends on context. Closed paths may be 'outer' contours or 'hole' contours. Which they are depends on orientation.

IntPoint 读取:

The IntPoint structure is used to represent all vertices in the Clipper Library.

所以这意味着您需要提供的数字必须是整数 - 而您尝试使用 float 或简称为 float 。所以如果你使用整数它应该总是工作正常,如果你的计算返回 float ,你可以使用像floor()这样的舍入方法去掉点后的值。

关于javascript - Clipper.js 不适用于坐标集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49293934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com