node/lib/metasm/metasm/gui/dasm_graph.rb
def auto_arrange_vertical_shrink
		# vertical shrink
		# TODO stuff may shrink vertically more if we could move it slightly horizontally...
		@box.sort_by { |b| b.y }.each { |b|

			next if b.from.empty?
			# move box up to its from, unless something blocks the way

			min_y = b.from.map { |bb|
					bb.y+bb.h
				}.find_all { |by|
					by <= b.y
				}.max

			moo = []
			moo << 8*b.from.length
			moo << 8*b.from[0].to.length
			cx = b.x+b.w/2
			moo << b.from.map { |bb| (cx - (bb.x+bb.w/2)).abs }.max / 10
			cx = b.from[0].x+b.from[0].w/2
			moo << b.from[0].to.map { |bb| (cx - (bb.x+bb.w/2)).abs }.max / 10
			margin_y = 16 + moo.max

			next if not min_y or b.y <= min_y + margin_y

			blocking = @box.find_all { |bb|
					next if bb == b
					bb.y+bb.h > min_y and bb.y+bb.h < b.y and
					bb.x-12 < b.x+b.w and bb.x+bb.w+12 > b.x
				}

			may_y = blocking.map { |bb| bb.y+bb.h } << min_y

			do_y = may_y.sort.map { |by| by + margin_y }.find { |by|
				# should not collision with b if moved to by+margin_y
				not blocking.find { |bb|
					bb.x-12 < b.x+b.w and bb.x+bb.w+12 > b.x and
					bb.y-12 < by+b.h and bb.y+bb.h+12 > by
				}
			}

			b.y = do_y if do_y < b.y

			# no need to re-sort outer loop
		}

		# TODO
		# energy-minimal positionning of boxes from this basic layout
		# avoid arrow confusions
	end
# one box, has a text, an id, and a list of other boxes to/from
one box, has a text, an id, and a list of other boxes to/from
one box has a text an id and a list of other boxes to / from
def auto_arrange_vertical_shrink
		@box.sort_by { |b| b.y }.each { |b|
			next if b.from.empty?
			min_y = b.from.map { |bb|
					bb.y+bb.h
				}.find_all { |by|
					by <= b.y
				}.max
			moo = []
			moo << 8*b.from.length
			moo << 8*b.from[0].to.length
			cx = b.x+b.w/2
			moo << b.from.map { |bb| (cx - (bb.x+bb.w/2)).abs }.max / 10
			cx = b.from[0].x+b.from[0].w/2
			moo << b.from[0].to.map { |bb| (cx - (bb.x+bb.w/2)).abs }.max / 10
			margin_y = 16 + moo.max
			next if not min_y or b.y <= min_y + margin_y
			blocking = @box.find_all { |bb|
					next if bb == b
					bb.y+bb.h > min_y and bb.y+bb.h < b.y and
					bb.x-12 < b.x+b.w and bb.x+bb.w+12 > b.x
				}
			may_y = blocking.map { |bb| bb.y+bb.h } << min_y
			do_y = may_y.sort.map { |by| by + margin_y }.find { |by|
				not blocking.find { |bb|
					bb.x-12 < b.x+b.w and bb.x+bb.w+12 > b.x and
					bb.y-12 < by+b.h and bb.y+bb.h+12 > by
				}
			}
			b.y = do_y if do_y < b.y
		}
	end
def auto_arrange_vertical_shrink @box . sort_by { | b | b . y } . each { | b | next if b . from . empty? min_y = b . from . map { | bb | bb . y + bb . h } . find_all { | by | by <= b . y } . max moo = [ ] moo << 8 * b . from . length moo << 8 * b . from [ 0 ] . to . length cx = b . x + b . w / 2 moo << b . from . map { | bb | ( cx - ( bb . x + bb . w / 2 ) ) . abs } . max / 10 cx = b . from [ 0 ] . x + b . from [ 0 ] . w / 2 moo << b . from [ 0 ] . to . map { | bb | ( cx - ( bb . x + bb . w / 2 ) ) . abs } . max / 10 margin_y = 16 + moo . max next if not min_y or b . y <= min_y + margin_y blocking = @box . find_all { | bb | next if bb == b bb . y + bb . h > min_y and bb . y + bb . h < b . y and bb . x - 12 < b . x + b . w and bb . x + bb . w + 12 > b . x } may_y = blocking . map { | bb | bb . y + bb . h } << min_y do_y = may_y . sort . map { | by | by + margin_y } . find { | by | not blocking . find { | bb | bb . x - 12 < b . x + b . w and bb . x + bb . w + 12 > b . x and bb . y - 12 < by + b . h and bb . y + bb . h + 12 > by } } b . y = do_y if do_y < b . y } end
one box, has a text, an id, and a list of other boxes to/from
one box has a text an id and a list of other boxes to / from
# vertical shrink # TODO stuff may shrink vertically more if we could move it slightly horizontally... # move box up to its from, unless something blocks the way # should not collision with b if moved to by+margin_y # no need to re-sort outer loop # TODO # energy-minimal positionning of boxes from this basic layout # avoid arrow confusions