Permalink
Browse files

Compiled

  • Loading branch information...
1 parent 38e78d5 commit 2fe874d606ad36167e27b1767da589b2f902e399 @josephg committed Feb 2, 2013
Showing with 18 additions and 11 deletions.
  1. +15 −8 cp.js
  2. +3 −3 cp.min.js
View
23 cp.js
@@ -233,8 +233,7 @@ var loopIndexes = cp.loopIndexes = function(verts)
minx = x;
miny = y;
start = i;
- }
- if(x > maxx || (x == maxx && y > maxy)){
+ } else if(x > maxx || (x == maxx && y > maxy)){
maxx = x;
maxy = y;
end = i;
@@ -311,6 +310,12 @@ var QHullReduce = function(tol, verts, offs, count, a, pivot, b, resultPos)
// QuickHull seemed like a neat algorithm, and efficient-ish for large input sets.
// My implementation performs an in place reduction using the result array as scratch space.
+//
+// Pass an Array into result to put the result of the calculation there. Otherwise, pass null
+// and the verts list will be edited in-place.
+//
+// Expects the verts to be described in the same way as cpPolyShape - which is to say, it should
+// be a list of [x1,y1,x2,y2,x3,y3,...].
var convexHull = cp.convexHull = function(verts, result, tol)
{
if(result){
@@ -323,12 +328,13 @@ var convexHull = cp.convexHull = function(verts, result, tol)
result = verts;
}
- // Degenerate case, all poins are the same.
+ // Degenerate case, all points are the same.
var indexes = loopIndexes(verts);
var start = indexes[0], end = indexes[1];
if(start == end){
//if(first) (*first) = 0;
- return 1;
+ result.length = 2;
+ return result;
}
SWAP(result, 0, start);
@@ -340,11 +346,12 @@ var convexHull = cp.convexHull = function(verts, result, tol)
var count = verts.length >> 1;
//if(first) (*first) = start;
var resultCount = QHullReduce(tol, result, 2, count - 2, a, b, a, 1) + 1;
- //assertSoft(cpPolyValidate(result, resultCount),
- // "Internal error: cpConvexHull() and cpPolyValidate() did not agree."
- // "Please report this error with as much info as you can.");
result.length = resultCount*2;
- return resultCount;
+
+ assertSoft(polyValidate(result),
+ "Internal error: cpConvexHull() and cpPolyValidate() did not agree." +
+ "Please report this error with as much info as you can.");
+ return result;
};
/// Clamp @c f to be between @c min and @c max.
Oops, something went wrong.

0 comments on commit 2fe874d

Please sign in to comment.