Remove use of shared vertices in geom package
This commit is contained in:
@@ -2,47 +2,34 @@ goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.SharedVertices');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {ol.CoordinateArray} coordinates Vertex array (e.g.
|
||||
* @param {ol.CoordinateArray} coordinates Array of coordinates (e.g.
|
||||
* [[x0, y0], [x1, y1]]).
|
||||
* @param {ol.geom.SharedVertices=} opt_shared Shared vertices.
|
||||
*/
|
||||
ol.geom.LineString = function(coordinates, opt_shared) {
|
||||
ol.geom.LineString = function(coordinates) {
|
||||
goog.base(this);
|
||||
goog.asserts.assert(goog.isArray(coordinates[0]));
|
||||
|
||||
var vertices = opt_shared,
|
||||
dimension;
|
||||
|
||||
if (!goog.isDef(vertices)) {
|
||||
dimension = coordinates[0].length;
|
||||
vertices = new ol.geom.SharedVertices({dimension: dimension});
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {ol.geom.SharedVertices}
|
||||
*/
|
||||
this.vertices = vertices;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* Array of coordinates.
|
||||
* @type {ol.CoordinateArray}
|
||||
* @private
|
||||
*/
|
||||
this.sharedId_ = vertices.add(coordinates);
|
||||
this.coordinates_ = coordinates;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.dimension = vertices.getDimension();
|
||||
this.dimension = coordinates[0].length;
|
||||
goog.asserts.assert(this.dimension >= 2);
|
||||
|
||||
/**
|
||||
@@ -62,7 +49,9 @@ goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||
* @return {number} The vertex coordinate value.
|
||||
*/
|
||||
ol.geom.LineString.prototype.get = function(index, dim) {
|
||||
return this.vertices.get(this.sharedId_, index, dim);
|
||||
var coordinates = this.getCoordinates();
|
||||
goog.asserts.assert(coordinates.length > index);
|
||||
return coordinates[index][dim];
|
||||
};
|
||||
|
||||
|
||||
@@ -71,17 +60,7 @@ ol.geom.LineString.prototype.get = function(index, dim) {
|
||||
* @return {ol.CoordinateArray} Coordinates array.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCoordinates = function() {
|
||||
var count = this.getCount();
|
||||
var coordinates = new Array(count);
|
||||
var vertex;
|
||||
for (var i = 0; i < count; ++i) {
|
||||
vertex = new Array(this.dimension);
|
||||
for (var j = 0; j < this.dimension; ++j) {
|
||||
vertex[j] = this.get(i, j);
|
||||
}
|
||||
coordinates[i] = vertex;
|
||||
}
|
||||
return coordinates;
|
||||
return this.coordinates_;
|
||||
};
|
||||
|
||||
|
||||
@@ -90,7 +69,7 @@ ol.geom.LineString.prototype.getCoordinates = function() {
|
||||
* @return {number} The vertex count.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCount = function() {
|
||||
return this.vertices.getCount(this.sharedId_);
|
||||
return this.getCoordinates().length;
|
||||
};
|
||||
|
||||
|
||||
@@ -99,34 +78,12 @@ ol.geom.LineString.prototype.getCount = function() {
|
||||
*/
|
||||
ol.geom.LineString.prototype.getBounds = function() {
|
||||
if (goog.isNull(this.bounds_)) {
|
||||
var dimension = this.dimension,
|
||||
vertices = this.vertices,
|
||||
id = this.sharedId_,
|
||||
count = vertices.getCount(id),
|
||||
start = vertices.getStart(id),
|
||||
end = start + (count * dimension),
|
||||
coordinates = vertices.coordinates,
|
||||
minX, maxX,
|
||||
minY, maxY,
|
||||
x, y, i;
|
||||
|
||||
minX = maxX = coordinates[start];
|
||||
minY = maxY = coordinates[start + 1];
|
||||
for (i = start + dimension; i < end; i += dimension) {
|
||||
x = coordinates[i];
|
||||
y = coordinates[i + 1];
|
||||
if (x < minX) {
|
||||
minX = x;
|
||||
} else if (x > maxX) {
|
||||
maxX = x;
|
||||
}
|
||||
if (y < minY) {
|
||||
minY = y;
|
||||
} else if (y > maxY) {
|
||||
maxY = y;
|
||||
}
|
||||
var coordinates = this.getCoordinates();
|
||||
var extent = ol.extent.createEmpty();
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
ol.extent.extendCoordinate(extent, coordinates[i]);
|
||||
}
|
||||
this.bounds_ = [minX, minY, maxX, maxY];
|
||||
this.bounds_ = extent;
|
||||
}
|
||||
return this.bounds_;
|
||||
};
|
||||
@@ -140,15 +97,6 @@ ol.geom.LineString.prototype.getType = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the identifier used to mark this line in the shared vertices structure.
|
||||
* @return {number} The identifier.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getSharedId = function() {
|
||||
return this.sharedId_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the distance from a coordinate to this linestring.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user