Unfolder V2, test on Ubuntu with Chromium
-
Hello, I'm testing the Unfolder. I'm starting with Chromium on Ubuntu. It works and the 2d output exports as svg, but it doesn't perform the last step that packs small pieces to reduce page count, and there's no error. To pack those pieces, I use align() and measureAggregateBoundingBox().
function aggregatePieces (P) {// join small pieces function minX (a, b) { return a.x > b.x } function minY (a, b) { return a.y > b.y } const align_centerXY = ['center','center','none'] var r = [] for (var i = 0, l = P.length; i < l; i++) { // measure pieces var b = measureAggregateBoundingBox(P[i]) r.push({d:align({modes:align_centerXY, grouped:true}, P[i]), x: b[1][0] - b[0][0], y: b[1][1] - b[0][1]}) } if (r.length > 1) { var ok = true do { // try to group smallest X pieces r.sort(minX) if (r[1] !== undefined) { if ((r[0].x + r[1].x) < V.frame[0]) { r[0].d.push(translateX((r[0].x + r[1].x) / 2, r[1].d)) r[0].d = align({modes:align_centerXY, grouped:true}, r[0].d) var b = measureGroup(r[0].d) r[0].x = b[0] r[0].y = b[1] r[1].d = null r.splice(1, 1) } else { ok = false } } else ok = false } while (ok) var ok = true do { // try to group smallest Y pieces r.sort(minY) if (r[1] !== undefined) { if ((r[0].y + r[1].y) < V.frame[1]) { r[0].d.push(translateY((r[0].y + r[1].y) / 2, r[1].d)) r[0].d = align({modes:align_centerXY, grouped:true}, r[0].d) var b = measureGroup(r[0].d) r[0].x = b[0] r[0].y = b[1] r[1].d = null r.splice(1, 1) } else { ok = false } } else ok = false } while (ok) } return r }
-
@gilboonet yes, specification for sort functions is to
- return zero if a==b
- return neg or positive number depending if u want to sort ASC or DESC
-
@gilboonet I tried Chrome and it does the same. After some investigations I found what was wrong, it was my sort functions : return a.x > b.x that needed to be changed to return a.x - b.x.