Allow geometries to use a shared vertex array

The ol.geom.SharedVertices structure represents a flattened array of vertex coordinates.  This is intended to support optimal WebGL rendering.
This commit is contained in:
Tim Schaub
2013-03-02 18:39:24 +01:00
parent bdfa2cc88c
commit b52d283641
23 changed files with 1086 additions and 217 deletions

View File

@@ -2,43 +2,53 @@ goog.provide('ol.geom.Polygon');
goog.require('goog.asserts');
goog.require('ol.Extent');
goog.require('ol.geom.CoordinateArray');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.GeometryType');
goog.require('ol.geom.LinearRing');
goog.require('ol.geom.SharedVertices');
goog.require('ol.geom.VertexArray');
/**
* @constructor
* @extends {ol.geom.Geometry}
* @param {Array.<ol.geom.CoordinateArray>} coordinates Array of rings. First
* @param {Array.<ol.geom.VertexArray>} coordinates Array of rings. First
* is outer, any remaining are inner.
* @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
*/
ol.geom.Polygon = function(coordinates) {
ol.geom.Polygon = function(coordinates, opt_shared) {
goog.base(this);
goog.asserts.assert(goog.isArray(coordinates[0][0]));
var numRings = coordinates.length,
var vertices = opt_shared,
dimension;
if (!goog.isDef(vertices)) {
// try to get dimension from first vertex in first ring
dimension = coordinates[0][0].length;
vertices = new ol.geom.SharedVertices({dimension: dimension});
}
/**
* @type {ol.geom.SharedVertices}
*/
this.vertices = vertices;
var numRings = coordinates.length;
/**
* @type {Array.<ol.geom.LinearRing>}
*/
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);
}
this.rings[i] = new ol.geom.LinearRing(coordinates[i], vertices);
}
/**
* @type {number}
*/
this.dimension = dimension;
this.dimension = vertices.getDimension();
goog.asserts.assert(this.dimension >= 2);
/**
@@ -59,6 +69,19 @@ ol.geom.Polygon.prototype.getBounds = function() {
};
/**
* @return {Array.<ol.geom.VertexArray>} Coordinates array.
*/
ol.geom.Polygon.prototype.getCoordinates = function() {
var count = this.rings.length;
var coordinates = new Array(count);
for (var i = 0; i < count; ++i) {
coordinates[i] = this.rings[i].getCoordinates();
}
return coordinates;
};
/**
* @inheritDoc
*/