Geometry.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** IBM Cognos Products: mdsrv
  5. **
  6. ** (C) Copyright IBM Corp. 2008, 2010
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *****************************************************************/
  10. //***********************************************************************************************
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. //
  14. // Component: Geometry support
  15. //***********************************************************************************************
  16. function CNamespace()
  17. {
  18. var parent = this;
  19. this.sCurrentDir = '.';
  20. }
  21. CNamespace.prototype.setCurrentDir = function ( sNewDirectory )
  22. {
  23. if ( sNewDirectory )
  24. this.sCurrentDir = sNewDirectory;
  25. }
  26. //------------------------------------------------------------------------------
  27. // CUiObject class
  28. //------------------------------------------------------------------------------
  29. function CUiObject( x, y, width, height )
  30. {
  31. this.x = x || 0;
  32. this.y = y || 0;
  33. this.width = width || 0;
  34. this.height = height || 0;
  35. }
  36. //------------------------------------------------------------------------------
  37. // CPoint class
  38. //------------------------------------------------------------------------------
  39. function CPoint( x, y )
  40. {
  41. CUiObject.call( this, x, y ); // constructor chaining
  42. }
  43. CPoint.inherits( CUiObject );
  44. // CPoint API
  45. CPoint.prototype.Set = function ( x, y )
  46. {
  47. this.x = x;
  48. this.y = y;
  49. }
  50. // We create this prototype object for inheritance purposes, but we
  51. // don't actually want to inherit the width and height properties,
  52. // so delete them from the prototype.
  53. delete CPoint.prototype.width;
  54. delete CPoint.prototype.height;
  55. //------------------------------------------------------------------------------
  56. // CPosition class
  57. //------------------------------------------------------------------------------
  58. function CPosition( x, y )
  59. {
  60. CPoint.call( this, x, y ); // constructor chaining
  61. }
  62. CPosition.inherits( CPoint );
  63. //------------------------------------------------------------------------------
  64. // Rectangle class
  65. //------------------------------------------------------------------------------
  66. function CRect( x, y, width, height )
  67. {
  68. CUiObject.call( this, x, y, width, height ); // constructor chaining
  69. }
  70. CRect.inherits( CUiObject );
  71. // CRect API
  72. CRect.prototype.isCoordInside = function ( x, y )
  73. {
  74. return ( x > this.x && x < this.x + this.width && y > this.y && y < this.y + this.height );
  75. }
  76. CRect.prototype.isPointInside = function ( pt )
  77. {
  78. return this.isCoordInside( pt.x, pt.y );
  79. }
  80. CRect.prototype.clone = function ( rect )
  81. {
  82. this.x = rect.x;
  83. this.y = rect.y;
  84. this.width = rect.width;
  85. this.height = rect.height;
  86. }
  87. CRect.prototype.SetSize = function ( width, height )
  88. {
  89. if ( width )
  90. this.width = width;
  91. if ( height )
  92. this.height = height;
  93. }
  94. CRect.prototype.SetPosition = function ( x, y, width, height )
  95. {
  96. if ( x )
  97. this.x = x;
  98. if ( y )
  99. this.y = y;
  100. if ( width )
  101. this.width = width;
  102. if ( height )
  103. this.height = height;
  104. }
  105. //------------------------------------------------------------------------------
  106. // CSize class
  107. //------------------------------------------------------------------------------
  108. function CSize( x, y, width, height )
  109. {
  110. CRect.call( this, x, y, width, height ); // constructor chaining
  111. }
  112. CSize.inherits( CRect );
  113. // CSize API
  114. CSize.prototype.getCenterX = function () { return this.x + ( this.width / 2 ); }
  115. CSize.prototype.getCenterY = function () { return this.y + ( this.height / 2 ); }
  116. CSize.prototype.getCenterPoint = function ()
  117. {
  118. return ( new CPoint( this.x + this.width / 2, this.y + this.height / 2 ) );
  119. }
  120. CSize.prototype.GetSize = function ()
  121. {
  122. return this;
  123. }
  124. CSize.prototype.HasIntersection = function ( size )
  125. {
  126. var bIsIntersection = false;
  127. if ( this.isCoordInside ( size.x, size.y ) ||
  128. this.isCoordInside ( size.x + size.width, size.y ) ||
  129. this.isCoordInside ( size.x, size.y + size.height ) ||
  130. this.isCoordInside ( size.x + size.width, size.y + size.height ) )
  131. {
  132. bIsIntersection = true;
  133. }
  134. return bIsIntersection;
  135. }
  136. //------------------------------------------------------------------------------
  137. // DragDrop class
  138. //------------------------------------------------------------------------------
  139. function CDragDrop()
  140. {
  141. var dragObject = null;
  142. var originalPosition = new CPosition(0,0);
  143. var originalMousePosition = new CPosition(0,0);
  144. }