Point, linestring, and linearring coordinates as Float32Array
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
goog.provide('ol.geom.Coordinate');
|
||||
goog.provide('ol.geom.CoordinateArray');
|
||||
goog.provide('ol.geom.Geometry');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.geom.Geometry = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array.<number>}
|
||||
*/
|
||||
ol.geom.Coordinate;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Array.<ol.geom.Coordinate>}
|
||||
*/
|
||||
ol.geom.CoordinateArray;
|
||||
|
||||
27
src/ol/geom/linearring.js
Normal file
27
src/ol/geom/linearring.js
Normal file
@@ -0,0 +1,27 @@
|
||||
goog.provide('ol.geom.LinearRing');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.vec.Float32Array');
|
||||
goog.require('ol.geom.CoordinateArray');
|
||||
goog.require('ol.geom.LineString');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.LineString}
|
||||
* @param {ol.geom.CoordinateArray} coordinates Coordinates array (e.g.
|
||||
* [[x0, y0], [x1, y1], [x0, y0]]).
|
||||
*/
|
||||
ol.geom.LinearRing = function(coordinates) {
|
||||
|
||||
goog.base(this, coordinates);
|
||||
|
||||
/**
|
||||
* We're intentionally not enforcing that rings be closed right now. This
|
||||
* will allow proper rendering of data from tiled vector sources that leave
|
||||
* open rings.
|
||||
*/
|
||||
|
||||
};
|
||||
goog.inherits(ol.geom.LinearRing, ol.geom.LineString);
|
||||
@@ -1,5 +1,8 @@
|
||||
goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.vec.Float32Array');
|
||||
goog.require('ol.geom.CoordinateArray');
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
|
||||
@@ -7,13 +10,29 @@ goog.require('ol.geom.Geometry');
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @param {Array} coordinates Coordinates array.
|
||||
* @param {ol.geom.CoordinateArray} coordinates Coordinates array (e.g.
|
||||
* [[x0, y0], [x1, y1]]).
|
||||
*/
|
||||
ol.geom.LineString = function(coordinates) {
|
||||
|
||||
// assume the same dimension for all coordinates
|
||||
var dimension = coordinates[0].length,
|
||||
count = coordinates.length,
|
||||
length = count * dimension;
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.coordinates = coordinates;
|
||||
this.coordinates = new Float32Array(length);
|
||||
for (var i = 0; i < count; ++i) {
|
||||
goog.asserts.assert(coordinates[i].length === dimension);
|
||||
this.coordinates.set(coordinates[i], i * dimension);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = dimension;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,19 +1,39 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.geom.CoordinateArray');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LineString');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @param {Array} coordinates Coordinates array.
|
||||
* @param {Array.<ol.geom.CoordinateArray>} coordinates Coordinates array.
|
||||
*/
|
||||
ol.geom.MultiLineString = function(coordinates) {
|
||||
|
||||
var numParts = coordinates.length,
|
||||
dimension;
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
* @type {Array.<ol.geom.LineString>}
|
||||
*/
|
||||
this.coordinates = coordinates;
|
||||
this.components = new Array(numParts);
|
||||
for (var i = 0; i < numParts; ++i) {
|
||||
this.components[i] = new ol.geom.LineString(coordinates[i]);
|
||||
if (!goog.isDef(dimension)) {
|
||||
dimension = this.components[i];
|
||||
} else {
|
||||
goog.asserts.assert(this.components[i].dimension === dimension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = dimension;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,19 +1,39 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.geom.CoordinateArray');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Point');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @param {Array} coordinates Coordinates array.
|
||||
* @param {ol.geom.CoordinateArray} coordinates Coordinates array.
|
||||
*/
|
||||
ol.geom.MultiPoint = function(coordinates) {
|
||||
|
||||
var numParts = coordinates.length,
|
||||
dimension;
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
* @type {Array.<ol.geom.Point>}
|
||||
*/
|
||||
this.coordinates = coordinates;
|
||||
this.components = new Array(numParts);
|
||||
for (var i = 0; i < numParts; ++i) {
|
||||
this.components[i] = new ol.geom.Point(coordinates[i]);
|
||||
if (!goog.isDef(dimension)) {
|
||||
dimension = this.components[i].dimension;
|
||||
} else {
|
||||
goog.asserts.assert(this.components[i].dimension === dimension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = dimension;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,19 +1,40 @@
|
||||
goog.provide('ol.geom.MultiPolygon');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.geom.CoordinateArray');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Polygon');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @param {Array} coordinates Coordinates array.
|
||||
* @param {Array.<Array.<ol.geom.CoordinateArray>>} coordinates Coordinates
|
||||
* array.
|
||||
*/
|
||||
ol.geom.MultiPolygon = function(coordinates) {
|
||||
|
||||
var numParts = coordinates.length,
|
||||
dimension;
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
* @type {Array.<ol.geom.Polygon>}
|
||||
*/
|
||||
this.coordinates = coordinates;
|
||||
this.components = new Array(numParts);
|
||||
for (var i = 0; i < numParts; ++i) {
|
||||
this.components[i] = new ol.geom.Polygon(coordinates[i]);
|
||||
if (!goog.isDef(dimension)) {
|
||||
dimension = this.components[i];
|
||||
} else {
|
||||
goog.asserts.assert(this.components[i].dimension === dimension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = dimension;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.vec.Float32Array');
|
||||
goog.require('ol.geom.Coordinate');
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
|
||||
@@ -7,13 +10,19 @@ goog.require('ol.geom.Geometry');
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @param {Array} coordinates Coordinates array.
|
||||
* @param {ol.geom.Coordinate} coordinates Coordinates array (e.g. [x, y]).
|
||||
*/
|
||||
ol.geom.Point = function(coordinates) {
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.coordinates = coordinates;
|
||||
this.coordinates = new Float32Array(coordinates);
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = coordinates.length;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
goog.provide('ol.geom.Polygon');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.vec.Float32Array');
|
||||
goog.require('ol.geom.CoordinateArray');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.geom.Geometry}
|
||||
* @param {Array} coordinates Coordinates array.
|
||||
* @param {Array.<ol.geom.CoordinateArray>} coordinates Array of rings. First
|
||||
* is outer, any remaining are inner.
|
||||
*/
|
||||
ol.geom.Polygon = function(coordinates) {
|
||||
|
||||
var numRings = coordinates.length,
|
||||
dimension;
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
* @type {Array.<ol.geom.LinearRing>}
|
||||
*/
|
||||
this.coordinates = coordinates;
|
||||
this.rings = new Array(numRings);
|
||||
for (var i = 0; i < numRings; ++i) {
|
||||
this.rings[i] = new ol.geom.LinearRing(coordinates[i]);
|
||||
if (!goog.isDef(dimension)) {
|
||||
dimension = this.rings[i].dimension;
|
||||
} else {
|
||||
goog.asserts.assert(this.rings[i].dimension === dimension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = dimension;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user