Use inherited dispatchChangeEvent and getRevision in ol.geom.Geometry

This commit is contained in:
Tom Payne
2014-01-21 11:43:08 +01:00
parent 911cb302e8
commit edcb38232f
10 changed files with 26 additions and 50 deletions

View File

@@ -88,14 +88,14 @@ ol.geom.Circle.prototype.getCenter = function() {
* @inheritDoc * @inheritDoc
*/ */
ol.geom.Circle.prototype.getExtent = function(opt_extent) { ol.geom.Circle.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) { if (this.extentRevision != this.getRevision()) {
var flatCoordinates = this.flatCoordinates; var flatCoordinates = this.flatCoordinates;
var radius = flatCoordinates[this.stride] - flatCoordinates[0]; var radius = flatCoordinates[this.stride] - flatCoordinates[0];
this.extent = ol.extent.createOrUpdate( this.extent = ol.extent.createOrUpdate(
flatCoordinates[0] - radius, flatCoordinates[1] - radius, flatCoordinates[0] - radius, flatCoordinates[1] - radius,
flatCoordinates[0] + radius, flatCoordinates[1] + radius, flatCoordinates[0] + radius, flatCoordinates[1] + radius,
this.extent); this.extent);
this.extentRevision = this.revision; this.extentRevision = this.getRevision();
} }
goog.asserts.assert(goog.isDef(this.extent)); goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent); return ol.extent.returnOrUpdate(this.extent, opt_extent);

View File

