HoleAssigner.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import STRtree from '../../index/strtree/STRtree'
  2. import EdgeRing from './EdgeRing'
  3. export default class HoleAssigner {
  4. constructor() {
  5. HoleAssigner.constructor_.apply(this, arguments)
  6. }
  7. static constructor_() {
  8. this._shells = null
  9. this._shellIndex = null
  10. const shells = arguments[0]
  11. this._shells = shells
  12. this.buildIndex()
  13. }
  14. static assignHolesToShells(holes, shells) {
  15. const assigner = new HoleAssigner(shells)
  16. assigner.assignHolesToShells(holes)
  17. }
  18. assignHolesToShells(holeList) {
  19. for (let i = holeList.iterator(); i.hasNext(); ) {
  20. const holeER = i.next()
  21. this.assignHoleToShell(holeER)
  22. }
  23. }
  24. buildIndex() {
  25. this._shellIndex = new STRtree()
  26. for (const shell of this._shells)
  27. this._shellIndex.insert(shell.getRing().getEnvelopeInternal(), shell)
  28. }
  29. queryOverlappingShells(ringEnv) {
  30. return this._shellIndex.query(ringEnv)
  31. }
  32. findShellContaining(testEr) {
  33. const testEnv = testEr.getRing().getEnvelopeInternal()
  34. const candidateShells = this.queryOverlappingShells(testEnv)
  35. return EdgeRing.findEdgeRingContaining(testEr, candidateShells)
  36. }
  37. assignHoleToShell(holeER) {
  38. const shell = this.findShellContaining(holeER)
  39. if (shell !== null)
  40. shell.addHole(holeER)
  41. }
  42. }