Refactor ol.geom.LineString

This commit is contained in:
Tom Payne
2013-11-09 15:43:09 +01:00
parent a415b66e88
commit ec748f254e
2 changed files with 166 additions and 41 deletions

View File

@@ -1,7 +1,5 @@
goog.provide('ol.geom.LineString');
goog.require('goog.asserts');
goog.require('ol.extent');
goog.require('ol.geom.Geometry');
@@ -10,17 +8,11 @@ goog.require('ol.geom.Geometry');
* @constructor
* @extends {ol.geom.Geometry}
* @param {ol.geom.RawLineString} coordinates Coordinates.
* @param {ol.geom.Layout=} opt_layout Layout.
*/
ol.geom.LineString = function(coordinates) {
ol.geom.LineString = function(coordinates, opt_layout) {
goog.base(this);
/**
* @private
* @type {ol.geom.RawLineString}
*/
this.coordinates_ = coordinates;
this.setCoordinates(coordinates, opt_layout);
};
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
@@ -29,21 +21,8 @@ goog.inherits(ol.geom.LineString, ol.geom.Geometry);
* @return {ol.geom.RawLineString} Coordinates.
*/
ol.geom.LineString.prototype.getCoordinates = function() {
return this.coordinates_;
};
/**
* @inheritDoc
*/
ol.geom.LineString.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) {
this.extent = ol.extent.createOrUpdateFromCoordinates(
this.coordinates_, this.extent);
this.extentRevision = this.revision;
}
goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent);
return ol.geom.inflateCoordinates(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
};
@@ -57,21 +36,11 @@ ol.geom.LineString.prototype.getType = function() {
/**
* @param {ol.geom.RawLineString} coordinates Coordinates.
* @param {ol.geom.Layout=} opt_layout Layout.
*/
ol.geom.LineString.prototype.setCoordinates = function(coordinates) {
this.coordinates_ = coordinates;
ol.geom.LineString.prototype.setCoordinates =
function(coordinates, opt_layout) {
this.setLayout(opt_layout, coordinates, 1);
ol.geom.deflateCoordinates(this.flatCoordinates, 0, coordinates, this.stride);
this.dispatchChangeEvent();
};
/**
* @inheritDoc
*/
ol.geom.LineString.prototype.transform = function(transformFn) {
var coordinates = this.coordinates_;
var i, ii;
for (i = 0, ii = coordinates.length; i < ii; ++i) {
var coordinate = coordinates[i];
transformFn(coordinate, coordinate, 2);
}
};