JSAN for OpenLayers.Pixel
git-svn-id: http://svn.openlayers.org/trunk/openlayers@43 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+100
-18
@@ -3,43 +3,125 @@
|
|||||||
*/
|
*/
|
||||||
OpenLayers.Util=new Object();
|
OpenLayers.Util=new Object();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class This class represents a screen coordinate, in x and y coordinates
|
||||||
|
*/
|
||||||
OpenLayers.Pixel = Class.create();
|
OpenLayers.Pixel = Class.create();
|
||||||
OpenLayers.Pixel.prototype = {
|
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 ("x="+this.x+",y="+this.y);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {OpenLayers.Pixel}
|
||||||
|
*/
|
||||||
copyOf:function() {
|
copyOf:function() {
|
||||||
return new OpenLayers.Pixel(this.x, this.y);
|
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);
|
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);
|
/** returns a Pixel object with the difference
|
||||||
return new OpenLayers.Pixel(sz.w,sz.h);
|
* 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);
|
/** returns whether or not the two points are equal
|
||||||
return (d.w==0&&d.h==0);
|
*
|
||||||
|
* @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);
|
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);
|
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);
|
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();
|
OpenLayers.Size = Class.create();
|
||||||
|
|||||||
Reference in New Issue
Block a user