- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
function getBounds(curve) {
var px;
var py;
var qx;
var qy;
var rx;
var ry;
var sx;
var sy;
var tx;
var ty;
var tobx;
var toby;
var tocx;
var tocy;
var todx;
var tody;
var toqx;
var toqy;
var torx;
var tory;
var totx;
var toty;
var step;
var x;
var y;
var minX;
var minY;
var maxX;
var maxY;
var ax = curve[0].x;
var ay = curve[0].y;
var bx = curve[1].x;
var by = curve[1].y;
var cx = curve[2].x;
var cy = curve[2].y;
var dx = curve[3].x;
var dy = curve[3].y;
var ITERATIONS_COUNT = 250;
minX = minY = Number.POSITIVE_INFINITY;
maxX = maxY = Number.NEGATIVE_INFINITY;
tobx = bx - ax;
toby = by - ay;
tocx = cx - bx;
tocy = cy - by;
todx = dx - cx;
tody = dy - cy;
step = 1 / ITERATIONS_COUNT;
for (var i = 0; i < ITERATIONS_COUNT; i++) {
var d = i * step;
px = ax + d * tobx;
py = ay + d * toby;
qx = bx + d * tocx;
qy = by + d * tocy;
rx = cx + d * todx;
ry = cy + d * tody;
toqx = qx - px;
toqy = qy - py;
torx = rx - qx;
tory = ry - qy;
sx = px + d * toqx;
sy = py + d * toqy;
tx = qx + d * torx;
ty = qy + d * tory;
totx = tx - sx;
toty = ty - sy;
x = sx + d * totx;
y = sy + d * toty;
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
return {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY
};
}