Move vector code out of the way

This commit is contained in:
Tom Payne
2013-11-06 16:40:26 +01:00
parent 81349d382b
commit 4e65fefc00
271 changed files with 881 additions and 0 deletions
-52
View File
@@ -1,52 +0,0 @@
goog.provide('ol.test.geom.Geometry');
describe('ol.geom.Geometry', function() {
describe('constructor', function() {
it('creates a new geometry', function() {
var geom = new ol.geom.Geometry();
expect(geom).to.be.a(ol.geom.Geometry);
expect(geom).to.be.a(goog.events.EventTarget);
});
});
describe('#clone()', function() {
it('clones a geometry', function() {
var line = new ol.geom.LineString([[0, 0], [1, 1]]);
var clone = line.clone();
expect(clone.getCoordinates().length).to.be(2);
expect(clone.getCoordinates()[0]).to.eql(line.getCoordinates()[0]);
expect(clone.getCoordinates()[0]).to.not.be(line.getCoordinates()[0]);
var coordinates = clone.getCoordinates();
coordinates[0] = [2, 2];
clone.setCoordinates(coordinates);
expect(clone.getCoordinates()[0]).to.not.eql(line.getCoordinates()[0]);
});
});
});
describe('ol.geom.GeometryEvent', function() {
describe('constructor', function() {
it('creates a new event', function() {
var point = new ol.geom.Point([1, 2]);
var bounds = point.getBounds();
var evt = new ol.geom.GeometryEvent('change', point, bounds);
expect(evt).to.be.a(ol.geom.GeometryEvent);
expect(evt).to.be.a(goog.events.Event);
expect(evt.target).to.be(point);
expect(evt.oldExtent).to.be(bounds);
});
});
});
goog.require('goog.events.Event');
goog.require('goog.events.EventTarget');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.GeometryEvent');
goog.require('ol.geom.Point');
goog.require('ol.geom.LineString');
@@ -1,78 +0,0 @@
goog.provide('ol.test.geom.GeometryCollection');
describe('ol.geom.GeometryCollection', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
describe('constructor', function() {
it('creates a geometry collection from an array of geometries', function() {
var point = new ol.geom.Point([10, 20]);
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var multi = new ol.geom.GeometryCollection([point, line, poly]);
expect(multi).to.be.a(ol.geom.GeometryCollection);
expect(multi).to.be.a(ol.geom.Geometry);
});
});
describe('#components', function() {
it('is an array of geometries', function() {
var point = new ol.geom.Point([10, 20]);
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var multi = new ol.geom.GeometryCollection([point, line, poly]);
var components = multi.getComponents();
expect(components.length).to.be(3);
expect(components[0]).to.be.a(ol.geom.Point);
expect(components[1]).to.be.a(ol.geom.LineString);
expect(components[2]).to.be.a(ol.geom.Polygon);
});
});
describe('#clone()', function() {
it('has a working clone method', function() {
var point = new ol.geom.Point([10, 20]);
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var multi = new ol.geom.GeometryCollection([point, line, poly]);
var clone = multi.clone();
expect(clone).to.not.be(multi);
var components = clone.getComponents();
expect(components[0].getCoordinates()).to.eql([10, 20]);
expect(components[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
expect(components[2].getCoordinates()).to.eql([outer, inner1, inner2]);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var point = new ol.geom.Point([10, 2]);
var line = new ol.geom.LineString([[1, 20], [30, 40]]);
var multi = new ol.geom.GeometryCollection([point, line]);
var bounds = multi.getBounds();
expect(bounds[0]).to.be(1);
expect(bounds[2]).to.be(30);
expect(bounds[1]).to.be(2);
expect(bounds[3]).to.be(40);
});
});
});
goog.require('ol.geom.Geometry');
goog.require('ol.geom.GeometryCollection');
goog.require('ol.geom.LineString');
goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
-125
View File
@@ -1,125 +0,0 @@
goog.provide('ol.test.geom.LinearRing');
describe('ol.geom.LinearRing', function() {
describe('constructor', function() {
it('creates a ring from an array', function() {
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
expect(ring).to.be.a(ol.geom.LinearRing);
});
});
describe('#getCoordinates()', function() {
it('is an array', function() {
var ring = new ol.geom.LinearRing([[10, 20], [30, 40]]);
expect(ring.getCoordinates()).to.eql([[10, 20], [30, 40]]);
});
});
describe('#containsCoordinate()', function() {
it('knows when a point coordinate is inside a ring', function() {
/**
* The ring:
* edge 3
* (5, 10) __________ (15, 10)
* / /
* edge 4 / / edge 2
* / /
* (0, 0) /_________/ (10, 0)
* edge 1
*/
var ring = new ol.geom.LinearRing(
[[0, 0], [10, 0], [15, 10], [5, 10]]);
// contains: 1 (touches - not implemented), true (within), false (outside)
var cases = [{
point: [5, 5], contains: true
}, {
point: [20, 20], contains: false
}, {
point: [15, 15], contains: false
}/*, {
point: [0, 0], contains: 1 // lower left corner
}, {
point: [10, 0], contains: 1 // lower right corner
}, {
point: [15, 10], contains: 1 // upper right corner
}, {
point: [5, 10], contains: 1 // upper left corner
}, {
point: [5, 0], contains: 1 // on edge 1
}*/, {
point: [5, -0.1], contains: false // below edge 1
}, {
point: [5, 0.1], contains: true // above edge 1
}/*, {
point: [12.5, 5], contains: 1 // on edge 2
}*/, {
point: [12.4, 5], contains: true // left of edge 2
}, {
point: [12.6, 5], contains: false // right of edge 2
}/*, {
point: [10, 10], contains: 1 // on edge 3
}*/, {
point: [10, 9.9], contains: true // below edge 3
}, {
point: [10, 10.1], contains: false // above edge 3
}/*, {
point: [2.5, 5], contains: 1 // on edge 4
}*/, {
point: [2.4, 5], contains: false // left of edge 4
}, {
point: [2.6, 5], contains: true // right of edge 4
}];
var c;
for (var i = 0, ii = cases.length; i < ii; ++i) {
c = cases[i];
expect(ring.containsCoordinate(c.point)).to.be(c.contains);
}
});
});
});
describe('ol.geom.LinearRing.isClockwise()', function() {
var isClockwise = ol.geom.LinearRing.isClockwise;
it('returns true for clockwise coordinates', function() {
var coordinates = [
[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]
];
expect(isClockwise(coordinates)).to.be(true);
});
it('returns false for counter-clockwise coordinates', function() {
var coordinates = [
[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]
];
expect(isClockwise(coordinates)).to.be(false);
});
it('returns true for mostly clockwise, self-intersecting ring', function() {
var coordinates = [
[0, 0], [0, 1], [1.5, 1], [1.5, 1.5], [1, 1.5], [1, 0], [0, 0]
];
expect(isClockwise(coordinates)).to.be(true);
});
it('returns false for mostly counter-clockwise, intersecting', function() {
var coordinates = [
[0, 0], [1, 0], [1, 1.5], [1.5, 1.5], [1.5, 1], [0, 1], [0, 0]
];
expect(isClockwise(coordinates)).to.be(false);
});
});
goog.require('ol.geom.LinearRing');
-102
View File
@@ -1,102 +0,0 @@
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('#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('#setCoordinates()', function() {
it('updates the coordinates', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
line.setCoordinates([[30, 40], [50, 60]]);
expect(line.getCoordinates()).to.eql([[30, 40], [50, 60]]);
});
it('invalidates bounds', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
line.setCoordinates([[30, 40], [50, 60]]);
expect(line.getBounds()).to.eql([30, 40, 50, 60]);
});
it('triggers a change event', function(done) {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.getBounds()).to.eql([10, 20, 30, 40]);
goog.events.listen(line, 'change', function(evt) {
expect(evt.target).to.equal(line);
expect(evt.oldExtent).to.eql([10, 20, 30, 40]);
expect(evt.target.getBounds()).to.eql([30, 40, 50, 60]);
expect(evt.target.getCoordinates()).to.eql([[30, 40], [50, 60]]);
done();
});
line.setCoordinates([[30, 40], [50, 60]]);
});
});
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('goog.events');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.LineString');
goog.require('ol.proj');
-65
View File
@@ -1,65 +0,0 @@
goog.provide('ol.test.geom.MultiLineString');
describe('ol.geom.MultiLineString', function() {
describe('constructor', function() {
it('creates a multi-linestring from an array', function() {
var multi = new ol.geom.MultiLineString([
[[10, 20], [30, 40]],
[[20, 30], [40, 50]]]);
expect(multi).to.be.a(ol.geom.MultiLineString);
expect(multi).to.be.a(ol.geom.Geometry);
});
});
describe('#components', function() {
it('is an array of linestrings', function() {
var multi = new ol.geom.MultiLineString([
[[10, 20], [30, 40]],
[[20, 30], [40, 50]]]);
var components = multi.getComponents();
expect(components.length).to.be(2);
expect(components[0]).to.be.a(ol.geom.LineString);
expect(components[1]).to.be.a(ol.geom.LineString);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var multi = new ol.geom.MultiLineString([
[[10, 20], [30, 40]],
[[20, 30], [40, 50]]]);
var bounds = multi.getBounds();
expect(bounds[0]).to.be(10);
expect(bounds[2]).to.be(40);
expect(bounds[1]).to.be(20);
expect(bounds[3]).to.be(50);
});
});
describe('#getCoordinates', function() {
it('returns an array', function() {
var coordinates = [
[[10, 20], [30, 40]],
[[20, 30], [40, 50]]
];
var multi = new ol.geom.MultiLineString(coordinates);
expect(multi.getCoordinates()).to.eql(coordinates);
});
});
});
goog.require('ol.geom.Geometry');
goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString');
-86
View File
@@ -1,86 +0,0 @@
goog.provide('ol.test.geom.MultiPoint');
describe('ol.geom.MultiPoint', function() {
describe('constructor', function() {
it('creates a multi-point from an array', function() {
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
expect(multi).to.be.a(ol.geom.MultiPoint);
expect(multi).to.be.a(ol.geom.Geometry);
});
});
describe('#components', function() {
it('is an array of points', function() {
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
var components = multi.getComponents();
expect(components.length).to.be(2);
expect(components[0]).to.be.a(ol.geom.Point);
expect(components[1]).to.be.a(ol.geom.Point);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
var bounds = multi.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 multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
expect(multi.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 multi-point', function() {
var multi = new ol.geom.MultiPoint([[10, 20], [30, 40]]);
multi.transform(forward);
var components = multi.getComponents();
expect(components[0].get(0)).to.roughlyEqual(1113195, 1);
expect(components[0].get(1)).to.roughlyEqual(2273031, 1);
expect(components[1].get(0)).to.roughlyEqual(3339584, 1);
expect(components[1].get(1)).to.roughlyEqual(4865942, 1);
});
it('inverse transforms a multi-point', function() {
var multi = new ol.geom.MultiPoint(
[[1113195, 2273031], [3339584, 4865942]]);
multi.transform(inverse);
var components = multi.getComponents();
expect(components[0].get(0)).to.roughlyEqual(10, 0.001);
expect(components[0].get(1)).to.roughlyEqual(20, 0.001);
expect(components[1].get(0)).to.roughlyEqual(30, 0.001);
expect(components[1].get(1)).to.roughlyEqual(40, 0.001);
});
});
});
goog.require('ol.geom.Geometry');
goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.Point');
goog.require('ol.proj');
-122
View File
@@ -1,122 +0,0 @@
goog.provide('ol.test.geom.MultiPolygon');
describe('ol.geom.MultiPolygon', function() {
var outer1 = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
inner1a = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
inner1b = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]],
outer2 = [[10, 10], [20, 0], [20, 50], [10, 50], [10, 10]];
describe('constructor', function() {
it('creates a multi-linestring from an array', function() {
var multi = new ol.geom.MultiPolygon([
[outer1, inner1a, inner1b],
[outer2]]);
expect(multi).to.be.a(ol.geom.MultiPolygon);
expect(multi).to.be.a(ol.geom.Geometry);
});
it('throws when given with insufficient dimensions', function() {
expect(function() {
var multi = new ol.geom.MultiPolygon([1]);
multi = multi; // suppress gjslint warning about unused variable
}).to.throwException();
});
});
describe('#components', function() {
it('is an array of polygons', function() {
var multi = new ol.geom.MultiPolygon([
[outer1, inner1a, inner1b],
[outer2]]);
var components = multi.getComponents();
expect(components.length).to.be(2);
expect(components[0]).to.be.a(ol.geom.Polygon);
expect(components[1]).to.be.a(ol.geom.Polygon);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var multi = new ol.geom.MultiPolygon([
[outer1, inner1a, inner1b],
[outer2]]);
var bounds = multi.getBounds();
expect(bounds[0]).to.be(0);
expect(bounds[2]).to.be(20);
expect(bounds[1]).to.be(0);
expect(bounds[3]).to.be(50);
});
});
describe('#getCoordinates', function() {
it('returns an array', function() {
var coordinates = [
[outer1, inner1a, inner1b],
[outer2]
];
var multi = new ol.geom.MultiPolygon(coordinates);
expect(multi.getCoordinates()).to.eql(coordinates);
});
});
describe('change event', function() {
var outer, inner;
beforeEach(function() {
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
});
it('is fired when outer ring is modified', function(done) {
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
var components = multi.getComponents();
var bounds = multi.getBounds();
goog.events.listen(multi, 'change', function(evt) {
expect(evt.target).to.be(multi);
expect(evt.oldExtent).to.eql(bounds);
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
done();
});
var outerOne = components[0].getRings()[0];
var outerCoords = outerOne.getCoordinates();
outerCoords[1][0] = 11;
outerOne.setCoordinates(outerCoords);
});
it('is fired when inner ring is modified', function(done) {
var multi = new ol.geom.MultiPolygon([[outer, inner], [outer, inner]]);
var components = multi.getComponents();
var bounds = multi.getBounds();
goog.events.listen(multi, 'change', function(evt) {
expect(evt.target).to.be(multi);
expect(evt.oldExtent).to.eql(bounds);
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
done();
});
var innerTwo = components[1].getRings()[1];
var innerCoords = innerTwo.getCoordinates();
innerCoords[1][0] = 3;
innerTwo.setCoordinates(innerCoords);
});
});
});
goog.require('goog.events');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.MultiPolygon');
goog.require('ol.geom.Polygon');
-92
View File
@@ -1,92 +0,0 @@
goog.provide('ol.test.geom.Point');
describe('ol.geom.Point', function() {
describe('constructor', function() {
it('creates a point from an array', function() {
var point = new ol.geom.Point([10, 20]);
expect(point).to.be.a(ol.geom.Point);
expect(point).to.be.a(ol.geom.Geometry);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var point = new ol.geom.Point([10, 20]);
var bounds = point.getBounds();
expect(bounds[0]).to.be(10);
expect(bounds[2]).to.be(10);
expect(bounds[1]).to.be(20);
expect(bounds[3]).to.be(20);
});
});
describe('#getCoordinates()', function() {
it('returns an array', function() {
var point = new ol.geom.Point([10, 20]);
expect(point.getCoordinates()).to.eql([10, 20]);
});
});
describe('#setCoordinates()', function() {
it('updates the coordinates', function() {
var point = new ol.geom.Point([10, 20]);
point.setCoordinates([30, 40]);
expect(point.getCoordinates()).to.eql([30, 40]);
});
it('invalidates bounds', function() {
var point = new ol.geom.Point([10, 20]);
point.setCoordinates([30, 40]);
expect(point.getBounds()).to.eql([30, 40, 30, 40]);
});
it('triggers a change event', function(done) {
var point = new ol.geom.Point([10, 20]);
expect(point.getBounds()).to.eql([10, 20, 10, 20]);
goog.events.listen(point, 'change', function(evt) {
expect(evt.target).to.equal(point);
expect(evt.oldExtent).to.eql([10, 20, 10, 20]);
expect(evt.target.getBounds()).to.eql([30, 40, 30, 40]);
expect(evt.target.getCoordinates()).to.eql([30, 40]);
done();
});
point.setCoordinates([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 point in place', function() {
var point = new ol.geom.Point([10, 20]);
point.transform(forward);
expect(point.get(0)).to.roughlyEqual(1113195, 1);
expect(point.get(1)).to.roughlyEqual(2273031, 1);
});
it('inverse transforms a point in place', function() {
var point = new ol.geom.Point([1113195, 2273031]);
point.transform(inverse);
expect(point.get(0)).to.roughlyEqual(10, 0.001);
expect(point.get(1)).to.roughlyEqual(20, 0.001);
});
});
});
goog.require('goog.events');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.Point');
goog.require('ol.proj');
-183
View File
@@ -1,183 +0,0 @@
goog.provide('ol.test.geom.Polygon');
describe('ol.geom.Polygon', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
describe('constructor', function() {
it('creates a polygon from an array', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
expect(poly).to.be.a(ol.geom.Polygon);
expect(poly).to.be.a(ol.geom.Geometry);
});
});
describe('#getRings()', function() {
it('returns an array of LinearRing', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var rings = poly.getRings();
expect(rings.length).to.be(3);
expect(rings[0]).to.be.a(ol.geom.LinearRing);
expect(rings[1]).to.be.a(ol.geom.LinearRing);
expect(rings[2]).to.be.a(ol.geom.LinearRing);
});
var isClockwise = ol.geom.LinearRing.isClockwise;
it('forces exterior ring to be clockwise', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
expect(isClockwise(outer)).to.be(false);
var poly = new ol.geom.Polygon([outer]);
var ring = poly.getRings()[0];
expect(isClockwise(ring.getCoordinates())).to.be(true);
});
it('forces interior ring to be counter-clockwise', function() {
var outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
var inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
expect(isClockwise(inner)).to.be(true);
var poly = new ol.geom.Polygon([outer, inner]);
var ring = poly.getRings()[1];
expect(isClockwise(ring.getCoordinates())).to.be(false);
});
});
describe('#getBounds()', function() {
it('returns the bounding extent', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
var bounds = poly.getBounds();
expect(bounds[0]).to.be(0);
expect(bounds[2]).to.be(10);
expect(bounds[1]).to.be(0);
expect(bounds[3]).to.be(10);
});
});
describe('#getCoordinates()', function() {
it('returns an array', function() {
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
expect(poly.getCoordinates()).to.eql([outer, inner1, inner2]);
});
});
describe('#transform()', function() {
var forward = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
var inverse = ol.proj.getTransform('EPSG:3857', 'EPSG:4326');
var gg, sm;
beforeEach(function() {
gg = [
[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]],
[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
[[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]]
];
sm = [[
[0, 0], [0, 1118890], [1113195, 1118890], [1113195, 0], [0, 0]
], [
[111319, 111325], [222639, 111325], [222639, 222684],
[111319, 222684], [111319, 111325]
], [
[890556, 893464], [1001875, 893464], [1001875, 1006021],
[890556, 1006021], [890556, 893464]
]];
});
it('forward transforms a polygon in place', function() {
var poly = new ol.geom.Polygon(gg);
poly.transform(forward);
var coordinates = poly.getCoordinates();
var ring;
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
var ring = coordinates[i];
for (var j = 0, jj = ring.length; j < jj; ++j) {
expect(ring[j][0]).to.roughlyEqual(sm[i][j][0], 1);
expect(ring[j][1]).to.roughlyEqual(sm[i][j][1], 1);
}
}
});
it('inverse transforms a polygon in place', function() {
var poly = new ol.geom.Polygon(sm);
poly.transform(inverse);
var coordinates = poly.getCoordinates();
var ring;
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
var ring = coordinates[i];
for (var j = 0, jj = ring.length; j < jj; ++j) {
expect(ring[j][0]).to.roughlyEqual(gg[i][j][0], 0.001);
expect(ring[j][1]).to.roughlyEqual(gg[i][j][1], 0.001);
}
}
});
});
describe('change event', function() {
var outer, inner;
beforeEach(function() {
outer = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
inner = [[2, 2], [2, 8], [8, 8], [8, 2], [2, 2]];
});
it('is fired when outer ring is modified', function(done) {
var poly = new ol.geom.Polygon([outer, inner]);
var rings = poly.getRings();
var bounds = poly.getBounds();
goog.events.listen(poly, 'change', function(evt) {
expect(evt.target).to.be(poly);
expect(evt.oldExtent).to.eql(bounds);
expect(evt.target.getBounds()).to.eql([0, 0, 11, 10]);
done();
});
var outerCoords = rings[0].getCoordinates();
outerCoords[1][0] = 11;
rings[0].setCoordinates(outerCoords);
});
it('is fired when inner ring is modified', function(done) {
var poly = new ol.geom.Polygon([outer, inner]);
var rings = poly.getRings();
var bounds = poly.getBounds();
goog.events.listen(poly, 'change', function(evt) {
expect(evt.target).to.be(poly);
expect(evt.oldExtent).to.eql(bounds);
expect(evt.target.getBounds()).to.eql([0, 0, 10, 10]);
done();
});
var innerCoords = rings[1].getCoordinates();
innerCoords[1][0] = 3;
rings[1].setCoordinates(innerCoords);
});
});
});
goog.require('goog.events');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.LinearRing');
goog.require('ol.geom.Polygon');
goog.require('ol.proj');