// Functions from http://cwestblog.com/2012/11/12/javascript-degree-and-radian-conversion/

// Converts from degrees to radians.
Math.toRadians = function(degrees) {
  return degrees * Math.PI / 180;
};
 
// Converts from radians to degrees.
Math.toDegrees = function(radians) {
  return radians * 180 / Math.PI;
};

function Queue() 
{
    var q = [];
    this.length = 0;

    this.isEmpty = function(){
        return this.length == 0;
    }

    this.enqueue = function(x){
        q.push(x);
        this.length++;
    }

    this.dequeue = function() {
        this.length--;
        return q.shift(); // O(n), so not great
    }

    this.items = function() {
        return q.slice();
    }

    this.print = function() {
        for ( var i = 0; i < this.length; i++)
        {
            console.log(q[i]);
        }
    }
}

function Stack()
{
    var s = [];
    this.length = 0;

    this.isEmpty = function() {
        return this.length == 0;
    }

    this.push = function(x) {
        s.push(x);
        this.length++;
    }

    this.pop = function() {
        this.length--;
        return s.pop();

    }

    this.items = function() {
        return s;
    }
}

function Iterator(items)
{
    var items  = items;
    var length = items.length;

    this.currentIndex = -1;
    this.next = function()
    {
        if (this.currentIndex + 1 < length)
            this.currentIndex++;
        return items[this.currentIndex];
    }
    this.prev = function()
    {
        if (this.currentIndex - 1 >= 0)
            this.currentIndex--;
        return items[this.currentIndex];
    }
}

CanvasRenderingContext2D.prototype.clear = function(width, height) {
    this.clearRect(0, 0, width, height);
}

function raiseUndefined()
{
    throw "not defined";
}

function generateOptions(selectElement, items)
{
    for (var i = 0; i < items.length; i++)
    {
        var opt = document.createElement('option');
        opt.value = items[i];
        opt.text  = items[i];

        selectElement.add(opt);
    }
}