BoundingBox.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. "use strict";
  2. var Exceptions_1 = require("../Exceptions");
  3. var PointF2D_1 = require("../../Common/DataObjects/PointF2D");
  4. var SizeF2D_1 = require("../../Common/DataObjects/SizeF2D");
  5. var RectangleF2D_1 = require("../../Common/DataObjects/RectangleF2D");
  6. var BoundingBox = (function () {
  7. function BoundingBox(dataObject, parent) {
  8. if (dataObject === void 0) { dataObject = undefined; }
  9. if (parent === void 0) { parent = undefined; }
  10. this.isSymbol = false;
  11. this.relativePositionHasBeenSet = false;
  12. this.xBordersHaveBeenSet = false;
  13. this.yBordersHaveBeenSet = false;
  14. this.absolutePosition = new PointF2D_1.PointF2D();
  15. this.relativePosition = new PointF2D_1.PointF2D();
  16. this.size = new SizeF2D_1.SizeF2D();
  17. this.borderLeft = 0;
  18. this.borderRight = 0;
  19. this.borderTop = 0;
  20. this.borderBottom = 0;
  21. this.borderMarginLeft = 0;
  22. this.borderMarginRight = 0;
  23. this.borderMarginTop = 0;
  24. this.borderMarginBottom = 0;
  25. this.childElements = [];
  26. this.parent = parent;
  27. this.dataObject = dataObject;
  28. this.xBordersHaveBeenSet = false;
  29. this.yBordersHaveBeenSet = false;
  30. }
  31. Object.defineProperty(BoundingBox.prototype, "RelativePositionHasBeenSet", {
  32. get: function () {
  33. return this.relativePositionHasBeenSet;
  34. },
  35. enumerable: true,
  36. configurable: true
  37. });
  38. Object.defineProperty(BoundingBox.prototype, "XBordersHaveBeenSet", {
  39. get: function () {
  40. return this.xBordersHaveBeenSet;
  41. },
  42. set: function (value) {
  43. this.xBordersHaveBeenSet = value;
  44. },
  45. enumerable: true,
  46. configurable: true
  47. });
  48. Object.defineProperty(BoundingBox.prototype, "YBordersHaveBeenSet", {
  49. get: function () {
  50. return this.yBordersHaveBeenSet;
  51. },
  52. set: function (value) {
  53. this.yBordersHaveBeenSet = value;
  54. },
  55. enumerable: true,
  56. configurable: true
  57. });
  58. Object.defineProperty(BoundingBox.prototype, "AbsolutePosition", {
  59. get: function () {
  60. return this.absolutePosition;
  61. },
  62. set: function (value) {
  63. this.absolutePosition = value;
  64. },
  65. enumerable: true,
  66. configurable: true
  67. });
  68. Object.defineProperty(BoundingBox.prototype, "RelativePosition", {
  69. get: function () {
  70. return this.relativePosition;
  71. },
  72. set: function (value) {
  73. this.relativePosition = value;
  74. this.relativePositionHasBeenSet = true;
  75. },
  76. enumerable: true,
  77. configurable: true
  78. });
  79. Object.defineProperty(BoundingBox.prototype, "Size", {
  80. get: function () {
  81. return this.size;
  82. },
  83. set: function (value) {
  84. this.size = value;
  85. },
  86. enumerable: true,
  87. configurable: true
  88. });
  89. Object.defineProperty(BoundingBox.prototype, "MarginSize", {
  90. get: function () {
  91. return this.marginSize;
  92. },
  93. enumerable: true,
  94. configurable: true
  95. });
  96. Object.defineProperty(BoundingBox.prototype, "UpperLeftCorner", {
  97. get: function () {
  98. return this.upperLeftCorner;
  99. },
  100. enumerable: true,
  101. configurable: true
  102. });
  103. Object.defineProperty(BoundingBox.prototype, "UpperLeftMarginCorner", {
  104. get: function () {
  105. return this.upperLeftMarginCorner;
  106. },
  107. enumerable: true,
  108. configurable: true
  109. });
  110. Object.defineProperty(BoundingBox.prototype, "BorderLeft", {
  111. get: function () {
  112. return this.borderLeft;
  113. },
  114. set: function (value) {
  115. this.borderLeft = value;
  116. this.calculateRectangle();
  117. },
  118. enumerable: true,
  119. configurable: true
  120. });
  121. Object.defineProperty(BoundingBox.prototype, "BorderRight", {
  122. get: function () {
  123. return this.borderRight;
  124. },
  125. set: function (value) {
  126. this.borderRight = value;
  127. this.calculateRectangle();
  128. },
  129. enumerable: true,
  130. configurable: true
  131. });
  132. Object.defineProperty(BoundingBox.prototype, "BorderTop", {
  133. get: function () {
  134. return this.borderTop;
  135. },
  136. set: function (value) {
  137. this.borderTop = value;
  138. this.calculateRectangle();
  139. },
  140. enumerable: true,
  141. configurable: true
  142. });
  143. Object.defineProperty(BoundingBox.prototype, "BorderBottom", {
  144. get: function () {
  145. return this.borderBottom;
  146. },
  147. set: function (value) {
  148. this.borderBottom = value;
  149. this.calculateRectangle();
  150. },
  151. enumerable: true,
  152. configurable: true
  153. });
  154. Object.defineProperty(BoundingBox.prototype, "BorderMarginLeft", {
  155. get: function () {
  156. return this.borderMarginLeft;
  157. },
  158. set: function (value) {
  159. this.borderMarginLeft = value;
  160. this.calculateMarginRectangle();
  161. },
  162. enumerable: true,
  163. configurable: true
  164. });
  165. Object.defineProperty(BoundingBox.prototype, "BorderMarginRight", {
  166. get: function () {
  167. return this.borderMarginRight;
  168. },
  169. set: function (value) {
  170. this.borderMarginRight = value;
  171. this.calculateMarginRectangle();
  172. },
  173. enumerable: true,
  174. configurable: true
  175. });
  176. Object.defineProperty(BoundingBox.prototype, "BorderMarginTop", {
  177. get: function () {
  178. return this.borderMarginTop;
  179. },
  180. set: function (value) {
  181. this.borderMarginTop = value;
  182. this.calculateMarginRectangle();
  183. },
  184. enumerable: true,
  185. configurable: true
  186. });
  187. Object.defineProperty(BoundingBox.prototype, "BorderMarginBottom", {
  188. get: function () {
  189. return this.borderMarginBottom;
  190. },
  191. set: function (value) {
  192. this.borderMarginBottom = value;
  193. this.calculateMarginRectangle();
  194. },
  195. enumerable: true,
  196. configurable: true
  197. });
  198. Object.defineProperty(BoundingBox.prototype, "BoundingRectangle", {
  199. get: function () {
  200. return this.boundingRectangle;
  201. },
  202. enumerable: true,
  203. configurable: true
  204. });
  205. Object.defineProperty(BoundingBox.prototype, "BoundingMarginRectangle", {
  206. get: function () {
  207. return this.boundingMarginRectangle;
  208. },
  209. enumerable: true,
  210. configurable: true
  211. });
  212. Object.defineProperty(BoundingBox.prototype, "ChildElements", {
  213. get: function () {
  214. return this.childElements;
  215. },
  216. set: function (value) {
  217. this.childElements = value;
  218. },
  219. enumerable: true,
  220. configurable: true
  221. });
  222. Object.defineProperty(BoundingBox.prototype, "Parent", {
  223. get: function () {
  224. return this.parent;
  225. },
  226. set: function (value) {
  227. this.parent = value;
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. Object.defineProperty(BoundingBox.prototype, "DataObject", {
  233. get: function () {
  234. return this.dataObject;
  235. },
  236. enumerable: true,
  237. configurable: true
  238. });
  239. BoundingBox.prototype.setAbsolutePositionFromParent = function () {
  240. if (this.parent !== undefined) {
  241. this.absolutePosition.x = this.parent.AbsolutePosition.x + this.relativePosition.x;
  242. this.absolutePosition.y = this.parent.AbsolutePosition.y + this.relativePosition.y;
  243. }
  244. else {
  245. this.absolutePosition = this.relativePosition;
  246. }
  247. };
  248. BoundingBox.prototype.calculateAbsolutePositionsRecursiveWithoutTopelement = function () {
  249. this.absolutePosition.x = 0.0;
  250. this.absolutePosition.y = 0.0;
  251. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  252. var child = this.ChildElements[idx];
  253. child.calculateAbsolutePositionsRecursive(this.absolutePosition.x, this.absolutePosition.y);
  254. }
  255. };
  256. BoundingBox.prototype.calculateAbsolutePositionsRecursive = function (x, y) {
  257. this.absolutePosition.x = this.relativePosition.x + x;
  258. this.absolutePosition.y = this.relativePosition.y + y;
  259. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  260. var child = this.ChildElements[idx];
  261. child.calculateAbsolutePositionsRecursive(this.absolutePosition.x, this.absolutePosition.y);
  262. }
  263. };
  264. BoundingBox.prototype.calculateBoundingBox = function () {
  265. if (this.childElements.length === 0) {
  266. return;
  267. }
  268. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  269. var childElement = this.ChildElements[idx];
  270. childElement.calculateBoundingBox();
  271. }
  272. var minLeft = Number.MAX_VALUE;
  273. var maxRight = Number.MIN_VALUE;
  274. var minTop = Number.MAX_VALUE;
  275. var maxBottom = Number.MIN_VALUE;
  276. var minMarginLeft = Number.MAX_VALUE;
  277. var maxMarginRight = Number.MIN_VALUE;
  278. var minMarginTop = Number.MAX_VALUE;
  279. var maxMarginBottom = Number.MIN_VALUE;
  280. if (this.isSymbol) {
  281. minLeft = this.borderLeft;
  282. maxRight = this.borderRight;
  283. minTop = this.borderTop;
  284. maxBottom = this.borderBottom;
  285. minMarginLeft = this.borderMarginLeft;
  286. maxMarginRight = this.borderMarginRight;
  287. minMarginTop = this.borderMarginTop;
  288. maxMarginBottom = this.borderMarginBottom;
  289. }
  290. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  291. var childElement = this.ChildElements[idx];
  292. minLeft = Math.min(minLeft, childElement.relativePosition.x + childElement.borderLeft);
  293. maxRight = Math.max(maxRight, childElement.relativePosition.x + childElement.borderRight);
  294. minTop = Math.min(minTop, childElement.relativePosition.y + childElement.borderTop);
  295. maxBottom = Math.max(maxBottom, childElement.relativePosition.y + childElement.borderBottom);
  296. minMarginLeft = Math.min(minMarginLeft, childElement.relativePosition.x + childElement.borderMarginLeft);
  297. maxMarginRight = Math.max(maxMarginRight, childElement.relativePosition.x + childElement.borderMarginRight);
  298. minMarginTop = Math.min(minMarginTop, childElement.relativePosition.y + childElement.borderMarginTop);
  299. maxMarginBottom = Math.max(maxMarginBottom, childElement.relativePosition.y + childElement.borderMarginBottom);
  300. }
  301. this.borderLeft = minLeft;
  302. this.borderRight = maxRight;
  303. this.borderTop = minTop;
  304. this.borderBottom = maxBottom;
  305. this.borderMarginLeft = minMarginLeft;
  306. this.borderMarginRight = maxMarginRight;
  307. this.borderMarginTop = minMarginTop;
  308. this.borderMarginBottom = maxMarginBottom;
  309. this.calculateRectangle();
  310. this.calculateMarginRectangle();
  311. this.xBordersHaveBeenSet = true;
  312. this.yBordersHaveBeenSet = true;
  313. };
  314. BoundingBox.prototype.calculateTopBottomBorders = function () {
  315. if (this.childElements.length === 0) {
  316. return;
  317. }
  318. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  319. var childElement = this.ChildElements[idx];
  320. childElement.calculateTopBottomBorders();
  321. }
  322. var minTop = Number.MAX_VALUE;
  323. var maxBottom = Number.MIN_VALUE;
  324. var minMarginTop = Number.MAX_VALUE;
  325. var maxMarginBottom = Number.MIN_VALUE;
  326. if (this.yBordersHaveBeenSet) {
  327. minTop = this.borderTop;
  328. maxBottom = this.borderBottom;
  329. minMarginTop = this.borderMarginTop;
  330. maxMarginBottom = this.borderMarginBottom;
  331. }
  332. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  333. var childElement = this.ChildElements[idx];
  334. minTop = Math.min(minTop, childElement.relativePosition.y + childElement.borderTop);
  335. maxBottom = Math.max(maxBottom, childElement.relativePosition.y + childElement.borderBottom);
  336. minMarginTop = Math.min(minMarginTop, childElement.relativePosition.y + childElement.borderMarginTop);
  337. maxMarginBottom = Math.max(maxMarginBottom, childElement.relativePosition.y + childElement.borderMarginBottom);
  338. }
  339. this.borderTop = minTop;
  340. this.borderBottom = maxBottom;
  341. this.borderMarginTop = minMarginTop;
  342. this.borderMarginBottom = maxMarginBottom;
  343. this.calculateRectangle();
  344. this.calculateMarginRectangle();
  345. };
  346. BoundingBox.prototype.computeNonOverlappingPositionWithMargin = function (placementPsi, direction, position) {
  347. this.RelativePosition = new PointF2D_1.PointF2D(position.x, position.y);
  348. this.setAbsolutePositionFromParent();
  349. var currentPosition = 0.0;
  350. var hasBeenMoved = false;
  351. do {
  352. switch (direction) {
  353. case ColDirEnum.Left:
  354. case ColDirEnum.Right:
  355. currentPosition = this.relativePosition.x;
  356. placementPsi.calculateMarginPositionAlongDirection(this, direction);
  357. hasBeenMoved = Math.abs(currentPosition - this.relativePosition.x) > 0.001;
  358. break;
  359. case ColDirEnum.Up:
  360. case ColDirEnum.Down:
  361. currentPosition = this.relativePosition.y;
  362. placementPsi.calculateMarginPositionAlongDirection(this, direction);
  363. hasBeenMoved = Math.abs(currentPosition - this.relativePosition.y) > 0.001;
  364. break;
  365. default:
  366. throw new Exceptions_1.ArgumentOutOfRangeException("direction");
  367. }
  368. } while (hasBeenMoved);
  369. };
  370. BoundingBox.prototype.collisionDetection = function (psi) {
  371. var overlapWidth = Math.min(this.AbsolutePosition.x + this.borderRight, psi.absolutePosition.x + psi.borderRight)
  372. - Math.max(this.AbsolutePosition.x + this.borderLeft, psi.absolutePosition.x + psi.borderLeft);
  373. var overlapHeight = Math.min(this.AbsolutePosition.y + this.borderBottom, psi.absolutePosition.y + psi.borderBottom)
  374. - Math.max(this.AbsolutePosition.y + this.borderTop, psi.absolutePosition.y + psi.borderTop);
  375. if (overlapWidth > 0 && overlapHeight > 0) {
  376. return true;
  377. }
  378. return false;
  379. };
  380. BoundingBox.prototype.liesInsideBorders = function (psi) {
  381. var leftBorderInside = (this.AbsolutePosition.x + this.borderLeft) <= (psi.absolutePosition.x + psi.borderLeft)
  382. && (psi.absolutePosition.x + psi.borderLeft) <= (this.AbsolutePosition.x + this.borderRight);
  383. var rightBorderInside = (this.AbsolutePosition.x + this.borderLeft) <= (psi.absolutePosition.x + psi.borderRight)
  384. && (psi.absolutePosition.x + psi.borderRight) <= (this.AbsolutePosition.x + this.borderRight);
  385. if (leftBorderInside && rightBorderInside) {
  386. var topBorderInside = (this.AbsolutePosition.y + this.borderTop) <= (psi.absolutePosition.y + psi.borderTop)
  387. && (psi.absolutePosition.y + psi.borderTop) <= (this.AbsolutePosition.y + this.borderBottom);
  388. var bottomBorderInside = (this.AbsolutePosition.y + this.borderTop) <= (psi.absolutePosition.y + psi.borderBottom)
  389. && (psi.absolutePosition.y + psi.borderBottom) <= (this.AbsolutePosition.y + this.borderBottom);
  390. if (topBorderInside && bottomBorderInside) {
  391. return true;
  392. }
  393. }
  394. return false;
  395. };
  396. BoundingBox.prototype.pointLiesInsideBorders = function (position) {
  397. var xInside = (this.AbsolutePosition.x + this.borderLeft) <= position.x && position.x <= (this.AbsolutePosition.x + this.borderRight);
  398. if (xInside) {
  399. var yInside = (this.AbsolutePosition.y + this.borderTop) <= position.y && position.y <= (this.AbsolutePosition.y + this.borderBottom);
  400. if (yInside) {
  401. return true;
  402. }
  403. }
  404. return false;
  405. };
  406. BoundingBox.prototype.marginCollisionDetection = function (psi) {
  407. var overlapWidth = Math.min(this.AbsolutePosition.x + this.borderMarginRight, psi.absolutePosition.x + psi.borderMarginRight)
  408. - Math.max(this.AbsolutePosition.x + this.borderMarginLeft, psi.absolutePosition.x + psi.borderMarginLeft);
  409. var overlapHeight = Math.min(this.AbsolutePosition.y + this.borderMarginBottom, psi.absolutePosition.y + psi.borderMarginBottom)
  410. - Math.max(this.AbsolutePosition.y + this.borderMarginTop, psi.absolutePosition.y + psi.borderMarginTop);
  411. if (overlapWidth > 0 && overlapHeight > 0) {
  412. return true;
  413. }
  414. return false;
  415. };
  416. BoundingBox.prototype.liesInsideMargins = function (psi) {
  417. var leftMarginInside = (this.AbsolutePosition.x + this.borderMarginLeft) <= (psi.absolutePosition.x + psi.borderMarginLeft)
  418. && (psi.absolutePosition.x + psi.borderMarginLeft) <= (this.AbsolutePosition.x + this.borderMarginRight);
  419. var rightMarginInside = (this.AbsolutePosition.x + this.borderMarginLeft) <= (psi.absolutePosition.x + psi.borderMarginRight)
  420. && (psi.absolutePosition.x + psi.borderMarginRight) <= (this.AbsolutePosition.x + this.borderMarginRight);
  421. if (leftMarginInside && rightMarginInside) {
  422. var topMarginInside = (this.AbsolutePosition.y + this.borderMarginTop) <= (psi.absolutePosition.y + psi.borderMarginTop)
  423. && (psi.absolutePosition.y + psi.borderMarginTop) <= (this.AbsolutePosition.y + this.borderMarginBottom);
  424. var bottomMarginInside = (this.AbsolutePosition.y + this.borderMarginTop) <= (psi.absolutePosition.y + psi.borderMarginBottom)
  425. && (psi.absolutePosition.y + psi.borderMarginBottom) <= (this.AbsolutePosition.y + this.borderMarginBottom);
  426. if (topMarginInside && bottomMarginInside) {
  427. return true;
  428. }
  429. }
  430. return false;
  431. };
  432. BoundingBox.prototype.pointLiesInsideMargins = function (position) {
  433. var xInside = (this.AbsolutePosition.x + this.borderMarginLeft) <= position.x
  434. && position.x <= (this.AbsolutePosition.x + this.borderMarginRight);
  435. if (xInside) {
  436. var yInside = (this.AbsolutePosition.y + this.borderMarginTop) <= position.y
  437. && position.y <= (this.AbsolutePosition.y + this.borderMarginBottom);
  438. if (yInside) {
  439. return true;
  440. }
  441. }
  442. return false;
  443. };
  444. BoundingBox.prototype.computeNonOverlappingPosition = function (placementPsi, direction, position) {
  445. this.RelativePosition = new PointF2D_1.PointF2D(position.x, position.y);
  446. this.setAbsolutePositionFromParent();
  447. var currentPosition = 0.0;
  448. var hasBeenMoved = false;
  449. do {
  450. switch (direction) {
  451. case ColDirEnum.Left:
  452. case ColDirEnum.Right:
  453. currentPosition = this.relativePosition.x;
  454. placementPsi.calculatePositionAlongDirection(this, direction);
  455. hasBeenMoved = Math.abs(currentPosition - this.relativePosition.x) > 0.0001;
  456. break;
  457. case ColDirEnum.Up:
  458. case ColDirEnum.Down:
  459. currentPosition = this.relativePosition.y;
  460. placementPsi.calculatePositionAlongDirection(this, direction);
  461. hasBeenMoved = Math.abs(currentPosition - this.relativePosition.y) > 0.0001;
  462. break;
  463. default:
  464. throw new Exceptions_1.ArgumentOutOfRangeException("direction");
  465. }
  466. } while (hasBeenMoved);
  467. };
  468. BoundingBox.prototype.getClickedObjectOfType = function (clickPosition) {
  469. var obj = this.dataObject;
  470. if (this.pointLiesInsideBorders(clickPosition) && (obj !== undefined)) {
  471. return obj;
  472. }
  473. for (var idx = 0, len = this.childElements.length; idx < len; ++idx) {
  474. var psi = this.childElements[idx];
  475. var innerObject = psi.getClickedObjectOfType(clickPosition);
  476. if (innerObject !== undefined) {
  477. return innerObject;
  478. }
  479. }
  480. return undefined;
  481. };
  482. BoundingBox.prototype.getObjectsInRegion = function (region, liesInside) {
  483. if (liesInside === void 0) { liesInside = true; }
  484. if (this.dataObject !== undefined) {
  485. if (liesInside) {
  486. if (region.liesInsideBorders(this)) {
  487. return [this.dataObject];
  488. }
  489. }
  490. else {
  491. if (region.collisionDetection(this)) {
  492. return [this.dataObject];
  493. }
  494. }
  495. }
  496. var result = [];
  497. for (var _i = 0, _a = this.childElements; _i < _a.length; _i++) {
  498. var child = _a[_i];
  499. result.concat(child.getObjectsInRegion(region, liesInside));
  500. }
  501. return result;
  502. //return this.childElements.SelectMany(psi => psi.getObjectsInRegion<T>(region, liesInside));
  503. };
  504. BoundingBox.prototype.calculateRectangle = function () {
  505. this.upperLeftCorner = new PointF2D_1.PointF2D(this.borderLeft, this.borderTop);
  506. this.size = new SizeF2D_1.SizeF2D(this.borderRight - this.borderLeft, this.borderBottom - this.borderTop);
  507. this.boundingRectangle = RectangleF2D_1.RectangleF2D.createFromLocationAndSize(this.upperLeftCorner, this.size);
  508. };
  509. BoundingBox.prototype.calculateMarginRectangle = function () {
  510. this.upperLeftMarginCorner = new PointF2D_1.PointF2D(this.borderMarginLeft, this.borderMarginTop);
  511. this.marginSize = new SizeF2D_1.SizeF2D(this.borderMarginRight - this.borderMarginLeft, this.borderMarginBottom - this.borderMarginTop);
  512. this.boundingMarginRectangle = RectangleF2D_1.RectangleF2D.createFromLocationAndSize(this.upperLeftMarginCorner, this.marginSize);
  513. };
  514. BoundingBox.prototype.calculateMarginPositionAlongDirection = function (toBePlaced, direction) {
  515. if (this === toBePlaced) {
  516. return;
  517. }
  518. if (this.isSymbol && this.marginCollisionDetection(toBePlaced)) {
  519. var shiftDistance = 0;
  520. switch (direction) {
  521. case ColDirEnum.Left:
  522. shiftDistance = (this.absolutePosition.x + this.borderMarginLeft) - (toBePlaced.absolutePosition.x + toBePlaced.borderMarginRight);
  523. toBePlaced.relativePosition.x += shiftDistance;
  524. toBePlaced.absolutePosition.x += shiftDistance;
  525. return;
  526. case ColDirEnum.Right:
  527. shiftDistance = (this.absolutePosition.x + this.borderMarginRight) - (toBePlaced.absolutePosition.x + toBePlaced.borderMarginLeft);
  528. toBePlaced.relativePosition.x += shiftDistance;
  529. toBePlaced.absolutePosition.x += shiftDistance;
  530. return;
  531. case ColDirEnum.Up:
  532. shiftDistance = (this.absolutePosition.y + this.borderMarginTop) - (toBePlaced.absolutePosition.y + toBePlaced.borderMarginBottom);
  533. toBePlaced.relativePosition.y += shiftDistance;
  534. toBePlaced.absolutePosition.y += shiftDistance;
  535. return;
  536. case ColDirEnum.Down:
  537. shiftDistance = (this.absolutePosition.y + this.borderMarginBottom) - (toBePlaced.absolutePosition.y + toBePlaced.borderMarginTop);
  538. toBePlaced.relativePosition.y += shiftDistance;
  539. toBePlaced.absolutePosition.y += shiftDistance;
  540. return;
  541. default:
  542. throw new Exceptions_1.ArgumentOutOfRangeException("direction");
  543. }
  544. }
  545. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  546. var childElement = this.ChildElements[idx];
  547. childElement.calculateMarginPositionAlongDirection(toBePlaced, direction);
  548. }
  549. };
  550. BoundingBox.prototype.calculatePositionAlongDirection = function (toBePlaced, direction) {
  551. if (this === toBePlaced) {
  552. return;
  553. }
  554. if (this.isSymbol && this.collisionDetection(toBePlaced)) {
  555. var shiftDistance = void 0;
  556. switch (direction) {
  557. case ColDirEnum.Left:
  558. shiftDistance = (this.absolutePosition.x + this.borderLeft) - (toBePlaced.absolutePosition.x + toBePlaced.borderRight);
  559. toBePlaced.relativePosition.x += shiftDistance;
  560. toBePlaced.absolutePosition.x += shiftDistance;
  561. return;
  562. case ColDirEnum.Right:
  563. shiftDistance = (this.absolutePosition.x + this.borderRight) - (toBePlaced.absolutePosition.x + toBePlaced.borderLeft);
  564. toBePlaced.relativePosition.x += shiftDistance;
  565. toBePlaced.absolutePosition.x += shiftDistance;
  566. return;
  567. case ColDirEnum.Up:
  568. shiftDistance = (this.absolutePosition.y + this.borderTop) - (toBePlaced.absolutePosition.y + toBePlaced.borderBottom);
  569. toBePlaced.relativePosition.y += shiftDistance;
  570. toBePlaced.absolutePosition.y += shiftDistance;
  571. return;
  572. case ColDirEnum.Down:
  573. shiftDistance = (this.absolutePosition.y + this.borderBottom) - (toBePlaced.absolutePosition.y + toBePlaced.borderTop);
  574. toBePlaced.relativePosition.y += shiftDistance;
  575. toBePlaced.absolutePosition.y += shiftDistance;
  576. return;
  577. default:
  578. throw new Exceptions_1.ArgumentOutOfRangeException("direction");
  579. }
  580. }
  581. for (var idx = 0, len = this.ChildElements.length; idx < len; ++idx) {
  582. var childElement = this.ChildElements[idx];
  583. childElement.calculatePositionAlongDirection(toBePlaced, direction);
  584. }
  585. };
  586. return BoundingBox;
  587. }());
  588. exports.BoundingBox = BoundingBox;
  589. (function (ColDirEnum) {
  590. ColDirEnum[ColDirEnum["Left"] = 0] = "Left";
  591. ColDirEnum[ColDirEnum["Right"] = 1] = "Right";
  592. ColDirEnum[ColDirEnum["Up"] = 2] = "Up";
  593. ColDirEnum[ColDirEnum["Down"] = 3] = "Down";
  594. })(exports.ColDirEnum || (exports.ColDirEnum = {}));
  595. var ColDirEnum = exports.ColDirEnum;