Skip to content

Commit 8a09469

Browse files
committed
Final methods added.
1 parent 9289f69 commit 8a09469

1 file changed

Lines changed: 113 additions & 10 deletions

File tree

src/geom/Rectangle.js

Lines changed: 113 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
/**
2-
* Rectangle
3-
*
4-
* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
5-
*
6-
* @version 1.6 - 24th May 2013
7-
* @author Richard Davey
8-
*/
9-
10-
111
/**
122
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
3+
*
134
* @class Rectangle
145
* @constructor
156
* @param {Number} x The x coordinate of the top-left corner of the Rectangle.
@@ -136,6 +127,118 @@ Phaser.Rectangle.prototype = {
136127

137128
},
138129

130+
/**
131+
* Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
132+
* @method inflate
133+
* @param {Number} dx The amount to be added to the left side of the Rectangle.
134+
* @param {Number} dy The amount to be added to the bottom side of the Rectangle.
135+
* @return {Phaser.Rectangle} This Rectangle object.
136+
*/
137+
inflate: function (dx, dy) {
138+
return Phaser.Rectangle.inflate(this, dx, dy);
139+
},
140+
141+
/**
142+
* The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
143+
* @method size
144+
* @param {Phaser.Point} output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
145+
* @return {Phaser.Point} The size of the Rectangle object
146+
*/
147+
size: function (output) {
148+
return Phaser.Rectangle.size(this, output);
149+
};
150+
151+
/**
152+
* Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
153+
* @method clone
154+
* @param {Phaser.Rectangle} output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
155+
* @return {Phaser.Rectangle}
156+
*/
157+
clone: function (output) {
158+
return Phaser.Rectangle.clone(this, output);
159+
},
160+
161+
/**
162+
* Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
163+
* @method contains
164+
* @param {Number} x The x coordinate of the point to test.
165+
* @param {Number} y The y coordinate of the point to test.
166+
* @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false.
167+
*/
168+
contains: function (x, y) {
169+
return Phaser.Rectangle.contains(this, x, y);
170+
},
171+
172+
/**
173+
* Determines whether the first Rectangle object is fully contained within the second Rectangle object.
174+
* A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
175+
* @method containsRect
176+
* @param {Phaser.Rectangle} b The second Rectangle object.
177+
* @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false.
178+
*/
179+
containsRect: function (b) {
180+
return Phaser.Rectangle.containsRect(this, b);
181+
},
182+
183+
/**
184+
* Determines whether the two Rectangles are equal.
185+
* This method compares the x, y, width and height properties of each Rectangle.
186+
* @method equals
187+
* @param {Phaser.Rectangle} b The second Rectangle object.
188+
* @return {bool} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
189+
*/
190+
equals: function (b) {
191+
return Phaser.Rectangle.equals(this, b);
192+
},
193+
194+
/**
195+
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
196+
* @method intersection
197+
* @param {Phaser.Rectangle} b The second Rectangle object.
198+
* @param {Phaser.Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
199+
* @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
200+
*/
201+
intersection: function (b, out) {
202+
return Phaser.Rectangle.intersection(this, b, output);
203+
},
204+
205+
/**
206+
* Determines whether the two Rectangles intersect with each other.
207+
* This method checks the x, y, width, and height properties of the Rectangles.
208+
* @method intersects
209+
* @param {Phaser.Rectangle} b The second Rectangle object.
210+
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
211+
* @return {bool} A value of true if the specified object intersects with this Rectangle object; otherwise false.
212+
*/
213+
intersects: function (b, tolerance) {
214+
return Phaser.Rectangle.intersects(this, b, tolerance);
215+
},
216+
217+
/**
218+
* Determines whether the object specified intersects (overlaps) with the given values.
219+
* @method intersectsRaw
220+
* @param {Number} left
221+
* @param {Number} right
222+
* @param {Number} top
223+
* @param {Number} bottomt
224+
* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0
225+
* @return {bool} A value of true if the specified object intersects with the Rectangle; otherwise false.
226+
*/
227+
intersectsRaw: function (left, right, top, bottom, tolerance) {
228+
return Phaser.Rectangle.intersectsRaw(this, left, right, top, bottom, tolerance);
229+
},
230+
231+
/**
232+
* Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
233+
* @method union
234+
* @param {Phaser.Rectangle} b The second Rectangle object.
235+
* @param {Phaser.Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
236+
* @return {Phaser.Rectangle} A Rectangle object that is the union of the two Rectangles.
237+
*/
238+
union: function (b, out) {
239+
return Phaser.Rectangle.union(this, b, out);
240+
},
241+
139242
/**
140243
* Returns a string representation of this object.
141244
* @method toString

0 commit comments

Comments
 (0)