Skip to content

Commit

Permalink
missing polygon functions
Browse files Browse the repository at this point in the history
  • Loading branch information
llafuente committed Jun 11, 2014
1 parent 812d0d1 commit fcc8899
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ var cfactor,
sfactor;

function rotate(out, poly, radians) {
if (out.length > poly.length) {
out.splice(poly.length);
}

len = poly.length - 1;

cfactor = cos(radians);
Expand All @@ -98,6 +102,37 @@ function rotate(out, poly, radians) {
return out;
}

function edges(out, poly) {
if (out.length > poly.length) {
out.splice(poly.length);
}

len = poly.length;
lens1 = len - 1;

// Calculate the edges/normals
for (i = 0; i < len; i++) {
Vec2.sub(out[i] = out[i] || [0, 0], poly[i < lens1 ? i + 1 : 0], poly[i]);
}

return out;
}

function normals(out, edges) {
if (out.length > poly.length) {
out.splice(poly.length);
}

len = edges.length - 1;
for (i = 0; i < len; i++) {
out[i] = out[i] || [0, 0];
Vec2.perp(out[i], e);
Vec2.normalize(out[i], out[i]);
}

return out;
}

var c_aux = [0, 0],
c_aux2 = [0, 0];
/**
Expand Down Expand Up @@ -130,6 +165,10 @@ var vec2_centroid = [0, 0];
* @returns {Polygon}
*/
function recenter(out, poly) {
if (out.length > poly.length) {
out.splice(poly.length);
}

centroid(vec2_centroid, poly);
var x = vec2_centroid[0],
y = vec2_centroid[1];
Expand Down Expand Up @@ -170,6 +209,10 @@ function area(poly) {


function transform(out, poly, m2d) {
if (out.length > poly.length) {
out.splice(poly.length);
}

for (i = 0, len = poly.length; i < len; ++i) {
Matrix23.transform(out[i] = out[i] || [], m2d, poly[i]);
}
Expand Down Expand Up @@ -212,6 +255,10 @@ var Polygon = {
//circumcenter: circumcenter,
area: area,
transform: transform,

normals: normals,
edges: edges,

isVec2Inside: isVec2Inside,

furthestPoint: furthestPoint,
Expand Down

0 comments on commit fcc8899

Please sign in to comment.