EdgeEndBuilder.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import EdgeEnd from '../../geomgraph/EdgeEnd'
  2. import Label from '../../geomgraph/Label'
  3. import ArrayList from '../../../../../java/util/ArrayList'
  4. export default class EdgeEndBuilder {
  5. createEdgeEndForNext(edge, l, eiCurr, eiNext) {
  6. const iNext = eiCurr.segmentIndex + 1
  7. if (iNext >= edge.getNumPoints() && eiNext === null) return null
  8. let pNext = edge.getCoordinate(iNext)
  9. if (eiNext !== null && eiNext.segmentIndex === eiCurr.segmentIndex) pNext = eiNext.coord
  10. const e = new EdgeEnd(edge, eiCurr.coord, pNext, new Label(edge.getLabel()))
  11. l.add(e)
  12. }
  13. createEdgeEndForPrev(edge, l, eiCurr, eiPrev) {
  14. let iPrev = eiCurr.segmentIndex
  15. if (eiCurr.dist === 0.0) {
  16. if (iPrev === 0) return null
  17. iPrev--
  18. }
  19. let pPrev = edge.getCoordinate(iPrev)
  20. if (eiPrev !== null && eiPrev.segmentIndex >= iPrev) pPrev = eiPrev.coord
  21. const label = new Label(edge.getLabel())
  22. label.flip()
  23. const e = new EdgeEnd(edge, eiCurr.coord, pPrev, label)
  24. l.add(e)
  25. }
  26. computeEdgeEnds() {
  27. if (arguments.length === 1) {
  28. const edges = arguments[0]
  29. const l = new ArrayList()
  30. for (let i = edges; i.hasNext(); ) {
  31. const e = i.next()
  32. this.computeEdgeEnds(e, l)
  33. }
  34. return l
  35. } else if (arguments.length === 2) {
  36. const edge = arguments[0], l = arguments[1]
  37. const eiList = edge.getEdgeIntersectionList()
  38. eiList.addEndpoints()
  39. const it = eiList.iterator()
  40. let eiPrev = null
  41. let eiCurr = null
  42. if (!it.hasNext()) return null
  43. let eiNext = it.next()
  44. do {
  45. eiPrev = eiCurr
  46. eiCurr = eiNext
  47. eiNext = null
  48. if (it.hasNext()) eiNext = it.next()
  49. if (eiCurr !== null) {
  50. this.createEdgeEndForPrev(edge, l, eiCurr, eiPrev)
  51. this.createEdgeEndForNext(edge, l, eiCurr, eiNext)
  52. }
  53. } while (eiCurr !== null)
  54. }
  55. }
  56. }