Named exports from ol/transform

This commit is contained in:
Marc Jansen
2018-02-14 19:37:29 +01:00
parent a01b38bc36
commit 183b8e29c4
28 changed files with 247 additions and 208 deletions

View File

@@ -1,4 +1,16 @@
import _ol_transform_ from '../../../src/ol/transform.js';
import {
create,
reset,
set,
setFromArray,
translate,
scale,
rotate,
multiply,
compose,
invert,
apply
} from '../../../src/ol/transform.js';
describe('ol.transform', function() {
@@ -9,71 +21,71 @@ describe('ol.transform', function() {
});
}
describe('ol.transform.create()', function() {
describe('create()', function() {
it('creates an identity transform', function() {
expect(_ol_transform_.create()).to.eql([1, 0, 0, 1, 0, 0]);
expect(create()).to.eql([1, 0, 0, 1, 0, 0]);
});
});
describe('ol.transform.reset()', function() {
describe('reset()', function() {
it('resets tansform to an identity transform', function() {
const transform = [1, 2, 3, 4, 5, 6];
expect(_ol_transform_.reset(transform)).to.eql([1, 0, 0, 1, 0, 0]);
expect(reset(transform)).to.eql([1, 0, 0, 1, 0, 0]);
expect(transform).to.eql([1, 0, 0, 1, 0, 0]);
});
});
describe('ol.transform.set()', function() {
describe('set()', function() {
it('sets the given values', function() {
const transform = _ol_transform_.create();
expect(_ol_transform_.set(transform, 1, 2, 3, 4, 5, 6)).to.eql([1, 2, 3, 4, 5, 6]);
const transform = create();
expect(set(transform, 1, 2, 3, 4, 5, 6)).to.eql([1, 2, 3, 4, 5, 6]);
expect(transform).to.eql([1, 2, 3, 4, 5, 6]);
});
});
describe('ol.transform.setFromArray()', function() {
describe('setFromArray()', function() {
it('sets values of 2nd transform on 1st transform', function() {
const transform1 = _ol_transform_.create();
const transform1 = create();
const transform2 = [1, 2, 3, 4, 5, 6];
expect(_ol_transform_.setFromArray(transform1, transform2)).to.eql(transform2);
expect(setFromArray(transform1, transform2)).to.eql(transform2);
expect(transform1).to.eql(transform2);
});
});
describe('ol.transform.translate()', function() {
describe('translate()', function() {
it('applies translation to a transform', function() {
const transform = _ol_transform_.create();
expect(_ol_transform_.translate(transform, 3, 4)).to.eql([1, 0, 0, 1, 3, 4]);
const transform = create();
expect(translate(transform, 3, 4)).to.eql([1, 0, 0, 1, 3, 4]);
expect(transform).to.eql([1, 0, 0, 1, 3, 4]);
});
});
describe('ol.transform.scale()', function() {
describe('scale()', function() {
it('applies scaling to a transform', function() {
const transform = _ol_transform_.create();
expect(_ol_transform_.scale(transform, 3, 4)).to.eql([3, 0, 0, 4, 0, 0]);
const transform = create();
expect(scale(transform, 3, 4)).to.eql([3, 0, 0, 4, 0, 0]);
expect(transform).to.eql([3, 0, 0, 4, 0, 0]);
});
});
describe('ol.transform.rotate()', function() {
describe('rotate()', function() {
it('applies rotation to a transform', function() {
const transform = _ol_transform_.create();
assertRoughlyEqual(_ol_transform_.rotate(transform, Math.PI / 2), [0, 1, -1, 0, 0, 0]);
const transform = create();
assertRoughlyEqual(rotate(transform, Math.PI / 2), [0, 1, -1, 0, 0, 0]);
assertRoughlyEqual(transform, [0, 1, -1, 0, 0, 0]);
});
});
describe('ol.transform.multiply()', function() {
describe('multiply()', function() {
it('multiplies two transforms', function() {
const transform1 = [1, 2, 1, 2, 1, 2];
const transform2 = [1, 2, 1, 2, 1, 2];
expect(_ol_transform_.multiply(transform1, transform2)).to.eql([3, 6, 3, 6, 4, 8]);
expect(multiply(transform1, transform2)).to.eql([3, 6, 3, 6, 4, 8]);
expect(transform1).to.eql([3, 6, 3, 6, 4, 8]);
});
});
describe('ol.transform.compose()', function() {
describe('compose()', function() {
it('composes a translate, scale, rotate, translate transform', function() {
const dx1 = 3;
const dy1 = 4;
@@ -83,36 +95,36 @@ describe('ol.transform', function() {
const dx2 = -dx1 / 2;
const dy2 = -dy1 / 2;
const expected = _ol_transform_.create();
_ol_transform_.translate(expected, dx1, dy1);
_ol_transform_.scale(expected, sx, sy);
_ol_transform_.rotate(expected, angle);
_ol_transform_.translate(expected, dx2, dy2);
const expected = create();
translate(expected, dx1, dy1);
scale(expected, sx, sy);
rotate(expected, angle);
translate(expected, dx2, dy2);
const composed = _ol_transform_.create();
const composedReturn = _ol_transform_.compose(composed, dx1, dy1, sx, sy, angle, dx2, dy2);
const composed = create();
const composedReturn = compose(composed, dx1, dy1, sx, sy, angle, dx2, dy2);
expect(composed).to.equal(composedReturn);
expect(composed).to.eql(expected);
});
});
describe('ol.transform.invert()', function() {
describe('invert()', function() {
it('inverts a transform', function() {
let transform = [1, 0, 1, 0, 1, 0];
expect(function() {
_ol_transform_.invert(transform);
invert(transform);
}).to.throwException();
transform = [1, 1, 1, 2, 2, 0];
expect(_ol_transform_.invert(transform)).to.eql([2, -1, -1, 1, -4, 2]);
expect(invert(transform)).to.eql([2, -1, -1, 1, -4, 2]);
expect(transform).to.eql([2, -1, -1, 1, -4, 2]);
});
});
describe('ol.transform.apply()', function() {
describe('apply()', function() {
it('applies a transform to a 2d vector', function() {
const transform = _ol_transform_.translate(_ol_transform_.create(), 2, 3);
const transform = translate(create(), 2, 3);
const point = [1, 2];
expect(_ol_transform_.apply(transform, point)).to.eql([3, 5]);
expect(apply(transform, point)).to.eql([3, 5]);
expect(point).to.eql([3, 5]);
});
});