// 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; }, /* */ base7_to_hex: function(n1, n2, index, data) { var d, i, j, len; for (i = j = 0, len = data.length; j < len; i = ++j) { d = data[i]; if (i < n1[index]) { d["class"] = 'n1'; } else if (i < n2[index]) { d["class"] = 'n2'; } else { d["class"] = 'empty'; } } return data; }, rotate_point: function(point, theta) { var new_point; theta = theta * Math.PI / 180; return new_point = { x: point.x * Math.cos(theta) - point.y * Math.sin(theta), y: point.x * Math.sin(theta) + point.y * Math.cos(theta) }; }, rotate_point_around_pivot: function(point, pivot, theta) { point.x -= pivot.x; point.y -= pivot.y; point = hept_tree_utils.rotate_point(point, theta); point.x += pivot.x; point.y += pivot.y; return point; }, /* HEXAGONS */ hex_generate_svg_path: function(a, theta) { var r; r = a / Math.sin(Math.PI / 3); /*points = [ hept_tree_utils.rotate_point {x: a, y: r/2}, theta hept_tree_utils.rotate_point {x: 0, y: r}, theta hept_tree_utils.rotate_point {x: -a, y: r/2}, theta hept_tree_utils.rotate_point {x: -a, y: -r/2}, theta hept_tree_utils.rotate_point {x: 0, y: -r}, theta hept_tree_utils.rotate_point {x: a, y: -r/2}, theta ] */ return "M" + a + " " + (r / 2) + " L0 " + r + " L" + (-a) + " " + (r / 2) + " L" + (-a) + " " + (-r / 2) + " L0 " + (-r) + " L" + a + " " + (-r / 2) + " Z"; } }; }).call(this);