Merge pull request #2967 from camptocamp/webgl-point
Add support for drawing points with WebGL
This commit is contained in:
158
test/spec/ol/render/webglreplay.test.js
Normal file
158
test/spec/ol/render/webglreplay.test.js
Normal file
@@ -0,0 +1,158 @@
|
||||
goog.provide('ol.test.render.webgl.Replay');
|
||||
|
||||
describe('ol.render.webgl.ImageReplay', function() {
|
||||
var replay;
|
||||
|
||||
var createImageStyle = function(image) {
|
||||
var imageStyle = new ol.style.Image({
|
||||
opacity: 0.1,
|
||||
rotateWithView: true,
|
||||
rotation: 1.5,
|
||||
scale: 2.0
|
||||
});
|
||||
imageStyle.getAnchor = function() {
|
||||
return [0.5, 1];
|
||||
};
|
||||
imageStyle.getImage = function() {
|
||||
return image;
|
||||
};
|
||||
imageStyle.getImageSize = function() {
|
||||
return [512, 512];
|
||||
};
|
||||
imageStyle.getOrigin = function() {
|
||||
return [200, 200];
|
||||
};
|
||||
imageStyle.getSize = function() {
|
||||
return [256, 256];
|
||||
};
|
||||
return imageStyle;
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
var tolerance = 0.1;
|
||||
var maxExtent = [-10000, -20000, 10000, 20000];
|
||||
replay = new ol.render.webgl.ImageReplay(tolerance, maxExtent);
|
||||
});
|
||||
|
||||
describe('#setImageStyle', function() {
|
||||
|
||||
var imageStyle1, imageStyle2;
|
||||
|
||||
beforeEach(function() {
|
||||
imageStyle1 = createImageStyle(new Image());
|
||||
imageStyle2 = createImageStyle(new Image());
|
||||
});
|
||||
|
||||
it('set expected states', function() {
|
||||
replay.setImageStyle(imageStyle1);
|
||||
expect(replay.anchorX_).to.be(0.5);
|
||||
expect(replay.anchorY_).to.be(1);
|
||||
expect(replay.height_).to.be(256);
|
||||
expect(replay.imageHeight_).to.be(512);
|
||||
expect(replay.imageWidth_).to.be(512);
|
||||
expect(replay.opacity_).to.be(0.1);
|
||||
expect(replay.originX_).to.be(200);
|
||||
expect(replay.originY_).to.be(200);
|
||||
expect(replay.rotation_).to.be(1.5);
|
||||
expect(replay.rotateWithView_).to.be(true);
|
||||
expect(replay.scale_).to.be(2.0);
|
||||
expect(replay.width_).to.be(256);
|
||||
expect(replay.images_).to.have.length(1);
|
||||
expect(replay.groupIndices_).to.have.length(0);
|
||||
|
||||
replay.setImageStyle(imageStyle1);
|
||||
expect(replay.images_).to.have.length(1);
|
||||
expect(replay.groupIndices_).to.have.length(0);
|
||||
|
||||
replay.setImageStyle(imageStyle2);
|
||||
expect(replay.images_).to.have.length(2);
|
||||
expect(replay.groupIndices_).to.have.length(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#drawPointGeometry', function() {
|
||||
beforeEach(function() {
|
||||
var imageStyle = createImageStyle(new Image());
|
||||
replay.setImageStyle(imageStyle);
|
||||
});
|
||||
|
||||
it('sets the buffer data', function() {
|
||||
var point;
|
||||
|
||||
point = new ol.geom.Point([1000, 2000]);
|
||||
replay.drawPointGeometry(point, null);
|
||||
expect(replay.vertices_).to.have.length(32);
|
||||
expect(replay.indices_).to.have.length(6);
|
||||
expect(replay.indices_[0]).to.be(0);
|
||||
expect(replay.indices_[1]).to.be(1);
|
||||
expect(replay.indices_[2]).to.be(2);
|
||||
expect(replay.indices_[3]).to.be(0);
|
||||
expect(replay.indices_[4]).to.be(2);
|
||||
expect(replay.indices_[5]).to.be(3);
|
||||
|
||||
point = new ol.geom.Point([2000, 3000]);
|
||||
replay.drawPointGeometry(point, null);
|
||||
expect(replay.vertices_).to.have.length(64);
|
||||
expect(replay.indices_).to.have.length(12);
|
||||
expect(replay.indices_[6]).to.be(4);
|
||||
expect(replay.indices_[7]).to.be(5);
|
||||
expect(replay.indices_[8]).to.be(6);
|
||||
expect(replay.indices_[9]).to.be(4);
|
||||
expect(replay.indices_[10]).to.be(6);
|
||||
expect(replay.indices_[11]).to.be(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#drawMultiPointGeometry', function() {
|
||||
beforeEach(function() {
|
||||
var imageStyle = createImageStyle(new Image());
|
||||
replay.setImageStyle(imageStyle);
|
||||
});
|
||||
|
||||
it('sets the buffer data', function() {
|
||||
var multiPoint;
|
||||
|
||||
multiPoint = new ol.geom.MultiPoint(
|
||||
[[1000, 2000], [2000, 3000]]);
|
||||
replay.drawMultiPointGeometry(multiPoint, null);
|
||||
expect(replay.vertices_).to.have.length(64);
|
||||
expect(replay.indices_).to.have.length(12);
|
||||
expect(replay.indices_[0]).to.be(0);
|
||||
expect(replay.indices_[1]).to.be(1);
|
||||
expect(replay.indices_[2]).to.be(2);
|
||||
expect(replay.indices_[3]).to.be(0);
|
||||
expect(replay.indices_[4]).to.be(2);
|
||||
expect(replay.indices_[5]).to.be(3);
|
||||
expect(replay.indices_[6]).to.be(4);
|
||||
expect(replay.indices_[7]).to.be(5);
|
||||
expect(replay.indices_[8]).to.be(6);
|
||||
expect(replay.indices_[9]).to.be(4);
|
||||
expect(replay.indices_[10]).to.be(6);
|
||||
expect(replay.indices_[11]).to.be(7);
|
||||
|
||||
multiPoint = new ol.geom.MultiPoint(
|
||||
[[3000, 4000], [4000, 5000]]);
|
||||
replay.drawMultiPointGeometry(multiPoint, null);
|
||||
expect(replay.vertices_).to.have.length(128);
|
||||
expect(replay.indices_).to.have.length(24);
|
||||
expect(replay.indices_[12]).to.be(8);
|
||||
expect(replay.indices_[13]).to.be(9);
|
||||
expect(replay.indices_[14]).to.be(10);
|
||||
expect(replay.indices_[15]).to.be(8);
|
||||
expect(replay.indices_[16]).to.be(10);
|
||||
expect(replay.indices_[17]).to.be(11);
|
||||
expect(replay.indices_[18]).to.be(12);
|
||||
expect(replay.indices_[19]).to.be(13);
|
||||
expect(replay.indices_[20]).to.be(14);
|
||||
expect(replay.indices_[21]).to.be(12);
|
||||
expect(replay.indices_[22]).to.be(14);
|
||||
expect(replay.indices_[23]).to.be(15);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.render.webgl.ImageReplay');
|
||||
goog.require('ol.style.Image');
|
||||
@@ -1,297 +0,0 @@
|
||||
goog.provide('ol.test.structs.Buffer');
|
||||
|
||||
|
||||
describe('ol.structs.Buffer', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
describe('without an argument', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.structs.Buffer();
|
||||
});
|
||||
|
||||
it('constructs an empty instance', function() {
|
||||
expect(b.getArray()).to.be.empty();
|
||||
expect(b.getCount()).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a single array argument', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.structs.Buffer([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
it('constructs a populated instance', function() {
|
||||
expect(b.getArray()).to.eql([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an empty instance', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.structs.Buffer();
|
||||
});
|
||||
|
||||
describe('forEachRange', function() {
|
||||
|
||||
it('does not call the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
b.forEachRange(callback);
|
||||
expect(callback).not.to.be.called();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getArray', function() {
|
||||
|
||||
it('returns an empty array', function() {
|
||||
expect(b.getArray()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getCount', function() {
|
||||
|
||||
it('returns 0', function() {
|
||||
expect(b.getCount()).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an empty instance with spare capacity', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.structs.Buffer(new Array(4), 0);
|
||||
});
|
||||
|
||||
describe('add', function() {
|
||||
|
||||
it('allows elements to be added', function() {
|
||||
expect(b.add([0, 1, 2, 3])).to.be(0);
|
||||
expect(b.getArray()).to.eql([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRange', function() {
|
||||
|
||||
it('does not call the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
b.forEachRange(callback);
|
||||
expect(callback).not.to.be.called();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getCount', function() {
|
||||
|
||||
it('returns 0', function() {
|
||||
expect(b.getCount()).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an instance with no spare capacity', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.structs.Buffer([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
describe('add', function() {
|
||||
|
||||
it('throws an exception', function() {
|
||||
expect(function() {
|
||||
b.add([4, 5]);
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRange', function() {
|
||||
|
||||
it('calls the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
b.forEachRange(callback);
|
||||
expect(callback.calledOnce).to.be(true);
|
||||
expect(callback.args[0]).to.eql([0, 4]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getCount', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(b.getCount()).to.be(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('remove', function() {
|
||||
|
||||
it('allows items to be removes', function() {
|
||||
expect(function() {
|
||||
b.remove(4, 2);
|
||||
}).to.not.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('set', function() {
|
||||
|
||||
it('updates the items', function() {
|
||||
b.set([5, 6], 2);
|
||||
expect(b.getArray()).to.eql([0, 1, 5, 6]);
|
||||
});
|
||||
|
||||
it('marks the set items as dirty', function() {
|
||||
var dirtySet = new ol.structs.IntegerSet();
|
||||
b.addDirtySet(dirtySet);
|
||||
expect(dirtySet.isEmpty()).to.be(true);
|
||||
b.set([5, 6], 2);
|
||||
expect(dirtySet.isEmpty()).to.be(false);
|
||||
expect(dirtySet.getArray()).to.eql([2, 4]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an instance with spare capacity', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
var arr = [0, 1, 2, 3];
|
||||
arr.length = 8;
|
||||
b = new ol.structs.Buffer(arr, 4);
|
||||
});
|
||||
|
||||
describe('add', function() {
|
||||
|
||||
it('allows more items to be added', function() {
|
||||
expect(b.add([4, 5, 6, 7])).to.be(4);
|
||||
expect(b.getArray()).to.eql([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRange', function() {
|
||||
|
||||
it('calls the callback with the expected values', function() {
|
||||
var callback = sinon.spy();
|
||||
b.forEachRange(callback);
|
||||
expect(callback.calledOnce).to.be(true);
|
||||
expect(callback.args[0]).to.eql([0, 4]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getCount', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(b.getCount()).to.be(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getFreeSet', function() {
|
||||
|
||||
it('returns the expected set', function() {
|
||||
var freeSet = b.getFreeSet();
|
||||
expect(freeSet.isEmpty()).to.be(false);
|
||||
expect(freeSet.getArray()).to.eql([4, 8]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a populated instance', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.structs.Buffer([1234567.1234567, -7654321.7654321]);
|
||||
});
|
||||
|
||||
describe('getSplit32', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
var split32 = b.getSplit32();
|
||||
expect(split32).to.be.a(Float32Array);
|
||||
expect(split32).to.have.length(4);
|
||||
expect(split32[0]).to.roughlyEqual(1179648.0, 1e1);
|
||||
expect(split32[1]).to.roughlyEqual(54919.12345670001, 1e-2);
|
||||
expect(split32[2]).to.roughlyEqual(-7602176.0, 1e1);
|
||||
expect(split32[3]).to.roughlyEqual(-52145.76543209981, 1e-2);
|
||||
});
|
||||
|
||||
it('tracks updates', function() {
|
||||
b.getSplit32();
|
||||
b.getArray()[0] = 0;
|
||||
b.markDirty(1, 0);
|
||||
var split32 = b.getSplit32();
|
||||
expect(split32).to.be.a(Float32Array);
|
||||
expect(split32).to.have.length(4);
|
||||
expect(split32[0]).to.be(0);
|
||||
expect(split32[1]).to.be(0);
|
||||
expect(split32[2]).to.roughlyEqual(-7602176.0, 1e1);
|
||||
expect(split32[3]).to.roughlyEqual(-52145.76543209981, 1e-2);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('usage tests', function() {
|
||||
|
||||
it('allows multiple adds and removes', function() {
|
||||
var b = new ol.structs.Buffer(new Array(8), 0);
|
||||
expect(b.add([0, 1])).to.be(0);
|
||||
expect(b.getArray()).to.arreqlNaN([0, 1, NaN, NaN, NaN, NaN, NaN, NaN]);
|
||||
expect(b.getCount()).to.be(2);
|
||||
expect(b.add([2, 3, 4, 5])).to.be(2);
|
||||
expect(b.getArray()).to.arreqlNaN([0, 1, 2, 3, 4, 5, NaN, NaN]);
|
||||
expect(b.getCount()).to.be(6);
|
||||
expect(b.add([6, 7])).to.be(6);
|
||||
expect(b.getArray()).to.eql([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||
expect(b.getCount()).to.be(8);
|
||||
b.remove(2, 2);
|
||||
expect(b.getArray()).to.arreqlNaN([0, 1, NaN, NaN, 4, 5, 6, 7]);
|
||||
expect(b.getCount()).to.be(6);
|
||||
expect(b.add([8, 9])).to.be(2);
|
||||
expect(b.getArray()).to.eql([0, 1, 8, 9, 4, 5, 6, 7]);
|
||||
expect(b.getCount()).to.be(8);
|
||||
b.remove(1, 1);
|
||||
expect(b.getArray()).to.arreqlNaN([0, NaN, 8, 9, 4, 5, 6, 7]);
|
||||
expect(b.getCount()).to.be(7);
|
||||
b.remove(4, 4);
|
||||
expect(b.getArray()).to.arreqlNaN([0, NaN, 8, 9, NaN, NaN, NaN, NaN]);
|
||||
expect(b.getCount()).to.be(3);
|
||||
expect(b.add([10, 11, 12])).to.be(4);
|
||||
expect(b.getArray()).to.arreqlNaN([0, NaN, 8, 9, 10, 11, 12, NaN]);
|
||||
expect(b.getCount()).to.be(6);
|
||||
expect(b.add([13])).to.be(1);
|
||||
expect(b.getArray()).to.arreqlNaN([0, 13, 8, 9, 10, 11, 12, NaN]);
|
||||
expect(b.getCount()).to.be(7);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.structs.Buffer');
|
||||
goog.require('ol.structs.IntegerSet');
|
||||
@@ -1,622 +0,0 @@
|
||||
goog.provide('ol.test.structs.IntegerSet');
|
||||
|
||||
|
||||
describe('ol.structs.IntegerSet', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
describe('without an argument', function() {
|
||||
|
||||
it('constructs an empty instance', function() {
|
||||
var is = new ol.structs.IntegerSet();
|
||||
expect(is).to.be.an(ol.structs.IntegerSet);
|
||||
expect(is.getArray()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an argument', function() {
|
||||
|
||||
it('constructs with a valid array', function() {
|
||||
var is = new ol.structs.IntegerSet([0, 2, 4, 6]);
|
||||
expect(is).to.be.an(ol.structs.IntegerSet);
|
||||
expect(is.getArray()).to.eql([0, 2, 4, 6]);
|
||||
});
|
||||
|
||||
it('throws an exception with an odd number of elements', function() {
|
||||
expect(function() {
|
||||
var is = new ol.structs.IntegerSet([0, 2, 4]);
|
||||
is = is; // suppress gjslint warning about unused variable
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
it('throws an exception with out-of-order elements', function() {
|
||||
expect(function() {
|
||||
var is = new ol.structs.IntegerSet([0, 2, 2, 4]);
|
||||
is = is; // suppress gjslint warning about unused variable
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an empty instance', function() {
|
||||
|
||||
var is;
|
||||
beforeEach(function() {
|
||||
is = new ol.structs.IntegerSet();
|
||||
});
|
||||
|
||||
describe('addRange', function() {
|
||||
|
||||
it('creates a new element', function() {
|
||||
is.addRange(0, 2);
|
||||
expect(is.getArray()).to.eql([0, 2]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('findRange', function() {
|
||||
|
||||
it('returns -1', function() {
|
||||
expect(is.findRange(2)).to.be(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRange', function() {
|
||||
|
||||
it('does not call the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
is.forEachRange(callback);
|
||||
expect(callback).to.not.be.called();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRangeInverted', function() {
|
||||
|
||||
it('does call the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
is.forEachRangeInverted(0, 8, callback);
|
||||
expect(callback.calledOnce).to.be(true);
|
||||
expect(callback.args[0]).to.eql([0, 8]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getFirst', function() {
|
||||
|
||||
it('returns -1', function() {
|
||||
expect(is.getFirst()).to.be(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getLast', function() {
|
||||
|
||||
it('returns -1', function() {
|
||||
expect(is.getLast()).to.be(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getSize', function() {
|
||||
|
||||
it('returns 0', function() {
|
||||
expect(is.getSize()).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('intersectsRange', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
expect(is.intersectsRange(0, 0)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('isEmpty', function() {
|
||||
|
||||
it('returns true', function() {
|
||||
expect(is.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
|
||||
it('returns an empty string', function() {
|
||||
expect(is.toString()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a populated instance', function() {
|
||||
|
||||
var is;
|
||||
beforeEach(function() {
|
||||
is = new ol.structs.IntegerSet([4, 6, 8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
describe('addRange', function() {
|
||||
|
||||
it('inserts before the first element', function() {
|
||||
is.addRange(0, 2);
|
||||
expect(is.getArray()).to.eql([0, 2, 4, 6, 8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('extends the first element to the left', function() {
|
||||
is.addRange(0, 4);
|
||||
expect(is.getArray()).to.eql([0, 6, 8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('extends the first element to the right', function() {
|
||||
is.addRange(6, 7);
|
||||
expect(is.getArray()).to.eql([4, 7, 8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('merges the first two elements', function() {
|
||||
is.addRange(6, 8);
|
||||
expect(is.getArray()).to.eql([4, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('extends middle elements to the left', function() {
|
||||
is.addRange(7, 8);
|
||||
expect(is.getArray()).to.eql([4, 6, 7, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('extends middle elements to the right', function() {
|
||||
is.addRange(10, 11);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 11, 12, 14]);
|
||||
});
|
||||
|
||||
it('merges the last two elements', function() {
|
||||
is.addRange(10, 12);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 14]);
|
||||
});
|
||||
|
||||
it('extends the last element to the left', function() {
|
||||
is.addRange(11, 12);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 10, 11, 14]);
|
||||
});
|
||||
|
||||
it('extends the last element to the right', function() {
|
||||
is.addRange(14, 15);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 10, 12, 15]);
|
||||
});
|
||||
|
||||
it('inserts after the last element', function() {
|
||||
is.addRange(16, 18);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 10, 12, 14, 16, 18]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('clear', function() {
|
||||
|
||||
it('clears the instance', function() {
|
||||
is.clear();
|
||||
expect(is.getArray()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('findRange', function() {
|
||||
|
||||
it('throws an exception when passed a negative size', function() {
|
||||
expect(function() {
|
||||
is.findRange(-1);
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
it('throws an exception when passed a zero size', function() {
|
||||
expect(function() {
|
||||
is.findRange(0);
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
it('finds the first range of size 1', function() {
|
||||
expect(is.findRange(1)).to.be(4);
|
||||
});
|
||||
|
||||
it('finds the first range of size 2', function() {
|
||||
expect(is.findRange(2)).to.be(4);
|
||||
});
|
||||
|
||||
it('returns -1 when no range can be found', function() {
|
||||
expect(is.findRange(3)).to.be(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRange', function() {
|
||||
|
||||
it('calls the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
is.forEachRange(callback);
|
||||
expect(callback).to.be.called();
|
||||
expect(callback.calledThrice).to.be(true);
|
||||
expect(callback.args[0]).to.eql([4, 6]);
|
||||
expect(callback.args[1]).to.eql([8, 10]);
|
||||
expect(callback.args[2]).to.eql([12, 14]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('forEachRangeInverted', function() {
|
||||
|
||||
it('does call the callback', function() {
|
||||
var callback = sinon.spy();
|
||||
is.forEachRangeInverted(0, 16, callback);
|
||||
expect(callback.callCount).to.be(4);
|
||||
expect(callback.args[0]).to.eql([0, 4]);
|
||||
expect(callback.args[1]).to.eql([6, 8]);
|
||||
expect(callback.args[2]).to.eql([10, 12]);
|
||||
expect(callback.args[3]).to.eql([14, 16]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('getFirst', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.getFirst()).to.be(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getLast', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.getLast()).to.be(14);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getSize', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.getSize()).to.be(6);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('intersectsRange', function() {
|
||||
|
||||
it('returns the expected value for small ranges', function() {
|
||||
expect(is.intersectsRange(1, 3)).to.be(false);
|
||||
expect(is.intersectsRange(2, 4)).to.be(false);
|
||||
expect(is.intersectsRange(3, 5)).to.be(true);
|
||||
expect(is.intersectsRange(4, 6)).to.be(true);
|
||||
expect(is.intersectsRange(5, 7)).to.be(true);
|
||||
expect(is.intersectsRange(6, 8)).to.be(false);
|
||||
expect(is.intersectsRange(7, 9)).to.be(true);
|
||||
expect(is.intersectsRange(8, 10)).to.be(true);
|
||||
expect(is.intersectsRange(9, 11)).to.be(true);
|
||||
expect(is.intersectsRange(10, 12)).to.be(false);
|
||||
expect(is.intersectsRange(11, 13)).to.be(true);
|
||||
expect(is.intersectsRange(12, 14)).to.be(true);
|
||||
expect(is.intersectsRange(13, 15)).to.be(true);
|
||||
expect(is.intersectsRange(14, 16)).to.be(false);
|
||||
expect(is.intersectsRange(15, 17)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns the expected value for large ranges', function() {
|
||||
expect(is.intersectsRange(-3, 1)).to.be(false);
|
||||
expect(is.intersectsRange(1, 5)).to.be(true);
|
||||
expect(is.intersectsRange(1, 9)).to.be(true);
|
||||
expect(is.intersectsRange(1, 13)).to.be(true);
|
||||
expect(is.intersectsRange(1, 17)).to.be(true);
|
||||
expect(is.intersectsRange(5, 9)).to.be(true);
|
||||
expect(is.intersectsRange(5, 13)).to.be(true);
|
||||
expect(is.intersectsRange(5, 17)).to.be(true);
|
||||
expect(is.intersectsRange(9, 13)).to.be(true);
|
||||
expect(is.intersectsRange(9, 17)).to.be(true);
|
||||
expect(is.intersectsRange(13, 17)).to.be(true);
|
||||
expect(is.intersectsRange(17, 21)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
expect(is.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('removeRange', function() {
|
||||
|
||||
it('removes the first part of the first element', function() {
|
||||
is.removeRange(4, 5);
|
||||
expect(is.getArray()).to.eql([5, 6, 8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('removes the last part of the first element', function() {
|
||||
is.removeRange(5, 6);
|
||||
expect(is.getArray()).to.eql([4, 5, 8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('removes the first element', function() {
|
||||
is.removeRange(4, 6);
|
||||
expect(is.getArray()).to.eql([8, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('removes the first part of a middle element', function() {
|
||||
is.removeRange(8, 9);
|
||||
expect(is.getArray()).to.eql([4, 6, 9, 10, 12, 14]);
|
||||
});
|
||||
|
||||
it('removes the last part of a middle element', function() {
|
||||
is.removeRange(9, 10);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 9, 12, 14]);
|
||||
});
|
||||
|
||||
it('removes a middle element', function() {
|
||||
is.removeRange(8, 10);
|
||||
expect(is.getArray()).to.eql([4, 6, 12, 14]);
|
||||
});
|
||||
|
||||
it('removes the first part of the last element', function() {
|
||||
is.removeRange(12, 13);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 10, 13, 14]);
|
||||
});
|
||||
|
||||
it('removes the last part of the last element', function() {
|
||||
is.removeRange(13, 14);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 10, 12, 13]);
|
||||
});
|
||||
|
||||
it('removes the last element', function() {
|
||||
is.removeRange(12, 14);
|
||||
expect(is.getArray()).to.eql([4, 6, 8, 10]);
|
||||
});
|
||||
|
||||
it('can remove multiple ranges near the start', function() {
|
||||
is.removeRange(3, 11);
|
||||
expect(is.getArray()).to.eql([12, 14]);
|
||||
});
|
||||
|
||||
it('can remove multiple ranges near the start', function() {
|
||||
is.removeRange(7, 15);
|
||||
expect(is.getArray()).to.eql([4, 6]);
|
||||
});
|
||||
|
||||
it('throws an exception when passed an invalid range', function() {
|
||||
expect(function() {
|
||||
is.removeRange(2, 0);
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.toString()).to.be('4-6, 8-10, 12-14');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with fragmentation', function() {
|
||||
|
||||
var is;
|
||||
beforeEach(function() {
|
||||
is = new ol.structs.IntegerSet([0, 1, 2, 4, 5, 8, 9, 12, 13, 15, 16, 17]);
|
||||
});
|
||||
|
||||
describe('findRange', function() {
|
||||
|
||||
it('finds the first range of size 1', function() {
|
||||
expect(is.findRange(1)).to.be(0);
|
||||
});
|
||||
|
||||
it('finds the first range of size 2', function() {
|
||||
expect(is.findRange(2)).to.be(2);
|
||||
});
|
||||
|
||||
it('finds the first range of size 3', function() {
|
||||
expect(is.findRange(3)).to.be(5);
|
||||
});
|
||||
|
||||
it('returns -1 when no range can be found', function() {
|
||||
expect(is.findRange(4)).to.be(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getFirst', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.getFirst()).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getLast', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.getLast()).to.be(17);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getSize', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.getSize()).to.be(12);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('removeRange', function() {
|
||||
|
||||
it('removing an empty range has no effect', function() {
|
||||
is.removeRange(0, 0);
|
||||
expect(is.getArray()).to.eql(
|
||||
[0, 1, 2, 4, 5, 8, 9, 12, 13, 15, 16, 17]);
|
||||
});
|
||||
|
||||
it('can remove elements from the middle of range', function() {
|
||||
is.removeRange(6, 7);
|
||||
expect(is.getArray()).to.eql(
|
||||
[0, 1, 2, 4, 5, 6, 7, 8, 9, 12, 13, 15, 16, 17]);
|
||||
});
|
||||
|
||||
it('can remove multiple ranges', function() {
|
||||
is.removeRange(2, 12);
|
||||
expect(is.getArray()).to.eql([0, 1, 13, 15, 16, 17]);
|
||||
});
|
||||
|
||||
it('can remove multiple ranges and reduce others', function() {
|
||||
is.removeRange(0, 10);
|
||||
expect(is.getArray()).to.eql([10, 12, 13, 15, 16, 17]);
|
||||
});
|
||||
|
||||
it('can remove all ranges', function() {
|
||||
is.removeRange(0, 18);
|
||||
expect(is.getArray()).to.eql([]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.toString()).to.be('0-1, 2-4, 5-8, 9-12, 13-15, 16-17');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('compared to a slow reference implementation', function() {
|
||||
|
||||
var SimpleIntegerSet = function() {
|
||||
this.integers_ = {};
|
||||
};
|
||||
|
||||
SimpleIntegerSet.prototype.addRange = function(addStart, addStop) {
|
||||
var i;
|
||||
for (i = addStart; i < addStop; ++i) {
|
||||
this.integers_[i.toString()] = true;
|
||||
}
|
||||
};
|
||||
|
||||
SimpleIntegerSet.prototype.clear = function() {
|
||||
this.integers_ = {};
|
||||
};
|
||||
|
||||
SimpleIntegerSet.prototype.getArray = function() {
|
||||
var integers = goog.array.map(
|
||||
goog.object.getKeys(this.integers_), Number);
|
||||
goog.array.sort(integers);
|
||||
var arr = [];
|
||||
var start = -1, stop;
|
||||
var i;
|
||||
for (i = 0; i < integers.length; ++i) {
|
||||
if (start == -1) {
|
||||
start = stop = integers[i];
|
||||
} else if (integers[i] == stop + 1) {
|
||||
++stop;
|
||||
} else {
|
||||
arr.push(start, stop + 1);
|
||||
start = stop = integers[i];
|
||||
}
|
||||
}
|
||||
if (start != -1) {
|
||||
arr.push(start, stop + 1);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
SimpleIntegerSet.prototype.removeRange = function(removeStart, removeStop) {
|
||||
var i;
|
||||
for (i = removeStart; i < removeStop; ++i) {
|
||||
delete this.integers_[i.toString()];
|
||||
}
|
||||
};
|
||||
|
||||
var is, sis;
|
||||
beforeEach(function() {
|
||||
is = new ol.structs.IntegerSet();
|
||||
sis = new SimpleIntegerSet();
|
||||
});
|
||||
|
||||
it('behaves identically with random adds', function() {
|
||||
var addStart, addStop, i;
|
||||
for (i = 0; i < 64; ++i) {
|
||||
addStart = goog.math.randomInt(128);
|
||||
addStop = addStart + goog.math.randomInt(16);
|
||||
is.addRange(addStart, addStop);
|
||||
sis.addRange(addStart, addStop);
|
||||
expect(is.getArray()).to.eql(sis.getArray());
|
||||
}
|
||||
});
|
||||
|
||||
it('behaves identically with random removes', function() {
|
||||
is.addRange(0, 128);
|
||||
sis.addRange(0, 128);
|
||||
var i, removeStart, removeStop;
|
||||
for (i = 0; i < 64; ++i) {
|
||||
removeStart = goog.math.randomInt(128);
|
||||
removeStop = removeStart + goog.math.randomInt(16);
|
||||
is.removeRange(removeStart, removeStop);
|
||||
sis.removeRange(removeStart, removeStop);
|
||||
expect(is.getArray()).to.eql(sis.getArray());
|
||||
}
|
||||
});
|
||||
|
||||
it('behaves identically with random adds and removes', function() {
|
||||
var i, start, stop;
|
||||
for (i = 0; i < 64; ++i) {
|
||||
start = goog.math.randomInt(128);
|
||||
stop = start + goog.math.randomInt(16);
|
||||
if (Math.random() < 0.5) {
|
||||
is.addRange(start, stop);
|
||||
sis.addRange(start, stop);
|
||||
} else {
|
||||
is.removeRange(start, stop);
|
||||
sis.removeRange(start, stop);
|
||||
}
|
||||
expect(is.getArray()).to.eql(sis.getArray());
|
||||
}
|
||||
});
|
||||
|
||||
it('behaves identically with random adds, removes, and clears', function() {
|
||||
var i, p, start, stop;
|
||||
for (i = 0; i < 64; ++i) {
|
||||
start = goog.math.randomInt(128);
|
||||
stop = start + goog.math.randomInt(16);
|
||||
p = Math.random();
|
||||
if (p < 0.45) {
|
||||
is.addRange(start, stop);
|
||||
sis.addRange(start, stop);
|
||||
} else if (p < 0.9) {
|
||||
is.removeRange(start, stop);
|
||||
sis.removeRange(start, stop);
|
||||
} else {
|
||||
is.clear();
|
||||
sis.clear();
|
||||
}
|
||||
expect(is.getArray()).to.eql(sis.getArray());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.math');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.structs.IntegerSet');
|
||||
273
test/spec/ol/style/atlasmanager.test.js
Normal file
273
test/spec/ol/style/atlasmanager.test.js
Normal file
@@ -0,0 +1,273 @@
|
||||
goog.provide('ol.test.style.AtlasManager');
|
||||
|
||||
|
||||
describe('ol.style.Atlas', function() {
|
||||
|
||||
var defaultRender = function(context, x, y) {
|
||||
};
|
||||
|
||||
describe('#constructor', function() {
|
||||
|
||||
it('inits the atlas', function() {
|
||||
var atlas = new ol.style.Atlas(256, 1);
|
||||
expect(atlas.emptyBlocks_).to.eql(
|
||||
[{x: 0, y: 0, width: 256, height: 256}]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add (squares with same size)', function() {
|
||||
|
||||
it('adds one entry', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
var info = atlas.add('1', 32, 32, defaultRender);
|
||||
|
||||
expect(info).to.eql(
|
||||
{offsetX: 1, offsetY: 1, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.get('1')).to.eql(info);
|
||||
});
|
||||
|
||||
it('adds two entries', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
atlas.add('1', 32, 32, defaultRender);
|
||||
var info = atlas.add('2', 32, 32, defaultRender);
|
||||
|
||||
expect(info).to.eql(
|
||||
{offsetX: 34, offsetY: 1, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.get('2')).to.eql(info);
|
||||
});
|
||||
|
||||
it('adds three entries', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
atlas.add('1', 32, 32, defaultRender);
|
||||
atlas.add('2', 32, 32, defaultRender);
|
||||
var info = atlas.add('3', 32, 32, defaultRender);
|
||||
|
||||
expect(info).to.eql(
|
||||
{offsetX: 67, offsetY: 1, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.get('3')).to.eql(info);
|
||||
});
|
||||
|
||||
it('adds four entries (new row)', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
atlas.add('1', 32, 32, defaultRender);
|
||||
atlas.add('2', 32, 32, defaultRender);
|
||||
atlas.add('3', 32, 32, defaultRender);
|
||||
var info = atlas.add('4', 32, 32, defaultRender);
|
||||
|
||||
expect(info).to.eql(
|
||||
{offsetX: 1, offsetY: 34, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.get('4')).to.eql(info);
|
||||
});
|
||||
|
||||
it('returns null when an entry is too big', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
atlas.add('1', 32, 32, defaultRender);
|
||||
atlas.add('2', 32, 32, defaultRender);
|
||||
atlas.add('3', 32, 32, defaultRender);
|
||||
var info = atlas.add(4, 100, 100, defaultRender);
|
||||
|
||||
expect(info).to.eql(null);
|
||||
});
|
||||
|
||||
it('fills up the whole atlas', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
for (var i = 1; i <= 16; i++) {
|
||||
expect(atlas.add(i.toString(), 28, 28, defaultRender)).to.be.ok();
|
||||
}
|
||||
|
||||
// there is no more space for items of this size, the next one will fail
|
||||
expect(atlas.add('17', 28, 28, defaultRender)).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add (rectangles with different sizes)', function() {
|
||||
|
||||
it('adds a bunch of rectangles', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
expect(atlas.add('1', 64, 32, defaultRender)).to.eql(
|
||||
{offsetX: 1, offsetY: 1, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.add('2', 64, 32, defaultRender)).to.eql(
|
||||
{offsetX: 1, offsetY: 34, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.add('3', 64, 32, defaultRender)).to.eql(
|
||||
{offsetX: 1, offsetY: 67, image: atlas.canvas_});
|
||||
|
||||
// this one can not be added anymore
|
||||
expect(atlas.add('4', 64, 32, defaultRender)).to.eql(null);
|
||||
|
||||
// but there is still room for smaller ones
|
||||
expect(atlas.add('5', 40, 32, defaultRender)).to.eql(
|
||||
{offsetX: 66, offsetY: 1, image: atlas.canvas_});
|
||||
|
||||
expect(atlas.add('6', 40, 32, defaultRender)).to.eql(
|
||||
{offsetX: 66, offsetY: 34, image: atlas.canvas_});
|
||||
});
|
||||
|
||||
it('fills up the whole atlas (rectangles in portrait format)', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
for (var i = 1; i <= 32; i++) {
|
||||
expect(atlas.add(i.toString(), 28, 14, defaultRender)).to.be.ok();
|
||||
}
|
||||
|
||||
// there is no more space for items of this size, the next one will fail
|
||||
expect(atlas.add('33', 28, 14, defaultRender)).to.eql(null);
|
||||
});
|
||||
|
||||
it('fills up the whole atlas (rectangles in landscape format)', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
for (var i = 1; i <= 32; i++) {
|
||||
expect(atlas.add(i.toString(), 14, 28, defaultRender)).to.be.ok();
|
||||
}
|
||||
|
||||
// there is no more space for items of this size, the next one will fail
|
||||
expect(atlas.add('33', 14, 28, defaultRender)).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add (rendering)', function() {
|
||||
|
||||
it('calls the render callback with the right values', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
var rendererCallback = sinon.spy();
|
||||
atlas.add('1', 32, 32, rendererCallback);
|
||||
|
||||
expect(rendererCallback.calledOnce).to.be.ok();
|
||||
expect(rendererCallback.calledWith(atlas.context_, 1, 1)).to.be.ok();
|
||||
|
||||
rendererCallback = sinon.spy();
|
||||
atlas.add('2', 32, 32, rendererCallback);
|
||||
|
||||
expect(rendererCallback.calledOnce).to.be.ok();
|
||||
expect(rendererCallback.calledWith(atlas.context_, 34, 1)).to.be.ok();
|
||||
});
|
||||
|
||||
it('is possible to actually draw on the canvas', function() {
|
||||
var atlas = new ol.style.Atlas(128, 1);
|
||||
|
||||
var rendererCallback = function(context, x, y) {
|
||||
context.fillStyle = '#FFA500';
|
||||
context.fillRect(x, y, 32, 32);
|
||||
};
|
||||
|
||||
expect(atlas.add('1', 32, 32, rendererCallback)).to.be.ok();
|
||||
expect(atlas.add('2', 32, 32, rendererCallback)).to.be.ok();
|
||||
// no error, ok
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ol.style.AtlasManager', function() {
|
||||
|
||||
var defaultRender = function(context, x, y) {
|
||||
};
|
||||
|
||||
describe('#constructor', function() {
|
||||
|
||||
it('inits the atlas manager', function() {
|
||||
var manager = new ol.style.AtlasManager();
|
||||
expect(manager.atlases_).to.not.be.empty();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#add', function() {
|
||||
|
||||
it('adds one entry', function() {
|
||||
var manager = new ol.style.AtlasManager({initialSize: 128});
|
||||
var info = manager.add('1', 32, 32, defaultRender);
|
||||
|
||||
expect(info).to.eql({
|
||||
offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_,
|
||||
hitOffsetX: undefined, hitOffsetY: undefined, hitImage: undefined});
|
||||
|
||||
expect(manager.getInfo('1')).to.eql(info);
|
||||
});
|
||||
|
||||
it('adds one entry (also to the hit detection atlas)', function() {
|
||||
var manager = new ol.style.AtlasManager({initialSize: 128});
|
||||
var info = manager.add('1', 32, 32, defaultRender, defaultRender);
|
||||
|
||||
expect(info).to.eql({
|
||||
offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_,
|
||||
hitOffsetX: 1, hitOffsetY: 1,
|
||||
hitImage: manager.hitAtlases_[0].canvas_});
|
||||
|
||||
expect(manager.getInfo('1')).to.eql(info);
|
||||
});
|
||||
|
||||
it('creates a new atlas if needed', function() {
|
||||
var manager = new ol.style.AtlasManager({initialSize: 128});
|
||||
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
|
||||
.to.be.ok();
|
||||
var info = manager.add('2', 100, 100, defaultRender, defaultRender);
|
||||
expect(info).to.be.ok();
|
||||
expect(info.image.width).to.eql(256);
|
||||
expect(manager.atlases_).to.have.length(2);
|
||||
expect(info.hitImage.width).to.eql(256);
|
||||
expect(manager.hitAtlases_).to.have.length(2);
|
||||
});
|
||||
|
||||
it('creates new atlases until one is large enough', function() {
|
||||
var manager = new ol.style.AtlasManager({initialSize: 128});
|
||||
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
|
||||
.to.be.ok();
|
||||
expect(manager.atlases_).to.have.length(1);
|
||||
expect(manager.hitAtlases_).to.have.length(1);
|
||||
var info = manager.add('2', 500, 500, defaultRender, defaultRender);
|
||||
expect(info).to.be.ok();
|
||||
expect(info.image.width).to.eql(512);
|
||||
expect(manager.atlases_).to.have.length(3);
|
||||
expect(info.hitImage.width).to.eql(512);
|
||||
expect(manager.hitAtlases_).to.have.length(3);
|
||||
});
|
||||
|
||||
it('checks all existing atlases and create a new if needed', function() {
|
||||
var manager = new ol.style.AtlasManager({initialSize: 128});
|
||||
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
|
||||
.to.be.ok();
|
||||
expect(manager.add('2', 100, 100, defaultRender, defaultRender))
|
||||
.to.be.ok();
|
||||
expect(manager.atlases_).to.have.length(2);
|
||||
expect(manager.hitAtlases_).to.have.length(2);
|
||||
var info = manager.add(3, 500, 500, defaultRender, defaultRender);
|
||||
expect(info).to.be.ok();
|
||||
expect(info.image.width).to.eql(512);
|
||||
expect(manager.atlases_).to.have.length(3);
|
||||
expect(info.hitImage.width).to.eql(512);
|
||||
expect(manager.hitAtlases_).to.have.length(3);
|
||||
});
|
||||
|
||||
it('returns null if the size exceeds the maximum size', function() {
|
||||
var manager = new ol.style.AtlasManager(
|
||||
{initialSize: 128, maxSize: 2048});
|
||||
expect(manager.add('1', 100, 100, defaultRender, defaultRender))
|
||||
.to.be.ok();
|
||||
expect(manager.add('2', 2048, 2048, defaultRender, defaultRender))
|
||||
.to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getInfo', function() {
|
||||
|
||||
it('returns null if no entry for the given id', function() {
|
||||
var manager = new ol.style.AtlasManager({initialSize: 128});
|
||||
expect(manager.getInfo('123456')).to.eql(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.style.Atlas');
|
||||
goog.require('ol.style.AtlasManager');
|
||||
240
test/spec/ol/style/circlestyle.test.js
Normal file
240
test/spec/ol/style/circlestyle.test.js
Normal file
@@ -0,0 +1,240 @@
|
||||
goog.provide('ol.test.style.Circle');
|
||||
|
||||
|
||||
describe('ol.style.Circle', function() {
|
||||
|
||||
describe('#constructor', function() {
|
||||
|
||||
it('creates a canvas if no atlas is used (no fill-style)', function() {
|
||||
var style = new ol.style.Circle({radius: 10});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([21, 21]);
|
||||
expect(style.getOrigin()).to.eql([0, 0]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// hit-detection image is created, because no fill style is set
|
||||
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
|
||||
});
|
||||
|
||||
it('creates a canvas if no atlas is used (fill-style)', function() {
|
||||
var style = new ol.style.Circle({
|
||||
radius: 10,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#FFFF00'
|
||||
})
|
||||
});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([21, 21]);
|
||||
expect(style.getOrigin()).to.eql([0, 0]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// no hit-detection image is created, because fill style is set
|
||||
expect(style.getImage()).to.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
|
||||
});
|
||||
|
||||
it('adds itself to an atlas manager (no fill-style)', function() {
|
||||
var atlasManager = new ol.style.AtlasManager({initialSize: 512});
|
||||
var style = new ol.style.Circle({radius: 10, atlasManager: atlasManager});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([512, 512]);
|
||||
expect(style.getOrigin()).to.eql([1, 1]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// hit-detection image is created, because no fill style is set
|
||||
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
|
||||
});
|
||||
|
||||
it('adds itself to an atlas manager (fill-style)', function() {
|
||||
var atlasManager = new ol.style.AtlasManager({initialSize: 512});
|
||||
var style = new ol.style.Circle({
|
||||
radius: 10,
|
||||
atlasManager: atlasManager,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#FFFF00'
|
||||
})
|
||||
});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([512, 512]);
|
||||
expect(style.getOrigin()).to.eql([1, 1]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// no hit-detection image is created, because fill style is set
|
||||
expect(style.getImage()).to.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getChecksum', function() {
|
||||
|
||||
it('calculates the same hash code for default options', function() {
|
||||
var style1 = new ol.style.Circle();
|
||||
var style2 = new ol.style.Circle();
|
||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
it('calculates not the same hash code (radius)', function() {
|
||||
var style1 = new ol.style.Circle();
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5
|
||||
});
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
it('calculates the same hash code (radius)', function() {
|
||||
var style1 = new ol.style.Circle({
|
||||
radius: 5
|
||||
});
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5
|
||||
});
|
||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
it('calculates not the same hash code (color)', function() {
|
||||
var style1 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
it('calculates the same hash code (everything set)', function() {
|
||||
var style1 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3',
|
||||
lineCap: 'round',
|
||||
lineDash: [5, 15, 25],
|
||||
lineJoin: 'miter',
|
||||
miterLimit: 4,
|
||||
width: 2
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.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() {
|
||||
var style1 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3',
|
||||
lineCap: 'round',
|
||||
lineDash: [5, 15, 25],
|
||||
lineJoin: 'miter',
|
||||
miterLimit: 4,
|
||||
width: 3
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.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() {
|
||||
var style1 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.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() {
|
||||
var style1 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.Circle({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
||||
|
||||
style1.getStroke().setWidth(4);
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.style.AtlasManager');
|
||||
goog.require('ol.style.Circle');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Stroke');
|
||||
@@ -1,36 +1,297 @@
|
||||
goog.provide('ol.test.style.RegularShape');
|
||||
|
||||
describe('ol.style.RegularShape', function() {
|
||||
it('can use radius', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
radius2: 10
|
||||
|
||||
describe('#constructor', function() {
|
||||
|
||||
it('can use radius', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
radius2: 10
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(10);
|
||||
});
|
||||
|
||||
it('can use radius1 as an alias for radius', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius1: 5,
|
||||
radius2: 10
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(10);
|
||||
});
|
||||
|
||||
it('will use radius for radius2 if radius2 not defined', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius: 5
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(5);
|
||||
});
|
||||
|
||||
it('will use radius1 for radius2 if radius2 not defined', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius1: 5
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(5);
|
||||
});
|
||||
|
||||
it('creates a canvas if no atlas is used (no fill-style)', function() {
|
||||
var style = new ol.style.RegularShape({radius: 10});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([21, 21]);
|
||||
expect(style.getOrigin()).to.eql([0, 0]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// hit-detection image is created, because no fill style is set
|
||||
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
|
||||
});
|
||||
|
||||
it('creates a canvas if no atlas is used (fill-style)', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius: 10,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#FFFF00'
|
||||
})
|
||||
});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([21, 21]);
|
||||
expect(style.getOrigin()).to.eql([0, 0]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// no hit-detection image is created, because fill style is set
|
||||
expect(style.getImage()).to.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
|
||||
});
|
||||
|
||||
it('adds itself to an atlas manager (no fill-style)', function() {
|
||||
var atlasManager = new ol.style.AtlasManager({initialSize: 512});
|
||||
var style = new ol.style.RegularShape(
|
||||
{radius: 10, atlasManager: atlasManager});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([512, 512]);
|
||||
expect(style.getOrigin()).to.eql([1, 1]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// hit-detection image is created, because no fill style is set
|
||||
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
|
||||
});
|
||||
|
||||
it('adds itself to an atlas manager (fill-style)', function() {
|
||||
var atlasManager = new ol.style.AtlasManager({initialSize: 512});
|
||||
var style = new ol.style.RegularShape({
|
||||
radius: 10,
|
||||
atlasManager: atlasManager,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#FFFF00'
|
||||
})
|
||||
});
|
||||
expect(style.getImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getSize()).to.eql([21, 21]);
|
||||
expect(style.getImageSize()).to.eql([512, 512]);
|
||||
expect(style.getOrigin()).to.eql([1, 1]);
|
||||
expect(style.getAnchor()).to.eql([10.5, 10.5]);
|
||||
// no hit-detection image is created, because fill style is set
|
||||
expect(style.getImage()).to.be(style.getHitDetectionImage());
|
||||
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
|
||||
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
|
||||
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(10);
|
||||
});
|
||||
it('can use radius1 as an alias for radius', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius1: 5,
|
||||
radius2: 10
|
||||
|
||||
|
||||
describe('#getChecksum', function() {
|
||||
|
||||
it('calculates not the same hash code (radius)', function() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 4,
|
||||
radius2: 5
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 3,
|
||||
radius2: 5
|
||||
});
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(10);
|
||||
});
|
||||
it('will use radius for radius2 if radius2 not defined', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius: 5
|
||||
|
||||
it('calculates not the same hash code (radius2)', function() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 4,
|
||||
radius2: 5
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 4,
|
||||
radius2: 6
|
||||
});
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(5);
|
||||
});
|
||||
it('will use radius1 for radius2 if radius2 not defined', function() {
|
||||
var style = new ol.style.RegularShape({
|
||||
radius1: 5
|
||||
|
||||
it('calculates the same hash code (radius)', function() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 5
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 5
|
||||
});
|
||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
||||
});
|
||||
expect(style.getRadius()).to.eql(5);
|
||||
expect(style.getRadius2()).to.eql(5);
|
||||
|
||||
it('calculates not the same hash code (color)', function() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
it('calculates the same hash code (everything set)', function() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
radius2: 3,
|
||||
angle: 1.41,
|
||||
points: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3',
|
||||
lineCap: 'round',
|
||||
lineDash: [5, 15, 25],
|
||||
lineJoin: 'miter',
|
||||
miterLimit: 4,
|
||||
width: 2
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
radius2: 3,
|
||||
angle: 1.41,
|
||||
points: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.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() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
radius2: 3,
|
||||
angle: 1.41,
|
||||
points: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3',
|
||||
lineCap: 'round',
|
||||
lineDash: [5, 15, 25],
|
||||
lineJoin: 'miter',
|
||||
miterLimit: 4,
|
||||
width: 3
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
radius2: 3,
|
||||
angle: 1.41,
|
||||
points: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.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() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.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() {
|
||||
var style1 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
var style2 = new ol.style.RegularShape({
|
||||
radius: 5,
|
||||
fill: new ol.style.Fill({
|
||||
color: '#319FD3'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#319FD3'
|
||||
})
|
||||
});
|
||||
expect(style1.getChecksum()).to.eql(style2.getChecksum());
|
||||
|
||||
style1.getStroke().setWidth(4);
|
||||
expect(style1.getChecksum()).to.not.eql(style2.getChecksum());
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.style.AtlasManager');
|
||||
goog.require('ol.style.RegularShape');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Stroke');
|
||||
|
||||
55
test/spec/ol/webgl/buffer.test.js
Normal file
55
test/spec/ol/webgl/buffer.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
goog.provide('ol.test.webgl.Buffer');
|
||||
|
||||
|
||||
describe('ol.webgl.Buffer', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
describe('without an argument', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.webgl.Buffer();
|
||||
});
|
||||
|
||||
it('constructs an empty instance', function() {
|
||||
expect(b.getArray()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a single array argument', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.webgl.Buffer([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
it('constructs a populated instance', function() {
|
||||
expect(b.getArray()).to.eql([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an empty instance', function() {
|
||||
|
||||
var b;
|
||||
beforeEach(function() {
|
||||
b = new ol.webgl.Buffer();
|
||||
});
|
||||
|
||||
describe('getArray', function() {
|
||||
|
||||
it('returns an empty array', function() {
|
||||
expect(b.getArray()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.webgl.Buffer');
|
||||
Reference in New Issue
Block a user