@@ -2,7 +2,6 @@ goog.provide('ol.geom.Geometry');
goog.provide('ol.geom.GeometryType'); goog.provide('ol.geom.GeometryType');
goog.require('goog.asserts'); goog.require('goog.asserts');
goog.require('goog.events.EventType');
goog.require('goog.functions'); goog.require('goog.functions');
goog.require('ol.Observable'); goog.require('ol.Observable');
@@ -43,12 +42,6 @@ ol.geom.Geometry = function() {
goog.base(this); goog.base(this);
/**
* @protected
* @type {number}
*/
this.revision = 0;
/** /**
* @protected * @protected
* @type {ol.Extent|undefined} * @type {ol.Extent|undefined}
@@ -129,15 +122,6 @@ ol.geom.Geometry.prototype.containsCoordinate = function(coordinate) {
ol.geom.Geometry.prototype.containsXY = goog.functions.FALSE; ol.geom.Geometry.prototype.containsXY = goog.functions.FALSE;
/**
* FIXME empty description for jsdoc
*/
ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
++this.revision;
this.dispatchEvent(goog.events.EventType.CHANGE);
};
/** /**
* @param {ol.Extent=} opt_extent Extent. * @param {ol.Extent=} opt_extent Extent.
* @return {ol.Extent} extent Extent. * @return {ol.Extent} extent Extent.
@@ -145,14 +129,6 @@ ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
ol.geom.Geometry.prototype.getExtent = goog.abstractMethod; ol.geom.Geometry.prototype.getExtent = goog.abstractMethod;
/**
* @return {number} Revision.
*/
ol.geom.Geometry.prototype.getRevision = function() {
return this.revision;
};
/** /**
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @return {ol.geom.Geometry} Simplified geometry. * @return {ol.geom.Geometry} Simplified geometry.

View File

@@ -91,7 +91,7 @@ ol.geom.GeometryCollection.prototype.containsXY = function(x, y) {
* @inheritDoc * @inheritDoc
*/ */
ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) { ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) { if (this.extentRevision != this.getRevision()) {
var extent = ol.extent.createOrUpdateEmpty(this.extent); var extent = ol.extent.createOrUpdateEmpty(this.extent);
var geometries = this.geometries_; var geometries = this.geometries_;
var i, ii; var i, ii;
@@ -99,7 +99,7 @@ ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
ol.extent.extend(extent, geometries[i].getExtent()); ol.extent.extend(extent, geometries[i].getExtent());
} }
this.extent = extent; this.extent = extent;
this.extentRevision = this.revision; this.extentRevision = this.getRevision();
} }
goog.asserts.assert(goog.isDef(this.extent)); goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent); return ol.extent.returnOrUpdate(this.extent, opt_extent);
@@ -127,10 +127,10 @@ ol.geom.GeometryCollection.prototype.getGeometriesArray = function() {
*/ */
ol.geom.GeometryCollection.prototype.getSimplifiedGeometry = ol.geom.GeometryCollection.prototype.getSimplifiedGeometry =
function(squaredTolerance) { function(squaredTolerance) {
if (this.simplifiedGeometryRevision != this.revision) { if (this.simplifiedGeometryRevision != this.getRevision()) {
goog.object.clear(this.simplifiedGeometryCache); goog.object.clear(this.simplifiedGeometryCache);
this.simplifiedGeometryMaxMinSquaredTolerance = 0; this.simplifiedGeometryMaxMinSquaredTolerance = 0;
this.simplifiedGeometryRevision = this.revision; this.simplifiedGeometryRevision = this.getRevision();
} }
if (squaredTolerance < 0 || if (squaredTolerance < 0 ||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 && (this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&

View File

@@ -56,10 +56,10 @@ ol.geom.LinearRing.prototype.closestPointXY =
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance; return minSquaredDistance;
} }
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.getRevision()) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
this.maxDeltaRevision_ = this.revision; this.maxDeltaRevision_ = this.getRevision();
} }
return ol.geom.closest.getClosestPoint( return ol.geom.closest.getClosestPoint(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,

View File

@@ -56,10 +56,10 @@ ol.geom.LineString.prototype.closestPointXY =
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance; return minSquaredDistance;
} }
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.getRevision()) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getMaxSquaredDelta(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0)); this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
this.maxDeltaRevision_ = this.revision; this.maxDeltaRevision_ = this.getRevision();
} }
return ol.geom.closest.getClosestPoint( return ol.geom.closest.getClosestPoint(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,

View File

@@ -66,10 +66,10 @@ ol.geom.MultiLineString.prototype.closestPointXY =
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance; return minSquaredDistance;
} }
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.getRevision()) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
this.flatCoordinates, 0, this.ends_, this.stride, 0)); this.flatCoordinates, 0, this.ends_, this.stride, 0));
this.maxDeltaRevision_ = this.revision; this.maxDeltaRevision_ = this.getRevision();
} }
return ol.geom.closest.getsClosestPoint( return ol.geom.closest.getsClosestPoint(
this.flatCoordinates, 0, this.ends_, this.stride, this.flatCoordinates, 0, this.ends_, this.stride,

View File

@@ -76,10 +76,10 @@ ol.geom.MultiPolygon.prototype.closestPointXY =
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance; return minSquaredDistance;
} }
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.getRevision()) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getssMaxSquaredDelta(
this.flatCoordinates, 0, this.endss_, this.stride, 0)); this.flatCoordinates, 0, this.endss_, this.stride, 0));
this.maxDeltaRevision_ = this.revision; this.maxDeltaRevision_ = this.getRevision();
} }
return ol.geom.closest.getssClosestPoint( return ol.geom.closest.getssClosestPoint(
this.flatCoordinates, 0, this.endss_, this.stride, this.flatCoordinates, 0, this.endss_, this.stride,
@@ -126,12 +126,12 @@ ol.geom.MultiPolygon.prototype.getEndss = function() {
* @return {Array.<ol.Coordinate>} Interior points. * @return {Array.<ol.Coordinate>} Interior points.
*/ */
ol.geom.MultiPolygon.prototype.getInteriorPoints = function() { ol.geom.MultiPolygon.prototype.getInteriorPoints = function() {
if (this.interiorPointsRevision_ != this.revision) { if (this.interiorPointsRevision_ != this.getRevision()) {
var ys = ol.geom.flat.linearRingssMidYs( var ys = ol.geom.flat.linearRingssMidYs(
this.flatCoordinates, 0, this.endss_, this.stride); this.flatCoordinates, 0, this.endss_, this.stride);
this.interiorPoints_ = ol.geom.flat.linearRingssGetInteriorPoints( this.interiorPoints_ = ol.geom.flat.linearRingssGetInteriorPoints(
this.flatCoordinates, 0, this.endss_, this.stride, ys); this.flatCoordinates, 0, this.endss_, this.stride, ys);
this.interiorPointsRevision_ = this.revision; this.interiorPointsRevision_ = this.getRevision();
} }
return this.interiorPoints_; return this.interiorPoints_;
}; };

View File

@@ -65,10 +65,10 @@ ol.geom.Point.prototype.getCoordinates = function() {
* @inheritDoc * @inheritDoc
*/ */
ol.geom.Point.prototype.getExtent = function(opt_extent) { ol.geom.Point.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) { if (this.extentRevision != this.getRevision()) {
this.extent = ol.extent.createOrUpdateFromCoordinate( this.extent = ol.extent.createOrUpdateFromCoordinate(
this.flatCoordinates, this.extent); this.flatCoordinates, this.extent);
this.extentRevision = this.revision; this.extentRevision = this.getRevision();
} }
goog.asserts.assert(goog.isDef(this.extent)); goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent); return ol.extent.returnOrUpdate(this.extent, opt_extent);

View File

@@ -76,10 +76,10 @@ ol.geom.Polygon.prototype.closestPointXY =
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) { ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance; return minSquaredDistance;
} }
if (this.maxDeltaRevision_ != this.revision) { if (this.maxDeltaRevision_ != this.getRevision()) {
this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta( this.maxDelta_ = Math.sqrt(ol.geom.closest.getsMaxSquaredDelta(
this.flatCoordinates, 0, this.ends_, this.stride, 0)); this.flatCoordinates, 0, this.ends_, this.stride, 0));
this.maxDeltaRevision_ = this.revision; this.maxDeltaRevision_ = this.getRevision();
} }
return ol.geom.closest.getsClosestPoint( return ol.geom.closest.getsClosestPoint(
this.flatCoordinates, 0, this.ends_, this.stride, this.flatCoordinates, 0, this.ends_, this.stride,
@@ -126,12 +126,12 @@ ol.geom.Polygon.prototype.getEnds = function() {
* @return {ol.Coordinate} Interior point. * @return {ol.Coordinate} Interior point.
*/ */
ol.geom.Polygon.prototype.getInteriorPoint = function() { ol.geom.Polygon.prototype.getInteriorPoint = function() {
if (this.interiorPointRevision_ != this.revision) { if (this.interiorPointRevision_ != this.getRevision()) {
var extent = this.getExtent(); var extent = this.getExtent();
var y = (extent[1] + extent[3]) / 2; var y = (extent[1] + extent[3]) / 2;
this.interiorPoint_ = ol.geom.flat.linearRingsGetInteriorPoint( this.interiorPoint_ = ol.geom.flat.linearRingsGetInteriorPoint(
this.flatCoordinates, 0, this.ends_, this.stride, y); this.flatCoordinates, 0, this.ends_, this.stride, y);
this.interiorPointRevision_ = this.revision; this.interiorPointRevision_ = this.getRevision();
} }
return this.interiorPoint_; return this.interiorPoint_;
}; };

View File

@@ -87,10 +87,10 @@ ol.geom.SimpleGeometry.prototype.containsXY = goog.functions.FALSE;
* @inheritDoc * @inheritDoc
*/ */
ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) { ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
if (this.extentRevision != this.revision) { if (this.extentRevision != this.getRevision()) {
this.extent = ol.extent.createOrUpdateFromFlatCoordinates( this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
this.flatCoordinates, this.stride, this.extent); this.flatCoordinates, this.stride, this.extent);
this.extentRevision = this.revision; this.extentRevision = this.getRevision();
} }
goog.asserts.assert(goog.isDef(this.extent)); goog.asserts.assert(goog.isDef(this.extent));
return ol.extent.returnOrUpdate(this.extent, opt_extent); return ol.extent.returnOrUpdate(this.extent, opt_extent);
@@ -118,10 +118,10 @@ ol.geom.SimpleGeometry.prototype.getLayout = function() {
*/ */
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry = ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry =
function(squaredTolerance) { function(squaredTolerance) {
if (this.simplifiedGeometryRevision != this.revision) { if (this.simplifiedGeometryRevision != this.getRevision()) {
goog.object.clear(this.simplifiedGeometryCache); goog.object.clear(this.simplifiedGeometryCache);
this.simplifiedGeometryMaxMinSquaredTolerance = 0; this.simplifiedGeometryMaxMinSquaredTolerance = 0;
this.simplifiedGeometryRevision = this.revision; this.simplifiedGeometryRevision = this.getRevision();
} }
// If squaredTolerance is negative or if we know that simplification will not // If squaredTolerance is negative or if we know that simplification will not
// have any effect then just return this. // have any effect then just return this.