Don't attempt to constrain values in setters
This commit is contained in:
+11
-28
@@ -122,13 +122,13 @@ ol.layer.Layer.prototype.getLayerState = function() {
|
|||||||
var saturation = this.getSaturation();
|
var saturation = this.getSaturation();
|
||||||
var visible = this.getVisible();
|
var visible = this.getVisible();
|
||||||
return {
|
return {
|
||||||
brightness: goog.isDef(brightness) ? brightness : 0,
|
brightness: goog.isDef(brightness) ? goog.math.clamp(brightness, -1, 1) : 0,
|
||||||
contrast: goog.isDef(contrast) ? contrast : 1,
|
contrast: goog.isDef(contrast) ? Math.max(contrast, 0) : 1,
|
||||||
hue: goog.isDef(hue) ? hue : 0,
|
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,
|
ready: ready,
|
||||||
saturation: goog.isDef(saturation) ? saturation : 1,
|
saturation: goog.isDef(saturation) ? Math.max(saturation, 0) : 1,
|
||||||
visible: goog.isDef(visible) ? visible : true
|
visible: goog.isDef(visible) ? !!visible : true
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -214,10 +214,7 @@ ol.layer.Layer.prototype.isReady = function() {
|
|||||||
* @param {number} brightness Brightness.
|
* @param {number} brightness Brightness.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.setBrightness = function(brightness) {
|
ol.layer.Layer.prototype.setBrightness = function(brightness) {
|
||||||
brightness = goog.math.clamp(brightness, -1, 1);
|
this.set(ol.layer.LayerProperty.BRIGHTNESS, brightness);
|
||||||
if (brightness != this.getBrightness()) {
|
|
||||||
this.set(ol.layer.LayerProperty.BRIGHTNESS, brightness);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Layer.prototype,
|
ol.layer.Layer.prototype,
|
||||||
@@ -233,10 +230,7 @@ goog.exportProperty(
|
|||||||
* @param {number} contrast Contrast.
|
* @param {number} contrast Contrast.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.setContrast = function(contrast) {
|
ol.layer.Layer.prototype.setContrast = function(contrast) {
|
||||||
contrast = Math.max(0, contrast);
|
this.set(ol.layer.LayerProperty.CONTRAST, contrast);
|
||||||
if (contrast != this.getContrast()) {
|
|
||||||
this.set(ol.layer.LayerProperty.CONTRAST, contrast);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Layer.prototype,
|
ol.layer.Layer.prototype,
|
||||||
@@ -250,9 +244,7 @@ goog.exportProperty(
|
|||||||
* @param {number} hue Hue.
|
* @param {number} hue Hue.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.setHue = function(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(
|
goog.exportProperty(
|
||||||
ol.layer.Layer.prototype,
|
ol.layer.Layer.prototype,
|
||||||
@@ -264,10 +256,7 @@ goog.exportProperty(
|
|||||||
* @param {number} opacity Opacity.
|
* @param {number} opacity Opacity.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.setOpacity = function(opacity) {
|
ol.layer.Layer.prototype.setOpacity = function(opacity) {
|
||||||
opacity = goog.math.clamp(opacity, 0, 1);
|
this.set(ol.layer.LayerProperty.OPACITY, opacity);
|
||||||
if (opacity != this.getOpacity()) {
|
|
||||||
this.set(ol.layer.LayerProperty.OPACITY, opacity);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Layer.prototype,
|
ol.layer.Layer.prototype,
|
||||||
@@ -284,10 +273,7 @@ goog.exportProperty(
|
|||||||
* @param {number} saturation Saturation.
|
* @param {number} saturation Saturation.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.setSaturation = function(saturation) {
|
ol.layer.Layer.prototype.setSaturation = function(saturation) {
|
||||||
saturation = Math.max(0, saturation);
|
this.set(ol.layer.LayerProperty.SATURATION, saturation);
|
||||||
if (saturation != this.getSaturation()) {
|
|
||||||
this.set(ol.layer.LayerProperty.SATURATION, saturation);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Layer.prototype,
|
ol.layer.Layer.prototype,
|
||||||
@@ -299,10 +285,7 @@ goog.exportProperty(
|
|||||||
* @param {boolean} visible Visible.
|
* @param {boolean} visible Visible.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.setVisible = function(visible) {
|
ol.layer.Layer.prototype.setVisible = function(visible) {
|
||||||
visible = !!visible;
|
this.set(ol.layer.LayerProperty.VISIBLE, visible);
|
||||||
if (visible != this.getVisible()) {
|
|
||||||
this.set(ol.layer.LayerProperty.VISIBLE, visible);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.layer.Layer.prototype,
|
ol.layer.Layer.prototype,
|
||||||
|
|||||||
@@ -101,16 +101,6 @@ describe('ol.layer.Layer', function() {
|
|||||||
expect(layer.getBrightness()).to.be(-0.7);
|
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() {
|
describe('#setContrast', function() {
|
||||||
@@ -134,11 +124,6 @@ describe('ol.layer.Layer', function() {
|
|||||||
expect(layer.getContrast()).to.be(0.3);
|
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() {
|
it('accepts a big positive number', function() {
|
||||||
layer.setContrast(42);
|
layer.setContrast(42);
|
||||||
expect(layer.getContrast()).to.be(42);
|
expect(layer.getContrast()).to.be(42);
|
||||||
@@ -207,16 +192,6 @@ describe('ol.layer.Layer', function() {
|
|||||||
expect(layer.getOpacity()).to.be(0.3);
|
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);
|
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() {
|
it('accepts a big positive number', function() {
|
||||||
layer.setSaturation(42);
|
layer.setSaturation(42);
|
||||||
expect(layer.getSaturation()).to.be(42);
|
expect(layer.getSaturation()).to.be(42);
|
||||||
|
|||||||
Reference in New Issue
Block a user