Point.html 4.0 KB

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