Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Point.html
1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-util.Point'>/**
2 </span> * @class Ext.util.Point
3  * @extends Ext.util.Region
4  *
5  * Represents a 2D point with x and y properties, useful for comparison and instantiation
6  * from an event:
7  * &lt;pre&gt;&lt;code&gt;
8  * var point = Ext.util.Point.fromEvent(e);
9  * &lt;/code&gt;&lt;/pre&gt;
10  */
11
12 Ext.define('Ext.util.Point', {
13
14     /* Begin Definitions */
15     extend: 'Ext.util.Region',
16
17     statics: {
18
19 <span id='Ext-util.Point-method-fromEvent'>        /**
20 </span>         * Returns a new instance of Ext.util.Point base on the pageX / pageY values of the given event
21          * @static
22          * @param {Event} e The event
23          * @returns Ext.util.Point
24          */
25         fromEvent: function(e) {
26             e = (e.changedTouches &amp;&amp; e.changedTouches.length &gt; 0) ? e.changedTouches[0] : e;
27             return new this(e.pageX, e.pageY);
28         }
29     },
30
31     /* End Definitions */
32
33     constructor: function(x, y) {
34         this.callParent([y, x, y, x]);
35     },
36
37 <span id='Ext-util.Point-method-toString'>    /**
38 </span>     * Returns a human-eye-friendly string that represents this point,
39      * useful for debugging
40      * @return {String}
41      */
42     toString: function() {
43         return &quot;Point[&quot; + this.x + &quot;,&quot; + this.y + &quot;]&quot;;
44     },
45
46 <span id='Ext-util.Point-method-equals'>    /**
47 </span>     * Compare this point and another point
48      * @param {Ext.util.Point/Object} The point to compare with, either an instance
49      * of Ext.util.Point or an object with left and top properties
50      * @return {Boolean} Returns whether they are equivalent
51      */
52     equals: function(p) {
53         return (this.x == p.x &amp;&amp; this.y == p.y);
54     },
55
56 <span id='Ext-util.Point-method-isWithin'>    /**
57 </span>     * Whether the given point is not away from this point within the given threshold amount.
58      * TODO: Rename this isNear.
59      * @param {Ext.util.Point/Object} The point to check with, either an instance
60      * of Ext.util.Point or an object with left and top properties
61      * @param {Object/Number} threshold Can be either an object with x and y properties or a number
62      * @return {Boolean}
63      */
64     isWithin: function(p, threshold) {
65         if (!Ext.isObject(threshold)) {
66             threshold = {
67                 x: threshold,
68                 y: threshold
69             };
70         }
71
72         return (this.x &lt;= p.x + threshold.x &amp;&amp; this.x &gt;= p.x - threshold.x &amp;&amp;
73                 this.y &lt;= p.y + threshold.y &amp;&amp; this.y &gt;= p.y - threshold.y);
74     },
75
76 <span id='Ext-util.Point-method-roundedEquals'>    /**
77 </span>     * Compare this point with another point when the x and y values of both points are rounded. E.g:
78      * [100.3,199.8] will equals to [100, 200]
79      * @param {Ext.util.Point/Object} The point to compare with, either an instance
80      * of Ext.util.Point or an object with x and y properties
81      * @return {Boolean}
82      */
83     roundedEquals: function(p) {
84         return (Math.round(this.x) == Math.round(p.x) &amp;&amp; Math.round(this.y) == Math.round(p.y));
85     }
86 }, function() {
87 <span id='Ext-util.Point-property-translate'>    /**
88 </span>     * Translate this region by the given offset amount. TODO: Either use translate or translateBy!
89      * @param {Ext.util.Offset/Object} offset Object containing the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; properties.
90      * Or the x value is using the two argument form.
91      * @param {Number} The y value unless using an Offset object.
92      * @return {Ext.util.Region} this This Region
93      */
94     this.prototype.translate = Ext.util.Region.prototype.translateBy;
95 });
96 </pre></pre></body></html>