Skip to content

Commit

Permalink
Enable no-lonely-if style rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviohartman committed Jun 16, 2017
1 parent 87952c0 commit a5adfa7
Show file tree
Hide file tree
Showing 21 changed files with 217 additions and 262 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./Tools/eslint-config-cesium/browser.js",
"rules": {
"no-lonely-if": "error",
"no-unused-vars": ["error", {"vars": "all", "args": "none"}]
}
}
8 changes: 3 additions & 5 deletions Source/Core/Cartesian3.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,10 @@ define([
} else {
result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
}
} else if (f.y <= f.z) {
result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
} else {
if (f.y <= f.z) {
result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
} else {
result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
}
result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
}

return result;
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/GoogleEarthEnterpriseMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,8 @@ define([
if (!isBitSet(x, bitmask)) { // Right to left
digit |= 1;
}
} else {
if (isBitSet(x, bitmask)) { // Left to right
digit |= 1;
}
} else if (isBitSet(x, bitmask)) { // Left to right
digit |= 1;
}

quadkey += digit;
Expand Down
10 changes: 4 additions & 6 deletions Source/Core/TimeIntervalCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,15 @@ define([
index = binarySearch(intervals, interval, compareIntervalStartTimes);
if (index < 0) {
index = ~index;
} else {
} else if (index > 0 && interval.isStartIncluded && intervals[index - 1].isStartIncluded && intervals[index - 1].start.equals(interval.start)) {
// interval's start date exactly equals the start date of at least one interval in the collection.
// It could actually equal the start date of two intervals if one of them does not actually
// include the date. In that case, the binary search could have found either. We need to
// look at the surrounding intervals and their IsStartIncluded properties in order to make sure
// we're working with the correct interval.
if (index > 0 && interval.isStartIncluded && intervals[index - 1].isStartIncluded && intervals[index - 1].start.equals(interval.start)) {
--index;
} else if (index < intervals.length && !interval.isStartIncluded && intervals[index].isStartIncluded && intervals[index].start.equals(interval.start)) {
++index;
}
--index;
} else if (index < intervals.length && !interval.isStartIncluded && intervals[index].isStartIncluded && intervals[index].start.equals(interval.start)) {
++index;
}

if (index > 0) {
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/loadKTX.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ define([
if (numberOfMipmapLevels === 0) {
throw new RuntimeError('Generating mipmaps for a compressed texture is unsupported.');
}
} else {
if (glBaseInternalFormat !== glFormat) {
throw new RuntimeError('The base internal format must be the same as the format for uncompressed textures.');
}
} else if (glBaseInternalFormat !== glFormat) {
throw new RuntimeError('The base internal format must be the same as the format for uncompressed textures.');
}

if (pixelDepth !== 0) {
Expand Down
20 changes: 8 additions & 12 deletions Source/DataSources/GeometryVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,16 @@ define([
if (updater.fillEnabled) {
if (updater.onTerrain) {
that._groundColorBatch.add(time, updater);
} else {
if (updater.isClosed) {
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
that._closedColorBatches[index].add(time, updater);
} else {
that._closedMaterialBatches[index].add(time, updater);
}
} else if (updater.isClosed) {
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
that._closedColorBatches[index].add(time, updater);
} else {
if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
that._openColorBatches[index].add(time, updater);
} else {
that._openMaterialBatches[index].add(time, updater);
}
that._closedMaterialBatches[index].add(time, updater);
}
} else if (updater.fillMaterialProperty instanceof ColorMaterialProperty) {
that._openColorBatches[index].add(time, updater);
} else {
that._openMaterialBatches[index].add(time, updater);
}
}
}
Expand Down
44 changes: 20 additions & 24 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,25 +1184,23 @@ define([
} else if (defined(polygon)) {
wall.outlineColor = defined(polygon.material) ? polygon.material.color : Color.WHITE;
}
} else {
if (dataSource._clampToGround && !canExtrude && tessellate) {
var corridor = new CorridorGraphics();
entity.corridor = corridor;
corridor.positions = coordinates;
if (defined(polyline)) {
corridor.material = defined(polyline.material) ? polyline.material.color.getValue(Iso8601.MINIMUM_VALUE) : Color.WHITE;
corridor.width = defaultValue(polyline.width, 1.0);
} else {
corridor.material = Color.WHITE;
corridor.width = 1.0;
}
} else if (dataSource._clampToGround && !canExtrude && tessellate) {
var corridor = new CorridorGraphics();
entity.corridor = corridor;
corridor.positions = coordinates;
if (defined(polyline)) {
corridor.material = defined(polyline.material) ? polyline.material.color.getValue(Iso8601.MINIMUM_VALUE) : Color.WHITE;
corridor.width = defaultValue(polyline.width, 1.0);
} else {
polyline = defined(polyline) ? polyline.clone() : new PolylineGraphics();
entity.polyline = polyline;
polyline.positions = createPositionPropertyArrayFromAltitudeMode(coordinates, altitudeMode, gxAltitudeMode);
if (!tessellate || canExtrude) {
polyline.followSurface = false;
}
corridor.material = Color.WHITE;
corridor.width = 1.0;
}
} else {
polyline = defined(polyline) ? polyline.clone() : new PolylineGraphics();
entity.polyline = polyline;
polyline.positions = createPositionPropertyArrayFromAltitudeMode(coordinates, altitudeMode, gxAltitudeMode);
if (!tessellate || canExtrude) {
polyline.followSurface = false;
}
}

Expand Down Expand Up @@ -2052,13 +2050,11 @@ define([
} else {
console.log('KML - refreshMode of onExpire requires the NetworkLinkControl to have an expires element');
}
} else if (dataSource._camera) { // Only allow onStop refreshes if we have a camera
networkLinkInfo.refreshMode = RefreshMode.STOP;
networkLinkInfo.time = defaultValue(queryNumericValue(link, 'viewRefreshTime', namespaces.kml), 0);
} else {
if (dataSource._camera) { // Only allow onStop refreshes if we have a camera
networkLinkInfo.refreshMode = RefreshMode.STOP;
networkLinkInfo.time = defaultValue(queryNumericValue(link, 'viewRefreshTime', namespaces.kml), 0);
} else {
console.log('A NetworkLink with viewRefreshMode=onStop requires a camera be passed in when creating the KmlDataSource');
}
console.log('A NetworkLink with viewRefreshMode=onStop requires a camera be passed in when creating the KmlDataSource');
}

if (defined(networkLinkInfo.refreshMode)) {
Expand Down
118 changes: 58 additions & 60 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,85 +1355,83 @@ define([
}

this._billboardsToUpdateIndex = 0;
} else {
} else if (billboardsToUpdateLength > 0) {
// Billboards were modified, but none were added or removed.
if (billboardsToUpdateLength > 0) {
var writers = scratchWriterArray;
writers.length = 0;
var writers = scratchWriterArray;
writers.length = 0;

if (properties[POSITION_INDEX] || properties[ROTATION_INDEX] || properties[SCALE_INDEX]) {
writers.push(writePositionScaleAndRotation);
}
if (properties[POSITION_INDEX] || properties[ROTATION_INDEX] || properties[SCALE_INDEX]) {
writers.push(writePositionScaleAndRotation);
}

if (properties[IMAGE_INDEX_INDEX] || properties[PIXEL_OFFSET_INDEX] || properties[HORIZONTAL_ORIGIN_INDEX] || properties[VERTICAL_ORIGIN_INDEX] || properties[SHOW_INDEX]) {
writers.push(writeCompressedAttrib0);
if (this._instanced) {
writers.push(writeEyeOffset);
}
if (properties[IMAGE_INDEX_INDEX] || properties[PIXEL_OFFSET_INDEX] || properties[HORIZONTAL_ORIGIN_INDEX] || properties[VERTICAL_ORIGIN_INDEX] || properties[SHOW_INDEX]) {
writers.push(writeCompressedAttrib0);
if (this._instanced) {
writers.push(writeEyeOffset);
}
}

if (properties[IMAGE_INDEX_INDEX] || properties[ALIGNED_AXIS_INDEX] || properties[TRANSLUCENCY_BY_DISTANCE_INDEX]) {
writers.push(writeCompressedAttrib1);
writers.push(writeCompressedAttrib2);
}
if (properties[IMAGE_INDEX_INDEX] || properties[ALIGNED_AXIS_INDEX] || properties[TRANSLUCENCY_BY_DISTANCE_INDEX]) {
writers.push(writeCompressedAttrib1);
writers.push(writeCompressedAttrib2);
}

if (properties[IMAGE_INDEX_INDEX] || properties[COLOR_INDEX]) {
writers.push(writeCompressedAttrib2);
}
if (properties[IMAGE_INDEX_INDEX] || properties[COLOR_INDEX]) {
writers.push(writeCompressedAttrib2);
}

if (properties[EYE_OFFSET_INDEX]) {
writers.push(writeEyeOffset);
}
if (properties[EYE_OFFSET_INDEX]) {
writers.push(writeEyeOffset);
}

if (properties[SCALE_BY_DISTANCE_INDEX]) {
writers.push(writeScaleByDistance);
}
if (properties[SCALE_BY_DISTANCE_INDEX]) {
writers.push(writeScaleByDistance);
}

if (properties[PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX]) {
writers.push(writePixelOffsetScaleByDistance);
}
if (properties[PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX]) {
writers.push(writePixelOffsetScaleByDistance);
}

if (properties[DISTANCE_DISPLAY_CONDITION_INDEX] || properties[DISABLE_DEPTH_DISTANCE]) {
writers.push(writeDistanceDisplayConditionAndDepthDisable);
}
if (properties[DISTANCE_DISPLAY_CONDITION_INDEX] || properties[DISABLE_DEPTH_DISTANCE]) {
writers.push(writeDistanceDisplayConditionAndDepthDisable);
}

var numWriters = writers.length;
vafWriters = this._vaf.writers;
var numWriters = writers.length;
vafWriters = this._vaf.writers;

if ((billboardsToUpdateLength / billboardsLength) > 0.1) {
// If more than 10% of billboard change, rewrite the entire buffer.
if ((billboardsToUpdateLength / billboardsLength) > 0.1) {
// If more than 10% of billboard change, rewrite the entire buffer.

// PERFORMANCE_IDEA: I totally made up 10% :).
// PERFORMANCE_IDEA: I totally made up 10% :).

for (var m = 0; m < billboardsToUpdateLength; ++m) {
var b = billboardsToUpdate[m];
b._dirty = false;
for (var m = 0; m < billboardsToUpdateLength; ++m) {
var b = billboardsToUpdate[m];
b._dirty = false;

for ( var n = 0; n < numWriters; ++n) {
writers[n](this, context, textureAtlasCoordinates, vafWriters, b);
}
}
this._vaf.commit(getIndexBuffer(context));
} else {
for (var h = 0; h < billboardsToUpdateLength; ++h) {
var bb = billboardsToUpdate[h];
bb._dirty = false;

for ( var o = 0; o < numWriters; ++o) {
writers[o](this, context, textureAtlasCoordinates, vafWriters, bb);
}

if (this._instanced) {
this._vaf.subCommit(bb._index, 1);
} else {
this._vaf.subCommit(bb._index * 4, 4);
}
for ( var n = 0; n < numWriters; ++n) {
writers[n](this, context, textureAtlasCoordinates, vafWriters, b);
}
this._vaf.endSubCommits();
}
this._vaf.commit(getIndexBuffer(context));
} else {
for (var h = 0; h < billboardsToUpdateLength; ++h) {
var bb = billboardsToUpdate[h];
bb._dirty = false;

for ( var o = 0; o < numWriters; ++o) {
writers[o](this, context, textureAtlasCoordinates, vafWriters, bb);
}

this._billboardsToUpdateIndex = 0;
if (this._instanced) {
this._vaf.subCommit(bb._index, 1);
} else {
this._vaf.subCommit(bb._index * 4, 4);
}
}
this._vaf.endSubCommits();
}

this._billboardsToUpdateIndex = 0;
}

// If the number of total billboards ever shrinks considerably
Expand Down
6 changes: 2 additions & 4 deletions Source/Scene/GroundPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,8 @@ define([
var instanceRectangle = getRectangle(frameState, geometry);
if (!defined(rectangle)) {
rectangle = instanceRectangle;
} else {
if (defined(instanceRectangle)) {
Rectangle.union(rectangle, instanceRectangle, rectangle);
}
} else if (defined(instanceRectangle)) {
Rectangle.union(rectangle, instanceRectangle, rectangle);
}

var id = instance.id;
Expand Down
6 changes: 2 additions & 4 deletions Source/Scene/LabelCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ define([
// no texture, and therefore no billboard, for this glyph.
// so, completely unbind glyph.
unbindGlyph(labelCollection, glyph);
} else {
} else if (defined(glyph.textureInfo)) {
// we have a texture and billboard. If we had one before, release
// our reference to that texture info, but reuse the billboard.
if (defined(glyph.textureInfo)) {
glyph.textureInfo = undefined;
}
glyph.textureInfo = undefined;
}
} else {
// create a glyph object
Expand Down
16 changes: 7 additions & 9 deletions Source/Scene/ModelAnimationCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,15 @@ define([
frameState.afterRender.push(scheduledAnimation._raiseUpdateEvent);
}
animationOccured = true;
} else {
} else if (pastStartTime && (scheduledAnimation._state === ModelAnimationState.ANIMATING)) {
// ANIMATING -> STOPPED state transition?
if (pastStartTime && (scheduledAnimation._state === ModelAnimationState.ANIMATING)) {
scheduledAnimation._state = ModelAnimationState.STOPPED;
if (scheduledAnimation.stop.numberOfListeners > 0) {
frameState.afterRender.push(scheduledAnimation._raiseStopEvent);
}
scheduledAnimation._state = ModelAnimationState.STOPPED;
if (scheduledAnimation.stop.numberOfListeners > 0) {
frameState.afterRender.push(scheduledAnimation._raiseStopEvent);
}

if (scheduledAnimation.removeOnStop) {
animationsToRemove.push(scheduledAnimation);
}
if (scheduledAnimation.removeOnStop) {
animationsToRemove.push(scheduledAnimation);
}
}
}
Expand Down
Loading

0 comments on commit a5adfa7

Please sign in to comment.