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
5 * Represents a 2D point with x and y properties, useful for comparison and instantiation
7 * <pre><code>
8 * var point = Ext.util.Point.fromEvent(e);
9 * </code></pre>
12 Ext.define('Ext.util.Point', {
14 /* Begin Definitions */
15 extend: 'Ext.util.Region',
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
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]);
37 <span id='Ext-util.Point-method-toString'> /**
38 </span> * Returns a human-eye-friendly string that represents this point,
39 * useful for debugging
42 toString: function() {
43 return "Point[" + this.x + "," + this.y + "]";
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
53 return (this.x == p.x && this.y == p.y);
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
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);
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
83 roundedEquals: function(p) {
84 return (Math.round(this.x) == Math.round(p.x) && Math.round(this.y) == Math.round(p.y));
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 <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;
96 </pre></pre></body></html>