"use strict";

var puckt = puckt || {};
puckt.util = (function () {
    // Convert pixels to representive metres
    var pixelsToMetres = function (pixels) {
        return pixels / puckt.pxpm;
    },
    metresToPixels = function (metres) {
        return metres * puckt.pxpm;
    },
    degreesToRadians = function (deg) {
        return deg * (Math.PI / 180); // To do: cache this value
    },
    radiansToDegrees = function (rad) {
        return rad * (180 / Math.PI); // To do: cache this value
    },
    clamp = function (min, max, x) {
        return Math.min(Math.max(x, min), max);
    },
    // Takes pixel x-axis, y-axis, width, & height and returns a b2Vect2 object
    dimTob2Vec2 = function (props) {
        return new box2d.b2Vec2(pixelsToMetres(props.x), pixelsToMetres(props.y)); 
    },
    // Takes a distance in pixels, and an array of times, converts pixels to
    // metres, and calculates the time period covered
    calcVelocity = function (distances, timestamps) {
        var distance = pixelsToMetres(distances[distances.length-1]-distances[0]),
            time = findDiff(timestamps[0], timestamps[timestamps.length-1]);
        return distance / (time * 0.001);
    },
    // Set the width and height of an HTML canvas element
    setCanvasSize = function (canvas, width, height) {
        canvas.setAttribute('width', width);
        canvas.setAttribute('height', height);
    },
    // Extend an object with more properties, overwriting exiting ones
    extendObject = function (original, newProps) {
        for (var prop in newProps) {
            original[prop] = newProps[prop];
        }
    },
    // Flushes out all the shit you got
    resetWorld = function (world) {
        var body = world.GetBodyList();
        while (body !== null) {
            world.DestroyBody(body);
            body = body.GetNext();
        }
        stage.removeAllChildren();
    };
    return {
        pixelsToMetres: pixelsToMetres,
        metresToPixels: metresToPixels,
        degreesToRadians: degreesToRadians,
        radiansToDegrees: radiansToDegrees,
        clamp: clamp,
        dimTob2Vec2: dimTob2Vec2,
        calcVelocity: calcVelocity,
        setCanvasSize: setCanvasSize,
        extendObject: extendObject,
        resetWorld: resetWorld
    }
}());
@@ -586,32 +586,204 @@
 ), max);%0A    %7D,%0A
+    // A helper function to find the difference between two numbers%0A    findDiff = function (num1, num2) %7B%0A        return (num1 %3E num2) ? num1 - num2 : num2 - num1;%0A    %7D,%0A
     // Takes pix
@@ -2276,16 +2276,44 @@
  clamp,%0A
+        findDiff: findDiff,%0A
         

Revert "Removed old until function findDiff"