IntervalRTreeNode.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import WKTWriter from '../../io/WKTWriter'
  2. import Coordinate from '../../geom/Coordinate'
  3. import Double from '../../../../../java/lang/Double'
  4. import Comparator from '../../../../../java/util/Comparator'
  5. export default class IntervalRTreeNode {
  6. constructor() {
  7. IntervalRTreeNode.constructor_.apply(this, arguments)
  8. }
  9. static constructor_() {
  10. this._min = Double.POSITIVE_INFINITY
  11. this._max = Double.NEGATIVE_INFINITY
  12. }
  13. getMin() {
  14. return this._min
  15. }
  16. intersects(queryMin, queryMax) {
  17. if (this._min > queryMax || this._max < queryMin) return false
  18. return true
  19. }
  20. getMax() {
  21. return this._max
  22. }
  23. toString() {
  24. return WKTWriter.toLineString(new Coordinate(this._min, 0), new Coordinate(this._max, 0))
  25. }
  26. }
  27. class NodeComparator {
  28. compare(o1, o2) {
  29. const n1 = o1
  30. const n2 = o2
  31. const mid1 = (n1._min + n1._max) / 2
  32. const mid2 = (n2._min + n2._max) / 2
  33. if (mid1 < mid2) return -1
  34. if (mid1 > mid2) return 1
  35. return 0
  36. }
  37. get interfaces_() {
  38. return [Comparator]
  39. }
  40. }
  41. IntervalRTreeNode.NodeComparator = NodeComparator