Pārlūkot izejas kodu

QuickHull3: Format

Mugen87 8 gadi atpakaļ
vecāks
revīzija
c706545ce4

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

@@ -10,98 +10,98 @@ import { Visible, Deleted } from '../../constants';
 
 function Face() {
 
-  this.normal = new Vector3();
-  this.midpoint = new Vector3();
-  this.area = 0;
+	this.normal = new Vector3();
+	this.midpoint = new Vector3();
+	this.area = 0;
 
-  this.constant = 0; // signed distance from face to the origin
-  this.outside = null; // reference to a vertex in a vertex list this face can see
-  this.mark = Visible;
-  this.edge = null;
+	this.constant = 0; // signed distance from face to the origin
+	this.outside = null; // reference to a vertex in a vertex list this face can see
+	this.mark = Visible;
+	this.edge = null;
 
 }
 
 Object.assign( Face, {
 
-  create: function( a, b, c ) {
+	create: function( a, b, c ) {
 
-    var face = new Face();
+		var face = new Face();
 
-    var e0 = new HalfEdge( a, face );
-    var e1 = new HalfEdge( b, face );
-    var e2 = new HalfEdge( c, face );
+		var e0 = new HalfEdge( a, face );
+		var e1 = new HalfEdge( b, face );
+		var e2 = new HalfEdge( c, face );
 
-    // join edges
+		// join edges
 
-    e0.next = e2.prev = e1;
-    e1.next = e0.prev = e2;
-    e2.next = e1.prev = e0;
+		e0.next = e2.prev = e1;
+		e1.next = e0.prev = e2;
+		e2.next = e1.prev = e0;
 
-    // main half edge reference
+		// main half edge reference
 
-    face.edge = e0;
+		face.edge = e0;
 
-    return face.compute();
+		return face.compute();
 
-  }
+	}
 
 } );
 
 Object.assign( Face.prototype, {
 
-  getEdge: function ( i ) {
+	getEdge: function ( i ) {
 
-    var edge = this.edge;
+		var edge = this.edge;
 
-    while ( i > 0 ) {
+		while ( i > 0 ) {
 
-      edge = edge.next;
-      i --;
+			edge = edge.next;
+			i --;
 
-    }
+		}
 
-    while ( i < 0 ) {
+		while ( i < 0 ) {
 
-      edge = edge.prev;
-      i ++;
+			edge = edge.prev;
+			i ++;
 
-    }
+		}
 
-    return edge;
+		return edge;
 
-  },
+	},
 
-  compute: function () {
+	compute: function () {
 
-    var triangle;
+		var triangle;
 
-    return function compute () {
+		return function compute () {
 
-      if ( triangle === undefined ) triangle = new Triangle();
+			if ( triangle === undefined ) triangle = new Triangle();
 
-      var a = this.edge.tail();
-      var b = this.edge.head();
-      var c = this.edge.next.head();
+			var a = this.edge.tail();
+			var b = this.edge.head();
+			var c = this.edge.next.head();
 
-      triangle.set( a.point, b.point, c.point );
+			triangle.set( a.point, b.point, c.point );
 
-      triangle.normal( this.normal );
-      triangle.midpoint( this.midpoint );
-      this.area = triangle.area();
+			triangle.normal( this.normal );
+			triangle.midpoint( this.midpoint );
+			this.area = triangle.area();
 
-      this.constant = this.normal.dot( this.midpoint );
+			this.constant = this.normal.dot( this.midpoint );
 
-      return this;
+			return this;
 
-    };
+		};
 
-  }(),
+	}(),
 
-  distanceToPoint: function ( point ) {
+	distanceToPoint: function ( point ) {
 
-    return this.normal.dot( point ) - this.constant;
+		return this.normal.dot( point ) - this.constant;
 
-  }
+	}
 
 } );
 

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

