2 * @class Ext.util.Point
3 * @extends Ext.util.Region
5 * Represents a 2D point with x and y properties, useful for comparison and instantiation
8 * var point = Ext.util.Point.fromEvent(e);
12 Ext.define('Ext.util.Point', {
14 /* Begin Definitions */
15 extend: 'Ext.util.Region',
20 * Returns a new instance of Ext.util.Point base on the pageX / pageY values of the given event
22 * @param {Event} e The event
23 * @returns Ext.util.Point
25 fromEvent: function(e) {
26 e = (e.changedTouches && e.changedTouches.length > 0) ? e.changedTouches[0] : e;
27 return new this(e.pageX, e.pageY);
33 constructor: function(x, y) {
34 this.callParent([y, x, y, x]);
38 * Returns a human-eye-friendly string that represents this point,
39 * useful for debugging
42 toString: function() {
43 return "Point[" + this.x + "," + this.y + "]";
47 * 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
53 return (this.x == p.x && this.y == p.y);
57 * 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
64 isWithin: function(p, threshold) {
65 if (!Ext.isObject(threshold)) {
72 return (this.x <= p.x + threshold.x && this.x >= p.x - threshold.x &&
73 this.y <= p.y + threshold.y && this.y >= p.y - threshold.y);
77 * 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
83 roundedEquals: function(p) {
84 return (Math.round(this.x) == Math.round(p.x) && Math.round(this.y) == Math.round(p.y));
88 * Translate this region by the given offset amount. TODO: Either use translate or translateBy!
89 * @param {Ext.util.Offset/Object} offset Object containing the <code>x</code> and <code>y</code> 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
94 this.prototype.translate = Ext.util.Region.prototype.translateBy;