Files
openlayers/test/spec/ol/geom/linestring.test.js
Tim Schaub 33457c48de Add transform method to geometries
In the typical sequence of parse-transform-render the most efficient place to transform coordinate values is deep within the parser immediately after values have been read (this would avoid a second pass over whatever structure is used to back geometries).  To accomplish this transform during parsing, we could add back parser read options to pass the transform function around.

Until then, a transform method on geometries is straightforward to implement.  This means we do a second pass through coordinate structures to transform, but this is typically done only once immediately after parsing.
2013-09-27 23:18:34 +01:00

87 lines
2.6 KiB
JavaScript

goog.provide('ol.test.geom.LineString');
describe('ol.geom.LineString', function() {
describe('constructor', function() {
it('creates a linestring from an array', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line).to.be.a(ol.geom.LineString);
expect(line).to.be.a(ol.geom.Geometry);
});
});
describe('#dimension', function() {
it('can be 2', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.dimension).to.be(2);
});
it('can be 3', function() {
var line = new ol.geom.LineString([[10, 20, 30], [40, 50, 60]]);
expect(line.dimension).to.be(3);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
var bounds = line.getBounds();
expect(bounds[0]).to.be(10);
expect(bounds[2]).to.be(30);
expect(bounds[1]).to.be(20);
expect(bounds[3]).to.be(40);
});
});
describe('#getCoordinates', function() {
it('returns an array', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.getCoordinates()).to.eql([[10, 20], [30, 40]]);
});
});
describe('#transform()', function() {
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
it('forward transforms a linestring in place', function() {
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
line.transform(forward);
expect(line.get(0, 0)).to.roughlyEqual(1113195, 1);
expect(line.get(0, 1)).to.roughlyEqual(2273031, 1);
expect(line.get(1, 0)).to.roughlyEqual(2226390, 1);
expect(line.get(1, 1)).to.roughlyEqual(3503550, 1);
expect(line.get(2, 0)).to.roughlyEqual(3339585, 1);
expect(line.get(2, 1)).to.roughlyEqual(4865942, 1);
});
it('inverse transforms a linestring in place', function() {
var line = new ol.geom.LineString([
[1113195, 2273031], [2226390, 3503550], [3339585, 4865942]
]);
line.transform(inverse);
expect(line.get(0, 0)).to.roughlyEqual(10, 0.001);
expect(line.get(0, 1)).to.roughlyEqual(20, 0.001);
expect(line.get(1, 0)).to.roughlyEqual(20, 0.001);
expect(line.get(1, 1)).to.roughlyEqual(30, 0.001);
expect(line.get(2, 0)).to.roughlyEqual(30, 0.001);
expect(line.get(2, 1)).to.roughlyEqual(40, 0.001);
});
});
});
goog.require('ol.geom.Geometry');
goog.require('ol.geom.LineString');
goog.require('ol.proj');