@@ -7,66 +7,66 @@
 
 function HalfEdge( vertex, face ) {
 
-  this.vertex = vertex;
-  this.prev = null;
-  this.next = null;
-  this.twin = null;
-  this.face = face;
+	this.vertex = vertex;
+	this.prev = null;
+	this.next = null;
+	this.twin = null;
+	this.face = face;
 
 }
 
 Object.assign( HalfEdge.prototype, {
 
-  head: function () {
+	head: function () {
 
-    return this.vertex;
+		return this.vertex;
 
-  },
+	},
 
-  tail: function () {
+	tail: function () {
 
-    return this.prev ? this.prev.vertex : null;
+		return this.prev ? this.prev.vertex : null;
 
-  },
+	},
 
-  length: function () {
+	length: function () {
 
-    var head = this.head();
-    var tail = this.tail();
+		var head = this.head();
+		var tail = this.tail();
 
-    if ( tail !== null ) {
+		if ( tail !== null ) {
 
-      return tail.point.distanceTo( head.point );
+			return tail.point.distanceTo( head.point );
 
-    }
+		}
 
-    return - 1;
+		return - 1;
 
-  },
+	},
 
-  lengthSquared: function () {
+	lengthSquared: function () {
 
-    var head = this.head();
-    var tail = this.tail();
+		var head = this.head();
+		var tail = this.tail();
 
-    if ( tail !== null ) {
+		if ( tail !== null ) {
 
-      return tail.point.distanceToSquared( head.point );
+			return tail.point.distanceToSquared( head.point );
 
-    }
+		}
 
-    return - 1;
+		return - 1;
 
-  },
+	},
 
-  setTwin: function ( edge ) {
+	setTwin: function ( edge ) {
 
-    this.twin = edge;
-    edge.twin = this;
+		this.twin = edge;
+		edge.twin = this;
 
-    return this;
+		return this;
 
-  }
+	}
 
 } );
 

+ 4 - 4
src/math/convexhull/Vertex.js

@@ -7,10 +7,10 @@
 
 function Vertex( point ) {
 
-  this.point = point;
-  this.prev = null;
-  this.next = null;
-  this.face = null; // the face that is able to see this vertex
+	this.point = point;
+	this.prev = null;
+	this.next = null;
+	this.face = null; // the face that is able to see this vertex
 
 }
 

+ 88 - 88
src/math/convexhull/VertexList.js

