JSAN for OpenLayers.Pixel

git-svn-id: http://svn.openlayers.org/trunk/openlayers@43 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-16 18:11:31 +00:00
parent bdd3fe8448
commit d3401763f3

View File

@@ -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 = {
/**
* @param {int} x
* @param {int} y
*/
initialize: function(x, y) {
this.x = x;
this.y = y;
},
/**
* @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);
},
/** 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));
},
/** returns a Pixel object with the difference
* between the two points
*
* @param {OpenLayers.Pixel} pt
*
* @return {OpenLayers.Pixel}
*/
diffPt:function(pt) {
sz=this.diff(pt);
var sz = this.diff(pt);
return new OpenLayers.Pixel(sz.w, sz.h);
},
/** returns whether or not the two points are equal
*
* @param {OpenLayers.Pixel} pt
*
* @return {bool}
*/
equal:function(pt) {
d = this.diff(pt);
return (d.w==0&&d.h==0);
var d = this.diff(pt);
return ((d.w==0) && (d.h==0));
},
/** 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);
},
/** 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);
},
/** 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);
},
/** 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);
return ((this.x == pt.x) && (this.y == pt.y));
}
};
OpenLayers.Size = Class.create();