First state of a geom package.

This commit is contained in:
Marc Jansen
2012-06-19 18:21:21 +02:00
parent 712070c1f0
commit 450f8f7b74
10 changed files with 384 additions and 1 deletions

52
src/ol/geom/Geometry.js Normal file
View File

@@ -0,0 +1,52 @@
goog.provide('ol.geom.Geometry');
goog.require('ol.Bounds');
goog.require('ol.mixins.coordinate');
/**
* Creates ol.Geometry objects.
*
* @constructor
*/
ol.geom.Geometry = function() {
/**
* @private
* @type {ol.Bounds|undefined}
*/
this.bounds_ = undefined;
};
/**
* @return {ol.Bounds|undefined} The ol.Bounds.
*/
ol.geom.Geometry.prototype.getBounds = function() {
return this.bounds_;
};
/**
* @param {ol.Bounds} bounds The new ol.Bounds.
* @return {ol.geom.Geometry} This.
*/
ol.geom.Geometry.prototype.setBounds = function(bounds) {
this.bounds_ = bounds;
return this;
};
/**
* @export
* @param {ol.Bounds=} opt_arg new Bounds.
* @return {ol.geom.Geometry|ol.Bounds|undefined} either a Geometry (when used as
* setter) or a Bounds/undefined (if used as getter).
*/
ol.geom.Geometry.prototype.bounds = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setBounds(opt_arg);
} else {
return this.getBounds();
}
};

65
src/ol/geom/Point.js Normal file
View File

@@ -0,0 +1,65 @@
goog.provide('ol.geom.Point');
goog.require('ol.geom.Geometry');
goog.require('ol.mixins.coordinate');
goog.require('ol.interfaces.coordinateAccessor');
/**
* Creates ol.geom.Point objects.
*
* @extends {ol.geom.Geometry}
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
*
* @implements {ol.interfaces.coordinateAccessor}
*
* @constructor
*/
ol.geom.Point = function(x, y, opt_z) {
/**
* @private
* @type {number}
*/
this.x_ = x;
/**
* @private
* @type {number}
*/
this.y_ = y;
/**
* @private
* @type {number|undefined}
*/
this.z_ = opt_z;
};
goog.inherits(ol.geom.Point, ol.geom.Geometry);
goog.mixin(ol.geom.Point.prototype, ol.mixins.coordinate);
///**
// * @override
// */
//ol.geom.Point.prototype.getX = ol.geom.Point.prototype.getX;
///**
// * @override
// */
//ol.geom.Point.prototype.setX = ol.geom.Point.prototype.setX;
///**
// * @override
// */
//ol.geom.Point.prototype.getY = ol.geom.Point.prototype.getY;
///**
// * @override
// */
//ol.geom.Point.prototype.setY = ol.geom.Point.prototype.setY;
///**
// * @override
// */
//ol.geom.Point.prototype.getZ = ol.geom.Point.prototype.getZ;
///**
// * @override
// */
//ol.geom.Point.prototype.setZ = ol.geom.Point.prototype.setZ;

View File

@@ -0,0 +1,48 @@
goog.provide('ol.interfaces.coordinateAccessor');
/**
* The coordinateAccessor interface
*
* @lends {ol.geom.Point#}
* @interface
*
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
*/
ol.interfaces.coordinateAccessor = function(x, y, opt_z){
};
/**
* @return {number} X.
*/
ol.interfaces.coordinateAccessor.prototype.getX = function(){};
/**
* @return {number} Y.
*/
ol.interfaces.coordinateAccessor.prototype.getY = function(){};
/**
* @return {number|undefined} Z.
*/
ol.interfaces.coordinateAccessor.prototype.getZ = function(){};
/**
* @param {number} x X.
* @return {Object} This.
*/
ol.interfaces.coordinateAccessor.prototype.setX = function(x){};
/**
* @param {number} y Y.
* @return {Object} This.
*/
ol.interfaces.coordinateAccessor.prototype.setY = function(y){};
/**
* @param {number|undefined} z Z.
* @return {Object} This.
*/
ol.interfaces.coordinateAccessor.prototype.setZ = function(z){};

View File

@@ -0,0 +1,31 @@
goog.provide('ol.mixins.coordinate');
goog.require('goog.object');
goog.object.extend(ol.mixins.coordinate, {
getX : function() {
return this.x_;
},
getY : function() {
return this.y_;
},
getZ : function() {
return this.z_;
},
setX : function(x) {
this.x_ = x;
return this;
},
setY : function(y) {
this.y_ = y;
return this;
},
setZ: function(z) {
this.z_ = z;
return this;
}
});