From b359730219637d02ae116a9bb79801bbead0b6f7 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Tue, 24 Aug 2021 03:01:03 +0300 Subject: [PATCH] =?UTF-8?q?Drop=20unused=20b=C3=A9zier=20utilities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/_path.js | 229 ----------------------------------------------- 1 file changed, 229 deletions(-) diff --git a/plugins/_path.js b/plugins/_path.js index 1d78fdd4..ea450168 100644 --- a/plugins/_path.js +++ b/plugins/_path.js @@ -172,235 +172,6 @@ const convertRelativeToAbsolute = (data) => { return newData; }; -/** - * Compute Cubic Bézie bounding box. - * - * @see https://pomax.github.io/bezierinfo/ - * - * @param {Float} xa - * @param {Float} ya - * @param {Float} xb - * @param {Float} yb - * @param {Float} xc - * @param {Float} yc - * @param {Float} xd - * @param {Float} yd - * - * @return {Object} - */ -exports.computeCubicBoundingBox = function (xa, ya, xb, yb, xc, yc, xd, yd) { - var minx = Number.POSITIVE_INFINITY, - miny = Number.POSITIVE_INFINITY, - maxx = Number.NEGATIVE_INFINITY, - maxy = Number.NEGATIVE_INFINITY, - ts, - t, - x, - y, - i; - - // X - if (xa < minx) { - minx = xa; - } - if (xa > maxx) { - maxx = xa; - } - if (xd < minx) { - minx = xd; - } - if (xd > maxx) { - maxx = xd; - } - - ts = computeCubicFirstDerivativeRoots(xa, xb, xc, xd); - - for (i = 0; i < ts.length; i++) { - t = ts[i]; - - if (t >= 0 && t <= 1) { - x = computeCubicBaseValue(t, xa, xb, xc, xd); - // y = computeCubicBaseValue(t, ya, yb, yc, yd); - - if (x < minx) { - minx = x; - } - if (x > maxx) { - maxx = x; - } - } - } - - // Y - if (ya < miny) { - miny = ya; - } - if (ya > maxy) { - maxy = ya; - } - if (yd < miny) { - miny = yd; - } - if (yd > maxy) { - maxy = yd; - } - - ts = computeCubicFirstDerivativeRoots(ya, yb, yc, yd); - - for (i = 0; i < ts.length; i++) { - t = ts[i]; - - if (t >= 0 && t <= 1) { - // x = computeCubicBaseValue(t, xa, xb, xc, xd); - y = computeCubicBaseValue(t, ya, yb, yc, yd); - - if (y < miny) { - miny = y; - } - if (y > maxy) { - maxy = y; - } - } - } - - return { - minx: minx, - miny: miny, - maxx: maxx, - maxy: maxy, - }; -}; - -// compute the value for the cubic bezier function at time=t -function computeCubicBaseValue(t, a, b, c, d) { - var mt = 1 - t; - - return ( - mt * mt * mt * a + 3 * mt * mt * t * b + 3 * mt * t * t * c + t * t * t * d - ); -} - -// compute the value for the first derivative of the cubic bezier function at time=t -function computeCubicFirstDerivativeRoots(a, b, c, d) { - var result = [-1, -1], - tl = -a + 2 * b - c, - tr = -Math.sqrt(-a * (c - d) + b * b - b * (c + d) + c * c), - dn = -a + 3 * b - 3 * c + d; - - if (dn !== 0) { - result[0] = (tl + tr) / dn; - result[1] = (tl - tr) / dn; - } - - return result; -} - -/** - * Compute Quadratic Bézier bounding box. - * - * @see https://pomax.github.io/bezierinfo/ - * - * @param {Float} xa - * @param {Float} ya - * @param {Float} xb - * @param {Float} yb - * @param {Float} xc - * @param {Float} yc - * - * @return {Object} - */ -exports.computeQuadraticBoundingBox = function (xa, ya, xb, yb, xc, yc) { - var minx = Number.POSITIVE_INFINITY, - miny = Number.POSITIVE_INFINITY, - maxx = Number.NEGATIVE_INFINITY, - maxy = Number.NEGATIVE_INFINITY, - t, - x, - y; - - // X - if (xa < minx) { - minx = xa; - } - if (xa > maxx) { - maxx = xa; - } - if (xc < minx) { - minx = xc; - } - if (xc > maxx) { - maxx = xc; - } - - t = computeQuadraticFirstDerivativeRoot(xa, xb, xc); - - if (t >= 0 && t <= 1) { - x = computeQuadraticBaseValue(t, xa, xb, xc); - // y = computeQuadraticBaseValue(t, ya, yb, yc); - - if (x < minx) { - minx = x; - } - if (x > maxx) { - maxx = x; - } - } - - // Y - if (ya < miny) { - miny = ya; - } - if (ya > maxy) { - maxy = ya; - } - if (yc < miny) { - miny = yc; - } - if (yc > maxy) { - maxy = yc; - } - - t = computeQuadraticFirstDerivativeRoot(ya, yb, yc); - - if (t >= 0 && t <= 1) { - // x = computeQuadraticBaseValue(t, xa, xb, xc); - y = computeQuadraticBaseValue(t, ya, yb, yc); - - if (y < miny) { - miny = y; - } - if (y > maxy) { - maxy = y; - } - } - - return { - minx: minx, - miny: miny, - maxx: maxx, - maxy: maxy, - }; -}; - -// compute the value for the quadratic bezier function at time=t -function computeQuadraticBaseValue(t, a, b, c) { - var mt = 1 - t; - - return mt * mt * a + 2 * mt * t * b + t * t * c; -} - -// compute the value for the first derivative of the quadratic bezier function at time=t -function computeQuadraticFirstDerivativeRoot(a, b, c) { - var t = -1, - denominator = a - 2 * b + c; - - if (denominator !== 0) { - t = (a - b) / denominator; - } - - return t; -} - /** * Convert path array to string. *