3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * Represents a 2D point with x and y properties, useful for comparison and instantiation
19 * var point = Ext.util.Point.fromEvent(e);
22 Ext.define('Ext.util.Point', {
24 /* Begin Definitions */
25 extend: 'Ext.util.Region',
30 * Returns a new instance of Ext.util.Point base on the pageX / pageY values of the given event
32 * @param {Event} e The event
33 * @return {Ext.util.Point}
35 fromEvent: function(e) {
36 e = (e.changedTouches && e.changedTouches.length > 0) ? e.changedTouches[0] : e;
37 return new this(e.pageX, e.pageY);
44 * Creates a point from two coordinates.
45 * @param {Number} x X coordinate.
46 * @param {Number} y Y coordinate.
48 constructor: function(x, y) {
49 this.callParent([y, x, y, x]);
53 * Returns a human-eye-friendly string that represents this point,
54 * useful for debugging
57 toString: function() {
58 return "Point[" + this.x + "," + this.y + "]";
62 * Compare this point and another point
63 * @param {Ext.util.Point/Object} The point to compare with, either an instance
64 * of Ext.util.Point or an object with left and top properties
65 * @return {Boolean} Returns whether they are equivalent
68 return (this.x == p.x && this.y == p.y);
72 * Whether the given point is not away from this point within the given threshold amount.
73 * @param {Ext.util.Point/Object} p The point to check with, either an instance
74 * of Ext.util.Point or an object with left and top properties
75 * @param {Object/Number} threshold Can be either an object with x and y properties or a number
78 isWithin: function(p, threshold) {
79 if (!Ext.isObject(threshold)) {
86 return (this.x <= p.x + threshold.x && this.x >= p.x - threshold.x &&
87 this.y <= p.y + threshold.y && this.y >= p.y - threshold.y);
91 * Compare this point with another point when the x and y values of both points are rounded. E.g:
92 * [100.3,199.8] will equals to [100, 200]
93 * @param {Ext.util.Point/Object} p The point to compare with, either an instance
94 * of Ext.util.Point or an object with x and y properties
97 roundedEquals: function(p) {
98 return (Math.round(this.x) == Math.round(p.x) && Math.round(this.y) == Math.round(p.y));
103 * Alias for {@link #translateBy}
104 * @alias Ext.util.Region#translateBy
106 this.prototype.translate = Ext.util.Region.prototype.translateBy;