d68c0a11c9b46b60aca3d02fa69fbe4e0f485d7111db9a251931f04ce860c38e03d7f6684d95d89d6048801b5c05fe86d7e423df358e939d566cf88a8ca62e 3.6 KB

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