Skip to content

Commit

Permalink
documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
llafuente committed Apr 12, 2014
1 parent 331d000 commit 1bbfa28
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 318 deletions.
366 changes: 198 additions & 168 deletions README.markdown

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var methods,
filename: "lib/segment2.js",
valid_arguments:{
out: "Segment2",

seg2: "Segment2",

x1: "Number",
Expand All @@ -64,6 +63,7 @@ var methods,
y2: "Number",
y3: "Number",

out_vec2: "Segment2",
vec2: "Vec2",
}
},
Expand Down Expand Up @@ -103,7 +103,7 @@ var methods,
vec2: "Vec2",
vec2_offset: "Vec2",
vec2_scale: "Vec2",
alignament: "Number (BB2.TOPLEFT, BB2.TOPMIDDLE, BB2.TOPRIGHT, BB2.CENTERLEFT, BB2.CENTER, BB2.CENTERRIGHT, BB2.BOTTOMLEFT, BB2.BOTTOM, BB2.BOTTOMRIGH)"
alignament: "Number"
}
},
Circle: {
Expand Down Expand Up @@ -137,7 +137,8 @@ var methods,
filename: "lib/polygon.js",
valid_arguments:{
out: "Polygon",
poly: "Polygon"
poly: "Polygon",
out_vec2: "Segment2"
}
},

Expand All @@ -146,6 +147,9 @@ var methods,
valid_arguments:{
out: "Beizer",
curve: "Beizer",

out_vec2: "Segment2",

t: "Number",
step: "Number",
cp0x: "Number",
Expand Down Expand Up @@ -208,7 +212,7 @@ for (cls in files) {
console.log(node);
throw new Error(files[cls].filename + ":" + arg + " is an invalid argument name, not in whitelist");
}
args.push("*" + arg + "*:" + valid_arguments[arg]);
args.push("*" + arg + "*: " + valid_arguments[arg]);
}

