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