Skip to content

Commit 1882ee8

Browse files
committed
Split Path up into includes.
1 parent 23f2016 commit 1882ee8

22 files changed

Lines changed: 456 additions & 402 deletions

v3/src/paths/Path.js

Lines changed: 24 additions & 402 deletions
Large diffs are not rendered by default.

v3/src/paths/inc/Add.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Add = function (curve)
2+
{
3+
this.curves.push(curve);
4+
5+
return this;
6+
};
7+
8+
module.exports = Add;

v3/src/paths/inc/CircleTo.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var CircleTo = function (radius, clockwise, rotation)
2+
{
3+
if (clockwise === undefined) { clockwise = false; }
4+
5+
return this.ellipseTo(radius, radius, 0, 360, clockwise, rotation);
6+
};
7+
8+
module.exports = CircleTo;

v3/src/paths/inc/ClosePath.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var LineCurve = require('../curves/line/LineCurve');
2+
3+
var ClosePath = function ()
4+
{
5+
// Add a line curve if start and end of lines are not connected
6+
var startPoint = this.curves[0].getPoint(0);
7+
var endPoint = this.curves[this.curves.length - 1].getPoint(1);
8+
9+
if (!startPoint.equals(endPoint))
10+
{
11+
// This will copy a reference to the vectors, which probably isn't sensible
12+
this.curves.push(new LineCurve(endPoint, startPoint));
13+
}
14+
15+
return this;
16+
};
17+
18+
module.exports = ClosePath;

v3/src/paths/inc/CubicBezierTo.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var CubicBezierCurve = require('../curves/cubicbezier/CubicBezierCurve');
2+
var Vector2 = require('../../math/Vector2');
3+
4+
// Creates a cubic bezier curve starting at the previous end point and ending at p3, using p1 and p2 as control points
5+
6+
var CubicBezierTo = function (x, y, control1X, control1Y, control2X, control2Y)
7+
{
8+
var p0 = this.getEndPoint();
9+
var p1;
10+
var p2;
11+
var p3;
12+
13+
// Assume they're all vec2s
14+
if (x instanceof Vector2)
15+
{
16+
p1 = x;
17+
p2 = y;
18+
p3 = control1X;
19+
}
20+
else
21+
{
22+
p1 = new Vector2(control1X, control1Y);
23+
p2 = new Vector2(control2X, control2Y);
24+
p3 = new Vector2(x, y);
25+
}
26+
27+
return this.add(new CubicBezierCurve(p0, p1, p2, p3));
28+
};
29+
30+
module.exports = CubicBezierTo;

v3/src/paths/inc/Destroy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Destroy = function ()
2+
{
3+
this.curves.length = 0;
4+
this.cacheLengths.length = 0;
5+
this.startPoint = undefined;
6+
};
7+
8+
module.exports = Destroy;

v3/src/paths/inc/Draw.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var Draw = function (graphics, pointsTotal)
2+
{
3+
for (var i = 0; i < this.curves.length; i++)
4+
{
5+
var curve = this.curves[i];
6+
7+
if (!curve.active)
8+
{
9+
continue;
10+
}
11+
12+
curve.draw(graphics, pointsTotal);
13+
}
14+
15+
return graphics;
16+
};
17+
18+
module.exports = Draw;

v3/src/paths/inc/EllipseTo.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var EllipseCurve = require('../curves/ellipse/EllipseCurve');
2+
3+
// Creates an ellipse curve positioned at the previous end point, using the given parameters
4+
var EllipseTo = function (xRadius, yRadius, startAngle, endAngle, clockwise, rotation)
5+
{
6+
var ellipse = new EllipseCurve(0, 0, xRadius, yRadius, startAngle, endAngle, clockwise, rotation);
7+
8+
var end = this.getEndPoint(this._tmpVec2A);
9+
10+
// Calculate where to center the ellipse
11+
var start = ellipse.getStartPoint(this._tmpVec2B);
12+
13+
end.sub(start);
14+
15+
ellipse.x = end.x;
16+
ellipse.y = end.y;
17+
18+
return this.add(ellipse);
19+
};
20+
21+
module.exports = EllipseTo;

v3/src/paths/inc/FromJSON.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var CubicBezierCurve = require('../curves/cubicbezier/CubicBezierCurve');
2+
var EllipseCurve = require('../curves/ellipse/EllipseCurve');
3+
var LineCurve = require('../curves/line/LineCurve');
4+
var SplineCurve = require('../curves/spline/SplineCurve');
5+
6+
var FromJSON = function (data)
7+
{
8+
// data should be an object matching the Path.toJSON object structure.
9+
10+
this.curves = [];
11+
this.cacheLengths = [];
12+
13+
this.startPoint.set(data.x, data.y);
14+
15+
this.autoClose = data.autoClose;
16+
17+
for (var i = 0; i < data.curves.length; i++)
18+
{
19+
var curve = data.curves[i];
20+
21+
switch (curve.type)
22+
{
23+
case 'LineCurve':
24+
this.add(LineCurve.fromJSON(curve));
25+
break;
26+
27+
case 'EllipseCurve':
28+
this.add(EllipseCurve.fromJSON(curve));
29+
break;
30+
31+
case 'SplineCurve':
32+
this.add(SplineCurve.fromJSON(curve));
33+
break;
34+
35+
case 'CubicBezierCurve':
36+
this.add(CubicBezierCurve.fromJSON(curve));
37+
break;
38+
}
39+
}
40+
41+
return this;
42+
};
43+
44+
module.exports = FromJSON;

v3/src/paths/inc/GetBounds.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var Rectangle = require('../../geom/rectangle/Rectangle');
2+
3+
var GetBounds = function (out, accuracy)
4+
{
5+
if (out === undefined) { out = new Rectangle(); }
6+
if (accuracy === undefined) { accuracy = 16; }
7+
8+
out.x = Number.MAX_SAFE_INTEGER;
9+
out.y = Number.MAX_SAFE_INTEGER;
10+
11+
var bounds = new Rectangle();
12+
var maxRight = Number.MIN_SAFE_INTEGER;
13+
var maxBottom = Number.MIN_SAFE_INTEGER;
14+
15+
for (var i = 0; i < this.curves.length; i++)
16+
{
17+
var curve = this.curves[i];
18+
19+
if (!curve.active)
20+
{
21+
continue;
22+
}
23+
24+
curve.getBounds(bounds, accuracy);
25+
26+
out.x = Math.min(out.x, bounds.x);
27+
out.y = Math.min(out.y, bounds.y);
28+
29+
maxRight = Math.max(maxRight, bounds.right);
30+
maxBottom = Math.max(maxBottom, bounds.bottom);
31+
}
32+
33+
out.right = maxRight;
34+
out.bottom = maxBottom;
35+
36+
return out;
37+
};
38+
39+
module.exports = GetBounds;

0 commit comments

Comments
 (0)