KdNode.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Coordinate from '../../geom/Coordinate'
  2. export default class KdNode {
  3. constructor() {
  4. KdNode.constructor_.apply(this, arguments)
  5. }
  6. static constructor_() {
  7. this._p = null
  8. this._data = null
  9. this._left = null
  10. this._right = null
  11. this._count = null
  12. if (arguments.length === 2) {
  13. const p = arguments[0], data = arguments[1]
  14. this._p = new Coordinate(p)
  15. this._left = null
  16. this._right = null
  17. this._count = 1
  18. this._data = data
  19. } else if (arguments.length === 3) {
  20. const _x = arguments[0], _y = arguments[1], data = arguments[2]
  21. this._p = new Coordinate(_x, _y)
  22. this._left = null
  23. this._right = null
  24. this._count = 1
  25. this._data = data
  26. }
  27. }
  28. isRepeated() {
  29. return this._count > 1
  30. }
  31. getRight() {
  32. return this._right
  33. }
  34. getCoordinate() {
  35. return this._p
  36. }
  37. setLeft(_left) {
  38. this._left = _left
  39. }
  40. getX() {
  41. return this._p.x
  42. }
  43. getData() {
  44. return this._data
  45. }
  46. getCount() {
  47. return this._count
  48. }
  49. getLeft() {
  50. return this._left
  51. }
  52. getY() {
  53. return this._p.y
  54. }
  55. increment() {
  56. this._count = this._count + 1
  57. }
  58. setRight(_right) {
  59. this._right = _right
  60. }
  61. }