Named exports from ol/geom/flat/area
This commit is contained in:
@@ -6,7 +6,7 @@ import {closestSquaredDistanceXY} from '../extent.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||
import _ol_geom_flat_area_ from '../geom/flat/area.js';
|
||||
import {linearRing as linearRingArea} from '../geom/flat/area.js';
|
||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
||||
import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js';
|
||||
import _ol_geom_flat_inflate_ from '../geom/flat/inflate.js';
|
||||
@@ -83,8 +83,7 @@ LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDis
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.getArea = function() {
|
||||
return _ol_geom_flat_area_.linearRing(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
return linearRingArea(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import GeometryType from '../geom/GeometryType.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||
import _ol_geom_flat_area_ from '../geom/flat/area.js';
|
||||
import {linearRingss as linearRingssArea} from '../geom/flat/area.js';
|
||||
import _ol_geom_flat_center_ from '../geom/flat/center.js';
|
||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
||||
import _ol_geom_flat_contains_ from '../geom/flat/contains.js';
|
||||
@@ -162,8 +162,7 @@ MultiPolygon.prototype.containsXY = function(x, y) {
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getArea = function() {
|
||||
return _ol_geom_flat_area_.linearRingss(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
|
||||
return linearRingssArea(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import LinearRing from '../geom/LinearRing.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||
import {offset as sphereOffset} from '../sphere.js';
|
||||
import _ol_geom_flat_area_ from '../geom/flat/area.js';
|
||||
import {linearRings as linearRingsArea} from '../geom/flat/area.js';
|
||||
import _ol_geom_flat_closest_ from '../geom/flat/closest.js';
|
||||
import _ol_geom_flat_contains_ from '../geom/flat/contains.js';
|
||||
import _ol_geom_flat_deflate_ from '../geom/flat/deflate.js';
|
||||
@@ -152,8 +152,7 @@ Polygon.prototype.containsXY = function(x, y) {
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getArea = function() {
|
||||
return _ol_geom_flat_area_.linearRings(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
|
||||
return linearRingsArea(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/geom/flat/area
|
||||
*/
|
||||
const _ol_geom_flat_area_ = {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +10,7 @@ const _ol_geom_flat_area_ = {};
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} Area.
|
||||
*/
|
||||
_ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride) {
|
||||
export function linearRing(flatCoordinates, offset, end, stride) {
|
||||
let twiceArea = 0;
|
||||
let x1 = flatCoordinates[end - stride];
|
||||
let y1 = flatCoordinates[end - stride + 1];
|
||||
@@ -23,7 +22,7 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride)
|
||||
y1 = y2;
|
||||
}
|
||||
return twiceArea / 2;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,15 +32,15 @@ _ol_geom_flat_area_.linearRing = function(flatCoordinates, offset, end, stride)
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} Area.
|
||||
*/
|
||||
_ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride) {
|
||||
export function linearRings(flatCoordinates, offset, ends, stride) {
|
||||
let area = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
area += _ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride);
|
||||
area += linearRing(flatCoordinates, offset, end, stride);
|
||||
offset = end;
|
||||
}
|
||||
return area;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,13 +50,12 @@ _ol_geom_flat_area_.linearRings = function(flatCoordinates, offset, ends, stride
|
||||
* @param {number} stride Stride.
|
||||
* @return {number} Area.
|
||||
*/
|
||||
_ol_geom_flat_area_.linearRingss = function(flatCoordinates, offset, endss, stride) {
|
||||
export function linearRingss(flatCoordinates, offset, endss, stride) {
|
||||
let area = 0;
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i];
|
||||
area += _ol_geom_flat_area_.linearRings(flatCoordinates, offset, ends, stride);
|
||||
area += linearRings(flatCoordinates, offset, ends, stride);
|
||||
offset = ends[ends.length - 1];
|
||||
}
|
||||
return area;
|
||||
};
|
||||
export default _ol_geom_flat_area_;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/geom/flat/topology
|
||||
*/
|
||||
import _ol_geom_flat_area_ from '../flat/area.js';
|
||||
import {linearRing as linearRingArea} from '../flat/area.js';
|
||||
const _ol_geom_flat_topology_ = {};
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ _ol_geom_flat_topology_.lineStringIsClosed = function(flatCoordinates, offset, e
|
||||
const lastCoord = end - stride;
|
||||
if (flatCoordinates[offset] === flatCoordinates[lastCoord] &&
|
||||
flatCoordinates[offset + 1] === flatCoordinates[lastCoord + 1] && (end - offset) / stride > 3) {
|
||||
return !!_ol_geom_flat_area_.linearRing(flatCoordinates, offset, end, stride);
|
||||
return !!linearRingArea(flatCoordinates, offset, end, stride);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import _ol_geom_flat_area_ from '../../../../../src/ol/geom/flat/area.js';
|
||||
import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js';
|
||||
|
||||
describe('ol.geom.flat.area', function() {
|
||||
|
||||
describe('ol.geom.flat.area.linearRing', function() {
|
||||
|
||||
it('calculates the area of a triangle', function() {
|
||||
const area = _ol_geom_flat_area_.linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
|
||||
const area = linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
|
||||
expect(area).to.be(0.5);
|
||||
});
|
||||
|
||||
it('calculates the area of a unit square', function() {
|
||||
const area =
|
||||
_ol_geom_flat_area_.linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
|
||||
const area = linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
|
||||
expect(area).to.be(1);
|
||||
});
|
||||
|
||||
@@ -20,7 +19,7 @@ describe('ol.geom.flat.area', function() {
|
||||
describe('ol.geom.flat.area.linearRings', function() {
|
||||
|
||||
it('calculates the area with holes', function() {
|
||||
const area = _ol_geom_flat_area_.linearRings(
|
||||
const area = linearRings(
|
||||
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2);
|
||||
expect(area).to.be(8);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user