@@ -5,193 +5,193 @@
 
 function VertexList() {
 
-  this.head = null;
-  this.tail = null;
+	this.head = null;
+	this.tail = null;
 
 }
 
 Object.assign( VertexList.prototype, {
 
-  first: function () {
+	first: function () {
 
-    return this.head;
+		return this.head;
 
-  },
+	},
 
-  last: function () {
+	last: function () {
 
-    return this.tail;
+		return this.tail;
 
-  },
+	},
 
 	clear: function () {
 
 		this.head = this.tail = null;
 
-    return this;
+		return this;
 
 	},
 
-  // Inserts a vertex before the target vertex
+	// Inserts a vertex before the target vertex
 
 	insertBefore: function ( target, vertex ) {
 
 		vertex.prev = target.prev;
-    vertex.next = target;
+		vertex.next = target;
 
-    if ( vertex.prev === null ) {
+		if ( vertex.prev === null ) {
 
-      this.head = vertex;
+			this.head = vertex;
 
-    } else {
+		} else {
 
-      vertex.prev.next = vertex;
+			vertex.prev.next = vertex;
 
-    }
+		}
 
-    target.prev = vertex;
+		target.prev = vertex;
 
-    return this;
+		return this;
 
 	},
 
-  // Inserts a vertex after the target vertex
+	// Inserts a vertex after the target vertex
 
-  insertAfter: function ( target, vertex ) {
+	insertAfter: function ( target, vertex ) {
 
-    vertex.prev = target;
-    vertex.next = target.next;
+		vertex.prev = target;
+		vertex.next = target.next;
 
-    if ( vertex.next === null ) {
+		if ( vertex.next === null ) {
 
-      this.tail = vertex;
+			this.tail = vertex;
 
-    } else {
+		} else {
 
-      vertex.next.prev = vertex;
+			vertex.next.prev = vertex;
 
-    }
+		}
 
-    target.next = vertex;
+		target.next = vertex;
 
-    return this;
+		return this;
 
-  },
+	},
 
-  // Appends a vertex to the end of the linked list
+	// Appends a vertex to the end of the linked list
 
-  append: function ( vertex ) {
+	append: function ( vertex ) {
 
-    if ( this.head === null ) {
+		if ( this.head === null ) {
 
-      this.head = vertex;
+			this.head = vertex;
 
-    } else {
+		} else {
 
-      this.tail.next = vertex;
+			this.tail.next = vertex;
 
-    }
+		}
 
-    vertex.prev = this.tail;
-    vertex.next = null; // the tail has no subsequent vertex
+		vertex.prev = this.tail;
+		vertex.next = null; // the tail has no subsequent vertex
 
-    this.tail = vertex;
+		this.tail = vertex;
 
-    return this;
+		return this;
 
-  },
+	},
 
-  // Appends a chain of vertices where 'vertex' is the head.
+	// Appends a chain of vertices where 'vertex' is the head.
 
-  appendChain: function ( vertex ) {
+	appendChain: function ( vertex ) {
 
-    if ( this.head === null ) {
+		if ( this.head === null ) {
 
-      this.head = vertex;
+			this.head = vertex;
 
-    } else {
+		} else {
 
-      this.tail.next = vertex;
+			this.tail.next = vertex;
 
-    }
+		}
 
-    vertex.prev = this.tail;
+		vertex.prev = this.tail;
 
-    // ensure that the 'tail' reference points to the last vertex of the chain
+		// ensure that the 'tail' reference points to the last vertex of the chain
 
-    while ( vertex.next !== null ) {
+		while ( vertex.next !== null ) {
 
-      vertex = vertex.next;
+			vertex = vertex.next;
 
-    }
+		}
 
-    this.tail = vertex;
+		this.tail = vertex;
 
-    return this;
+		return this;
 
-  },
+	},
 
-  // Removes a vertex from the linked list
+	// Removes a vertex from the linked list
 
-  remove: function ( vertex ) {
+	remove: function ( vertex ) {
 
-    if ( vertex.prev === null ) {
+		if ( vertex.prev === null ) {
 
-      this.head = vertex.next;
+			this.head = vertex.next;
 
-    } else {
+		} else {
 
-      vertex.prev.next = vertex.next;
+			vertex.prev.next = vertex.next;
 
-    }
+		}
 
-    if ( vertex.next === null ) {
+		if ( vertex.next === null ) {
 
-      this.tail = vertex.prev;
+			this.tail = vertex.prev;
 
-    } else {
+		} else {
 
-      vertex.next.prev = vertex.prev;
+			vertex.next.prev = vertex.prev;
 
-    }
+		}
 
-    return this;
+		return this;
 
-  },
+	},
 
-  // Removes a list of vertices whose 'head' is 'a' and whose 'tail' is b
+	// Removes a list of vertices whose 'head' is 'a' and whose 'tail' is b
 
-  removeSubList: function ( a, b ) {
+	removeSubList: function ( a, b ) {
 
-    if ( a.prev === null ) {
+		if ( a.prev === null ) {
 
-      this.head = b.next;
+			this.head = b.next;
 
-    } else {
+		} else {
 
-      a.prev.next = b.next;
+			a.prev.next = b.next;
 
-    }
+		}
 
-    if ( b.next === null ) {
+		if ( b.next === null ) {
 
-      this.tail = a.prev;
+			this.tail = a.prev;
 
-    } else {
+		} else {
 
-      b.next.prev = a.prev;
+			b.next.prev = a.prev;
 
-    }
+		}
 
-    return this;
+		return this;
 
-  },
+	},
 
-  isEmpty: function() {
+	isEmpty: function() {
 
-    return this.head === null;
+		return this.head === null;
 
-  }
+	}
 
 } );