Browse Source

QuickHull3: Bugfixing

Mugen87 8 years ago
parent
commit
18d2035668
3 changed files with 43 additions and 39 deletions
  1. 5 5
      src/math/convexhull/Face.js
  2. 13 13
      src/math/convexhull/HalfEdge.js
  3. 25 21
      src/math/convexhull/QuickHull3.js

+ 5 - 5
src/math/convexhull/Face.js

@@ -79,9 +79,9 @@ Object.assign( Face.prototype, {
 
       if ( triangle === undefined ) triangle = new Triangle();
 
-      var a = this.edge.start();
-      var b = this.edge.end();
-      var c = this.edge.next.end();
+      var a = this.edge.tail();
+      var b = this.edge.head();
+      var c = this.edge.next.head();
 
       triangle.set( a.point, b.point, c.point );
 
@@ -103,7 +103,7 @@ Object.assign( Face.prototype, {
 
   },
 
-  // Connects two edges assuming that prev.end().point === next.start().point
+  // Connects two edges assuming that prev.head().point === next.tail().point
 
   connectHalfEdges: function ( prev, next ) {
 
@@ -215,7 +215,7 @@ Object.assign( Face.prototype, {
      discardedFaces.push( discardedFace );
 
    }
-   
+
    this.compute();
 
    return discardedFaces;

+ 13 - 13
src/math/convexhull/HalfEdge.js

@@ -17,26 +17,26 @@ function HalfEdge( vertex, face ) {
 
 Object.assign( HalfEdge.prototype, {
 
-	start: function () {
+  head: function () {
 
-		return this.vertex;
+    return this.vertex;
 
-	},
+  },
 
-  end: function () {
+  tail: function () {
 
-    return this.next ? this.next.vertex : null;
+    return this.prev ? this.prev.vertex : null;
 
   },
 
   length: function () {
 
-    var start = this.end();
-    var end = this.end();
+    var head = this.head();
+    var tail = this.tail();
 
-    if ( end !== null ) {
+    if ( tail !== null ) {
 
-      return start.point.distanceTo( end.point );
+      return tail.point.distanceTo( head.point );
 
     }
 
@@ -46,12 +46,12 @@ Object.assign( HalfEdge.prototype, {
 
   lengthSquared: function () {
 
-    var start = this.end();
-    var end = this.end();
+    var head = this.head();
+    var tail = this.tail();
 
-    if ( end !== null ) {
+    if ( tail !== null ) {
 
-      return start.point.distanceToSquared( end.point );
+      return tail.point.distanceToSquared( head.point );
 
     }
 

+ 25 - 21
src/math/convexhull/QuickHull3.js

@@ -188,46 +188,50 @@ Object.assign( QuickHull3.prototype, {
 
 	resolveUnclaimedPoints: function ( newFaces ) {
 
-		var vertex = this.unclaimed.first();
+		if ( this.unclaimed.isEmpty() === false ) {
 
-		do {
+			var vertex = this.unclaimed.first();
 
-			// buffer 'next' reference, see .deleteFaceVertices()
+			do {
 
-			var nextVertex = vertex.next;
+				// buffer 'next' reference, see .deleteFaceVertices()
 
-			var maxDistance = this.tolerance;
+				var nextVertex = vertex.next;
 
-			var maxFace = null;
+				var maxDistance = this.tolerance;
 
-			for ( var i = 0; i < newFaces.length; i ++ ) {
+				var maxFace = null;
 
-				var face = newFaces[ i ];
+				for ( var i = 0; i < newFaces.length; i ++ ) {
 
-				if ( face.mark === Visible ) {
+					var face = newFaces[ i ];
 
-					var distance = face.distanceToPoint( vertex.point );
+					if ( face.mark === Visible ) {
 
-					if ( distance > maxDistance ) {
+						var distance = face.distanceToPoint( vertex.point );
 
-						maxDistance = distance;
-						maxFace = face;
+						if ( distance > maxDistance ) {
 
-					}
+							maxDistance = distance;
+							maxFace = face;
 
-					if ( maxDistance > 1000 * this.tolerance ) break; // TODO: Why this?
+						}
+
+						if ( maxDistance > 1000 * this.tolerance ) break; // TODO: Why this?
+
+					}
 
 				}
 
-			}
+				if ( maxFace !== null ) {
 
-			if ( maxFace !== null ) {
+					this.addVertexToFace( vertex, maxFace );
 
-				this.addVertexToFace( vertex, maxFace );
+				}
 
-			}
+			} while ( vertex !== null );
 
-		} while ( vertex !== null );
+		}
 
 	},
 
@@ -628,7 +632,7 @@ Object.assign( QuickHull3.prototype, {
 
 		// all the half edges are created in ccw order thus the face is always pointing outside the hull
 
-		var face = Face.create( eyeVertex, horizonEdge.start(), horizonEdge.end() );
+		var face = Face.create( eyeVertex, horizonEdge.tail(), horizonEdge.head() );
 
 		this.faces.push( face );