Refactor ol.geom.MultiLineString
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
|
||||
@@ -9,45 +7,39 @@ goog.require('ol.geom.Geometry');
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.geom.RawMultiLineString} coordinatess Coordinatess.
|
||||
* @param {ol.geom.RawMultiLineString} coordinates Coordinates.
|
||||
* @param {ol.geom.Layout=} opt_layout Layout.
|
||||
*/
|
||||
ol.geom.MultiLineString = function(coordinatess) {
|
||||
ol.geom.MultiLineString = function(coordinates, opt_layout) {
|
||||
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
* @type {ol.geom.RawMultiLineString}
|
||||
*/
|
||||
this.coordinatess_ = coordinatess;
|
||||
this.ends_ = [];
|
||||
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.Geometry);
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.geom.RawMultiLineString} Coordinatess.
|
||||
* @return {ol.geom.RawMultiLineString} Coordinates.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getCoordinatess = function() {
|
||||
return this.coordinatess_;
|
||||
ol.geom.MultiLineString.prototype.getCoordinates = function() {
|
||||
return ol.geom.inflateCoordinatess(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {Array.<number>} Ends.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision != this.revision) {
|
||||
this.extent = ol.extent.createOrUpdateEmpty(this.extent);
|
||||
var coordinatess = this.coordinatess_;
|
||||
var i, ii;
|
||||
for (i = 0, ii = coordinatess.length; i < ii; ++i) {
|
||||
this.extent = ol.extent.extendCoordinates(this.extent, coordinatess[i]);
|
||||
}
|
||||
this.extentRevision = this.revision;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(this.extent));
|
||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||
ol.geom.MultiLineString.prototype.getEnds = function() {
|
||||
return this.ends_;
|
||||
};
|
||||
|
||||
|
||||
@@ -60,25 +52,13 @@ ol.geom.MultiLineString.prototype.getType = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.RawMultiLineString} coordinatess Coordinatess.
|
||||
* @param {ol.geom.RawMultiLineString} coordinates Coordinates.
|
||||
* @param {ol.geom.Layout=} opt_layout Layout.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.setCoordinatess = function(coordinatess) {
|
||||
this.coordinatess_ = coordinatess;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.transform = function(transformFn) {
|
||||
var coordinatess = this.coordinatess_;
|
||||
var i, ii;
|
||||
for (i = 0, ii = coordinatess.length; i < ii; ++i) {
|
||||
var coordinates = coordinatess[i];
|
||||
var j, jj;
|
||||
for (j = 0, jj = coordinates.length; j < jj; ++j) {
|
||||
var coordinate = coordinates[j];
|
||||
transformFn(coordinate, coordinate, 2);
|
||||
}
|
||||
}
|
||||
ol.geom.MultiLineString.prototype.setCoordinates =
|
||||
function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
ol.geom.deflateCoordinatess(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -239,7 +239,7 @@ ol.replay.canvas.LineStringBatch.prototype.drawLineStringGeometry =
|
||||
ol.replay.canvas.LineStringBatch.prototype.drawMultiLineStringGeometry =
|
||||
function(multiLineStringGeometry) {
|
||||
goog.asserts.assert(!goog.isNull(this.state_));
|
||||
var coordinatess = multiLineStringGeometry.getCoordinatess();
|
||||
var coordinatess = multiLineStringGeometry.getCoordinates();
|
||||
var i, ii;
|
||||
for (i = 0, ii = coordinatess.length; i < ii; ++i) {
|
||||
this.drawCoordinates_(coordinatess[i]);
|
||||
|
||||
168
test/spec/ol/geom/multilinestring.test.js
Normal file
168
test/spec/ol/geom/multilinestring.test.js
Normal file
@@ -0,0 +1,168 @@
|
||||
goog.provide('ol.test.geom.MultiLineString');
|
||||
|
||||
|
||||
describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
describe('construct empty', function() {
|
||||
|
||||
var multiLineString;
|
||||
beforeEach(function() {
|
||||
multiLineString = new ol.geom.MultiLineString([]);
|
||||
});
|
||||
|
||||
it('defaults to layout XY', function() {
|
||||
expect(multiLineString.getLayout()).to.be(ol.geom.Layout.XY);
|
||||
});
|
||||
|
||||
it('has empty coordinates', function() {
|
||||
expect(multiLineString.getCoordinates()).to.be.empty();
|
||||
});
|
||||
|
||||
it('has an empty extent', function() {
|
||||
expect(ol.extent.isEmpty(multiLineString.getExtent())).to.be(true);
|
||||
});
|
||||
|
||||
it('has empty flat coordinates', function() {
|
||||
expect(multiLineString.getFlatCoordinates()).to.be.empty();
|
||||
});
|
||||
|
||||
it('has stride the expected stride', function() {
|
||||
expect(multiLineString.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 2D coordinates', function() {
|
||||
|
||||
var multiLineString;
|
||||
beforeEach(function() {
|
||||
multiLineString = new ol.geom.MultiLineString(
|
||||
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
|
||||
});
|
||||
|
||||
it('has the expected layout', function() {
|
||||
expect(multiLineString.getLayout()).to.be(ol.geom.Layout.XY);
|
||||
});
|
||||
|
||||
it('has the expected coordinates', function() {
|
||||
expect(multiLineString.getCoordinates()).to.eql(
|
||||
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
|
||||
});
|
||||
|
||||
it('has the expected extent', function() {
|
||||
expect(multiLineString.getExtent()).to.eql([1, 2, 7, 8]);
|
||||
});
|
||||
|
||||
it('has the expected flat coordinates', function() {
|
||||
expect(multiLineString.getFlatCoordinates()).to.eql(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
});
|
||||
|
||||
it('has stride the expected stride', function() {
|
||||
expect(multiLineString.getStride()).to.be(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates', function() {
|
||||
|
||||
var multiLineString;
|
||||
beforeEach(function() {
|
||||
multiLineString = new ol.geom.MultiLineString(
|
||||
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
|
||||
});
|
||||
|
||||
it('has the expected layout', function() {
|
||||
expect(multiLineString.getLayout()).to.be(ol.geom.Layout.XYZ);
|
||||
});
|
||||
|
||||
it('has the expected coordinates', function() {
|
||||
expect(multiLineString.getCoordinates()).to.eql(
|
||||
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
|
||||
});
|
||||
|
||||
it('has the expected extent', function() {
|
||||
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
|
||||
});
|
||||
|
||||
it('has the expected flat coordinates', function() {
|
||||
expect(multiLineString.getFlatCoordinates()).to.eql(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
|
||||
});
|
||||
|
||||
it('has stride the expected stride', function() {
|
||||
expect(multiLineString.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 3D coordinates and layout XYM', function() {
|
||||
|
||||
var multiLineString;
|
||||
beforeEach(function() {
|
||||
multiLineString = new ol.geom.MultiLineString(
|
||||
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
|
||||
ol.geom.Layout.XYM);
|
||||
});
|
||||
|
||||
it('has the expected layout', function() {
|
||||
expect(multiLineString.getLayout()).to.be(ol.geom.Layout.XYM);
|
||||
});
|
||||
|
||||
it('has the expected coordinates', function() {
|
||||
expect(multiLineString.getCoordinates()).to.eql(
|
||||
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
|
||||
});
|
||||
|
||||
it('has the expected extent', function() {
|
||||
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
|
||||
});
|
||||
|
||||
it('has the expected flat coordinates', function() {
|
||||
expect(multiLineString.getFlatCoordinates()).to.eql(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
|
||||
});
|
||||
|
||||
it('has stride the expected stride', function() {
|
||||
expect(multiLineString.getStride()).to.be(3);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('construct with 4D coordinates', function() {
|
||||
|
||||
var multiLineString;
|
||||
beforeEach(function() {
|
||||
multiLineString = new ol.geom.MultiLineString(
|
||||
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
|
||||
});
|
||||
|
||||
it('has the expected layout', function() {
|
||||
expect(multiLineString.getLayout()).to.be(ol.geom.Layout.XYZM);
|
||||
});
|
||||
|
||||
it('has the expected coordinates', function() {
|
||||
expect(multiLineString.getCoordinates()).to.eql(
|
||||
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
|
||||
});
|
||||
|
||||
it('has the expected extent', function() {
|
||||
expect(multiLineString.getExtent()).to.eql([1, 2, 13, 14]);
|
||||
});
|
||||
|
||||
it('has the expected flat coordinates', function() {
|
||||
expect(multiLineString.getFlatCoordinates()).to.eql(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
|
||||
});
|
||||
|
||||
it('has stride the expected stride', function() {
|
||||
expect(multiLineString.getStride()).to.be(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
Reference in New Issue
Block a user