]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Geometry/Rectangle.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Geometry / Rectangle.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  * @requires OpenLayers/Geometry.js
7  */
8
9 /**
10  * Class: OpenLayers.Geometry.Rectangle
11  * This class is *not supported*, and probably isn't what you're looking for.
12  *     Instead, most users probably want something like:
13  *     (code)
14  *     var poly = new OpenLayers.Bounds(0,0,10,10).toGeometry();
15  *     (end)
16  *     This will create a rectangular Polygon geometry. 
17  * 
18  * Inherits:
19  *  - <OpenLayers.Geometry>
20  */
21
22 OpenLayers.Geometry.Rectangle = OpenLayers.Class(OpenLayers.Geometry, {
23
24     /** 
25      * Property: x
26      * {Float}
27      */
28     x: null,
29
30     /** 
31      * Property: y
32      * {Float}
33      */
34     y: null,
35
36     /** 
37      * Property: width
38      * {Float}
39      */
40     width: null,
41
42     /** 
43      * Property: height
44      * {Float}
45      */
46     height: null,
47
48     /**
49      * Constructor: OpenLayers.Geometry.Rectangle
50      * 
51      * Parameters:
52      * points - {Array(<OpenLayers.Geometry.Point>}
53      */
54     initialize: function(x, y, width, height) {
55         OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
56         
57         this.x = x;
58         this.y = y;
59
60         this.width = width;
61         this.height = height;
62     },
63     
64     /**
65      * Method: calculateBounds
66      * Recalculate the bounds for the geometry.
67      */
68     calculateBounds: function() {
69         this.bounds = new OpenLayers.Bounds(this.x, this.y,
70                                             this.x + this.width, 
71                                             this.y + this.height);
72     },
73     
74     
75     /**
76      * APIMethod: getLength
77      * 
78      * Returns:
79      * {Float} The length of the geometry
80      */
81     getLength: function() {
82         var length = (2 * this.width) + (2 * this.height);
83         return length;
84     },
85
86     /**
87      * APIMethod: getArea
88      * 
89      * Returns:
90      * {Float} The area of the geometry
91      */
92     getArea: function() {
93         var area = this.width * this.height;
94         return area;
95     },    
96
97     CLASS_NAME: "OpenLayers.Geometry.Rectangle"
98 });