Don't attempt to constrain values in setters

This commit is contained in:
Tom Payne
2013-06-19 13:38:57 +02:00
parent bf9b0b4dd2
commit aa1a71ed96
2 changed files with 11 additions and 58 deletions

View File

@@ -122,13 +122,13 @@ ol.layer.Layer.prototype.getLayerState = function() {
var saturation = this.getSaturation();
var visible = this.getVisible();
return {
brightness: goog.isDef(brightness) ? brightness : 0,
contrast: goog.isDef(contrast) ? contrast : 1,
brightness: goog.isDef(brightness) ? goog.math.clamp(brightness, -1, 1) : 0,
contrast: goog.isDef(contrast) ? Math.max(contrast, 0) : 1,
hue: goog.isDef(hue) ? hue : 0,
opacity: goog.isDef(opacity) ? opacity : 1,
opacity: goog.isDef(opacity) ? goog.math.clamp(opacity, 0, 1) : 1,
ready: ready,
saturation: goog.isDef(saturation) ? saturation : 1,
visible: goog.isDef(visible) ? visible : true
saturation: goog.isDef(saturation) ? Math.max(saturation, 0) : 1,
visible: goog.isDef(visible) ? !!visible : true
};
};
@@ -214,10 +214,7 @@ ol.layer.Layer.prototype.isReady = function() {
* @param {number} brightness Brightness.
*/
ol.layer.Layer.prototype.setBrightness = function(brightness) {
brightness = goog.math.clamp(brightness, -1, 1);
if (brightness != this.getBrightness()) {
this.set(ol.layer.LayerProperty.BRIGHTNESS, brightness);
}
this.set(ol.layer.LayerProperty.BRIGHTNESS, brightness);
};
goog.exportProperty(
ol.layer.Layer.prototype,
@@ -233,10 +230,7 @@ goog.exportProperty(
* @param {number} contrast Contrast.
*/
ol.layer.Layer.prototype.setContrast = function(contrast) {
contrast = Math.max(0, contrast);
if (contrast != this.getContrast()) {
this.set(ol.layer.LayerProperty.CONTRAST, contrast);
}
this.set(ol.layer.LayerProperty.CONTRAST, contrast);
};
goog.exportProperty(
ol.layer.Layer.prototype,
@@ -250,9 +244,7 @@ goog.exportProperty(
* @param {number} hue Hue.
*/
ol.layer.Layer.prototype.setHue = function(hue) {
if (hue != this.getHue()) {
this.set(ol.layer.LayerProperty.HUE, hue);
}
this.set(ol.layer.LayerProperty.HUE, hue);
};
goog.exportProperty(
ol.layer.Layer.prototype,
@@ -264,10 +256,7 @@ goog.exportProperty(
* @param {number} opacity Opacity.
*/
ol.layer.Layer.prototype.setOpacity = function(opacity) {
opacity = goog.math.clamp(opacity, 0, 1);
if (opacity != this.getOpacity()) {
this.set(ol.layer.LayerProperty.OPACITY, opacity);
}
this.set(ol.layer.LayerProperty.OPACITY, opacity);
};
goog.exportProperty(
ol.layer.Layer.prototype,
@@ -284,10 +273,7 @@ goog.exportProperty(
* @param {number} saturation Saturation.
*/
ol.layer.Layer.prototype.setSaturation = function(saturation) {
saturation = Math.max(0, saturation);
if (saturation != this.getSaturation()) {
this.set(ol.layer.LayerProperty.SATURATION, saturation);
}
this.set(ol.layer.LayerProperty.SATURATION, saturation);
};
goog.exportProperty(
ol.layer.Layer.prototype,
@@ -299,10 +285,7 @@ goog.exportProperty(
* @param {boolean} visible Visible.
*/
ol.layer.Layer.prototype.setVisible = function(visible) {
visible = !!visible;
if (visible != this.getVisible()) {
this.set(ol.layer.LayerProperty.VISIBLE, visible);
}
this.set(ol.layer.LayerProperty.VISIBLE, visible);
};
goog.exportProperty(
ol.layer.Layer.prototype,

View File

@@ -101,16 +101,6 @@ describe('ol.layer.Layer', function() {
expect(layer.getBrightness()).to.be(-0.7);
});
it('clamps to 1', function() {
layer.setBrightness(1.5);
expect(layer.getBrightness()).to.be(1);
});
it('clamps to -1', function() {
layer.setBrightness(-3);
expect(layer.getBrightness()).to.be(-1);
});
});
describe('#setContrast', function() {
@@ -134,11 +124,6 @@ describe('ol.layer.Layer', function() {
expect(layer.getContrast()).to.be(0.3);
});
it('clamps to 0', function() {
layer.setContrast(-0.7);
expect(layer.getContrast()).to.be(0);
});
it('accepts a big positive number', function() {
layer.setContrast(42);
expect(layer.getContrast()).to.be(42);
@@ -207,16 +192,6 @@ describe('ol.layer.Layer', function() {
expect(layer.getOpacity()).to.be(0.3);
});
it('clamps to 0', function() {
layer.setOpacity(-1.5);
expect(layer.getOpacity()).to.be(0);
});
it('clamps to 1', function() {
layer.setOpacity(3);
expect(layer.getOpacity()).to.be(1);
});
});
@@ -241,11 +216,6 @@ describe('ol.layer.Layer', function() {
expect(layer.getSaturation()).to.be(0.3);
});
it('clamps to 0', function() {
layer.setSaturation(-0.7);
expect(layer.getSaturation()).to.be(0);
});
it('accepts a big positive number', function() {
layer.setSaturation(42);
expect(layer.getSaturation()).to.be(42);