Merge pull request #1830 from twpayne/geom-fixes
Extra geometry functions
This commit is contained in:
@@ -37,6 +37,13 @@ describe('ol.geom.LineString', function() {
|
||||
expect(lineString.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('can append coordinates', function() {
|
||||
lineString.appendCoordinate([1, 2]);
|
||||
expect(lineString.getCoordinates()).to.eql([[1, 2]]);
|
||||
lineString.appendCoordinate([3, 4]);
|
||||
expect(lineString.getCoordinates()).to.eql([[1, 2], [3, 4]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 2D coordinates', function() {
|
||||
|
||||
@@ -37,6 +37,17 @@ describe('ol.geom.MultiLineString', function() {
|
||||
expect(multiLineString.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('can append line strings', function() {
|
||||
multiLineString.appendLineString(
|
||||
new ol.geom.LineString([[1, 2], [3, 4]]));
|
||||
expect(multiLineString.getCoordinates()).to.eql(
|
||||
[[[1, 2], [3, 4]]]);
|
||||
multiLineString.appendLineString(
|
||||
new ol.geom.LineString([[5, 6], [7, 8]]));
|
||||
expect(multiLineString.getCoordinates()).to.eql(
|
||||
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 2D coordinates', function() {
|
||||
@@ -142,6 +153,17 @@ describe('ol.geom.MultiLineString', function() {
|
||||
expect(multiLineString.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('can return individual line strings', function() {
|
||||
var lineString0 = multiLineString.getLineString(0);
|
||||
expect(lineString0).to.be.an(ol.geom.LineString);
|
||||
expect(lineString0.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(lineString0.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
|
||||
var lineString1 = multiLineString.getLineString(1);
|
||||
expect(lineString1).to.be.an(ol.geom.LineString);
|
||||
expect(lineString1.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(lineString1.getCoordinates()).to.eql([[7, 8, 9], [10, 11, 12]]);
|
||||
});
|
||||
|
||||
describe('#getCoordinateAtM', function() {
|
||||
|
||||
describe('with extrapolation and interpolation', function() {
|
||||
|
||||
@@ -37,6 +37,13 @@ describe('ol.geom.MultiPoint', function() {
|
||||
expect(multiPoint.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('can append points', function() {
|
||||
multiPoint.appendPoint(new ol.geom.Point([1, 2]));
|
||||
expect(multiPoint.getCoordinates()).to.eql([[1, 2]]);
|
||||
multiPoint.appendPoint(new ol.geom.Point([3, 4]));
|
||||
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 2D coordinates', function() {
|
||||
@@ -125,6 +132,26 @@ describe('ol.geom.MultiPoint', function() {
|
||||
expect(multiPoint.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
it('can return individual points', function() {
|
||||
var point0 = multiPoint.getPoint(0);
|
||||
expect(point0.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(point0.getCoordinates()).to.eql([1, 2, 3]);
|
||||
var point1 = multiPoint.getPoint(1);
|
||||
expect(point1.getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(point1.getCoordinates()).to.eql([4, 5, 6]);
|
||||
});
|
||||
|
||||
it('can return all points', function() {
|
||||
var points = multiPoint.getPoints();
|
||||
expect(points).to.have.length(2);
|
||||
expect(points[0]).to.be.an(ol.geom.Point);
|
||||
expect(points[0].getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(points[0].getCoordinates()).to.eql([1, 2, 3]);
|
||||
expect(points[1]).to.be.an(ol.geom.Point);
|
||||
expect(points[1].getLayout()).to.be(ol.geom.GeometryLayout.XYM);
|
||||
expect(points[1].getCoordinates()).to.eql([4, 5, 6]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 4D coordinates', function() {
|
||||
@@ -170,3 +197,4 @@ describe('ol.geom.MultiPoint', function() {
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.Point');
|
||||
|
||||
@@ -10,6 +10,28 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('with an empty MultiPolygon', function() {
|
||||
|
||||
var multiPolygon;
|
||||
beforeEach(function() {
|
||||
multiPolygon = new ol.geom.MultiPolygon(null);
|
||||
});
|
||||
|
||||
it('can append polygons', function() {
|
||||
multiPolygon.appendPolygon(
|
||||
new ol.geom.Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
|
||||
expect(multiPolygon.getCoordinates()).to.eql(
|
||||
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
|
||||
multiPolygon.appendPolygon(
|
||||
new ol.geom.Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
|
||||
expect(multiPolygon.getCoordinates()).to.eql([
|
||||
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
|
||||
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a simple MultiPolygon', function() {
|
||||
|
||||
var multiPolygon;
|
||||
@@ -20,6 +42,29 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('can return individual polygons', function() {
|
||||
var polygon0 = multiPolygon.getPolygon(0);
|
||||
expect(polygon0).to.be.an(ol.geom.Polygon);
|
||||
expect(polygon0.getCoordinates()).to.eql(
|
||||
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
|
||||
var polygon1 = multiPolygon.getPolygon(1);
|
||||
expect(polygon1).to.be.an(ol.geom.Polygon);
|
||||
expect(polygon1.getCoordinates()).to.eql(
|
||||
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
|
||||
});
|
||||
|
||||
it('can return all polygons', function() {
|
||||
var polygons = multiPolygon.getPolygons();
|
||||
expect(polygons).to.be.an(Array);
|
||||
expect(polygons).to.have.length(2);
|
||||
expect(polygons[0]).to.be.an(ol.geom.Polygon);
|
||||
expect(polygons[0].getCoordinates()).to.eql(
|
||||
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
|
||||
expect(polygons[1]).to.be.an(ol.geom.Polygon);
|
||||
expect(polygons[1].getCoordinates()).to.eql(
|
||||
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
|
||||
});
|
||||
|
||||
describe('#getSimplifiedGeometry', function() {
|
||||
|
||||
it('returns the expected result', function() {
|
||||
@@ -38,3 +83,4 @@ describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
@@ -37,6 +37,17 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('can append linear rings', function() {
|
||||
polygon.appendLinearRing(
|
||||
new ol.geom.LinearRing([[1, 2], [3, 4], [5, 6]]));
|
||||
expect(polygon.getCoordinates()).to.eql(
|
||||
[[[1, 2], [3, 4], [5, 6]]]);
|
||||
polygon.appendLinearRing(
|
||||
new ol.geom.LinearRing([[7, 8], [9, 10], [11, 12]]));
|
||||
expect(polygon.getCoordinates()).to.eql(
|
||||
[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 2D coordinates', function() {
|
||||
@@ -73,6 +84,11 @@ describe('ol.geom.Polygon', function() {
|
||||
expect(polygon.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
it('can return individual rings', function() {
|
||||
expect(polygon.getLinearRing(0).getCoordinates()).to.eql(outerRing);
|
||||
expect(polygon.getLinearRing(1).getCoordinates()).to.eql(innerRing);
|
||||
});
|
||||
|
||||
it('has the expected rings', function() {
|
||||
var linearRings = polygon.getLinearRings();
|
||||
expect(linearRings).to.be.an(Array);
|
||||
|
||||
Reference in New Issue
Block a user