Point.html
4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-util-Point'>/**
</span> * Represents a 2D point with x and y properties, useful for comparison and instantiation
* from an event:
*
* var point = Ext.util.Point.fromEvent(e);
*
*/
Ext.define('Ext.util.Point', {
/* Begin Definitions */
extend: 'Ext.util.Region',
statics: {
<span id='Ext-util-Point-static-method-fromEvent'> /**
</span> * Returns a new instance of Ext.util.Point base on the pageX / pageY values of the given event
* @static
* @param {Event} e The event
* @return {Ext.util.Point}
*/
fromEvent: function(e) {
e = (e.changedTouches && e.changedTouches.length > 0) ? e.changedTouches[0] : e;
return new this(e.pageX, e.pageY);
}
},
/* End Definitions */
<span id='Ext-util-Point-method-constructor'> /**
</span> * Creates a point from two coordinates.
* @param {Number} x X coordinate.
* @param {Number} y Y coordinate.
*/
constructor: function(x, y) {
this.callParent([y, x, y, x]);
},
<span id='Ext-util-Point-method-toString'> /**
</span> * Returns a human-eye-friendly string that represents this point,
* useful for debugging
* @return {String}
*/
toString: function() {
return "Point[" + this.x + "," + this.y + "]";
},
<span id='Ext-util-Point-method-equals'> /**
</span> * Compare this point and another point
* @param {Ext.util.Point/Object} The point to compare with, either an instance
* of Ext.util.Point or an object with left and top properties
* @return {Boolean} Returns whether they are equivalent
*/
equals: function(p) {
return (this.x == p.x && this.y == p.y);
},
<span id='Ext-util-Point-method-isWithin'> /**
</span> * Whether the given point is not away from this point within the given threshold amount.
* @param {Ext.util.Point/Object} p The point to check with, either an instance
* of Ext.util.Point or an object with left and top properties
* @param {Object/Number} threshold Can be either an object with x and y properties or a number
* @return {Boolean}
*/
isWithin: function(p, threshold) {
if (!Ext.isObject(threshold)) {
threshold = {
x: threshold,
y: threshold
};
}
return (this.x <= p.x + threshold.x && this.x >= p.x - threshold.x &&
this.y <= p.y + threshold.y && this.y >= p.y - threshold.y);
},
<span id='Ext-util-Point-method-roundedEquals'> /**
</span> * Compare this point with another point when the x and y values of both points are rounded. E.g:
* [100.3,199.8] will equals to [100, 200]
* @param {Ext.util.Point/Object} p The point to compare with, either an instance
* of Ext.util.Point or an object with x and y properties
* @return {Boolean}
*/
roundedEquals: function(p) {
return (Math.round(this.x) == Math.round(p.x) && Math.round(this.y) == Math.round(p.y));
}
}, function() {
<span id='Ext-util-Point-method-translate'> /**
</span> * @method
* Alias for {@link #translateBy}
* @inheritdoc Ext.util.Region#translateBy
*/
this.prototype.translate = Ext.util.Region.prototype.translateBy;
});
</pre>
</body>
</html>