Skip to content

Commit 0437fb4

Browse files
committed
Curves code clean up.
1 parent facbcd3 commit 0437fb4

9 files changed

+72
-70
lines changed

src/extras/FontUtils.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ THREE.FontUtils = {
109109

110110
var pts = [];
111111

112+
var b2 = THREE.ShapeUtils.b2;
113+
var b3 = THREE.ShapeUtils.b3;
114+
112115
var i, i2, divisions,
113116
outline, action, length,
114117
scaleX, scaleY,
@@ -174,8 +177,8 @@ THREE.FontUtils = {
174177
for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
175178

176179
var t = i2 / divisions;
177-
THREE.ShapeUtils.b2( t, cpx0, cpx1, cpx );
178-
THREE.ShapeUtils.b2( t, cpy0, cpy1, cpy );
180+
b2( t, cpx0, cpx1, cpx );
181+
b2( t, cpy0, cpy1, cpy );
179182

180183
}
181184

@@ -187,12 +190,12 @@ THREE.FontUtils = {
187190

188191
// Cubic Bezier Curve
189192

190-
cpx = outline[ i ++ ] * scaleX + offset;
191-
cpy = outline[ i ++ ] * scaleY;
192-
cpx1 = outline[ i ++ ] * scaleX + offset;
193-
cpy1 = outline[ i ++ ] * scaleY;
194-
cpx2 = outline[ i ++ ] * scaleX + offset;
195-
cpy2 = outline[ i ++ ] * scaleY;
193+
cpx = outline[ i ++ ] * scaleX + offset;
194+
cpy = outline[ i ++ ] * scaleY;
195+
cpx1 = outline[ i ++ ] * scaleX + offset;
196+
cpy1 = outline[ i ++ ] * scaleY;
197+
cpx2 = outline[ i ++ ] * scaleX + offset;
198+
cpy2 = outline[ i ++ ] * scaleY;
196199

197200
path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
198201

@@ -206,8 +209,8 @@ THREE.FontUtils = {
206209
for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
207210

208211
var t = i2 / divisions;
209-
THREE.ShapeUtils.b3( t, cpx0, cpx1, cpx2, cpx );
210-
THREE.ShapeUtils.b3( t, cpy0, cpy1, cpy2, cpy );
212+
b3( t, cpx0, cpx1, cpx2, cpx );
213+
b3( t, cpy0, cpy1, cpy2, cpy );
211214

212215
}
213216

src/extras/core/Path.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
199199

200200
divisions = divisions || 12;
201201

202+
var b2 = THREE.ShapeUtils.b2;
203+
var b3 = THREE.ShapeUtils.b3;
204+
202205
var points = [];
203206

204207
var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
@@ -253,8 +256,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
253256

254257
var t = j / divisions;
255258

256-
tx = THREE.ShapeUtils.b2( t, cpx0, cpx1, cpx );
257-
ty = THREE.ShapeUtils.b2( t, cpy0, cpy1, cpy );
259+
tx = b2( t, cpx0, cpx1, cpx );
260+
ty = b2( t, cpy0, cpy1, cpy );
258261

259262
points.push( new THREE.Vector2( tx, ty ) );
260263

@@ -294,8 +297,8 @@ THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
294297

295298
var t = j / divisions;
296299

297-
tx = THREE.ShapeUtils.b3( t, cpx0, cpx1, cpx2, cpx );
298-
ty = THREE.ShapeUtils.b3( t, cpy0, cpy1, cpy2, cpy );
300+
tx = b3( t, cpx0, cpx1, cpx2, cpx );
301+
ty = b3( t, cpy0, cpy1, cpy2, cpy );
299302

300303
points.push( new THREE.Vector2( tx, ty ) );
301304

@@ -571,6 +574,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
571574

572575
}
573576

577+
var isClockWise = THREE.ShapeUtils.isClockWise;
574578

575579
var subPaths = extractSubpaths( this.actions );
576580
if ( subPaths.length === 0 ) return [];
@@ -591,7 +595,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
591595

592596
}
593597

594-
var holesFirst = ! THREE.ShapeUtils.isClockWise( subPaths[ 0 ].getPoints() );
598+
var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
595599
holesFirst = isCCW ? ! holesFirst : holesFirst;
596600

597601
// console.log("Holes first", holesFirst);
@@ -609,7 +613,7 @@ THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
609613

610614
tmpPath = subPaths[ i ];
611615
tmpPoints = tmpPath.getPoints();
612-
solid = THREE.ShapeUtils.isClockWise( tmpPoints );
616+
solid = isClockWise( tmpPoints );
613617
solid = isCCW ? ! solid : solid;
614618

