1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
6 * @requires OpenLayers/Console.js
10 * Class: OpenLayers.Pixel
11 * This class represents a screen coordinate, in x and y coordinates
13 OpenLayers.Pixel = OpenLayers.Class({
17 * {Number} The x coordinate
23 * {Number} The y coordinate
28 * Constructor: OpenLayers.Pixel
29 * Create a new OpenLayers.Pixel instance
32 * x - {Number} The x coordinate
33 * y - {Number} The y coordinate
36 * An instance of OpenLayers.Pixel
38 initialize: function(x, y) {
39 this.x = parseFloat(x);
40 this.y = parseFloat(y);
45 * Cast this object into a string
48 * {String} The string representation of Pixel. ex: "x=200.4,y=242.2"
51 return ("x=" + this.x + ",y=" + this.y);
56 * Return a clone of this pixel object
59 * {<OpenLayers.Pixel>} A clone pixel
62 return new OpenLayers.Pixel(this.x, this.y);
67 * Determine whether one pixel is equivalent to another
70 * px - {<OpenLayers.Pixel>}
73 * {Boolean} The point passed in as parameter is equal to this. Note that
74 * if px passed in is null, returns false.
79 equals = ((this.x == px.x && this.y == px.y) ||
80 (isNaN(this.x) && isNaN(this.y) && isNaN(px.x) && isNaN(px.y)));
93 * {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the
97 if ( (x == null) || (y == null) ) {
98 var msg = OpenLayers.i18n("pixelAddError");
99 OpenLayers.Console.error(msg);
102 return new OpenLayers.Pixel(this.x + x, this.y + y);
109 * px - {<OpenLayers.Pixel>}
112 * {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the
113 * x&y values of the pixel passed in.
115 offset:function(px) {
116 var newPx = this.clone();
118 newPx = this.add(px.x, px.y);
123 CLASS_NAME: "OpenLayers.Pixel"