Better variables scoping

This commit is contained in:
Frederic Junod
2018-01-17 09:05:39 +01:00
parent ee348c50e9
commit 4c5ca75ca6
21 changed files with 93 additions and 147 deletions

View File

@@ -260,8 +260,7 @@ CanvasReplayGroup.prototype.hasReplays = function(replays) {
* FIXME empty description for jsdoc
*/
CanvasReplayGroup.prototype.finish = function() {
let zKey;
for (zKey in this.replaysByZIndex_) {
for (const zKey in this.replaysByZIndex_) {
const replays = this.replaysByZIndex_[zKey];
for (const replayKey in replays) {
replays[replayKey].finish();

View File

@@ -652,16 +652,14 @@ WebGLPolygonReplay.prototype.removeItem_ = function(s0, s1, list, rtree) {
* @param {boolean=} opt_reflex Only include reflex points.
* @return {Array.<ol.WebglPolygonVertex>} Points in the triangle.
*/
WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1,
p2, rtree, opt_reflex) {
let i, ii, j, p;
WebGLPolygonReplay.prototype.getPointsInTriangle_ = function(p0, p1, p2, rtree, opt_reflex) {
const result = [];
const segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x, p2.x),
Math.min(p0.y, p1.y, p2.y), Math.max(p0.x, p1.x, p2.x), Math.max(p0.y,
p1.y, p2.y)]);
for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
for (j in segmentsInExtent[i]) {
p = segmentsInExtent[i][j];
for (let i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
for (const j in segmentsInExtent[i]) {
const p = segmentsInExtent[i][j];
if (typeof p === 'object' && (!opt_reflex || p.reflex)) {
if ((p.x !== p0.x || p.y !== p0.y) && (p.x !== p1.x || p.y !== p1.y) &&
(p.x !== p2.x || p.y !== p2.y) && result.indexOf(p) === -1 &&
@@ -689,8 +687,7 @@ WebGLPolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_to
const segmentsInExtent = rtree.getInExtent([Math.min(p0.x, p1.x),
Math.min(p0.y, p1.y), Math.max(p0.x, p1.x), Math.max(p0.y, p1.y)]);
const result = [];
let i, ii;
for (i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
for (let i = 0, ii = segmentsInExtent.length; i < ii; ++i) {
const currSeg = segmentsInExtent[i];
if (segment !== currSeg && (opt_touch || currSeg.p0 !== p1 || currSeg.p1 !== p0) &&
this.calculateIntersection_(p0, p1, currSeg.p0, currSeg.p1, opt_touch)) {
@@ -713,8 +710,7 @@ WebGLPolygonReplay.prototype.getIntersections_ = function(segment, rtree, opt_to
* @param {boolean=} opt_touch Touching segments should be considered an intersection.
* @return {Array.<number>|undefined} Intersection coordinates.
*/
WebGLPolygonReplay.prototype.calculateIntersection_ = function(p0,
p1, p2, p3, opt_touch) {
WebGLPolygonReplay.prototype.calculateIntersection_ = function(p0, p1, p2, p3, opt_touch) {
const denom = (p3.y - p2.y) * (p1.x - p0.x) - (p3.x - p2.x) * (p1.y - p0.y);
if (denom !== 0) {
const ua = ((p3.x - p2.x) * (p0.y - p2.y) - (p3.y - p2.y) * (p0.x - p2.x)) / denom;

View File

@@ -215,8 +215,7 @@ WebGLTextReplay.prototype.getTextSize_ = function(lines) {
//Split every line to an array of chars, sum up their width, and select the longest.
const textWidth = lines.map(function(str) {
let sum = 0;
let i, ii;
for (i = 0, ii = str.length; i < ii; ++i) {
for (let i = 0, ii = str.length; i < ii; ++i) {
const curr = str[i];
if (!glyphAtlas.width[curr]) {
self.addCharToAtlas_(curr);
@@ -239,10 +238,8 @@ WebGLTextReplay.prototype.getTextSize_ = function(lines) {
* @param {number} end End.
* @param {number} stride Stride.
*/
WebGLTextReplay.prototype.drawText_ = function(flatCoordinates, offset,
end, stride) {
let i, ii;
for (i = offset, ii = end; i < ii; i += stride) {
WebGLTextReplay.prototype.drawText_ = function(flatCoordinates, offset, end, stride) {
for (let i = offset, ii = end; i < ii; i += stride) {
this.drawCoordinates(flatCoordinates, offset, end, stride);
}
};
@@ -402,8 +399,7 @@ WebGLTextReplay.prototype.setTextStyle = function(textStyle) {
*/
WebGLTextReplay.prototype.getAtlas_ = function(state) {
let params = [];
let i;
for (i in state) {
for (const i in state) {
if (state[i] || state[i] === 0) {
if (Array.isArray(state[i])) {
params = params.concat(state[i]);
@@ -438,9 +434,8 @@ WebGLTextReplay.prototype.getAtlas_ = function(state) {
*/
WebGLTextReplay.prototype.calculateHash_ = function(params) {
//TODO: Create a more performant, reliable, general hash function.
let i, ii;
let hash = '';
for (i = 0, ii = params.length; i < ii; ++i) {
for (let i = 0, ii = params.length; i < ii; ++i) {
hash += params[i];
}
return hash;