615619
if ( solid ) {

src/extras/curves/ClosedSplineCurve3.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ THREE.ClosedSplineCurve3 = THREE.Curve.create(
2626
var point2 = points[ ( intPoint + 1 ) % points.length ];
2727
var point3 = points[ ( intPoint + 2 ) % points.length ];
2828

29-
var vector = new THREE.Vector3();
29+
var interpolate = THREE.CurveUtils.interpolate;
3030

31-
vector.x = THREE.CurveUtils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
32-
vector.y = THREE.CurveUtils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
33-
vector.z = THREE.CurveUtils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
34-
35-
return vector;
31+
return new THREE.Vector3(
32+
interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
33+
interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
34+
interpolate( point0.z, point1.z, point2.z, point3.z, weight )
35+
);
3636

3737
}
3838

src/extras/curves/CubicBezierCurve.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,22 @@ THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
1616

1717
THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
1818

19-
var tx, ty;
19+
var b3 = THREE.ShapeUtils.b3;
2020

21-
tx = THREE.ShapeUtils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
22-
ty = THREE.ShapeUtils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
23-
24-
return new THREE.Vector2( tx, ty );
21+
return new THREE.Vector2(
22+
b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
23+
b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
24+
);
2525

2626
};
2727

2828
THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
2929

30-
var tx, ty;
31-
32-
tx = THREE.CurveUtils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
33-
ty = THREE.CurveUtils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
34-
35-
var tangent = new THREE.Vector2( tx, ty );
36-
tangent.normalize();
30+
var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
3731

38-
return tangent;
32+
return new THREE.Vector2(
33+
tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
34+
tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
35+
).normalize();
3936

4037
};

src/extras/curves/CubicBezierCurve3.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ THREE.CubicBezierCurve3 = THREE.Curve.create(
1515

1616
function ( t ) {
1717

18-
var vector = new THREE.Vector3();
18+
var b3 = THREE.ShapeUtils.b3;
1919

20-
vector.x = THREE.ShapeUtils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
21-
vector.y = THREE.ShapeUtils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
22-
vector.z = THREE.ShapeUtils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
23-
24-
return vector;
20+
return new THREE.Vector3(
21+
b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
22+
b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
23+
b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
24+
);
2525

2626
}
2727

src/extras/curves/QuadraticBezierCurve.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,23 @@ THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
1717

1818
THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
1919

20-
var vector = new THREE.Vector2();
20+
var b2 = THREE.ShapeUtils.b2;
2121

22-
vector.x = THREE.ShapeUtils.b2( t, this.v0.x, this.v1.x, this.v2.x );
23-
vector.y = THREE.ShapeUtils.b2( t, this.v0.y, this.v1.y, this.v2.y );
24-
25-
return vector;
22+
return new THREE.Vector2(
23+
b2( t, this.v0.x, this.v1.x, this.v2.x ),
24+
b2( t, this.v0.y, this.v1.y, this.v2.y )
25+
);
2626

2727
};
2828

2929

3030
THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
3131

32-
var vector = new THREE.Vector2();
33-
34-
vector.x = THREE.CurveUtils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
35-
vector.y = THREE.CurveUtils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
36-
37-
// returns unit vector
32+
var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
3833

39-
return vector.normalize();
34+
return new THREE.Vector2(
35+
tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
36+
tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
37+
).normalize();
4038

4139
};

src/extras/curves/QuadraticBezierCurve3.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ THREE.QuadraticBezierCurve3 = THREE.Curve.create(
1414

1515
function ( t ) {
1616

17-
var vector = new THREE.Vector3();
17+
var b2 = THREE.ShapeUtils.b2;
1818

19-
vector.x = THREE.ShapeUtils.b2( t, this.v0.x, this.v1.x, this.v2.x );
20-
vector.y = THREE.ShapeUtils.b2( t, this.v0.y, this.v1.y, this.v2.y );
21-
vector.z = THREE.ShapeUtils.b2( t, this.v0.z, this.v1.z, this.v2.z );
22-
23-
return vector;
19+
return new THREE.Vector3(
20+
b2( t, this.v0.x, this.v1.x, this.v2.x ),
21+
b2( t, this.v0.y, this.v1.y, this.v2.y ),
22+
b2( t, this.v0.z, this.v1.z, this.v2.z )
23+
);
2424

2525
}
2626

src/extras/curves/SplineCurve.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ THREE.SplineCurve.prototype.getPoint = function ( t ) {
2424
var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
2525
var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
2626

27-
var vector = new THREE.Vector2();
27+
var interpolate = THREE.CurveUtils.interpolate;
2828

29-
vector.x = THREE.CurveUtils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
30-
vector.y = THREE.CurveUtils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
31-
32-
return vector;
29+
return new THREE.Vector2(
30+
interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
31+
interpolate( point0.y, point1.y, point2.y, point3.y, weight )
32+
);
3333

3434
};

src/extras/curves/SplineCurve3.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ THREE.SplineCurve3 = THREE.Curve.create(
2525
var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
2626
var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
2727

28-
var vector = new THREE.Vector3();
28+
var interpolate = THREE.CurveUtils.interpolate;
2929

30-
vector.x = THREE.CurveUtils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
31-
vector.y = THREE.CurveUtils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
32-
vector.z = THREE.CurveUtils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
33-
34-
return vector;
30+
return new THREE.Vector3(
31+
interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
32+
interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
33+
interpolate( point0.z, point1.z, point2.z, point3.z, weight )
34+
);
3535

3636
}
3737

0 commit comments

Comments
 (0)