Merge pull request #5619 from ahocevar/remove-goog-asserts

Remove goog.asserts.*
This commit is contained in:
Andreas Hocevar
2016-08-04 23:02:38 +02:00
committed by GitHub
157 changed files with 1429 additions and 1676 deletions

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.Circle');
goog.require('goog.asserts');
goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType');
@@ -163,7 +162,7 @@ ol.geom.Circle.prototype.intersectsExtent = function(extent) {
*/
ol.geom.Circle.prototype.setCenter = function(center) {
var stride = this.stride;
goog.asserts.assert(center.length == stride,
goog.DEBUG && console.assert(center.length == stride,
'center array length should match stride');
var radius = this.flatCoordinates[stride] - this.flatCoordinates[0];
var flatCoordinates = center.slice();
@@ -223,8 +222,6 @@ ol.geom.Circle.prototype.setFlatCoordinates = function(layout, flatCoordinates)
* @api
*/
ol.geom.Circle.prototype.setRadius = function(radius) {
goog.asserts.assert(this.flatCoordinates,
'truthy this.flatCoordinates expected');
this.flatCoordinates[this.stride] = this.flatCoordinates[0] + radius;
this.changed();
};

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.flat.closest');
goog.require('goog.asserts');
goog.require('ol.math');
@@ -148,7 +147,7 @@ ol.geom.flat.closest.getClosestPoint = function(flatCoordinates, offset, end,
return minSquaredDistance;
}
}
goog.asserts.assert(maxDelta > 0, 'maxDelta should be larger than 0');
goog.DEBUG && console.assert(maxDelta > 0, 'maxDelta should be larger than 0');
var tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN];
var index = offset + stride;
while (index < end) {

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.flat.contains');
goog.require('goog.asserts');
goog.require('ol.extent');
@@ -65,7 +64,7 @@ ol.geom.flat.contains.linearRingContainsXY = function(flatCoordinates, offset, e
* @return {boolean} Contains (x, y).
*/
ol.geom.flat.contains.linearRingsContainsXY = function(flatCoordinates, offset, ends, stride, x, y) {
goog.asserts.assert(ends.length > 0, 'ends should not be an empty array');
goog.DEBUG && console.assert(ends.length > 0, 'ends should not be an empty array');
if (ends.length === 0) {
return false;
}
@@ -94,7 +93,7 @@ ol.geom.flat.contains.linearRingsContainsXY = function(flatCoordinates, offset,
* @return {boolean} Contains (x, y).
*/
ol.geom.flat.contains.linearRingssContainsXY = function(flatCoordinates, offset, endss, stride, x, y) {
goog.asserts.assert(endss.length > 0, 'endss should not be an empty array');
goog.DEBUG && console.assert(endss.length > 0, 'endss should not be an empty array');
if (endss.length === 0) {
return false;
}

View File

@@ -1,7 +1,5 @@
goog.provide('ol.geom.flat.deflate');
goog.require('goog.asserts');
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
@@ -11,7 +9,7 @@ goog.require('goog.asserts');
* @return {number} offset Offset.
*/
ol.geom.flat.deflate.coordinate = function(flatCoordinates, offset, coordinate, stride) {
goog.asserts.assert(coordinate.length == stride,
goog.DEBUG && console.assert(coordinate.length == stride,
'length of the coordinate array should match stride');
var i, ii;
for (i = 0, ii = coordinate.length; i < ii; ++i) {
@@ -32,7 +30,7 @@ ol.geom.flat.deflate.coordinates = function(flatCoordinates, offset, coordinates
var i, ii;
for (i = 0, ii = coordinates.length; i < ii; ++i) {
var coordinate = coordinates[i];
goog.asserts.assert(coordinate.length == stride,
goog.DEBUG && console.assert(coordinate.length == stride,
'length of coordinate array should match stride');
var j;
for (j = 0; j < stride; ++j) {

View File

@@ -1,7 +1,5 @@
goog.provide('ol.geom.flat.flip');
goog.require('goog.asserts');
/**
* @param {Array.<number>} flatCoordinates Flat coordinates.
@@ -18,8 +16,6 @@ ol.geom.flat.flip.flipXY = function(flatCoordinates, offset, end, stride, opt_de
dest = opt_dest;
destOffset = opt_destOffset !== undefined ? opt_destOffset : 0;
} else {
goog.asserts.assert(opt_destOffset === undefined,
'opt_destOffSet should be defined');
dest = [];
destOffset = 0;
}

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.flat.geodesic');
goog.require('goog.asserts');
goog.require('ol.math');
goog.require('ol.proj');
@@ -65,7 +64,7 @@ ol.geom.flat.geodesic.line_ = function(interpolate, transform, squaredTolerance)
// segment.
flatCoordinates.push(b[0], b[1]);
key = fracB.toString();
goog.asserts.assert(!(key in fractions),
goog.DEBUG && console.assert(!(key in fractions),
'fractions object should contain key : ' + key);
fractions[key] = true;
} else {
@@ -76,7 +75,7 @@ ol.geom.flat.geodesic.line_ = function(interpolate, transform, squaredTolerance)
geoStack.push(geoB, geoM, geoM, geoA);
}
}
goog.asserts.assert(maxIterations > 0,
goog.DEBUG && console.assert(maxIterations > 0,
'maxIterations should be more than 0');
return flatCoordinates;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.flat.interiorpoint');
goog.require('goog.asserts');
goog.require('ol.array');
goog.require('ol.geom.flat.contains');
@@ -79,7 +78,7 @@ ol.geom.flat.interiorpoint.linearRings = function(flatCoordinates, offset,
* @return {Array.<number>} Interior points.
*/
ol.geom.flat.interiorpoint.linearRingss = function(flatCoordinates, offset, endss, stride, flatCenters) {
goog.asserts.assert(2 * endss.length == flatCenters.length,
goog.DEBUG && console.assert(2 * endss.length == flatCenters.length,
'endss.length times 2 should be flatCenters.length');
var interiorPoints = [];
var i, ii;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.flat.interpolate');
goog.require('goog.asserts');
goog.require('ol.array');
goog.require('ol.math');
@@ -17,13 +16,13 @@ goog.require('ol.math');
ol.geom.flat.interpolate.lineString = function(flatCoordinates, offset, end, stride, fraction, opt_dest) {
// FIXME does not work when vertices are repeated
// FIXME interpolate extra dimensions
goog.asserts.assert(0 <= fraction && fraction <= 1,
goog.DEBUG && console.assert(0 <= fraction && fraction <= 1,
'fraction should be in between 0 and 1');
var pointX = NaN;
var pointY = NaN;
var n = (end - offset) / stride;
if (n === 0) {
goog.asserts.fail('n cannot be 0');
goog.DEBUG && console.assert(false, 'n cannot be 0');
} else if (n == 1) {
pointX = flatCoordinates[offset];
pointY = flatCoordinates[offset + 1];
@@ -121,8 +120,8 @@ ol.geom.flat.lineStringCoordinateAtM = function(flatCoordinates, offset, end, st
return flatCoordinates.slice((lo - 1) * stride, (lo - 1) * stride + stride);
}
var m1 = flatCoordinates[(lo + 1) * stride - 1];
goog.asserts.assert(m0 < m, 'm0 should be less than m');
goog.asserts.assert(m <= m1, 'm should be less than or equal to m1');
goog.DEBUG && console.assert(m0 < m, 'm0 should be less than m');
goog.DEBUG && console.assert(m <= m1, 'm should be less than or equal to m1');
var t = (m - m0) / (m1 - m0);
coordinate = [];
var i;
@@ -131,7 +130,7 @@ ol.geom.flat.lineStringCoordinateAtM = function(flatCoordinates, offset, end, st
flatCoordinates[lo * stride + i], t));
}
coordinate.push(m);
goog.asserts.assert(coordinate.length == stride,
goog.DEBUG && console.assert(coordinate.length == stride,
'length of coordinate array should match stride');
return coordinate;
};
@@ -186,7 +185,7 @@ ol.geom.flat.lineStringsCoordinateAtM = function(
}
offset = end;
}
goog.asserts.fail(
goog.DEBUG && console.assert(false,
'ol.geom.flat.lineStringsCoordinateAtM should have returned');
return null;
};

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.flat.intersectsextent');
goog.require('goog.asserts');
goog.require('ol.extent');
goog.require('ol.geom.flat.contains');
goog.require('ol.geom.flat.segments');
@@ -107,7 +106,7 @@ ol.geom.flat.intersectsextent.linearRing = function(flatCoordinates, offset, end
* @return {boolean} True if the geometry and the extent intersect.
*/
ol.geom.flat.intersectsextent.linearRings = function(flatCoordinates, offset, ends, stride, extent) {
goog.asserts.assert(ends.length > 0, 'ends should not be an empty array');
goog.DEBUG && console.assert(ends.length > 0, 'ends should not be an empty array');
if (!ol.geom.flat.intersectsextent.linearRing(
flatCoordinates, offset, ends[0], stride, extent)) {
return false;
@@ -135,7 +134,7 @@ ol.geom.flat.intersectsextent.linearRings = function(flatCoordinates, offset, en
* @return {boolean} True if the geometry and the extent intersect.
*/
ol.geom.flat.intersectsextent.linearRingss = function(flatCoordinates, offset, endss, stride, extent) {
goog.asserts.assert(endss.length > 0, 'endss should not be an empty array');
goog.DEBUG && console.assert(endss.length > 0, 'endss should not be an empty array');
var i, ii;
for (i = 0, ii = endss.length; i < ii; ++i) {
var ends = endss[i];

View File

@@ -2,7 +2,6 @@ goog.provide('ol.geom.Geometry');
goog.provide('ol.geom.GeometryLayout');
goog.provide('ol.geom.GeometryType');
goog.require('goog.asserts');
goog.require('ol.functions');
goog.require('ol.Object');
goog.require('ol.extent');
@@ -276,7 +275,7 @@ ol.geom.Geometry.prototype.translate = function(deltaX, deltaY) {};
* @api stable
*/
ol.geom.Geometry.prototype.transform = function(source, destination) {
goog.asserts.assert(
goog.DEBUG && console.assert(
ol.proj.get(source).getUnits() !== ol.proj.Units.TILE_PIXELS &&
ol.proj.get(destination).getUnits() !== ol.proj.Units.TILE_PIXELS,
'cannot transform geometries with TILE_PIXELS units');

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.LineString');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent');
@@ -67,7 +66,7 @@ ol.inherits(ol.geom.LineString, ol.geom.SimpleGeometry);
* @api stable
*/
ol.geom.LineString.prototype.appendCoordinate = function(coordinate) {
goog.asserts.assert(coordinate.length == this.stride,
goog.DEBUG && console.assert(coordinate.length == this.stride,
'length of coordinate array should match stride');
if (!this.flatCoordinates) {
this.flatCoordinates = coordinate.slice();

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.MultiLineString');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent');
@@ -60,7 +59,7 @@ ol.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
* @api stable
*/
ol.geom.MultiLineString.prototype.appendLineString = function(lineString) {
goog.asserts.assert(lineString.getLayout() == this.layout,
goog.DEBUG && console.assert(lineString.getLayout() == this.layout,
'layout of lineString should match the layout');
if (!this.flatCoordinates) {
this.flatCoordinates = lineString.getFlatCoordinates().slice();
@@ -166,7 +165,7 @@ ol.geom.MultiLineString.prototype.getEnds = function() {
* @api stable
*/
ol.geom.MultiLineString.prototype.getLineString = function(index) {
goog.asserts.assert(0 <= index && index < this.ends_.length,
goog.DEBUG && console.assert(0 <= index && index < this.ends_.length,
'index should be in between 0 and length of the this.ends_ array');
if (index < 0 || this.ends_.length <= index) {
return null;
@@ -287,13 +286,13 @@ ol.geom.MultiLineString.prototype.setCoordinates = function(coordinates, opt_lay
*/
ol.geom.MultiLineString.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
if (!flatCoordinates) {
goog.asserts.assert(ends && ends.length === 0,
goog.DEBUG && console.assert(ends && ends.length === 0,
'ends must be truthy and ends.length should be 0');
} else if (ends.length === 0) {
goog.asserts.assert(flatCoordinates.length === 0,
goog.DEBUG && console.assert(flatCoordinates.length === 0,
'flatCoordinates should be an empty array');
} else {
goog.asserts.assert(flatCoordinates.length == ends[ends.length - 1],
goog.DEBUG && console.assert(flatCoordinates.length == ends[ends.length - 1],
'length of flatCoordinates array should match the last value of ends');
}
this.setFlatCoordinatesInternal(layout, flatCoordinates);
@@ -316,7 +315,7 @@ ol.geom.MultiLineString.prototype.setLineStrings = function(lineStrings) {
layout = lineString.getLayout();
} else {
// FIXME better handle the case of non-matching layouts
goog.asserts.assert(lineString.getLayout() == layout,
goog.DEBUG && console.assert(lineString.getLayout() == layout,
'layout of lineString should match layout');
}
ol.array.extend(flatCoordinates, lineString.getFlatCoordinates());

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.MultiPoint');
goog.require('goog.asserts');
goog.require('ol.array');
goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout');
@@ -35,7 +34,7 @@ ol.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry);
* @api stable
*/
ol.geom.MultiPoint.prototype.appendPoint = function(point) {
goog.asserts.assert(point.getLayout() == this.layout,
goog.DEBUG && console.assert(point.getLayout() == this.layout,
'the layout of point should match layout');
if (!this.flatCoordinates) {
this.flatCoordinates = point.getFlatCoordinates().slice();
@@ -104,7 +103,7 @@ ol.geom.MultiPoint.prototype.getCoordinates = function() {
ol.geom.MultiPoint.prototype.getPoint = function(index) {
var n = !this.flatCoordinates ?
0 : this.flatCoordinates.length / this.stride;
goog.asserts.assert(0 <= index && index < n,
goog.DEBUG && console.assert(0 <= index && index < n,
'index should be in between 0 and n');
if (index < 0 || n <= index) {
return null;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.MultiPolygon');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent');
@@ -89,7 +88,7 @@ ol.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry);
* @api stable
*/
ol.geom.MultiPolygon.prototype.appendPolygon = function(polygon) {
goog.asserts.assert(polygon.getLayout() == this.layout,
goog.DEBUG && console.assert(polygon.getLayout() == this.layout,
'layout of polygon should match layout');
/** @type {Array.<number>} */
var ends;
@@ -280,7 +279,7 @@ ol.geom.MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredT
* @api stable
*/
ol.geom.MultiPolygon.prototype.getPolygon = function(index) {
goog.asserts.assert(0 <= index && index < this.endss_.length,
goog.DEBUG && console.assert(0 <= index && index < this.endss_.length,
'index should be in between 0 and the length of this.endss_');
if (index < 0 || this.endss_.length <= index) {
return null;
@@ -390,13 +389,13 @@ ol.geom.MultiPolygon.prototype.setCoordinates = function(coordinates, opt_layout
* @param {Array.<Array.<number>>} endss Endss.
*/
ol.geom.MultiPolygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, endss) {
goog.asserts.assert(endss, 'endss must be truthy');
goog.DEBUG && console.assert(endss, 'endss must be truthy');
if (!flatCoordinates || flatCoordinates.length === 0) {
goog.asserts.assert(endss.length === 0, 'the length of endss should be 0');
goog.DEBUG && console.assert(endss.length === 0, 'the length of endss should be 0');
} else {
goog.asserts.assert(endss.length > 0, 'endss cannot be an empty array');
goog.DEBUG && console.assert(endss.length > 0, 'endss cannot be an empty array');
var ends = endss[endss.length - 1];
goog.asserts.assert(flatCoordinates.length == ends[ends.length - 1],
goog.DEBUG && console.assert(flatCoordinates.length == ends[ends.length - 1],
'the length of flatCoordinates should be the last value of ends');
}
this.setFlatCoordinatesInternal(layout, flatCoordinates);
@@ -419,7 +418,7 @@ ol.geom.MultiPolygon.prototype.setPolygons = function(polygons) {
layout = polygon.getLayout();
} else {
// FIXME better handle the case of non-matching layouts
goog.asserts.assert(polygon.getLayout() == layout,
goog.DEBUG && console.assert(polygon.getLayout() == layout,
'layout of polygon should be layout');
}
var offset = flatCoordinates.length;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.Polygon');
goog.require('goog.asserts');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent');
@@ -89,7 +88,7 @@ ol.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
* @api stable
*/
ol.geom.Polygon.prototype.appendLinearRing = function(linearRing) {
goog.asserts.assert(linearRing.getLayout() == this.layout,
goog.DEBUG && console.assert(linearRing.getLayout() == this.layout,
'layout of linearRing should match layout');
if (!this.flatCoordinates) {
this.flatCoordinates = linearRing.getFlatCoordinates().slice();
@@ -237,7 +236,7 @@ ol.geom.Polygon.prototype.getLinearRingCount = function() {
* @api stable
*/
ol.geom.Polygon.prototype.getLinearRing = function(index) {
goog.asserts.assert(0 <= index && index < this.ends_.length,
goog.DEBUG && console.assert(0 <= index && index < this.ends_.length,
'index should be in between 0 and and length of this.ends_');
if (index < 0 || this.ends_.length <= index) {
return null;
@@ -358,13 +357,13 @@ ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
*/
ol.geom.Polygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
if (!flatCoordinates) {
goog.asserts.assert(ends && ends.length === 0,
goog.DEBUG && console.assert(ends && ends.length === 0,
'ends must be an empty array');
} else if (ends.length === 0) {
goog.asserts.assert(flatCoordinates.length === 0,
goog.DEBUG && console.assert(flatCoordinates.length === 0,
'flatCoordinates should be an empty array');
} else {
goog.asserts.assert(flatCoordinates.length == ends[ends.length - 1],
goog.DEBUG && console.assert(flatCoordinates.length == ends[ends.length - 1],
'the length of flatCoordinates should be the last entry of ends');
}
this.setFlatCoordinatesInternal(layout, flatCoordinates);
@@ -461,7 +460,7 @@ ol.geom.Polygon.makeRegular = function(polygon, center, radius, opt_angle) {
var layout = polygon.getLayout();
var stride = polygon.getStride();
var ends = polygon.getEnds();
goog.asserts.assert(ends.length === 1, 'only 1 ring is supported');
goog.DEBUG && console.assert(ends.length === 1, 'only 1 ring is supported');
var sides = flatCoordinates.length / stride - 1;
var startAngle = opt_angle ? opt_angle : 0;
var angle, offset;

View File

@@ -1,6 +1,5 @@
goog.provide('ol.geom.SimpleGeometry');
goog.require('goog.asserts');
goog.require('ol.functions');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
@@ -50,15 +49,16 @@ ol.inherits(ol.geom.SimpleGeometry, ol.geom.Geometry);
* @return {ol.geom.GeometryLayout} layout Layout.
*/
ol.geom.SimpleGeometry.getLayoutForStride_ = function(stride) {
var layout;
if (stride == 2) {
return ol.geom.GeometryLayout.XY;
layout = ol.geom.GeometryLayout.XY;
} else if (stride == 3) {
return ol.geom.GeometryLayout.XYZ;
layout = ol.geom.GeometryLayout.XYZ;
} else if (stride == 4) {
return ol.geom.GeometryLayout.XYZM;
} else {
goog.asserts.fail('unsupported stride: ' + stride);
layout = ol.geom.GeometryLayout.XYZM;
}
goog.DEBUG && console.assert(layout, 'unsupported stride: ' + stride);
return /** @type {ol.geom.GeometryLayout} */ (layout);
};
@@ -67,17 +67,16 @@ ol.geom.SimpleGeometry.getLayoutForStride_ = function(stride) {
* @return {number} Stride.
*/
ol.geom.SimpleGeometry.getStrideForLayout = function(layout) {
var stride;
if (layout == ol.geom.GeometryLayout.XY) {
return 2;
} else if (layout == ol.geom.GeometryLayout.XYZ) {
return 3;
} else if (layout == ol.geom.GeometryLayout.XYM) {
return 3;
stride = 2;
} else if (layout == ol.geom.GeometryLayout.XYZ || layout == ol.geom.GeometryLayout.XYM) {
stride = 3;
} else if (layout == ol.geom.GeometryLayout.XYZM) {
return 4;
} else {
goog.asserts.fail('unsupported layout: ' + layout);
stride = 4;
}
goog.DEBUG && console.assert(stride, 'unsupported layout: ' + layout);
return /** @type {number} */ (stride);
};