Point, linestring, and linearring coordinates as Float32Array

This commit is contained in:
Tim Schaub
2013-01-18 15:57:48 -07:00
parent 278d32061f
commit fd0a5f3622
13 changed files with 372 additions and 18 deletions

View File

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