Dedicated function for inverting a transform without modifying the source

This commit is contained in:
Tim Schaub
2018-11-17 14:41:33 +01:00
parent 06ae175cef
commit 63cf21b668
2 changed files with 64 additions and 27 deletions

View File

@@ -9,6 +9,7 @@ import {
multiply,
compose,
invert,
makeInverse,
apply
} from '../../../src/ol/transform.js';
@@ -110,13 +111,39 @@ describe('ol.transform', function() {
describe('invert()', function() {
it('inverts a transform', function() {
let transform = [1, 0, 1, 0, 1, 0];
expect(function() {
invert(transform);
}).to.throwException();
transform = [1, 1, 1, 2, 2, 0];
const transform = [1, 1, 1, 2, 2, 0];
expect(invert(transform)).to.eql([2, -1, -1, 1, -4, 2]);
expect(transform).to.eql([2, -1, -1, 1, -4, 2]);
});
it('throws if the transform cannot be inverted', function() {
const indeterminant = [1, 0, 1, 0, 1, 0];
expect(function() {
invert(indeterminant);
}).to.throwException();
});
it('modifies the source', function() {
const source = [1, 1, 1, 2, 2, 0];
const inverted = invert(source);
expect(inverted).to.eql([2, -1, -1, 1, -4, 2]);
expect(source).to.be(inverted);
});
});
describe('makeInverse()', function() {
it('makes the target the inverse of the source', function() {
const source = [1, 1, 1, 2, 2, 0];
const target = [1, 0, 0, 1, 0, 0];
makeInverse(source, target);
expect(source).to.eql([1, 1, 1, 2, 2, 0]);
expect(target).to.eql([2, -1, -1, 1, -4, 2]);
});
it('returns the target', function() {
const source = [1, 1, 1, 2, 2, 0];
const target = [1, 0, 0, 1, 0, 0];
const inverted = makeInverse(source, target);
expect(target).to.be(inverted);
});
});