ol/geom/flat/interpolate export
This commit is contained in:
@@ -10,7 +10,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js';
|
|||||||
import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js';
|
import {assignClosestPoint, maxSquaredDelta} from '../geom/flat/closest.js';
|
||||||
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
||||||
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
||||||
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
import {interpolatePoint, lineStringCoordinateAtM} from '../geom/flat/interpolate.js';
|
||||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||||
import {lineStringLength} from '../geom/flat/length.js';
|
import {lineStringLength} from '../geom/flat/length.js';
|
||||||
import {forEach as forEachSegment} from '../geom/flat/segments.js';
|
import {forEach as forEachSegment} from '../geom/flat/segments.js';
|
||||||
@@ -143,7 +143,7 @@ LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||||
return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(this.flatCoordinates, 0,
|
return lineStringCoordinateAtM(this.flatCoordinates, 0,
|
||||||
this.flatCoordinates.length, this.stride, m, extrapolate);
|
this.flatCoordinates.length, this.stride, m, extrapolate);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ LineString.prototype.getCoordinates = function() {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
LineString.prototype.getCoordinateAt = function(fraction, opt_dest) {
|
LineString.prototype.getCoordinateAt = function(fraction, opt_dest) {
|
||||||
return _ol_geom_flat_interpolate_.lineString(
|
return interpolatePoint(
|
||||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||||
fraction, opt_dest);
|
fraction, opt_dest);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import SimpleGeometry from '../geom/SimpleGeometry.js';
|
|||||||
import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js';
|
import {assignClosestArrayPoint, arrayMaxSquaredDelta} from '../geom/flat/closest.js';
|
||||||
import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
import {deflateCoordinatesArray} from '../geom/flat/deflate.js';
|
||||||
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
import {inflateCoordinatesArray} from '../geom/flat/inflate.js';
|
||||||
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
import {interpolatePoint, lineStringsCoordinateAtM} from '../geom/flat/interpolate.js';
|
||||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||||
import {douglasPeuckerArray} from '../geom/flat/simplify.js';
|
import {douglasPeuckerArray} from '../geom/flat/simplify.js';
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_in
|
|||||||
}
|
}
|
||||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||||
const interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
|
const interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
|
||||||
return _ol_geom_flat_interpolate_.lineStringsCoordinateAtM(this.flatCoordinates, 0,
|
return lineStringsCoordinateAtM(this.flatCoordinates, 0,
|
||||||
this.ends_, this.stride, m, extrapolate, interpolate);
|
this.ends_, this.stride, m, extrapolate, interpolate);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ MultiLineString.prototype.getFlatMidpoints = function() {
|
|||||||
const stride = this.stride;
|
const stride = this.stride;
|
||||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||||
const end = ends[i];
|
const end = ends[i];
|
||||||
const midpoint = _ol_geom_flat_interpolate_.lineString(
|
const midpoint = interpolatePoint(
|
||||||
flatCoordinates, offset, end, stride, 0.5);
|
flatCoordinates, offset, end, stride, 0.5);
|
||||||
extend(midpoints, midpoint);
|
extend(midpoints, midpoint);
|
||||||
offset = end;
|
offset = end;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
import {binarySearch} from '../../array.js';
|
import {binarySearch} from '../../array.js';
|
||||||
import {lerp} from '../../math.js';
|
import {lerp} from '../../math.js';
|
||||||
const _ol_geom_flat_interpolate_ = {};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +14,7 @@ const _ol_geom_flat_interpolate_ = {};
|
|||||||
* @param {Array.<number>=} opt_dest Destination.
|
* @param {Array.<number>=} opt_dest Destination.
|
||||||
* @return {Array.<number>} Destination.
|
* @return {Array.<number>} Destination.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, stride, fraction, opt_dest) {
|
export function interpolatePoint(flatCoordinates, offset, end, stride, fraction, opt_dest) {
|
||||||
let pointX = NaN;
|
let pointX = NaN;
|
||||||
let pointY = NaN;
|
let pointY = NaN;
|
||||||
const n = (end - offset) / stride;
|
const n = (end - offset) / stride;
|
||||||
@@ -62,7 +61,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s
|
|||||||
} else {
|
} else {
|
||||||
return [pointX, pointY];
|
return [pointX, pointY];
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,7 +73,7 @@ _ol_geom_flat_interpolate_.lineString = function(flatCoordinates, offset, end, s
|
|||||||
* @param {boolean} extrapolate Extrapolate.
|
* @param {boolean} extrapolate Extrapolate.
|
||||||
* @return {ol.Coordinate} Coordinate.
|
* @return {ol.Coordinate} Coordinate.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, offset, end, stride, m, extrapolate) {
|
export function lineStringCoordinateAtM(flatCoordinates, offset, end, stride, m, extrapolate) {
|
||||||
if (end == offset) {
|
if (end == offset) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -123,7 +122,7 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o
|
|||||||
}
|
}
|
||||||
coordinate.push(m);
|
coordinate.push(m);
|
||||||
return coordinate;
|
return coordinate;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,10 +135,10 @@ _ol_geom_flat_interpolate_.lineStringCoordinateAtM = function(flatCoordinates, o
|
|||||||
* @param {boolean} interpolate Interpolate.
|
* @param {boolean} interpolate Interpolate.
|
||||||
* @return {ol.Coordinate} Coordinate.
|
* @return {ol.Coordinate} Coordinate.
|
||||||
*/
|
*/
|
||||||
_ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function(
|
export function lineStringsCoordinateAtM(
|
||||||
flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
|
flatCoordinates, offset, ends, stride, m, extrapolate, interpolate) {
|
||||||
if (interpolate) {
|
if (interpolate) {
|
||||||
return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(
|
return lineStringCoordinateAtM(
|
||||||
flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
|
flatCoordinates, offset, ends[ends.length - 1], stride, m, extrapolate);
|
||||||
}
|
}
|
||||||
let coordinate;
|
let coordinate;
|
||||||
@@ -169,11 +168,10 @@ _ol_geom_flat_interpolate_.lineStringsCoordinateAtM = function(
|
|||||||
if (m < flatCoordinates[offset + stride - 1]) {
|
if (m < flatCoordinates[offset + stride - 1]) {
|
||||||
return null;
|
return null;
|
||||||
} else if (m <= flatCoordinates[end - 1]) {
|
} else if (m <= flatCoordinates[end - 1]) {
|
||||||
return _ol_geom_flat_interpolate_.lineStringCoordinateAtM(
|
return lineStringCoordinateAtM(
|
||||||
flatCoordinates, offset, end, stride, m, false);
|
flatCoordinates, offset, end, stride, m, false);
|
||||||
}
|
}
|
||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
}
|
||||||
export default _ol_geom_flat_interpolate_;
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCent
|
|||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import {linearRingss as linearRingssCenter} from '../geom/flat/center.js';
|
import {linearRingss as linearRingssCenter} from '../geom/flat/center.js';
|
||||||
import {getInteriorPointOfArray, getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js';
|
import {getInteriorPointOfArray, getInteriorPointsOfMultiArray} from '../geom/flat/interiorpoint.js';
|
||||||
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
import {interpolatePoint} from '../geom/flat/interpolate.js';
|
||||||
import _ol_geom_flat_transform_ from '../geom/flat/transform.js';
|
import _ol_geom_flat_transform_ from '../geom/flat/transform.js';
|
||||||
import _ol_transform_ from '../transform.js';
|
import _ol_transform_ from '../transform.js';
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ RenderFeature.prototype.getFlatInteriorPoints = function() {
|
|||||||
*/
|
*/
|
||||||
RenderFeature.prototype.getFlatMidpoint = function() {
|
RenderFeature.prototype.getFlatMidpoint = function() {
|
||||||
if (!this.flatMidpoints_) {
|
if (!this.flatMidpoints_) {
|
||||||
this.flatMidpoints_ = _ol_geom_flat_interpolate_.lineString(
|
this.flatMidpoints_ = interpolatePoint(
|
||||||
this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5);
|
this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5);
|
||||||
}
|
}
|
||||||
return this.flatMidpoints_;
|
return this.flatMidpoints_;
|
||||||
@@ -169,7 +169,7 @@ RenderFeature.prototype.getFlatMidpoints = function() {
|
|||||||
const ends = this.ends_;
|
const ends = this.ends_;
|
||||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||||
const end = ends[i];
|
const end = ends[i];
|
||||||
const midpoint = _ol_geom_flat_interpolate_.lineString(
|
const midpoint = interpolatePoint(
|
||||||
flatCoordinates, offset, end, 2, 0.5);
|
flatCoordinates, offset, end, 2, 0.5);
|
||||||
extend(this.flatMidpoints_, midpoint);
|
extend(this.flatMidpoints_, midpoint);
|
||||||
offset = end;
|
offset = end;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ol_geom_flat_interpolate_ from '../../../../../src/ol/geom/flat/interpolate.js';
|
import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js';
|
||||||
|
|
||||||
|
|
||||||
describe('ol.geom.flat.interpolate', function() {
|
describe('ol.geom.flat.interpolate', function() {
|
||||||
@@ -8,14 +8,14 @@ describe('ol.geom.flat.interpolate', function() {
|
|||||||
it('returns the expected value for single points', function() {
|
it('returns the expected value for single points', function() {
|
||||||
const flatCoordinates = [0, 1];
|
const flatCoordinates = [0, 1];
|
||||||
const point =
|
const point =
|
||||||
_ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 2, 2, 0.5);
|
interpolatePoint(flatCoordinates, 0, 2, 2, 0.5);
|
||||||
expect(point).to.eql([0, 1]);
|
expect(point).to.eql([0, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the expected value for simple line segments', function() {
|
it('returns the expected value for simple line segments', function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3];
|
const flatCoordinates = [0, 1, 2, 3];
|
||||||
const point =
|
const point =
|
||||||
_ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 4, 2, 0.5);
|
interpolatePoint(flatCoordinates, 0, 4, 2, 0.5);
|
||||||
expect(point).to.eql([1, 2]);
|
expect(point).to.eql([1, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -23,14 +23,14 @@ describe('ol.geom.flat.interpolate', function() {
|
|||||||
'coordinate',
|
'coordinate',
|
||||||
function() {
|
function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 4, 5];
|
const flatCoordinates = [0, 1, 2, 3, 4, 5];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 6, 2, 0.5);
|
flatCoordinates, 0, 6, 2, 0.5);
|
||||||
expect(point).to.eql([2, 3]);
|
expect(point).to.eql([2, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('also when vertices are repeated', function() {
|
xit('also when vertices are repeated', function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5];
|
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 6, 2, 0.5);
|
flatCoordinates, 0, 6, 2, 0.5);
|
||||||
expect(point).to.eql([2, 3]);
|
expect(point).to.eql([2, 3]);
|
||||||
});
|
});
|
||||||
@@ -39,14 +39,14 @@ describe('ol.geom.flat.interpolate', function() {
|
|||||||
'two existing coordinates',
|
'two existing coordinates',
|
||||||
function() {
|
function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
|
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 8, 2, 0.5);
|
flatCoordinates, 0, 8, 2, 0.5);
|
||||||
expect(point).to.eql([3, 4]);
|
expect(point).to.eql([3, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('also when vertices are repeated', function() {
|
xit('also when vertices are repeated', function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7];
|
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 8, 2, 0.5);
|
flatCoordinates, 0, 8, 2, 0.5);
|
||||||
expect(point).to.eql([3, 4]);
|
expect(point).to.eql([3, 4]);
|
||||||
});
|
});
|
||||||
@@ -54,7 +54,7 @@ describe('ol.geom.flat.interpolate', function() {
|
|||||||
it('returns the expected value when the coordinates are not evenly spaced',
|
it('returns the expected value when the coordinates are not evenly spaced',
|
||||||
function() {
|
function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 6, 7];
|
const flatCoordinates = [0, 1, 2, 3, 6, 7];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 6, 2, 0.5);
|
flatCoordinates, 0, 6, 2, 0.5);
|
||||||
expect(point).to.eql([3, 4]);
|
expect(point).to.eql([3, 4]);
|
||||||
});
|
});
|
||||||
@@ -62,7 +62,7 @@ describe('ol.geom.flat.interpolate', function() {
|
|||||||
xit('also when vertices are repeated',
|
xit('also when vertices are repeated',
|
||||||
function() {
|
function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
|
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 6, 2, 0.5);
|
flatCoordinates, 0, 6, 2, 0.5);
|
||||||
expect(point).to.eql([3, 4]);
|
expect(point).to.eql([3, 4]);
|
||||||
});
|
});
|
||||||
@@ -70,7 +70,7 @@ describe('ol.geom.flat.interpolate', function() {
|
|||||||
it('returns the expected value when using opt_dest',
|
it('returns the expected value when using opt_dest',
|
||||||
function() {
|
function() {
|
||||||
const flatCoordinates = [0, 1, 2, 3, 6, 7];
|
const flatCoordinates = [0, 1, 2, 3, 6, 7];
|
||||||
const point = _ol_geom_flat_interpolate_.lineString(
|
const point = interpolatePoint(
|
||||||
flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
|
flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
|
||||||
expect(point).to.eql([3, 4]);
|
expect(point).to.eql([3, 4]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user