IndexedNestedRingTester.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import STRtree from '../../index/strtree/STRtree'
  2. import IsValidOp from './IsValidOp'
  3. import PointLocation from '../../algorithm/PointLocation'
  4. import ArrayList from '../../../../../java/util/ArrayList'
  5. import Envelope from '../../geom/Envelope'
  6. export default class IndexedNestedRingTester {
  7. constructor() {
  8. IndexedNestedRingTester.constructor_.apply(this, arguments)
  9. }
  10. static constructor_() {
  11. this._graph = null
  12. this._rings = new ArrayList()
  13. this._totalEnv = new Envelope()
  14. this._index = null
  15. this._nestedPt = null
  16. const graph = arguments[0]
  17. this._graph = graph
  18. }
  19. buildIndex() {
  20. this._index = new STRtree()
  21. for (let i = 0; i < this._rings.size(); i++) {
  22. const ring = this._rings.get(i)
  23. const env = ring.getEnvelopeInternal()
  24. this._index.insert(env, ring)
  25. }
  26. }
  27. getNestedPoint() {
  28. return this._nestedPt
  29. }
  30. isNonNested() {
  31. this.buildIndex()
  32. for (let i = 0; i < this._rings.size(); i++) {
  33. const innerRing = this._rings.get(i)
  34. const innerRingPts = innerRing.getCoordinates()
  35. const results = this._index.query(innerRing.getEnvelopeInternal())
  36. for (let j = 0; j < results.size(); j++) {
  37. const searchRing = results.get(j)
  38. const searchRingPts = searchRing.getCoordinates()
  39. if (innerRing === searchRing) continue
  40. if (!innerRing.getEnvelopeInternal().intersects(searchRing.getEnvelopeInternal())) continue
  41. const innerRingPt = IsValidOp.findPtNotNode(innerRingPts, searchRing, this._graph)
  42. if (innerRingPt === null) continue
  43. const isInside = PointLocation.isInRing(innerRingPt, searchRingPts)
  44. if (isInside) {
  45. this._nestedPt = innerRingPt
  46. return false
  47. }
  48. }
  49. }
  50. return true
  51. }
  52. add(ring) {
  53. this._rings.add(ring)
  54. this._totalEnv.expandToInclude(ring.getEnvelopeInternal())
  55. }
  56. }