Browse Source

CurveUtils: Moved tangent*Bezier to Bezier.

Mr.doob 8 years ago
parent
commit
4ea73e5808

+ 0 - 17
src/extras/CurveUtils.js

@@ -4,23 +4,6 @@
 
 var CurveUtils = {
 
-	tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
-
-		return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
-
-	},
-
-	// Puay Bing, thanks for helping with this derivative!
-
-	tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
-
-		return - 3 * p0 * ( 1 - t ) * ( 1 - t )  +
-			3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
-			6 * t *  p2 * ( 1 - t ) - 3 * t * t * p2 +
-			3 * t * t * p3;
-
-	},
-
 	tangentSpline: function ( t, p0, p1, p2, p3 ) {
 
 		// To check if my formulas are correct

+ 18 - 1
src/extras/core/Bezier.js

@@ -67,4 +67,21 @@ function b3( t, p0, p1, p2, p3 ) {
 
 }
 
-export { b2, b3 };
+//
+
+function tangentQuadraticBezier( t, p0, p1, p2 ) {
+
+	return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
+
+}
+
+function tangentCubicBezier( t, p0, p1, p2, p3 ) {
+
+	return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
+		3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
+		6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
+		3 * t * t * p3;
+
+}
+
+export { b2, b3, tangentQuadraticBezier, tangentCubicBezier };

+ 2 - 5
src/extras/curves/CubicBezierCurve.js

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

+ 2 - 5
src/extras/curves/QuadraticBezierCurve.js

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