/* TODO: get rid of this constant */
var margin = 0.271828;

/*          _1_                *
 *      _.-`   `-._            *               _.-`-._
 * 0 .-`           `-. 2       *           _.-`   |   `-._ width/sqrt(3)
 *   |`-._       _.-`|         *       _,-` width/|       `-._
 *   |    `-. .-`    |         *    .-`(2*sqrt(3))|___________`-.
 *   |       |       |         *    `-._             width/2 _.-`
 *   |       |       |         *        `-._             _.-`
 * 5 `-._    |    _.-` 3       *            `-._     _.-`
 *       `-._|_.-`             *                `-.-`
 *           4                 *    |---------------------------|
 *  |-----------------|        *                width
 *        width                *
 */

function slope_width_to_height(width) { return width / Math.sqrt(3) }

function points_UFR(width) {
   var slope_height = slope_width_to_height(width / 2);
   var x0 = 0.0 * width,
       x1 = 0.5 * width,
       x2 = 1.0 * width;
   var y0 = 1.0 * slope_height,
       y1 = 0.0 * slope_height,
       y3 = 3.0 * slope_height,
       y4 = 4.0 * slope_height;
   return [ { x : x0, y : y0 }, { x : x1, y : y1 }, { x : x2, y : y0 }
          , { x : x2, y : y3 }, { x : x1, y : y4 }, { x : x0, y : y3 }
          ] }

/*          _1_
 *      _.-`   `-._
 *  0.-`           `-.2
 *    `-._       _.-`
 *        `-._.-`    
 *           3
 */
 
function points_UD(width) {
    var slope_height = slope_width_to_height(width / 2);
    var x0 = 0.0 * width,
        x1 = 0.5 * width,
        x2 = 1.0 * width;
    var y0 = 1.0 * slope_height,
        y1 = 0.0 * slope_height,
        y3 = 2.0 * slope_height;
    return [{x:x0, y:y0}, {x:x1, y:y1}, {x:x2, y:y0}, {x:x1, y:y3}] }

/*          _.-._
 *      _.-`  8  `-._
 *   _-`  5       7  `-_
 * .`  2      4       6 `.
 *  `-._  1       3  _.-`
 *      `-._  0  _.-`   
 *          `-.-`
 */

function sticker_points_UD(width) {
    var height = slope_width_to_height(width);
    var offset = { x : (margin * width ) / 6
                 , y : (margin * height) / 6 };
    var out = new Array(9);
    for (var i = 0; i < 3; i++) {
        for (var j = 0; j < 3; j++) {
            out[i * 3 + j] = { x : offset.x + (width  / 6) * (i + 2 - j)
                             , y : offset.y + (height / 6) * (4 - i - j) } } }
    return out }

/*  0 _
 *   | `-._   
 *   |     `-.1
 *   |       |
 *   |       |
 *  3`-._    |
 *       `-._|
 *           2
 */

function points_FB(width) {
    var slope_height = slope_width_to_height(width);
    var x0 = 0.0 * width,
        x1 = 1.0 * width;
    var y0 = 0.0 * slope_height,
        y1 = 1.0 * slope_height,
        y2 = 3.0 * slope_height,
        y3 = 2.0 * slope_height;
    return [{x:x0, y:y0}, {x:x1, y:y1}, {x:x1, y:y2}, {x:x0, y:y3}] }

/*
 * |`-._
 * |    `-._
 * |  2     `-._
 * |      1     `.
 * |  5       0  |
 * |      4      |
 * |  8       3  |
 * |_     7      |
 *   `-._     6  |
 *       `-._    |
 *           `-._|
 */

function sticker_points_FB(width) {
    var height = 3 * slope_width_to_height(width);
    var offset = { x : margin * (width  / 6)
                 , y : margin * (height / 6) };
    var out = new Array(9);
    for (var i = 0; i < 3; i++) {
        for (var j = 0; j < 3; j++) {
            out[i * 3 + j] =
                { x : offset.x + (width  / 3) * (2 - j)
                , y : offset.y + (height / 9) * (2 * (i + 1) - j) } } }
    return out }

/*            1
 *       _.-`|
 *  0 .-`    |
 *   |       |
 *   |       |
 *   |    _.-`2
 *   |_.-`
 *  3
 */

function points_RL(width) {
    var slope_height = slope_width_to_height(width);
    var x0 = 0.0 * width,
        x1 = 1.0 * width;
    var y0 = 1.0 * slope_height,
        y1 = 0.0 * slope_height,
        y2 = 2.0 * slope_height,
        y3 = 3.0 * slope_height;
    return [{x:x0, y:y0}, {x:x1, y:y1}, {x:x1, y:y2}, {x:x0, y:y3}] }

/*           _.-`|
 *       _.-`    |
 *   _.-`     2  |
 * .`     1      |
 * |  0       5  |
 * |      4      |
 * |  3       8  |
 * |      7     _|
 * |  6     _.-`
 * |    _.-`
 * |_.-`
 */

function sticker_points_RL(width) {
    var height = 3 * slope_width_to_height(width);
    var offset = { x : margin * (width  / 6)
                 , y : margin * (height / 6) };
    var out = new Array(9);
    for (var i = 0; i < 3; i++) {
        for (var j = 0; j < 3; j++) {
            out[i * 3 + j] =
                { x : offset.x + (width  / 3) * j
                , y : offset.y + (height / 9) * (2 * (i + 1) - j) } } }
    return out }

function points_square(width) {
    return points_rectangle(width, width) }

function points_rectangle(width, height) {
    return [{x:0, y:0}, {x:width, y:0}, {x:width, y:height}, {x:0, y:height}] }


