]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/BaseTypes/Size.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / BaseTypes / Size.js
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. */
4
5 /**
6  * Class: OpenLayers.Size
7  * Instances of this class represent a width/height pair
8  */
9 OpenLayers.Size = OpenLayers.Class({
10
11     /**
12      * APIProperty: w
13      * {Number} width
14      */
15     w: 0.0,
16     
17     /**
18      * APIProperty: h
19      * {Number} height
20      */
21     h: 0.0,
22
23
24     /**
25      * Constructor: OpenLayers.Size
26      * Create an instance of OpenLayers.Size
27      *
28      * Parameters:
29      * w - {Number} width
30      * h - {Number} height
31      */
32     initialize: function(w, h) {
33         this.w = parseFloat(w);
34         this.h = parseFloat(h);
35     },
36
37     /**
38      * Method: toString
39      * Return the string representation of a size object
40      *
41      * Returns:
42      * {String} The string representation of OpenLayers.Size object. 
43      * (ex. <i>"w=55,h=66"</i>)
44      */
45     toString:function() {
46         return ("w=" + this.w + ",h=" + this.h);
47     },
48
49     /**
50      * APIMethod: clone
51      * Create a clone of this size object
52      *
53      * Returns:
54      * {<OpenLayers.Size>} A new OpenLayers.Size object with the same w and h
55      * values
56      */
57     clone:function() {
58         return new OpenLayers.Size(this.w, this.h);
59     },
60
61     /**
62      *
63      * APIMethod: equals
64      * Determine where this size is equal to another
65      *
66      * Parameters:
67      * sz - {<OpenLayers.Size>}
68      *
69      * Returns: 
70      * {Boolean} The passed in size has the same h and w properties as this one.
71      * Note that if sz passed in is null, returns false.
72      *
73      */
74     equals:function(sz) {
75         var equals = false;
76         if (sz != null) {
77             equals = ((this.w == sz.w && this.h == sz.h) ||
78                       (isNaN(this.w) && isNaN(this.h) && isNaN(sz.w) && isNaN(sz.h)));
79         }
80         return equals;
81     },
82
83     CLASS_NAME: "OpenLayers.Size"
84 });