all repos — simplyrpg @ main

Fork of https://github.com/harperd1/simplyRPG — multi-map VTT, token visibility, dark theme, stream HUD

libraries/EaselJS_docs/files/easeljs_geom_Rectangle.js.html (view raw)

  1<!DOCTYPE html>
  2<html lang="en">
  3<head>
  4    <meta charset="utf-8">
  5    <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
  6    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
  7    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
  8    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
  9    <script src="../assets/js/yui-source.js"></script>
 10	<title>EaselJS v1.0.0 API Documentation : easeljs/geom/Rectangle.js</title>
 11</head>
 12<body class="yui3-skin-sam">
 13
 14<div id="doc">
 15    <div id="hd" class="yui3-g header">
 16        <div class="yui3-u-3-4">
 17            
 18                <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
 19            
 20        </div>
 21        <div class="version">
 22            <em>API Documentation for: 1.0.0</em>
 23        </div>
 24    </div>
 25    <div id="bd" class="yui3-g">
 26
 27        <div class="yui3-u-1-4">
 28            <div id="docs-sidebar" class="sidebar apidocs">
 29                <div id="api-list">
 30    <h2 class="off-left">APIs</h2>
 31    <div id="api-tabview" class="tabview">
 32        <ul class="tabs">
 33            <li><a href="#api-classes">Classes</a></li>
 34        </ul>
 35
 36        <div id="api-tabview-filter">
 37            <input type="search" id="api-filter" placeholder="Type to filter APIs">
 38        </div>
 39
 40        <div id="api-tabview-panel">
 41            <ul id="api-classes" class="apis classes">
 42            
 43                <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
 44            
 45                <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
 46            
 47                <li><a href="../classes/Bitmap.html">Bitmap</a></li>
 48            
 49                <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
 50            
 51                <li><a href="../classes/BitmapText.html">BitmapText</a></li>
 52            
 53                <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
 54            
 55                <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
 56            
 57                <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
 58            
 59                <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
 60            
 61                <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
 62            
 63                <li><a href="../classes/Container.html">Container</a></li>
 64            
 65                <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
 66            
 67                <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
 68            
 69                <li><a href="../classes/DOMElement.html">DOMElement</a></li>
 70            
 71                <li><a href="../classes/EaselJS.html">EaselJS</a></li>
 72            
 73                <li><a href="../classes/Event.html">Event</a></li>
 74            
 75                <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
 76            
 77                <li><a href="../classes/Filter.html">Filter</a></li>
 78            
 79                <li><a href="../classes/Graphics.html">Graphics</a></li>
 80            
 81                <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
 82            
 83                <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
 84            
 85                <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
 86            
 87                <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
 88            
 89                <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
 90            
 91                <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
 92            
 93                <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
 94            
 95                <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
 96            
 97                <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
 98            
 99                <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100            
