Skip to content

Commit

Permalink
comment out unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjlockwood committed Mar 2, 2017
1 parent d448d87 commit 0dabb5f
Showing 1 changed file with 96 additions and 96 deletions.
192 changes: 96 additions & 96 deletions src/app/scripts/common/SvgUtil.ts
Expand Up @@ -14,7 +14,7 @@ export interface EllipticalArc {

/** Estimates an elliptical arc as a sequence of bezier curves. */
export function arcToBeziers(arc: EllipticalArc) {
const {startX: xf, startY: yf, largeArcFlag, sweepFlag, endX: xt, endY: yt} = arc;
const { startX: xf, startY: yf, largeArcFlag, sweepFlag, endX: xt, endY: yt } = arc;
let rx = arc.rx;
let ry = arc.ry;
let xAxisRotation = arc.xAxisRotation;
Expand Down Expand Up @@ -188,98 +188,98 @@ function unitCircleArcToBeziers(angleStart: number, angleExtent: number): number

// Code adapted from here:
// https://gist.github.com/alexjlockwood/c037140879806fb4d9820b7e70195494#file-flatten-js-L441-L547
export function transformArc(initialArc: EllipticalArc, transformMatrices: Matrix[]) {
const isNearZero = n => Math.abs(n) < 0.0000000000000001;
return transformMatrices.reduce((arc, matrix) => {
let rx = arc.rx;
let ry = arc.ry;
let xAxisRotation = arc.xAxisRotation;
const largeArcFlag = arc.largeArcFlag;
let sweepFlag = arc.sweepFlag;
const endX = arc.endX;
const endY = arc.endY;

xAxisRotation = xAxisRotation * Math.PI / 180;

const s = Math.sin(xAxisRotation);
const c = Math.cos(xAxisRotation);

// Matrix representation of transformed ellipse.
const m = [];

// Build ellipse representation matrix (unit circle transformation).
// The 2x2 matrix multiplication with the upper 2x2 of a_mat is inlined.
m[0] = matrix.a * +rx * c + matrix.c * rx * s;
m[1] = matrix.b * +rx * c + matrix.d * rx * s;
m[2] = matrix.a * -ry * s + matrix.c * ry * c;
m[3] = matrix.b * -ry * s + matrix.d * ry * c;

// To implict equation (centered).
const A = (m[0] * m[0]) + (m[2] * m[2]);
const C = (m[1] * m[1]) + (m[3] * m[3]);
const B = (m[0] * m[1] + m[2] * m[3]) * 2.0;

// Precalculate distance A to C.
const ac = A - C;

// Convert implicit equation to angle and halfaxis.
let A2, C2;
if (isNearZero(B)) {
xAxisRotation = 0;
A2 = A;
C2 = C;
} else {
if (isNearZero(ac)) {
A2 = A + B * 0.5;
C2 = A - B * 0.5;
xAxisRotation = Math.PI / 4.0;
} else {
// Precalculate radical.
let K = 1 + B * B / (ac * ac);

// Clamp (precision issues might need this... not likely, but better safe than sorry).
K = K < 0 ? 0 : Math.sqrt(K);

A2 = 0.5 * (A + C + K * ac);
C2 = 0.5 * (A + C - K * ac);
xAxisRotation = 0.5 * Math.atan2(B, ac);
}
}

// This can get slightly below zero due to rounding issues.
// It's safe to clamp to zero in this case (this yields a zero length halfaxis).
A2 = A2 < 0 ? 0 : Math.sqrt(A2);
C2 = C2 < 0 ? 0 : Math.sqrt(C2);

// Now A2 and C2 are half-axis.
if (ac <= 0) {
ry = A2;
rx = C2;
} else {
ry = C2;
rx = A2;
}

// If the transformation matrix contain a mirror-component
// winding order of the ellise needs to be changed.
if ((matrix.a * matrix.d) - (matrix.b * matrix.c) < 0) {
sweepFlag = sweepFlag ? 0 : 1;
}

// Finally, transform arc endpoint. This takes care about the
// translational part which we ignored at the whole math-showdown above.
const end = MathUtil.transformPoint(new Point(endX, endY), matrix);

xAxisRotation = xAxisRotation * 180 / Math.PI;

return {
rx,
ry,
xAxisRotation,
largeArcFlag,
sweepFlag,
endX: end.x,
endY: end.y,
} as EllipticalArc;
}, initialArc);
}
// export function transformArc(initialArc: EllipticalArc, transformMatrices: Matrix[]) {
// const isNearZero = n => Math.abs(n) < 0.0000000000000001;
// return transformMatrices.reduce((arc, matrix) => {
// let rx = arc.rx;
// let ry = arc.ry;
// let xAxisRotation = arc.xAxisRotation;
// const largeArcFlag = arc.largeArcFlag;
// let sweepFlag = arc.sweepFlag;
// const endX = arc.endX;
// const endY = arc.endY;

// xAxisRotation = xAxisRotation * Math.PI / 180;

// const s = Math.sin(xAxisRotation);
// const c = Math.cos(xAxisRotation);

// // Matrix representation of transformed ellipse.
// const m = [];

// // Build ellipse representation matrix (unit circle transformation).
// // The 2x2 matrix multiplication with the upper 2x2 of a_mat is inlined.
// m[0] = matrix.a * +rx * c + matrix.c * rx * s;
// m[1] = matrix.b * +rx * c + matrix.d * rx * s;
// m[2] = matrix.a * -ry * s + matrix.c * ry * c;
// m[3] = matrix.b * -ry * s + matrix.d * ry * c;

// // To implict equation (centered).
// const A = (m[0] * m[0]) + (m[2] * m[2]);
// const C = (m[1] * m[1]) + (m[3] * m[3]);
// const B = (m[0] * m[1] + m[2] * m[3]) * 2.0;

// // Precalculate distance A to C.
// const ac = A - C;

// // Convert implicit equation to angle and halfaxis.
// let A2, C2;
// if (isNearZero(B)) {
// xAxisRotation = 0;
// A2 = A;
// C2 = C;
// } else {
// if (isNearZero(ac)) {
// A2 = A + B * 0.5;
// C2 = A - B * 0.5;
// xAxisRotation = Math.PI / 4.0;
// } else {
// // Precalculate radical.
// let K = 1 + B * B / (ac * ac);

// // Clamp (precision issues might need this... not likely, but better safe than sorry).
// K = K < 0 ? 0 : Math.sqrt(K);

// A2 = 0.5 * (A + C + K * ac);
// C2 = 0.5 * (A + C - K * ac);
// xAxisRotation = 0.5 * Math.atan2(B, ac);
// }
// }

// // This can get slightly below zero due to rounding issues.
// // It's safe to clamp to zero in this case (this yields a zero length halfaxis).
// A2 = A2 < 0 ? 0 : Math.sqrt(A2);
// C2 = C2 < 0 ? 0 : Math.sqrt(C2);

// // Now A2 and C2 are half-axis.
// if (ac <= 0) {
// ry = A2;
// rx = C2;
// } else {
// ry = C2;
// rx = A2;
// }

// // If the transformation matrix contain a mirror-component
// // winding order of the ellise needs to be changed.
// if ((matrix.a * matrix.d) - (matrix.b * matrix.c) < 0) {
// sweepFlag = sweepFlag ? 0 : 1;
// }

// // Finally, transform arc endpoint. This takes care about the
// // translational part which we ignored at the whole math-showdown above.
// const end = MathUtil.transformPoint(new Point(endX, endY), matrix);

// xAxisRotation = xAxisRotation * 180 / Math.PI;

// return {
// rx,
// ry,
// xAxisRotation,
// largeArcFlag,
// sweepFlag,
// endX: end.x,
// endY: end.y,
// } as EllipticalArc;
// }, initialArc);
// }

0 comments on commit 0dabb5f

Please sign in to comment.