From d3401763f3d9940404e1e6c3a140d067ed25784c Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 16 May 2006 18:11:31 +0000 Subject: [PATCH] JSAN for OpenLayers.Pixel git-svn-id: http://svn.openlayers.org/trunk/openlayers@43 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 118 ++++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 45d8947192..b1ebf36bcb 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -3,43 +3,125 @@ */ OpenLayers.Util=new Object(); + + + +/** +* @class This class represents a screen coordinate, in x and y coordinates +*/ OpenLayers.Pixel = Class.create(); OpenLayers.Pixel.prototype = { - initialize: function(x,y) { - this.x=x; - this.y=y; + + /** + * @param {int} x + * @param {int} y + */ + initialize: function(x, y) { + this.x = x; + this.y = y; }, - toString:function(){ + + /** + * @return {str} ex: "x=200,y=242" + */ + toString:function() { return ("x="+this.x+",y="+this.y); }, + + /** + * @return {OpenLayers.Pixel} + */ copyOf:function() { return new OpenLayers.Pixel(this.x, this.y); }, - diff:function(pt){ // subtract pt from this + + /** returns a Size object with the difference + * between the two points + * + * @return {OpenLayers.Size} + */ + diff:function(pt) { // subtract pt from this return new OpenLayers.Size(this.x - pt.x, this.y - pt.y); }, - absDiff:function(pt){ // subtract pt from this - return new OpenLayers.Size(Math.abs(this.x - pt.x), Math.abs(this.y - pt.y)); + + /** returns a Size object with the absolute difference + * between the two points + * + * @param {OpenLayers.Pixel} pt + * + * @return {OpenLayers.Size} + */ + absDiff:function(pt) { + return new OpenLayers.Size(Math.abs(this.x - pt.x), + Math.abs(this.y - pt.y)); }, - diffPt:function(pt){ - sz=this.diff(pt); - return new OpenLayers.Pixel(sz.w,sz.h); + + /** returns a Pixel object with the difference + * between the two points + * + * @param {OpenLayers.Pixel} pt + * + * @return {OpenLayers.Pixel} + */ + diffPt:function(pt) { + var sz = this.diff(pt); + return new OpenLayers.Pixel(sz.w, sz.h); }, - equal:function(pt){ - d = this.diff(pt); - return (d.w==0&&d.h==0); + + /** returns whether or not the two points are equal + * + * @param {OpenLayers.Pixel} pt + * + * @return {bool} + */ + equal:function(pt) { + var d = this.diff(pt); + return ((d.w==0) && (d.h==0)); }, - addSize:function(sz){ + + + /** Return a new Pixel with this pixel's x&y augmented by + * the Size value passed in. + * + * @param {OpenLayers.Size} sz + * + * @return {OpenLayers.Pixel} + */ + addSize:function(sz) { return new OpenLayers.Pixel(this.x+sz.w, this.y+sz.h); }, - addX:function(w){ + + + /** Return a new Pixel with this pixel's x&y augmented by + * the Size value passed in. + * + * @param {int} w + * + * @return {OpenLayers.Pixel} + */ + addX:function(w) { return new OpenLayers.Pixel(this.x+w, this.y); }, - addY:function(h){ + + /** Return a new Pixel with this pixel's y augmented by + * the int value passed in. + * + * @param {int} h + * + * @return {OpenLayers.Pixel} + */ + addY:function(h) { return new OpenLayers.Pixel(this.x, this.y+h); }, - samePT:function(pt){ - return (this.x==pt.x && this.y==pt.y); + + /** returns whether or not the two points are equal + * + * @param {OpenLayers.Pixel} pt + * + * @return {bool} + */ + samePT:function(pt) { + return ((this.x == pt.x) && (this.y == pt.y)); } }; OpenLayers.Size = Class.create();