mirror of
https://github.com/svg/svgo.git
synced 2026-01-27 07:02:06 +03:00
Drop unused bézier utilities
This commit is contained in:
229
plugins/_path.js
229
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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user