// Generated by CoffeeScript 1.10.0 (function() { window.hept_tree_utils = { /* Returns an array with 7 object nodes */ get_children: function() { return [ { name: '', type: '', children: [] }, { name: '', type: '', children: [] }, { name: '', type: '', children: [] }, { name: '', type: '', children: [] }, { name: '', type: '', children: [] }, { name: '', type: '', children: [] }, { name: '', type: '', children: [] } ]; }, /* Given a base10 number, returns the base7 conversion */ base10_to_base7: function(n) { var base7; base7 = []; while (n > 0) { base7.unshift(n % 7); n = Math.floor(n / 7); } return base7; }, _align_arrays: function(a, n) { var i, j, ref; for (i = j = 0, ref = Math.abs(n); 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) { a = [0].concat(a); } return a; }, align_arrays: function(a, b) { var n; n = a.length - b.length; if (n > 0) { b = hept_tree_utils._align_arrays(b, n); } else if (n < 0) { a = hept_tree_utils._align_arrays(a, n); } return [a, b]; }, /* Given a base7 number, returns the corresponding HEPT TREE structure */ make_tree: function(node, n1, n2, name1, name2, index) { var child, i, j, len, ref; node.children = hept_tree_utils.get_children(); ref = node.children; for (i = j = 0, len = ref.length; j < len; i = ++j) { child = ref[i]; if (i === n1[index]) { child.name = name1; if (index < n1.length - 1) { child.type = 'partially full'; if (n1[index] === n2[index]) { hept_tree_utils.make_tree(child, n1, n2, name1, name2, index + 1); } else { hept_tree_utils.make_tree(child, n1, [], name1, name2, index + 1); } } else { if (name2 !== 'empty') { child.type = 'full'; } child.name = name2; } } else if (i === n2[index]) { child.name = name2; if (index < n2.length - 1) { child.type = 'partially full'; hept_tree_utils.make_tree(child, n2, [], name2, 'empty', index + 1); } else { child.type = 'full'; } } else if (i <= n1[index]) { child.name = name1; child.type = 'full'; } else if (i <= n2[index] || (n2.length === 0 && name2 !== 'empty')) { child.name = name2; child.type = 'full'; } else { child.name = 'empty'; } } return node; }, /* HEXAGONS */ hex_generate_svg_path: function(scale) { var a, r; a = scale / 2; r = a / Math.sin(Math.PI / 3); return "M" + r + " 0 L" + (r / 2) + " " + a + " L" + (-r / 2) + " " + a + " L" + (-r) + " 0 L" + (-r / 2) + " " + (-a) + " L" + (r / 2) + " " + (-a) + " Z"; } }; }).call(this);