ol/geom/flat/length export

This commit is contained in:
raiyni
2018-02-12 23:27:38 -06:00
parent fb548b1b45
commit 05a648d4f3
5 changed files with 24 additions and 26 deletions

View File

@@ -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);
};

View File

@@ -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_;
}

View File

@@ -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;