ol/geom/flat/length export
This commit is contained in:
@@ -12,7 +12,7 @@ import {deflateCoordinates} from '../geom/flat/deflate.js';
|
||||
import {inflateCoordinates} from '../geom/flat/inflate.js';
|
||||
import _ol_geom_flat_interpolate_ from '../geom/flat/interpolate.js';
|
||||
import _ol_geom_flat_intersectsextent_ from '../geom/flat/intersectsextent.js';
|
||||
import _ol_geom_flat_length_ from '../geom/flat/length.js';
|
||||
import {lineStringLength} from '../geom/flat/length.js';
|
||||
import {forEach as forEachSegment} from '../geom/flat/segments.js';
|
||||
import _ol_geom_flat_simplify_ from '../geom/flat/simplify.js';
|
||||
|
||||
@@ -183,7 +183,7 @@ LineString.prototype.getCoordinateAt = function(fraction, opt_dest) {
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.getLength = function() {
|
||||
return _ol_geom_flat_length_.lineString(
|
||||
return lineStringLength(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/flat/length
|
||||
*/
|
||||
const _ol_geom_flat_length_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +10,7 @@ const _ol_geom_flat_length_ = {};
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} Length.
|
||||
*/
|
||||
_ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride) {
|
||||
export function lineStringLength(flatCoordinates, offset, end, stride) {
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
let length = 0;
|
||||
@@ -23,7 +22,7 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride
|
||||
y1 = y2;
|
||||
}
|
||||
return length;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,11 +32,10 @@ _ol_geom_flat_length_.lineString = function(flatCoordinates, offset, end, stride
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} Perimeter.
|
||||
*/
|
||||
_ol_geom_flat_length_.linearRing = function(flatCoordinates, offset, end, stride) {
|
||||
let perimeter = _ol_geom_flat_length_.lineString(flatCoordinates, offset, end, stride);
|
||||
export function linearRingLength(flatCoordinates, offset, end, stride) {
|
||||
let perimeter = lineStringLength(flatCoordinates, offset, end, stride);
|
||||
const dx = flatCoordinates[end - stride] - flatCoordinates[offset];
|
||||
const dy = flatCoordinates[end - stride + 1] - flatCoordinates[offset + 1];
|
||||
perimeter += Math.sqrt(dx * dx + dy * dy);
|
||||
return perimeter;
|
||||
};
|
||||
export default _ol_geom_flat_length_;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {buffer, clone, coordinateRelationship, createEmpty, createOrUpdate,
|
||||
import Relationship from '../../extent/Relationship.js';
|
||||
import GeometryType from '../../geom/GeometryType.js';
|
||||
import {inflateCoordinates, inflateCoordinatesArray, inflateMultiCoordinatesArray} from '../../geom/flat/inflate.js';
|
||||
import _ol_geom_flat_length_ from '../../geom/flat/length.js';
|
||||
import {lineStringLength} from '../../geom/flat/length.js';
|
||||
import _ol_geom_flat_textpath_ from '../../geom/flat/textpath.js';
|
||||
import _ol_geom_flat_transform_ from '../../geom/flat/transform.js';
|
||||
import {CANVAS_LINE_DASH} from '../../has.js';
|
||||
@@ -710,7 +710,7 @@ CanvasReplay.prototype.replay_ = function(
|
||||
const textKey = /** @type {string} */ (instruction[13]);
|
||||
const textScale = /** @type {number} */ (instruction[14]);
|
||||
|
||||
const pathLength = _ol_geom_flat_length_.lineString(pixelCoordinates, begin, end, 2);
|
||||
const pathLength = lineStringLength(pixelCoordinates, begin, end, 2);
|
||||
const textLength = measure(text);
|
||||
if (overflow || textLength <= pathLength) {
|
||||
const textAlign = /** @type {ol.render.canvas.TextReplay} */ (this).textStates[textKey].textAlign;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js';
|
||||
import {lineStringLength, linearRingLength} from '../../../../../src/ol/geom/flat/length.js';
|
||||
|
||||
|
||||
describe('ol.geom.flat.length', function() {
|
||||
@@ -13,7 +13,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 0;
|
||||
const end = 8;
|
||||
const expected = 3;
|
||||
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 2;
|
||||
const end = 8;
|
||||
const expected = 2;
|
||||
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 0;
|
||||
const end = 4;
|
||||
const expected = 1;
|
||||
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 0;
|
||||
const end = 12;
|
||||
const expected = 3;
|
||||
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 3;
|
||||
const end = 12;
|
||||
const expected = 2;
|
||||
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 0;
|
||||
const end = 6;
|
||||
const expected = 1;
|
||||
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 0;
|
||||
const end = 8;
|
||||
const expected = 4;
|
||||
const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride);
|
||||
const got = linearRingLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ describe('ol.geom.flat.length', function() {
|
||||
const offset = 0;
|
||||
const end = 14;
|
||||
const expected = 8;
|
||||
const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride);
|
||||
const got = linearRingLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ol_geom_flat_textpath_ from '../../../../../src/ol/geom/flat/textpath.js';
|
||||
import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js';
|
||||
import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js';
|
||||
|
||||
describe('textpath', function() {
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('textpath', function() {
|
||||
});
|
||||
|
||||
it('renders angled text', function() {
|
||||
const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2);
|
||||
const length = lineStringLength(angled, 0, angled.length, 2);
|
||||
const startM = length / 2 - 15;
|
||||
const instructions = _ol_geom_flat_textpath_.lineString(
|
||||
angled, 0, angled.length, 2, 'foo', measure, startM, Infinity);
|
||||
@@ -78,7 +78,7 @@ describe('textpath', function() {
|
||||
});
|
||||
|
||||
it('respects maxAngle', function() {
|
||||
const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2);
|
||||
const length = lineStringLength(angled, 0, angled.length, 2);
|
||||
const startM = length / 2 - 15;
|
||||
const instructions = _ol_geom_flat_textpath_.lineString(
|
||||
angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4);
|
||||
@@ -86,7 +86,7 @@ describe('textpath', function() {
|
||||
});
|
||||
|
||||
it('uses the smallest angle for maxAngleDelta', function() {
|
||||
const length = _ol_geom_flat_length_.lineString(reverseangled, 0, reverseangled.length, 2);
|
||||
const length = lineStringLength(reverseangled, 0, reverseangled.length, 2);
|
||||
const startM = length / 2 - 15;
|
||||
const instructions = _ol_geom_flat_textpath_.lineString(
|
||||
reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI);
|
||||
@@ -94,7 +94,7 @@ describe('textpath', function() {
|
||||
});
|
||||
|
||||
it('respects the offset option', function() {
|
||||
const length = _ol_geom_flat_length_.lineString(angled, 2, angled.length, 2);
|
||||
const length = lineStringLength(angled, 2, angled.length, 2);
|
||||
const startM = length / 2 - 15;
|
||||
const instructions = _ol_geom_flat_textpath_.lineString(
|
||||
angled, 2, angled.length, 2, 'foo', measure, startM, Infinity);
|
||||
@@ -103,7 +103,7 @@ describe('textpath', function() {
|
||||
});
|
||||
|
||||
it('respects the end option', function() {
|
||||
const length = _ol_geom_flat_length_.lineString(angled, 0, 4, 2);
|
||||
const length = lineStringLength(angled, 0, 4, 2);
|
||||
const startM = length / 2 - 15;
|
||||
const instructions = _ol_geom_flat_textpath_.lineString(
|
||||
angled, 0, 4, 2, 'foo', measure, startM, Infinity);
|
||||
|
||||
Reference in New Issue
Block a user