I need to figure out the rendered size of a curve on 2d canvas
context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
with this code, for example
// pontos de controle
var cp1x = 200,
cp1y = 150,
cp2x = 260,
cp2y = 10;
var x = 0,
y = 0;
// calculação
var curveWidth = cp1x > x ? cp1x - x : x - cp1x,
curveHeight = cp1y > y ? cp1y - y : y - cp1y;
However, point cp2 can further lengthen the curve if it exceeds a starting or ending point (that is what happens in that code, cp1x = 200, cp2x = 260
). For example, let's assume that point cp2 is marked with the red ball in this image and that its x-coordinate is greater than the x-coordinate of cp1, which appears to be the end point of the curve:
So, how can I consider the width of point cp2 in the value of curveWidth
and in the value of curveHeight
to be exact?