提交 5fe8effb 编写于 作者: M Mr.doob

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

上级 70b086fe
...@@ -687,80 +687,7 @@ var ShapeUtils = { ...@@ -687,80 +687,7 @@ var ShapeUtils = {
return ShapeUtils.area( pts ) < 0; 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 );
};
} )()
}; };
......
/**
* @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 };
import { ShapeUtils } from '../ShapeUtils'; import { b2, b3 } from './Bezier';
import { ShapePath } from './ShapePath'; import { ShapePath } from './ShapePath';
/** /**
...@@ -47,7 +47,7 @@ Object.assign( Font.prototype, { ...@@ -47,7 +47,7 @@ Object.assign( Font.prototype, {
var path = new ShapePath(); 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; var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
if ( glyph.o ) { if ( glyph.o ) {
......
import { b3 } from '../core/Bezier';
import { Curve } from '../core/Curve'; import { Curve } from '../core/Curve';
import { Vector2 } from '../../math/Vector2'; import { Vector2 } from '../../math/Vector2';
import { CurveUtils } from '../CurveUtils'; import { CurveUtils } from '../CurveUtils';
import { ShapeUtils } from '../ShapeUtils';
/************************************************************** /**************************************************************
* Cubic Bezier curve * Cubic Bezier curve
...@@ -21,8 +21,6 @@ CubicBezierCurve.prototype.constructor = CubicBezierCurve; ...@@ -21,8 +21,6 @@ CubicBezierCurve.prototype.constructor = CubicBezierCurve;
CubicBezierCurve.prototype.getPoint = function ( t ) { CubicBezierCurve.prototype.getPoint = function ( t ) {
var b3 = ShapeUtils.b3;
return new Vector2( return new Vector2(
b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ), 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 ) b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
......
import { Vector3 } from '../../math/Vector3'; import { b3 } from '../core/Bezier';
import { ShapeUtils } from '../ShapeUtils';
import { Curve } from '../core/Curve'; import { Curve } from '../core/Curve';
import { Vector3 } from '../../math/Vector3';
/************************************************************** /**************************************************************
* Cubic Bezier 3D curve * Cubic Bezier 3D curve
...@@ -19,8 +19,6 @@ var CubicBezierCurve3 = Curve.create( ...@@ -19,8 +19,6 @@ var CubicBezierCurve3 = Curve.create(
function ( t ) { function ( t ) {
var b3 = ShapeUtils.b3;
return new Vector3( return new Vector3(
b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ), 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 ), b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
......
import { b2 } from '../core/Bezier';
import { Curve } from '../core/Curve'; import { Curve } from '../core/Curve';
import { Vector2 } from '../../math/Vector2'; import { Vector2 } from '../../math/Vector2';
import { CurveUtils } from '../CurveUtils'; import { CurveUtils } from '../CurveUtils';
import { ShapeUtils } from '../ShapeUtils';
/************************************************************** /**************************************************************
* Quadratic Bezier curve * Quadratic Bezier curve
...@@ -22,8 +22,6 @@ QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve; ...@@ -22,8 +22,6 @@ QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
QuadraticBezierCurve.prototype.getPoint = function ( t ) { QuadraticBezierCurve.prototype.getPoint = function ( t ) {
var b2 = ShapeUtils.b2;
return new Vector2( return new Vector2(
b2( t, this.v0.x, this.v1.x, this.v2.x ), b2( t, this.v0.x, this.v1.x, this.v2.x ),
b2( t, this.v0.y, this.v1.y, this.v2.y ) b2( t, this.v0.y, this.v1.y, this.v2.y )
......
import { Vector3 } from '../../math/Vector3'; import { b2 } from '../core/Bezier';
import { ShapeUtils } from '../ShapeUtils';
import { Curve } from '../core/Curve'; import { Curve } from '../core/Curve';
import { Vector3 } from '../../math/Vector3';
/************************************************************** /**************************************************************
* Quadratic Bezier 3D curve * Quadratic Bezier 3D curve
...@@ -18,8 +18,6 @@ var QuadraticBezierCurve3 = Curve.create( ...@@ -18,8 +18,6 @@ var QuadraticBezierCurve3 = Curve.create(
function ( t ) { function ( t ) {
var b2 = ShapeUtils.b2;
return new Vector3( return new Vector3(
b2( t, this.v0.x, this.v1.x, this.v2.x ), b2( t, this.v0.x, this.v1.x, this.v2.x ),
b2( t, this.v0.y, this.v1.y, this.v2.y ), b2( t, this.v0.y, this.v1.y, this.v2.y ),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册