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 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.
-
@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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login