methods[node.id.name] = {
Expand Down
29 changes: 20 additions & 9 deletions lib/beizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ var sqrt = Math.sqrt,
t2 = 0,
t3 = 0;

/**
* @return {Beizer}
*/
function cubic(cp0x, cp0y, cp1x, cp1y, cp2x, cp2y, cp3x, cp3y) {
return [[cp0x, cp0y], [cp1x, cp1y], [cp2x, cp2y], [cp3x, cp3y]];
}

/**
* @return {Beizer}
*/
function quadric(cp0x, cp0y, cp1x, cp1y, cp2x, cp2y) {
return [[cp0x, cp0y], [cp1x, cp1y], [cp2x, cp2y]];
}

function get(out, curve, t) {
/**
* @return {Vec2}
*/
function get(out_vec2, curve, t) {
if (curve.length === 4) {
//cubic
t2 = t * t;
Expand All @@ -25,11 +32,11 @@ function get(out, curve, t) {
cl2 = curve[2];
cl3 = curve[3];

out[0] = (cl0[0] + t * (-cl0[0] * 3 + t * (3 * cl0[0] - cl0[0] * t))) +
out_vec2[0] = (cl0[0] + t * (-cl0[0] * 3 + t * (3 * cl0[0] - cl0[0] * t))) +
t * (3 * cl1[0] + t * (-6 * cl1[0] + cl1[0] * 3 * t)) +
t2 * (cl2[0] * 3 - cl2[0] * 3 * t) +
cl3[0] * t3;
out[1] = (cl0[1] + t * (-cl0[1] * 3 + t * (3 * cl0[1] - cl0[1] * t))) +
out_vec2[1] = (cl0[1] + t * (-cl0[1] * 3 + t * (3 * cl0[1] - cl0[1] * t))) +
t * (3 * cl1[1] + t * (-6 * cl1[1] + cl1[1] * 3 * t)) +
t2 * (cl2[1] * 3 - cl2[1] * 3 * t) +
cl3[1] * t3;
Expand All @@ -41,11 +48,11 @@ function get(out, curve, t) {
cl2 = curve[2];
t1 = 1 - t;

out[0] = t1 * t1 * cl0[0] + 2 * t1 * t * cl1[0] + t * t * cl2[0];
out[1] = t1 * t1 * cl0[1] + 2 * t1 * t * cl1[1] + t * t * cl2[1];
out_vec2[0] = t1 * t1 * cl0[0] + 2 * t1 * t * cl1[0] + t * t * cl2[0];
out_vec2[1] = t1 * t1 * cl0[1] + 2 * t1 * t * cl1[1] + t * t * cl2[1];
}

return out;
return out_vec2;
}

/**
Expand Down Expand Up @@ -75,7 +82,11 @@ function length(curve, step) {
return llength;
}

// credits - CAAT
/**
* credits - CAAT
*
* @class Beizer
*/
var Beizer = {
cubic: cubic,
quadric: quadric,
Expand Down
71 changes: 53 additions & 18 deletions lib/boundingbox2.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ var min = Math.min,
min_y = 0,
max_y = 0;


/**
* BoundingBox2 is an array [left: Number, bottom: Number, right: Number, top: Number, nomalized: Boolean]
* @returns {BB2}
*/
function create(l, b, r, t) {
var out = [l, b, r, t, false];
normalize(out, out);
return out;
}

/**
* @returns {BB2}
*/
function fromCircle(circle) {
r = circle[1];
x = circle[0][0];
Expand All @@ -39,21 +44,29 @@ function fromCircle(circle) {
y + r
);
}

/**
* @returns {BB2}
*/
function fromRectangle(rect) {
var out = [rect[0][0], rect[0][1], rect[1][0], rect[1][1], false];
normalize(out, out);
return out;
}

/**
* @returns {BB2}
*/
function zero() {
return [0, 0, 0, 0, true];
}

/**
* @returns {BB2}
*/
function clone(bb2) {
return [bb2[0], bb2[1], bb2[2], bb2[3], bb2[4]];
}

/**
* @returns {BB2}
*/
function copy(out, bb2) {
out[0] = bb2[0];
out[1] = bb2[1];
Expand All @@ -63,7 +76,9 @@ function copy(out, bb2) {

return out;
}

/**
* @returns {BB2}
*/
function merge(out, bb2_1, bb2_2) {
out[0] = min(bb2_1[0], bb2_2[0]);
out[1] = min(bb2_1[1], bb2_2[1]);
Expand All @@ -72,7 +87,9 @@ function merge(out, bb2_1, bb2_2) {

return out;
}

/**
* @returns {BB2}
*/
function offsetMerge(out, bb2_1, bb2_2, vec2_offset) {
out[0] = min(bb2_1[0], bb2_2[0] + vec2_offset[0]);
out[1] = min(bb2_1[1], bb2_2[1] + vec2_offset[1]);
Expand All @@ -81,8 +98,10 @@ function offsetMerge(out, bb2_1, bb2_2, vec2_offset) {

return out;
}

// offset & scale merge
/**
* offset & scale merge
* @returns {BB2}
*/
function osMerge(out, bb2_1, bb2_2, vec2_offset, vec2_scale) {
out[0] = min(bb2_1[0], (bb2_2[0] * vec2_scale[0]) + vec2_offset[0]);
out[1] = min(bb2_1[1], (bb2_2[1] * vec2_scale[1]) + vec2_offset[1]);
Expand All @@ -91,11 +110,15 @@ function osMerge(out, bb2_1, bb2_2, vec2_offset, vec2_scale) {

return out;
}

/**
* @returns {Number}
*/
function area(bb2) {
return (bb2.r - bb2.l) * (bb2.t - bb2.b);
}

/**
* @returns {BB2}
*/
function normalize(out, bb2) {
min_x = bb2[0] > bb2[2] ? bb2[2] : bb2[0];
max_x = bb2[0] > bb2[2] ? bb2[0] : bb2[2];
Expand All @@ -111,7 +134,9 @@ function normalize(out, bb2) {
out[4] = true;

}

/**
* @returns {BB2}
*/
function translate(out, bb2, vec2) {
x = vec2[0];
y = vec2[1];
Expand All @@ -123,14 +148,20 @@ function translate(out, bb2, vec2) {

return out;
}
/**
* @returns {Vec2}
*/
function clampVec(out_vec2, bb2, vec2) {
out_vec2[0] = min(max(bb2.l, vec2[0]), bb2.r);
out_vec2[1] = min(max(bb2.b, vec2[1]), bb2.t);

function clampVec(out, bb2, vec2) {
out[0] = min(max(bb2.l, vec2[0]), bb2.r);
out[1] = min(max(bb2.b, vec2[1]), bb2.t);

return out;
return out_vec2;
}

/**
* alignament values: BB2.TOPLEFT, BB2.TOPMIDDLE, BB2.TOPRIGHT, BB2.CENTERLEFT, BB2.CENTER, BB2.CENTERRIGHT, BB2.BOTTOMLEFT, BB2.BOTTOM, BB2.BOTTOMRIGH
* @returns {Vec2}
*/
function align(out_vec2, bb2, alignament) {
switch (alignament) {
case TOPLEFT:
Expand Down Expand Up @@ -177,7 +208,11 @@ function align(out_vec2, bb2, alignament) {
return out_vec2;
}

/**
* @class BB2
*/
var BB2 = {
// defines
TOPLEFT: TOPLEFT,
TOPMIDDLE: TOPMIDDLE,
TOPRIGHT: TOPRIGHT,
Expand Down
32 changes: 24 additions & 8 deletions lib/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,59 @@ var browser = "undefined" === typeof module,
max = Math.max,
TWOPI = Math.TWOPI,
PI = Math.PI;

/**
* @returns {Circle}
*/
function create(x, y, radius) {
return [[x, y], radius];
}

/**
* @returns {Circle}
*/
function clone(circle) {
return [[circle[0][0], circle[0][1]], circle[1]];
}

/**
* @returns {Circle}
*/
function copy(out, circle) {
out[0][0] = circle[0][0];
out[0][1] = circle[0][1];
out[1] = circle[1];

return out;
}

/**
* @returns {Circle}
*/
function translate(out, circle, vec2) {
out[0][0] = circle[0][0] + vec2[0];
out[0][1] = circle[0][1] + vec2[1];
out[1] = circle[1];

return out;
}

/**
* @returns {Number}
*/
function distance(circle, circle_2) {
return max(0, Vec2.distance(circle[0], circle_2[0]) - circle[1] - circle_2[1]);
}

/**
* @returns {Number}
*/
function length(circle) {
return TWOPI * circle[1];
}

/**
* @returns {Number}
*/
function area(circle) {
return PI * circle[1] * circle[1];
}

/**
* @class Circle
*/
var Circle = {
create: create,
clone: clone,
Expand Down
Loading

0 comments on commit 1bbfa28

Please sign in to comment.