Add ol.geom.LineString#getFlatMidpoint
This commit is contained in:
@@ -20,6 +20,18 @@ ol.geom.LineString = function(coordinates, opt_layout) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Coordinate}
|
||||||
|
*/
|
||||||
|
this.flatMidpoint_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.flatMidpointRevision_ = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -88,6 +100,20 @@ ol.geom.LineString.prototype.getLength = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array.<number>} Flat midpoint.
|
||||||
|
*/
|
||||||
|
ol.geom.LineString.prototype.getFlatMidpoint = function() {
|
||||||
|
if (this.flatMidpointRevision_ != this.getRevision()) {
|
||||||
|
this.flatMidpoint_ = ol.geom.flat.lineStringInterpolate(
|
||||||
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||||
|
0.5, this.flatMidpoint_);
|
||||||
|
this.flatMidpointRevision_ = this.getRevision();
|
||||||
|
}
|
||||||
|
return this.flatMidpoint_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -164,6 +164,18 @@ describe('ol.geom.LineString', function() {
|
|||||||
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
|
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getFlatMidpoint', function() {
|
||||||
|
|
||||||
|
it('returns the expected result', function() {
|
||||||
|
var midpoint = lineString.getFlatMidpoint();
|
||||||
|
expect(midpoint).to.be.an(Array);
|
||||||
|
expect(midpoint).to.have.length(2);
|
||||||
|
expect(midpoint[0]).to.roughlyEqual(4, 1e-1);
|
||||||
|
expect(midpoint[1]).to.roughlyEqual(2, 1e-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#getSimplifiedGeometry', function() {
|
describe('#getSimplifiedGeometry', function() {
|
||||||
|
|
||||||
it('returns the expectedResult', function() {
|
it('returns the expectedResult', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user