Refactor ol.geom.Point

This commit is contained in:
Tom Payne
2013-11-09 16:05:30 +01:00
parent 6d32756adf
commit a89bf0c329
4 changed files with 114 additions and 21 deletions

View File

@@ -58,7 +58,7 @@ describe('ol.format.GeoJSON', function() {
expect(feature).to.be.an(ol.Feature);
var geometry = feature.getGeometry();
expect(geometry).to.be.an(ol.geom.Point);
expect(geometry.getCoordinate()).to.eql([102.0, 0.5]);
expect(geometry.getCoordinates()).to.eql([102.0, 0.5]);
expect(feature.get('prop0')).to.be('value0');
});

View File

@@ -0,0 +1,97 @@
goog.provide('ol.test.geom.Point');
describe('ol.geom.Point', function() {
describe('construct with 2D coordinates', function() {
var point;
beforeEach(function() {
point = new ol.geom.Point([1, 2]);
});
it('has the expected layout', function() {
expect(point.getLayout()).to.be(ol.geom.Layout.XY);
});
it('has the expected coordinates', function() {
expect(point.getCoordinates()).to.eql([1, 2]);
});
it('has the expected extent', function() {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
expect(point.getFlatCoordinates()).to.eql([1, 2]);
});
it('has stride the expected stride', function() {
expect(point.getStride()).to.be(2);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
var point;
beforeEach(function() {
point = new ol.geom.Point([1, 2, 3], ol.geom.Layout.XYM);
});
it('has the expected layout', function() {
expect(point.getLayout()).to.be(ol.geom.Layout.XYM);
});
it('has the expected coordinates', function() {
expect(point.getCoordinates()).to.eql([1, 2, 3]);
});
it('has the expected extent', function() {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
expect(point.getFlatCoordinates()).to.eql([1, 2, 3]);
});
it('has the expected stride', function() {
expect(point.getStride()).to.be(3);
});
});
describe('construct with 4D coordinates', function() {
var point;
beforeEach(function() {
point = new ol.geom.Point([1, 2, 3, 4]);
});
it('has the expected layout', function() {
expect(point.getLayout()).to.be(ol.geom.Layout.XYZM);
});
it('has the expected coordinates', function() {
expect(point.getCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has the expected extent', function() {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
expect(point.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has the expected stride', function() {
expect(point.getStride()).to.be(4);
});
});
});
goog.require('ol.extent');
goog.require('ol.geom.Point');

View File

@@ -128,7 +128,7 @@ describe('ol.source.Vector', function() {
it('fires a change event', function() {
var listener = sinon.spy();
goog.events.listen(vectorSource, 'change', listener);
features[0].getGeometry().setCoordinate([100, 100]);
features[0].getGeometry().setCoordinates([100, 100]);
expect(listener).to.be.called();
});
@@ -136,10 +136,10 @@ describe('ol.source.Vector', function() {
it('keeps the R-Tree index up to date', function() {
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
features[0].getGeometry().setCoordinate([100, 100]);
features[0].getGeometry().setCoordinates([100, 100]);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
to.have.length(9);
features[0].getGeometry().setCoordinate([0.5, 0.5]);
features[0].getGeometry().setCoordinates([0.5, 0.5]);
expect(vectorSource.getAllFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
});