4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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> * Represents a 2D point with x and y properties, useful for comparison and instantiation
22 * var point = Ext.util.Point.fromEvent(e);
25 Ext.define('Ext.util.Point', {
27 /* Begin Definitions */
28 extend: 'Ext.util.Region',
32 <span id='Ext-util-Point-static-method-fromEvent'> /**
33 </span> * Returns a new instance of Ext.util.Point base on the pageX / pageY values of the given event
35 * @param {Event} e The event
36 * @return {Ext.util.Point}
38 fromEvent: function(e) {
39 e = (e.changedTouches && e.changedTouches.length > 0) ? e.changedTouches[0] : e;
40 return new this(e.pageX, e.pageY);
46 <span id='Ext-util-Point-method-constructor'> /**
47 </span> * Creates a point from two coordinates.
48 * @param {Number} x X coordinate.
49 * @param {Number} y Y coordinate.
51 constructor: function(x, y) {
52 this.callParent([y, x, y, x]);
55 <span id='Ext-util-Point-method-toString'> /**
56 </span> * Returns a human-eye-friendly string that represents this point,
57 * useful for debugging
60 toString: function() {
61 return "Point[" + this.x + "," + this.y + "]";
64 <span id='Ext-util-Point-method-equals'> /**
65 </span> * Compare this point and another point
66 * @param {Ext.util.Point/Object} The point to compare with, either an instance
67 * of Ext.util.Point or an object with left and top properties
68 * @return {Boolean} Returns whether they are equivalent
71 return (this.x == p.x && this.y == p.y);
74 <span id='Ext-util-Point-method-isWithin'> /**
75 </span> * Whether the given point is not away from this point within the given threshold amount.
76 * @param {Ext.util.Point/Object} p 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} p 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'> /**
106 * Alias for {@link #translateBy}
107 * @alias Ext.util.Region#translateBy
109 this.prototype.translate = Ext.util.Region.prototype.translateBy;