SIRtree.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import Interval from './Interval'
  2. import Comparator from '../../../../../java/util/Comparator'
  3. import AbstractSTRtree from './AbstractSTRtree'
  4. export default class SIRtree extends AbstractSTRtree {
  5. constructor() {
  6. super()
  7. SIRtree.constructor_.apply(this, arguments)
  8. }
  9. static constructor_() {
  10. this._comparator = new (class {
  11. get interfaces_() {
  12. return [Comparator]
  13. }
  14. compare(o1, o2) {
  15. return AbstractSTRtree.compareDoubles(o1.getBounds().getCentre(), o2.getBounds().getCentre())
  16. }
  17. })()
  18. this._intersectsOp = new (class {
  19. get interfaces_() {
  20. return [IntersectsOp]
  21. }
  22. intersects(aBounds, bBounds) {
  23. return aBounds.intersects(bBounds)
  24. }
  25. })()
  26. if (arguments.length === 0) {
  27. SIRtree.constructor_.call(this, 10)
  28. } else if (arguments.length === 1) {
  29. const nodeCapacity = arguments[0]
  30. AbstractSTRtree.constructor_.call(this, nodeCapacity)
  31. }
  32. }
  33. createNode(level) {
  34. return new (class {
  35. computeBounds() {
  36. let bounds = null
  37. for (let i = this.getChildBoundables().iterator(); i.hasNext(); ) {
  38. const childBoundable = i.next()
  39. if (bounds === null)
  40. bounds = new Interval(childBoundable.getBounds())
  41. else
  42. bounds.expandToInclude(childBoundable.getBounds())
  43. }
  44. return bounds
  45. }
  46. })(level)
  47. }
  48. insert() {
  49. if (arguments.length === 3) {
  50. const x1 = arguments[0], x2 = arguments[1], item = arguments[2]
  51. super.insert.call(this, new Interval(Math.min(x1, x2), Math.max(x1, x2)), item)
  52. } else {
  53. return super.insert.apply(this, arguments)
  54. }
  55. }
  56. getIntersectsOp() {
  57. return this._intersectsOp
  58. }
  59. query() {
  60. if (arguments.length === 1) {
  61. const x = arguments[0]
  62. return this.query(x, x)
  63. } else if (arguments.length === 2) {
  64. const x1 = arguments[0], x2 = arguments[1]
  65. return super.query.call(this, new Interval(Math.min(x1, x2), Math.max(x1, x2)))
  66. }
  67. }
  68. getComparator() {
  69. return this._comparator
  70. }
  71. }