101                <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102            
103                <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104            
105                <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106            
107                <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108            
109                <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110            
111                <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112            
113                <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114            
115                <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116            
117                <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118            
119                <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120            
121                <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122            
123                <li><a href="../classes/Point.html">Point</a></li>
124            
125                <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126            
127                <li><a href="../classes/Shadow.html">Shadow</a></li>
128            
129                <li><a href="../classes/Shape.html">Shape</a></li>
130            
131                <li><a href="../classes/Sprite.html">Sprite</a></li>
132            
133                <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134            
135                <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136            
137                <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138            
139                <li><a href="../classes/Stage.html">Stage</a></li>
140            
141                <li><a href="../classes/StageGL.html">StageGL</a></li>
142            
143                <li><a href="../classes/Text.html">Text</a></li>
144            
145                <li><a href="../classes/Ticker.html">Ticker</a></li>
146            
147                <li><a href="../classes/Touch.html">Touch</a></li>
148            
149                <li><a href="../classes/UID.html">UID</a></li>
150            
151                <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152            
153                <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154            
155                <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156            
157            </ul>
158
159            <ul id="api-modules" class="apis modules">
160            
161                <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162            
163                <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164            
165            </ul>
166        </div>
167    </div>
168</div>
169
170            </div>
171        </div>
172        <div class="yui3-u-3-4">
173            <div id="api-options">
174        Show:
175        <label for="api-show-inherited">
176            <input type="checkbox" id="api-show-inherited" checked>
177            Inherited
178        </label>
179
180        <label for="api-show-protected">
181            <input type="checkbox" id="api-show-protected">
182            Protected
183        </label>
184
185        <label for="api-show-private">
186            <input type="checkbox" id="api-show-private">
187            Private
188        </label>
189        <label for="api-show-deprecated">
190            <input type="checkbox" id="api-show-deprecated">
191            Deprecated
192        </label>
193
194    </div>
195            <div class="apidocs">
196                <div id="docs-main">
197                    <div class="content source-content">
198                        <script>
199	var name = easeljs/geom/Rectangle.js      
200</script>
201<h1 class="file-heading">File:Rectangle.js</h1>
202
203<div class="file">
204    <pre class="code prettyprint linenums">
205/*
206* Rectangle
207* Visit http://createjs.com/ for documentation, updates and examples.
208*
209* Copyright (c) 2010 gskinner.com, inc.
210*
211* Permission is hereby granted, free of charge, to any person
212* obtaining a copy of this software and associated documentation
213* files (the &quot;Software&quot;), to deal in the Software without
214* restriction, including without limitation the rights to use,
215* copy, modify, merge, publish, distribute, sublicense, and/or sell
216* copies of the Software, and to permit persons to whom the
217* Software is furnished to do so, subject to the following
218* conditions:
219*
220* The above copyright notice and this permission notice shall be
221* included in all copies or substantial portions of the Software.
222*
223* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
224* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
225* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
226* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
227* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
228* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230* OTHER DEALINGS IN THE SOFTWARE.
231*/
232
233/**
234 * @module EaselJS
235 */
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241	&quot;use strict&quot;;
242
243
244// constructor:
245	/**
246	 * Represents a rectangle as defined by the points (x, y) and (x+width, y+height).
247	 *
248	 * &lt;h4&gt;Example&lt;/h4&gt;
249	 *
250	 *      var rect = new createjs.Rectangle(0, 0, 100, 100);
251	 *
252	 * @class Rectangle
253	 * @param {Number} [x=0] X position.
254	 * @param {Number} [y=0] Y position.
255	 * @param {Number} [width=0] The width of the Rectangle.
256	 * @param {Number} [height=0] The height of the Rectangle.
257	 * @constructor
258	 **/
259	function Rectangle(x, y, width, height) {
260		this.setValues(x, y, width, height);
261		
262		
263	// public properties:
264		// assigned in the setValues method.
265		/**
266		 * X position.
267		 * @property x
268		 * @type Number
269		 **/
270	
271		/**
272		 * Y position.
273		 * @property y
274		 * @type Number
275		 **/
276	
277		/**
278		 * Width.
279		 * @property width
280		 * @type Number
281		 **/
282	
283		/**
284		 * Height.
285		 * @property height
286		 * @type Number
287		 **/
288	}
289	var p = Rectangle.prototype;
290
291// public methods:
292	/** 
293	 * Sets the specified values on this instance.
294	 * @method setValues
295	 * @param {Number} [x=0] X position.
296	 * @param {Number} [y=0] Y position.
297	 * @param {Number} [width=0] The width of the Rectangle.
298	 * @param {Number} [height=0] The height of the Rectangle.
299	 * @return {Rectangle} This instance. Useful for chaining method calls.
300	 * @chainable
301	*/
302	p.setValues = function(x, y, width, height) {
303		// don&#x27;t forget to update docs in the constructor if these change:
304		this.x = x||0;
305		this.y = y||0;
306		this.width = width||0;
307		this.height = height||0;
308		return this;
309	};
310	
311	/** 
312	 * Extends the rectangle&#x27;s bounds to include the described point or rectangle.
313	 * @method extend
314	 * @param {Number} x X position of the point or rectangle.
315	 * @param {Number} y Y position of the point or rectangle.
316	 * @param {Number} [width=0] The width of the rectangle.
317	 * @param {Number} [height=0] The height of the rectangle.
318	 * @return {Rectangle} This instance. Useful for chaining method calls.
319	 * @chainable
320	*/
321	p.extend = function(x, y, width, height) {
322		width = width||0;
323		height = height||0;
324		if (x+width &gt; this.x+this.width) { this.width = x+width-this.x; }
325		if (y+height &gt; this.y+this.height) { this.height = y+height-this.y; }
326		if (x &lt; this.x) { this.width += this.x-x; this.x = x; }
327		if (y &lt; this.y) { this.height += this.y-y; this.y = y; }
328		return this;
329	};
330	
331	/** 
332	 * Adds the specified padding to the rectangle&#x27;s bounds.
333	 * @method pad
334	 * @param {Number} top
335	 * @param {Number} left
336	 * @param {Number} bottom
337	 * @param {Number} right
338	 * @return {Rectangle} This instance. Useful for chaining method calls.
339	 * @chainable
340	*/
341	p.pad = function(top, left, bottom, right) {
342		this.x -= left;
343		this.y -= top;
344		this.width += left+right;
345		this.height += top+bottom;
346		return this;
347	};
348	
349	/**
350	 * Copies all properties from the specified rectangle to this rectangle.
351	 * @method copy
352	 * @param {Rectangle} rectangle The rectangle to copy properties from.
353	 * @return {Rectangle} This rectangle. Useful for chaining method calls.
354	 * @chainable
355	*/
356	p.copy = function(rectangle) {
357		return this.setValues(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
358	};
359	
360	/** 
361	 * Returns true if this rectangle fully encloses the described point or rectangle.
362	 * @method contains
363	 * @param {Number} x X position of the point or rectangle.
364	 * @param {Number} y Y position of the point or rectangle.
365	 * @param {Number} [width=0] The width of the rectangle.
366	 * @param {Number} [height=0] The height of the rectangle.
367	 * @return {Boolean} True if the described point or rectangle is contained within this rectangle.
368	*/
369	p.contains = function(x, y, width, height) {
370		width = width||0;
371		height = height||0;
372		return (x &gt;= this.x &amp;&amp; x+width &lt;= this.x+this.width &amp;&amp; y &gt;= this.y &amp;&amp; y+height &lt;= this.y+this.height);
373	};
374	
375	/** 
376	 * Returns a new rectangle which contains this rectangle and the specified rectangle.
377	 * @method union
378	 * @param {Rectangle} rect The rectangle to calculate a union with.
379	 * @return {Rectangle} A new rectangle describing the union.
380	*/
381	p.union = function(rect) {
382		return this.clone().extend(rect.x, rect.y, rect.width, rect.height);
383	};
384	
385	/** 
386	 * Returns a new rectangle which describes the intersection (overlap) of this rectangle and the specified rectangle,
387	 * or null if they do not intersect.
388	 * @method intersection
389	 * @param {Rectangle} rect The rectangle to calculate an intersection with.
390	 * @return {Rectangle} A new rectangle describing the intersection or null.
391	*/
392	p.intersection = function(rect) {
393		var x1 = rect.x, y1 = rect.y, x2 = x1+rect.width, y2 = y1+rect.height;
394		if (this.x &gt; x1) { x1 = this.x; }
395		if (this.y &gt; y1) { y1 = this.y; }
396		if (this.x + this.width &lt; x2) { x2 = this.x + this.width; }
397		if (this.y + this.height &lt; y2) { y2 = this.y + this.height; }
398		return (x2 &lt;= x1 || y2 &lt;= y1) ? null : new Rectangle(x1, y1, x2-x1, y2-y1);
399	};
400	
401	/** 
402	 * Returns true if the specified rectangle intersects (has any overlap) with this rectangle.
403	 * @method intersects
404	 * @param {Rectangle} rect The rectangle to compare.
405	 * @return {Boolean} True if the rectangles intersect.
406	*/
407	p.intersects = function(rect) {
408		return (rect.x &lt;= this.x+this.width &amp;&amp; this.x &lt;= rect.x+rect.width &amp;&amp; rect.y &lt;= this.y+this.height &amp;&amp; this.y &lt;= rect.y + rect.height);
409	};
410	
411	/** 
412	 * Returns true if the width or height are equal or less than 0.
413	 * @method isEmpty
414	 * @return {Boolean} True if the rectangle is empty.
415	*/
416	p.isEmpty = function() {
417		return this.width &lt;= 0 || this.height &lt;= 0;
418	};
419	
420	/**
421	 * Returns a clone of the Rectangle instance.
422	 * @method clone
423	 * @return {Rectangle} a clone of the Rectangle instance.
424	 **/
425	p.clone = function() {
426		return new Rectangle(this.x, this.y, this.width, this.height);
427	};
428
429	/**
430	 * Returns a string representation of this object.
431	 * @method toString
432	 * @return {String} a string representation of the instance.
433	 **/
434	p.toString = function() {
435		return &quot;[Rectangle (x=&quot;+this.x+&quot; y=&quot;+this.y+&quot; width=&quot;+this.width+&quot; height=&quot;+this.height+&quot;)]&quot;;
436	};
437	
438	
439	createjs.Rectangle = Rectangle;
440}());
441
442    </pre>
443</div>
444
445                    </div>
446                </div>
447            </div>
448        </div>
449    </div>
450</div>
451<script src="../assets/vendor/prettify/prettify-min.js"></script>
452<script>prettyPrint();</script>
453<script src="../assets/js/yui-prettify.js"></script>
454<script src="../assets/../api.js"></script>
455<script src="../assets/js/api-filter.js"></script>
456<script src="../assets/js/api-list.js"></script>
457<script src="../assets/js/api-search.js"></script>
458<script src="../assets/js/apidocs.js"></script>
459</body>
460</html>