You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ave a HTML project that uses Clipper1, I randomly generate two polygons at one coordinate and then take the difference set between these two polygons. However, I found that the results of Clipper1 xor sometimes differ and cannot return the difference set correctly, which makes me very distressed. I don't know if Clipper2 will still have this problem.
`function coordsXOR (subjCoords, clipCoords) {
var subj = _coordsToPoints(subjCoords);
var clip = _coordsToPoints(clipCoords);
var solution = ClipperLib.Paths();
var cpr = new ClipperLib.Clipper();
for (var s = 0, slen = subj.length; s < slen; s++) {
cpr.AddPaths(subj[s], ClipperLib.PolyType.ptSubject, true);
}
for (var c = 0, clen = clip.length; c < clen; c++) {
cpr.AddPaths(clip[c], ClipperLib.PolyType.ptClip, true);
}
cpr.Execute(ClipperLib.ClipType.ctXor, solution, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero);
let res = _pointsToCoords([solution], true)
// console.log(res);
return res
}
function _coordsToPoints (polygons, latlng) {
var points = [], amp = _pointAmplifier();
for (var i = 0, ilen = polygons.length; i < ilen; i++) {
points.push([]);
for (var j = 0, jlen = polygons[i].length; j < jlen; j++) {
var coords = polygons[i][j];
points[i].push([]);
for (var k = 0, klen = coords.length; k < klen; k++) {
var coord = coords[k];
if (Array.isArray(coord)) {
if (latlng) {
points[i][j].push({ X: Math.round(coord[1] * amp), Y: Math.round(coord[0] * amp) });
} else {
points[i][j].push({ X: Math.round(coord[0] * amp), Y: Math.round(coord[1] * amp) });
}
} else {
points[i][j].push({ X: Math.round(coord.lng * amp), Y: Math.round(coord.lat * amp) });
}
}
}
}
return points;
}
function _pointsToCoords (polygons, latlng) {
var coords = [], amp = _pointAmplifier();
for (var i = 0, ilen = polygons.length; i < ilen; i++) {
coords.push([]);
for (var j = 0, jlen = polygons[i].length; j < jlen; j++) {
var points = polygons[i][j];
coords[i].push([]);
for (var k = 0, klen = points.length; k < klen; k++) {
var point = points[k];
if (latlng) {
coords[i][j].push([point.Y / amp, point.X / amp]);
} else {
coords[i][j].push([point.X / amp, point.Y / amp]);
}
}
}
}
return coords;
}
function _pointAmplifier () {
return Math.pow(10, 13);
}`
This is my method, which involves passing two polygons generated using latitude and longitude to coordsXOR, and then calculating the difference set
This discussion was converted from issue #888 on September 21, 2024 02:28.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
ave a HTML project that uses Clipper1, I randomly generate two polygons at one coordinate and then take the difference set between these two polygons. However, I found that the results of Clipper1 xor sometimes differ and cannot return the difference set correctly, which makes me very distressed. I don't know if Clipper2 will still have this problem.
`function coordsXOR (subjCoords, clipCoords) {
}
function _coordsToPoints (polygons, latlng) {
var points = [], amp = _pointAmplifier();
}
function _pointsToCoords (polygons, latlng) {
var coords = [], amp = _pointAmplifier();
}
function _pointAmplifier () {
return Math.pow(10, 13);
}`
This is my method, which involves passing two polygons generated using latitude and longitude to coordsXOR, and then calculating the difference set
Beta Was this translation helpful? Give feedback.
All reactions