Skip to content
Browse files

Merge branch 'dev'

  • Loading branch information...
2 parents 2e42dea + 0b5f72e commit cb0ec9508404ddd605bb9e9f3a621876000f6c56 @deepsweet deepsweet committed May 7, 2013
Showing with 31 additions and 31 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +25 −30 plugins/transformsWithOnePath.js
View
5 CHANGELOG.md
@@ -1,3 +1,8 @@
+### [ [>](https://github.com/svg/svgo/tree/v0.3.5) ] 0.3.5 / 07.05.2013
+* plugins/transformsWithOnePath: fix curves bounding box calculation
+* plugins/transformsWithOnePath: fix possible c+t or q+s bug
+
+
### [ [>](https://github.com/svg/svgo/tree/v0.3.4) ] 0.3.4 / 06.05.2013
* plugins/convertPathData: fix m->M bug in some cases
* plugins/transformsWithOnePath: fix last point calculation for C/S/Q/T
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "svgo",
- "version": "0.3.4",
+ "version": "0.3.5",
"description": "Nodejs-based tool for optimizing SVG vector graphics files",
"keywords": [ "svgo", "svg", "optimize", "minify" ],
"homepage": "http://svg.github.com/svgo/",
View
55 plugins/transformsWithOnePath.js
@@ -55,30 +55,28 @@ exports.fn = function(data, params) {
path = relative2absolute(EXTEND(true, [], pathElem.pathJS)),
xs = [],
ys = [],
- controlPoint = [0, 0],
+ cubicСontrolPoint = [0, 0],
+ quadraticСontrolPoint = [0, 0],
+ lastPoint = [0, 0],
cubicBoundingBox,
quadraticBoundingBox,
i,
- segment,
- lastPoint = [0, 0];
+ segment;
path.forEach(function(pathItem) {
// ML
if ('ML'.indexOf(pathItem.instruction) > -1) {
- pathItem.data.forEach(function(d, i) {
-
+ for (i = 0; i < pathItem.data.length; i++) {
if (i % 2 === 0) {
- xs.push(d);
+ xs.push(pathItem.data[i]);
} else {
- ys.push(d);
+ ys.push(pathItem.data[i]);
}
+ }
- });
-
- controlPoint = pathItem.data.slice(-2);
- lastPoint = pathItem.data.slice(-2);
+ lastPoint = cubicСontrolPoint = quadraticСontrolPoint = pathItem.data.slice(-2);
// H
} else if (pathItem.instruction === 'H') {
@@ -87,8 +85,7 @@ exports.fn = function(data, params) {
xs.push(d);
});
- controlPoint[0] = pathItem.data[pathItem.data.length - 2];
- lastPoint[0] = pathItem.data[pathItem.data.length - 2];
+ lastPoint[0] = cubicСontrolPoint[0] = quadraticСontrolPoint[0] = pathItem.data[pathItem.data.length - 2];
// V
} else if (pathItem.instruction === 'V') {
@@ -97,8 +94,7 @@ exports.fn = function(data, params) {
ys.push(d);
});
- controlPoint[1] = pathItem.data[pathItem.data.length - 1];
- lastPoint[1] = pathItem.data[pathItem.data.length - 1];
+ lastPoint[1] = cubicСontrolPoint[1] = quadraticСontrolPoint[1] = pathItem.data[pathItem.data.length - 1];
// C
} else if (pathItem.instruction === 'C') {
@@ -116,12 +112,12 @@ exports.fn = function(data, params) {
ys.push(cubicBoundingBox.maxy);
// reflected control point for the next possible S
- controlPoint = [
+ cubicСontrolPoint = [
2 * segment[4] - segment[2],
2 * segment[5] - segment[3]
];
- lastPoint = pathItem.data.slice(-2);
+ lastPoint = segment.slice(-2);
}
@@ -132,7 +128,7 @@ exports.fn = function(data, params) {
segment = pathItem.data.slice(i, i + 4);
- cubicBoundingBox = computeCubicBoundingBox.apply(this, lastPoint.concat(controlPoint).concat(segment));
+ cubicBoundingBox = computeCubicBoundingBox.apply(this, lastPoint.concat(cubicСontrolPoint).concat(segment));
xs.push(cubicBoundingBox.minx);
xs.push(cubicBoundingBox.maxx);
@@ -141,12 +137,12 @@ exports.fn = function(data, params) {
ys.push(cubicBoundingBox.maxy);
// reflected control point for the next possible S
- controlPoint = [
- 2 * segment[2] - controlPoint[0],
- 2 * segment[3] - controlPoint[1],
+ cubicСontrolPoint = [
+ 2 * segment[2] - cubicСontrolPoint[0],
+ 2 * segment[3] - cubicСontrolPoint[1],
];
- lastPoint = pathItem.data.slice(-2);
+ lastPoint = segment.slice(-2);
}
@@ -166,12 +162,12 @@ exports.fn = function(data, params) {
ys.push(quadraticBoundingBox.maxy);
// reflected control point for the next possible T
- controlPoint = [
+ quadraticСontrolPoint = [
2 * segment[2] - segment[0],
2 * segment[3] - segment[1]
];
- lastPoint = pathItem.data.slice(-2);
+ lastPoint = segment.slice(-2);
}
@@ -182,22 +178,21 @@ exports.fn = function(data, params) {
segment = pathItem.data.slice(i, i + 2);
- quadraticBoundingBox = computeQuadraticBoundingBox.apply(this, lastPoint.concat(controlPoint).concat(segment));
+ quadraticBoundingBox = computeQuadraticBoundingBox.apply(this, lastPoint.concat(quadraticСontrolPoint).concat(segment));
xs.push(quadraticBoundingBox.minx);
xs.push(quadraticBoundingBox.maxx);
ys.push(quadraticBoundingBox.miny);
ys.push(quadraticBoundingBox.maxy);
- // TODO: BUGGY
// reflected control point for the next possible T
- controlPoint = [
- 2 * segment[0] - lastPoint[0],
- 2 * segment[1] - lastPoint[1]
+ quadraticСontrolPoint = [
+ 2 * segment[0] - quadraticСontrolPoint[0],
+ 2 * segment[1] - quadraticСontrolPoint[1]
];
- lastPoint = pathItem.data.slice(-2);
+ lastPoint = segment.slice(-2);
}

0 comments on commit cb0ec95

Please sign in to comment.
Something went wrong with that request. Please try again.