4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-util-Point'>/**
19 </span> * @class Ext.util.Point
20 * @extends Ext.util.Region
22 * Represents a 2D point with x and y properties, useful for comparison and instantiation
24 * <pre><code>
25 * var point = Ext.util.Point.fromEvent(e);
26 * </code></pre>
29 Ext.define('Ext.util.Point', {
31 /* Begin Definitions */
32 extend: 'Ext.util.Region',
36 <span id='Ext-util-Point-method-fromEvent'> /**
37 </span> * Returns a new instance of Ext.util.Point base on the pageX / pageY values of the given event
39 * @param {Event} e The event
40 * @returns Ext.util.Point
42 fromEvent: function(e) {
43 e = (e.changedTouches && e.changedTouches.length > 0) ? e.changedTouches[0] : e;
44 return new this(e.pageX, e.pageY);
50 constructor: function(x, y) {
51 this.callParent([y, x, y, x]);
54 <span id='Ext-util-Point-method-toString'> /**
55 </span> * Returns a human-eye-friendly string that represents this point,
56 * useful for debugging
59 toString: function() {
60 return "Point[" + this.x + "," + this.y + "]";
63 <span id='Ext-util-Point-method-equals'> /**
64 </span> * Compare this point and another point
65 * @param {Ext.util.Point/Object} The point to compare with, either an instance
66 * of Ext.util.Point or an object with left and top properties
67 * @return {Boolean} Returns whether they are equivalent
70 return (this.x == p.x && this.y == p.y);
73 <span id='Ext-util-Point-method-isWithin'> /**
74 </span> * Whether the given point is not away from this point within the given threshold amount.
75 * TODO: Rename this isNear.
76 * @param {Ext.util.Point/Object} The point to check with, either an instance
77 * of Ext.util.Point or an object with left and top properties
78 * @param {Object/Number} threshold Can be either an object with x and y properties or a number
81 isWithin: function(p, threshold) {
82 if (!Ext.isObject(threshold)) {
89 return (this.x <= p.x + threshold.x && this.x >= p.x - threshold.x &&
90 this.y <= p.y + threshold.y && this.y >= p.y - threshold.y);
93 <span id='Ext-util-Point-method-roundedEquals'> /**
94 </span> * Compare this point with another point when the x and y values of both points are rounded. E.g:
95 * [100.3,199.8] will equals to [100, 200]
96 * @param {Ext.util.Point/Object} The point to compare with, either an instance
97 * of Ext.util.Point or an object with x and y properties
100 roundedEquals: function(p) {
101 return (Math.round(this.x) == Math.round(p.x) && Math.round(this.y) == Math.round(p.y));
104 <span id='Ext-util-Point-method-translate'> /**
105 </span> * Translate this region by the given offset amount. TODO: Either use translate or translateBy!
106 * @param {Ext.util.Offset/Object} offset Object containing the <code>x</code> and <code>y</code> properties.
107 * Or the x value is using the two argument form.
108 * @param {Number} The y value unless using an Offset object.
109 * @return {Ext.util.Region} this This Region
112 this.prototype.translate = Ext.util.Region.prototype.translateBy;