Yet another optimisation in Path#transformContent(): Only transform handles if they are not [0, 0].

This commit is contained in:
Jürg Lehni 2011-02-20 11:20:23 +01:00
parent 98837cbe98
commit 3374e50def

View file

@ -106,24 +106,37 @@ Path = PathItem.extend({
// Point.read() and Point constructors are necessary. // Point.read() and Point constructors are necessary.
var point = segment.point; var point = segment.point;
var handleIn = segment.handleIn; var handleIn = segment.handleIn;
if (handleIn.isZero())
handleIn = null;
var handleOut = segment.handleOut; var handleOut = segment.handleOut;
if (handleOut.isZero())
handleOut = null;
var x = point.x, y = point.y; var x = point.x, y = point.y;
// We need to convert handles to absolute coordinates in order
// to transform them.
// TODO: Is transformation even required if they are [0, 0]?
coords[0] = x; coords[0] = x;
coords[1] = y; coords[1] = y;
coords[2] = handleIn.x + x; var index = 2;
coords[3] = handleIn.y + y; // We need to convert handles to absolute coordinates in order
coords[4] = handleOut.x + x; // to transform them.
coords[5] = handleOut.y + y; if (handleIn) {
matrix.transform(coords, 0, coords, 0, 3); coords[index++] = handleIn.x + x;
point.x = x = coords[0]; coords[index++] = handleIn.y + y;
point.y = y = coords[1]; }
handleIn.x = coords[2] - x; if (handleOut) {
handleIn.y = coords[3] - y; coords[index++] = handleOut.x + x;
handleOut.x = coords[4] - x; coords[index++] = handleOut.y + y;
handleOut.y = coords[5] - y; }
matrix.transform(coords, 0, coords, 0, index / 2);
x = point.x = coords[0];
y = point.y = coords[1];
index = 2;
if (handleIn) {
handleIn.x = coords[index++] - x;
handleIn.y = coords[index++] - y;
}
if (handleOut) {
handleOut.x = coords[index++] - x;
handleOut.y = coords[index++] - y;
}
} }
}, },