Remove getChecksum functions
This commit is contained in:
@@ -29,12 +29,6 @@ class Fill {
|
|||||||
* @type {import("../color.js").Color|import("../colorlike.js").ColorLike}
|
* @type {import("../color.js").Color|import("../colorlike.js").ColorLike}
|
||||||
*/
|
*/
|
||||||
this.color_ = options.color !== undefined ? options.color : null;
|
this.color_ = options.color !== undefined ? options.color : null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {string|undefined}
|
|
||||||
*/
|
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,28 +60,8 @@ class Fill {
|
|||||||
*/
|
*/
|
||||||
setColor(color) {
|
setColor(color) {
|
||||||
this.color_ = color;
|
this.color_ = color;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {string} The checksum.
|
|
||||||
*/
|
|
||||||
getChecksum() {
|
|
||||||
if (this.checksum_ === undefined) {
|
|
||||||
const color = this.color_;
|
|
||||||
if (color) {
|
|
||||||
if (Array.isArray(color) || typeof color == 'string') {
|
|
||||||
this.checksum_ = 'f' + asString(/** @type {import("../color.js").Color|string} */ (color));
|
|
||||||
} else {
|
|
||||||
this.checksum_ = getUid(this.color_);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.checksum_ = 'f-';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.checksum_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Fill;
|
export default Fill;
|
||||||
|
|||||||
@@ -64,12 +64,6 @@ class RegularShape extends ImageStyle {
|
|||||||
scale: 1
|
scale: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {Array<string|number>}
|
|
||||||
*/
|
|
||||||
this.checksums_ = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {HTMLCanvasElement}
|
* @type {HTMLCanvasElement}
|
||||||
@@ -502,35 +496,6 @@ class RegularShape extends ImageStyle {
|
|||||||
context.closePath();
|
context.closePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {string} The checksum.
|
|
||||||
*/
|
|
||||||
getChecksum() {
|
|
||||||
const strokeChecksum = this.stroke_ ?
|
|
||||||
this.stroke_.getChecksum() : '-';
|
|
||||||
const fillChecksum = this.fill_ ?
|
|
||||||
this.fill_.getChecksum() : '-';
|
|
||||||
|
|
||||||
const recalculate = !this.checksums_ ||
|
|
||||||
(strokeChecksum != this.checksums_[1] ||
|
|
||||||
fillChecksum != this.checksums_[2] ||
|
|
||||||
this.radius_ != this.checksums_[3] ||
|
|
||||||
this.radius2_ != this.checksums_[4] ||
|
|
||||||
this.angle_ != this.checksums_[5] ||
|
|
||||||
this.points_ != this.checksums_[6]);
|
|
||||||
|
|
||||||
if (recalculate) {
|
|
||||||
const checksum = 'r' + strokeChecksum + fillChecksum +
|
|
||||||
(this.radius_ !== undefined ? this.radius_.toString() : '-') +
|
|
||||||
(this.radius2_ !== undefined ? this.radius2_.toString() : '-') +
|
|
||||||
(this.angle_ !== undefined ? this.angle_.toString() : '-') +
|
|
||||||
(this.points_ !== undefined ? this.points_.toString() : '-');
|
|
||||||
this.checksums_ = [checksum, strokeChecksum, fillChecksum,
|
|
||||||
this.radius_, this.radius2_, this.angle_, this.points_];
|
|
||||||
}
|
|
||||||
|
|
||||||
return /** @type {string} */ (this.checksums_[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,12 +76,6 @@ class Stroke {
|
|||||||
* @type {number|undefined}
|
* @type {number|undefined}
|
||||||
*/
|
*/
|
||||||
this.width_ = options.width;
|
this.width_ = options.width;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {string|undefined}
|
|
||||||
*/
|
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,7 +167,6 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setColor(color) {
|
setColor(color) {
|
||||||
this.color_ = color;
|
this.color_ = color;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,7 +177,6 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setLineCap(lineCap) {
|
setLineCap(lineCap) {
|
||||||
this.lineCap_ = lineCap;
|
this.lineCap_ = lineCap;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,7 +193,6 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setLineDash(lineDash) {
|
setLineDash(lineDash) {
|
||||||
this.lineDash_ = lineDash;
|
this.lineDash_ = lineDash;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,7 +203,6 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setLineDashOffset(lineDashOffset) {
|
setLineDashOffset(lineDashOffset) {
|
||||||
this.lineDashOffset_ = lineDashOffset;
|
this.lineDashOffset_ = lineDashOffset;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,7 +213,6 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setLineJoin(lineJoin) {
|
setLineJoin(lineJoin) {
|
||||||
this.lineJoin_ = lineJoin;
|
this.lineJoin_ = lineJoin;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,7 +223,6 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setMiterLimit(miterLimit) {
|
setMiterLimit(miterLimit) {
|
||||||
this.miterLimit_ = miterLimit;
|
this.miterLimit_ = miterLimit;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -245,41 +233,8 @@ class Stroke {
|
|||||||
*/
|
*/
|
||||||
setWidth(width) {
|
setWidth(width) {
|
||||||
this.width_ = width;
|
this.width_ = width;
|
||||||
this.checksum_ = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {string} The checksum.
|
|
||||||
*/
|
|
||||||
getChecksum() {
|
|
||||||
if (this.checksum_ === undefined) {
|
|
||||||
this.checksum_ = 's';
|
|
||||||
if (this.color_) {
|
|
||||||
if (typeof this.color_ === 'string') {
|
|
||||||
this.checksum_ += this.color_;
|
|
||||||
} else {
|
|
||||||
this.checksum_ += getUid(this.color_);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.checksum_ += '-';
|
|
||||||
}
|
|
||||||
this.checksum_ += ',' +
|
|
||||||
(this.lineCap_ !== undefined ?
|
|
||||||
this.lineCap_.toString() : '-') + ',' +
|
|
||||||
(this.lineDash_ ?
|
|
||||||
this.lineDash_.toString() : '-') + ',' +
|
|
||||||
(this.lineDashOffset_ !== undefined ?
|
|
||||||
this.lineDashOffset_ : '-') + ',' +
|
|
||||||
(this.lineJoin_ !== undefined ?
|
|
||||||
this.lineJoin_ : '-') + ',' +
|
|
||||||
(this.miterLimit_ !== undefined ?
|
|
||||||
this.miterLimit_.toString() : '-') + ',' +
|
|
||||||
(this.width_ !== undefined ?
|
|
||||||
this.width_.toString() : '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.checksum_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Stroke;
|
export default Stroke;
|
||||||
|
|||||||
@@ -90,164 +90,6 @@ describe('ol.style.Circle', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getChecksum', function() {
|
|
||||||
|
|
||||||
it('calculates the same hash code for default options', function() {
|
|
||||||
const style1 = new CircleStyle();
|
|
||||||
const style2 = new CircleStyle();
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates not the same hash code (radius)', function() {
|
|
||||||
const style1 = new CircleStyle();
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates the same hash code (radius)', function() {
|
|
||||||
const style1 = new CircleStyle({
|
|
||||||
radius: 5
|
|
||||||
});
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates not the same hash code (color)', function() {
|
|
||||||
const style1 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates the same hash code (everything set)', function() {
|
|
||||||
const style1 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 2
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 2
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates not the same hash code (stroke width differs)', function() {
|
|
||||||
const style1 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 3
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 2
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('invalidates a cached checksum if values change (fill)', function() {
|
|
||||||
const style1 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
|
|
||||||
style1.getFill().setColor('red');
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('invalidates a cached checksum if values change (stroke)', function() {
|
|
||||||
const style1 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new CircleStyle({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
|
|
||||||
style1.getStroke().setWidth(4);
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#setRadius', function() {
|
describe('#setRadius', function() {
|
||||||
it('changes the circle radius', function() {
|
it('changes the circle radius', function() {
|
||||||
const style = new CircleStyle({
|
const style = new CircleStyle({
|
||||||
|
|||||||
@@ -127,184 +127,4 @@ describe('ol.style.RegularShape', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('#getChecksum', function() {
|
|
||||||
|
|
||||||
it('calculates not the same hash code (radius)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 4,
|
|
||||||
radius2: 5
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 3,
|
|
||||||
radius2: 5
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates not the same hash code (radius2)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 4,
|
|
||||||
radius2: 5
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 4,
|
|
||||||
radius2: 6
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates the same hash code (radius)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 5
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 5
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates not the same hash code (color)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates the same hash code (everything set)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
radius2: 3,
|
|
||||||
angle: 1.41,
|
|
||||||
points: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 2
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
radius2: 3,
|
|
||||||
angle: 1.41,
|
|
||||||
points: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 2
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calculates not the same hash code (stroke width differs)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
radius2: 3,
|
|
||||||
angle: 1.41,
|
|
||||||
points: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 3
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
radius2: 3,
|
|
||||||
angle: 1.41,
|
|
||||||
points: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3',
|
|
||||||
lineCap: 'round',
|
|
||||||
lineDash: [5, 15, 25],
|
|
||||||
lineJoin: 'miter',
|
|
||||||
miterLimit: 4,
|
|
||||||
width: 2
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('invalidates a cached checksum if values change (fill)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
|
|
||||||
style1.getFill().setColor('red');
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('invalidates a cached checksum if values change (stroke)', function() {
|
|
||||||
const style1 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
const style2 = new RegularShape({
|
|
||||||
radius: 5,
|
|
||||||
fill: new Fill({
|
|
||||||
color: '#319FD3'
|
|
||||||
}),
|
|
||||||
stroke: new Stroke({
|
|
||||||
color: '#319FD3'
|
|
||||||
})
|
|
||||||
});
|
|
||||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
|
||||||
|
|
||||||
style1.getStroke().setWidth(4);
|
|
||||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user