dca694dbee7d37cf17632c43301ada9d8a17eb699c241ea5d01722037e929c7576d7cea5d098c989708bf96b7992a2de7dffa8568699abb9d3309752116e8e 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. /**
  6. * CellCoords holds cell coordinates (row, column) and few method to validate them and
  7. * retrieve as an array or an object
  8. *
  9. * @class CellCoords
  10. */
  11. var CellCoords = function () {
  12. /**
  13. * @param {Number} row Row index
  14. * @param {Number} col Column index
  15. */
  16. function CellCoords(row, col) {
  17. _classCallCheck(this, CellCoords);
  18. if (typeof row !== 'undefined' && typeof col !== 'undefined') {
  19. this.row = row;
  20. this.col = col;
  21. } else {
  22. this.row = null;
  23. this.col = null;
  24. }
  25. }
  26. /**
  27. * Checks if given set of coordinates is valid in context of a given Walkontable instance
  28. *
  29. * @param {Walkontable} wotInstance
  30. * @returns {Boolean}
  31. */
  32. _createClass(CellCoords, [{
  33. key: 'isValid',
  34. value: function isValid(wotInstance) {
  35. // is it a valid cell index (0 or higher)
  36. if (this.row < 0 || this.col < 0) {
  37. return false;
  38. }
  39. // is selection within total rows and columns
  40. if (this.row >= wotInstance.getSetting('totalRows') || this.col >= wotInstance.getSetting('totalColumns')) {
  41. return false;
  42. }
  43. return true;
  44. }
  45. /**
  46. * Checks if this cell coords are the same as cell coords given as a parameter
  47. *
  48. * @param {CellCoords} cellCoords
  49. * @returns {Boolean}
  50. */
  51. }, {
  52. key: 'isEqual',
  53. value: function isEqual(cellCoords) {
  54. if (cellCoords === this) {
  55. return true;
  56. }
  57. return this.row === cellCoords.row && this.col === cellCoords.col;
  58. }
  59. /**
  60. * Checks if tested coordinates are positioned in south-east from this cell coords
  61. *
  62. * @param {Object} testedCoords
  63. * @returns {Boolean}
  64. */
  65. }, {
  66. key: 'isSouthEastOf',
  67. value: function isSouthEastOf(testedCoords) {
  68. return this.row >= testedCoords.row && this.col >= testedCoords.col;
  69. }
  70. /**
  71. * Checks if tested coordinates are positioned in north-east from this cell coords
  72. *
  73. * @param {Object} testedCoords
  74. * @returns {Boolean}
  75. */
  76. }, {
  77. key: 'isNorthWestOf',
  78. value: function isNorthWestOf(testedCoords) {
  79. return this.row <= testedCoords.row && this.col <= testedCoords.col;
  80. }
  81. /**
  82. * Checks if tested coordinates are positioned in south-west from this cell coords
  83. *
  84. * @param {Object} testedCoords
  85. * @returns {Boolean}
  86. */
  87. }, {
  88. key: 'isSouthWestOf',
  89. value: function isSouthWestOf(testedCoords) {
  90. return this.row >= testedCoords.row && this.col <= testedCoords.col;
  91. }
  92. /**
  93. * Checks if tested coordinates are positioned in north-east from this cell coords
  94. *
  95. * @param {Object} testedCoords
  96. * @returns {Boolean}
  97. */
  98. }, {
  99. key: 'isNorthEastOf',
  100. value: function isNorthEastOf(testedCoords) {
  101. return this.row <= testedCoords.row && this.col >= testedCoords.col;
  102. }
  103. }]);
  104. return CellCoords;
  105. }();
  106. exports.default = CellCoords;