Add a method to scale geometries
This commit is contained in:
@@ -242,6 +242,31 @@ describe('ol.geom.LineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a linestring', function() {
|
||||
var geom = new ol.geom.LineString([[-10, -20], [10, 20]]);
|
||||
geom.scale(10);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.LineString([[-10, -20], [10, 20]]);
|
||||
geom.scale(2, 3);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.LineString([[-10, -20], [10, 20]]);
|
||||
geom.scale(3, 2, [10, 20]);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[-50, -60], [10, 20]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a simple line string', function() {
|
||||
|
||||
var lineString;
|
||||
|
||||
@@ -313,6 +313,31 @@ describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a multi-linestring', function() {
|
||||
var geom = new ol.geom.MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
|
||||
geom.scale(10);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[-100, -200], [100, 200]], [[50, -100], [-50, 100]]]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
|
||||
geom.scale(2, 3);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[-20, -60], [20, 60]], [[10, -30], [-10, 30]]]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
|
||||
geom.scale(3, 2, [10, 20]);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[[-50, -60], [10, 20]], [[-5, -40], [-35, 0]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setLineStrings', function() {
|
||||
|
||||
it('sets the line strings', function() {
|
||||
|
||||
@@ -203,6 +203,31 @@ describe('ol.geom.MultiPoint', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a multi-point', function() {
|
||||
var geom = new ol.geom.MultiPoint([[-10, -20], [10, 20]]);
|
||||
geom.scale(10);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.MultiPoint([[-10, -20], [10, 20]]);
|
||||
geom.scale(2, 3);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.MultiPoint([[-10, -20], [10, 20]]);
|
||||
geom.scale(3, 2, [-10, -20]);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([[-10, -20], [50, 60]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#applyTransform()', function() {
|
||||
|
||||
var multi, transform;
|
||||
|
||||
@@ -129,6 +129,31 @@ describe('ol.geom.Point', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('#scale()', function() {
|
||||
|
||||
it('scales a point', function() {
|
||||
var geom = new ol.geom.Point([1, 2]);
|
||||
geom.scale(10e6);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
it('accepts sx and sy', function() {
|
||||
var geom = new ol.geom.Point([1, 2]);
|
||||
geom.scale(1e6, -42);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
it('accepts an anchor', function() {
|
||||
var geom = new ol.geom.Point([1, 2]);
|
||||
geom.scale(10, 15, [0, 0]);
|
||||
var coordinates = geom.getCoordinates();
|
||||
expect(coordinates).to.eql([10, 30]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#applyTransform()', function() {
|
||||
|
||||
var point, transform;
|
||||
|
||||
Reference in New Issue
Block a user