2
0
Эх сурвалжийг харах

ShapeUtils: Moved b2 and b3 to it's own file.

Mr.doob 8 жил өмнө
parent
commit
5fe8effbf8

+ 1 - 74
src/extras/ShapeUtils.js

@@ -687,80 +687,7 @@ var ShapeUtils = {
 
 		return ShapeUtils.area( pts ) < 0;
 
-	},
-
-	// Bezier Curves formulas obtained from
-	// http://en.wikipedia.org/wiki/B%C3%A9zier_curve
-
-	// Quad Bezier Functions
-
-	b2: ( function () {
-
-		function b2p0( t, p ) {
-
-			var k = 1 - t;
-			return k * k * p;
-
-		}
-
-		function b2p1( t, p ) {
-
-			return 2 * ( 1 - t ) * t * p;
-
-		}
-
-		function b2p2( t, p ) {
-
-			return t * t * p;
-
-		}
-
-		return function b2( t, p0, p1, p2 ) {
-
-			return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
-
-		};
-
-	} )(),
-
-	// Cubic Bezier Functions
-
-	b3: ( function () {
-
-		function b3p0( t, p ) {
-
-			var k = 1 - t;
-			return k * k * k * p;
-
-		}
-
-		function b3p1( t, p ) {
-
-			var k = 1 - t;
-			return 3 * k * k * t * p;
-
-		}
-
-		function b3p2( t, p ) {
-
-			var k = 1 - t;
-			return 3 * k * t * t * p;
-
-		}
-
-		function b3p3( t, p ) {
-
-			return t * t * t * p;
-
-		}
-
-		return function b3( t, p0, p1, p2, p3 ) {
-
-			return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
-
-		};
-
-	} )()
+	}
 
 };
 

+ 70 - 0
src/extras/core/Bezier.js

@@ -0,0 +1,70 @@
+/**
+ * @author zz85 / http://www.lab4games.net/zz85/blog
+ *
+ * Bezier Curves formulas obtained from
+ * http://en.wikipedia.org/wiki/Bézier_curve
+ */
+
+// Quad Bezier Functions
+
+function b2p0( t, p ) {
+
+	var k = 1 - t;
+	return k * k * p;
+
+}
+
+function b2p1( t, p ) {
+
+	return 2 * ( 1 - t ) * t * p;
+
+}
+
+function b2p2( t, p ) {
+
+	return t * t * p;
+
+}
+
+function b2( t, p0, p1, p2 ) {
+
+	return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
+
+}
+
+// Cubic Bezier Functions
+
+function b3p0( t, p ) {
+
+	var k = 1 - t;
+	return k * k * k * p;
+
+}
+
+function b3p1( t, p ) {
+
+	var k = 1 - t;
+	return 3 * k * k * t * p;
+
+}
+
+function b3p2( t, p ) {
+
+	var k = 1 - t;
+	return 3 * k * t * t * p;
+
+}
+
+function b3p3( t, p ) {
+
+	return t * t * t * p;
+
+}
+
+function b3( t, p0, p1, p2, p3 ) {
+
+	return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
+
+}
+
+export { b2, b3 };

+ 2 - 2
src/extras/core/Font.js

@@ -1,4 +1,4 @@
-import { ShapeUtils } from '../ShapeUtils';
+import { b2, b3 } from './Bezier';
 import { ShapePath } from './ShapePath';
 
 /**
@@ -47,7 +47,7 @@ Object.assign( Font.prototype, {
 
 			var path = new ShapePath();
 
-			var pts = [], b2 = ShapeUtils.b2, b3 = ShapeUtils.b3;
+			var pts = [];
 			var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
 
 			if ( glyph.o ) {

+ 1 - 3
src/extras/curves/CubicBezierCurve.js

@@ -1,7 +1,7 @@
+import { b3 } from '../core/Bezier';
 import { Curve } from '../core/Curve';
 import { Vector2 } from '../../math/Vector2';
 import { CurveUtils } from '../CurveUtils';
-import { ShapeUtils } from '../ShapeUtils';
 
 /**************************************************************
  *	Cubic Bezier curve
@@ -21,8 +21,6 @@ CubicBezierCurve.prototype.constructor = CubicBezierCurve;
 
 CubicBezierCurve.prototype.getPoint = function ( t ) {
 
-	var b3 = ShapeUtils.b3;
-
 	return new Vector2(
 		b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
 		b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )

+ 2 - 4
src/extras/curves/CubicBezierCurve3.js

@@ -1,6 +1,6 @@
-import { Vector3 } from '../../math/Vector3';
-import { ShapeUtils } from '../ShapeUtils';
+import { b3 } from '../core/Bezier';
 import { Curve } from '../core/Curve';
+import { Vector3 } from '../../math/Vector3';
 
 /**************************************************************
  *	Cubic Bezier 3D curve
@@ -19,8 +19,6 @@ var CubicBezierCurve3 = Curve.create(
 
 	function ( t ) {
 
-		var b3 = ShapeUtils.b3;
-
 		return new Vector3(
 			b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
 			b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),

+ 1 - 3
src/extras/curves/QuadraticBezierCurve.js

@@ -1,7 +1,7 @@
+import { b2 } from '../core/Bezier';
 import { Curve } from '../core/Curve';
 import { Vector2 } from '../../math/Vector2';
 import { CurveUtils } from '../CurveUtils';
-import { ShapeUtils } from '../ShapeUtils';
 
 /**************************************************************
  *	Quadratic Bezier curve
@@ -22,8 +22,6 @@ QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
 
 QuadraticBezierCurve.prototype.getPoint = function ( t ) {
 
-	var b2 = ShapeUtils.b2;
-
 	return new Vector2(
 		b2( t, this.v0.x, this.v1.x, this.v2.x ),
 		b2( t, this.v0.y, this.v1.y, this.v2.y )

+ 2 - 4
src/extras/curves/QuadraticBezierCurve3.js

@@ -1,6 +1,6 @@
-import { Vector3 } from '../../math/Vector3';
-import { ShapeUtils } from '../ShapeUtils';
+import { b2 } from '../core/Bezier';
 import { Curve } from '../core/Curve';
+import { Vector3 } from '../../math/Vector3';
 
 /**************************************************************
  *	Quadratic Bezier 3D curve
@@ -18,8 +18,6 @@ var QuadraticBezierCurve3 = Curve.create(
 
 	function ( t ) {
 
-		var b2 = ShapeUtils.b2;
-
 		return new Vector3(
 			b2( t, this.v0.x, this.v1.x, this.v2.x ),
 			b2( t, this.v0.y, this.v1.y, this.v2.y ),