Bug 1435373 - Minor refactor for shape output string guarding against empty this.geometryBox. Round values in getDistance() util function to avoid verbose precision. r=gl

MozReview-Commit-ID: IBB4mkvAu6h

--HG--
extra : rebase_source : b40e9c29a1ccef116fcfceb0d01dd28d31fec46c
extra : histedit_source : 0d59aad3dd327a550fac40e04e3a733158dd7577
This commit is contained in:
Razvan Caliman 2018-02-19 17:51:10 +01:00
Родитель 094e34e37c
Коммит 369a3b985d
2 изменённых файлов: 20 добавлений и 35 удалений

Просмотреть файл

@ -841,8 +841,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
return `${newX}${unitX} ${newY}${unitY}`;
}).join(", ");
polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` :
`polygon(${polygonDef})`;
polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, polygonDef, "important");
}
@ -865,11 +864,9 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
radius = `${Math.abs((newCx - transX) * ratioRad)}${unitRad}`;
}
let circleDef = (this.geometryBox) ?
`circle(${radius} at ${newCx * ratioX}${unitX} ` +
`${newCy * ratioY}${unitY} ${this.geometryBox}` :
`circle(${radius} at ${newCx * ratioX}${unitX} ${newCy * ratioY}${unitY}`;
this.currentNode.style.setProperty(this.property, circleDef, "important");
let circleDef = `circle(${radius} at ${newCx * ratioX}${unitX} ` +
`${newCy * ratioY}${unitY}) ${this.geometryBox}`.trim();
this.emit("highlighter-event", { type: "shape-change", value: circleDef });
}
/**
@ -893,12 +890,9 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
ry = `${Math.abs((newCy - transY) * ratioRY)}${unitRY}`;
}
let ellipseDef = (this.geometryBox) ?
`ellipse(${rx} ${ry} at ${newCx * ratioX}${unitX} ` +
`${newCy * ratioY}${unitY}) ${this.geometryBox}` :
`ellipse(${rx} ${ry} at ${newCx * ratioX}${unitX} ` +
`${newCy * ratioY}${unitY})`;
this.currentNode.style.setProperty(this.property, ellipseDef, "important");
let ellipseDef = `ellipse(${rx} ${ry} at ${newCx * ratioX}${unitX} ` +
`${newCy * ratioY}${unitY}) ${this.geometryBox}`.trim();
this.emit("highlighter-event", { type: "shape-change", value: ellipseDef });
}
/**
@ -980,8 +974,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
return (i === point) ?
`${newX}${unitX} ${newY}${unitY}` : `${coords[0]} ${coords[1]}`;
}).join(", ");
polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` :
`polygon(${polygonDef})`;
polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, polygonDef, "important");
}
@ -1001,8 +994,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
return (i === after) ? `${coords[0]} ${coords[1]}, ${x}% ${y}%` :
`${coords[0]} ${coords[1]}`;
}).join(", ");
polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` :
`polygon(${polygonDef})`;
polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim();
this.hoveredPoint = after + 1;
this._emitHoverEvent(this.hoveredPoint);
@ -1020,8 +1012,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
polygonDef += coordinates.map((coords, i) => {
return `${coords[0]} ${coords[1]}`;
}).join(", ");
polygonDef = (this.geometryBox) ? `polygon(${polygonDef}) ${this.geometryBox}` :
`polygon(${polygonDef})`;
polygonDef = `polygon(${polygonDef}) ${this.geometryBox}`.trim();
this.hoveredPoint = null;
this._emitHoverEvent(this.hoveredPoint);
@ -1086,9 +1077,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
let deltaY = (pageY - y) * ratioY;
let newCx = `${valueX + deltaX}${unitX}`;
let newCy = `${valueY + deltaY}${unitY}`;
let circleDef = (this.geometryBox) ?
`circle(${radius} at ${newCx} ${newCy}) ${this.geometryBox}` :
`circle(${radius} at ${newCx} ${newCy})`;
// if not defined by the user, geometryBox will be an empty string; trim() cleans up
let circleDef = `circle(${radius} at ${newCx} ${newCy}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, circleDef, "important");
} else if (point === "radius") {
@ -1101,9 +1091,7 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
let delta = (newRadiusPx - origRadius) * ratio;
let newRadius = `${value + delta}${unit}`;
let circleDef = (this.geometryBox) ?
`circle(${newRadius} at ${cx} ${cy} ${this.geometryBox}` :
`circle(${newRadius} at ${cx} ${cy}`;
let circleDef = `circle(${newRadius} at ${cx} ${cy}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, circleDef, "important");
}
@ -1177,9 +1165,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
let deltaY = (pageY - y) * ratioY;
let newCx = `${valueX + deltaX}${unitX}`;
let newCy = `${valueY + deltaY}${unitY}`;
let ellipseDef = (this.geometryBox) ?
`ellipse(${rx} ${ry} at ${newCx} ${newCy}) ${this.geometryBox}` :
`ellipse(${rx} ${ry} at ${newCx} ${newCy})`;
let ellipseDef =
`ellipse(${rx} ${ry} at ${newCx} ${newCy}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, ellipseDef, "important");
} else if (point === "rx") {
@ -1189,9 +1176,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
let delta = ((newRadiusPercent / 100 * width) - origRadius) * ratio;
let newRadius = `${value + delta}${unit}`;
let ellipseDef = (this.geometryBox) ?
`ellipse(${newRadius} ${ry} at ${cx} ${cy}) ${this.geometryBox}` :
`ellipse(${newRadius} ${ry} at ${cx} ${cy})`;
let ellipseDef =
`ellipse(${newRadius} ${ry} at ${cx} ${cy}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, ellipseDef, "important");
} else if (point === "ry") {
@ -1201,9 +1187,8 @@ class ShapesHighlighter extends AutoRefreshHighlighter {
let delta = ((newRadiusPercent / 100 * height) - origRadius) * ratio;
let newRadius = `${value + delta}${unit}`;
let ellipseDef = (this.geometryBox) ?
`ellipse(${rx} ${newRadius} at ${cx} ${cy}) ${this.geometryBox}` :
`ellipse(${rx} ${newRadius} at ${cx} ${cy})`;
let ellipseDef =
`ellipse(${rx} ${newRadius} at ${cx} ${cy}) ${this.geometryBox}`.trim();
this.currentNode.style.setProperty(this.property, ellipseDef, "important");
}

Просмотреть файл

@ -9,7 +9,7 @@
* @returns {Number} the distance between the two points
*/
const getDistance = (x1, y1, x2, y2) => {
return Math.hypot(x2 - x1, y2 - y1);
return Math.round(Math.hypot(x2 - x1, y2 - y1));
};
/**