JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Unfolder V2, test on Ubuntu with Chromium

    Development Discussions
    2
    3
    289
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gilboonet
      gilboonet last edited by

      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
      }
      

      Capture d’écran de 2022-01-29 14-13-12.png

      gilboonet 1 Reply Last reply Reply Quote 0
      • hrgdavor
        hrgdavor @gilboonet last edited by

        @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
        1 Reply Last reply Reply Quote 0
        • gilboonet
          gilboonet @gilboonet last edited by gilboonet

          @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.

          hrgdavor 1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB | Contributors