EdgeEndBundle.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import Location from '../../geom/Location'
  2. import EdgeEnd from '../../geomgraph/EdgeEnd'
  3. import Position from '../../geomgraph/Position'
  4. import GeometryGraph from '../../geomgraph/GeometryGraph'
  5. import Label from '../../geomgraph/Label'
  6. import ArrayList from '../../../../../java/util/ArrayList'
  7. import Edge from '../../geomgraph/Edge'
  8. export default class EdgeEndBundle extends EdgeEnd {
  9. constructor() {
  10. super()
  11. EdgeEndBundle.constructor_.apply(this, arguments)
  12. }
  13. static constructor_() {
  14. this._edgeEnds = new ArrayList()
  15. if (arguments.length === 1) {
  16. const e = arguments[0]
  17. EdgeEndBundle.constructor_.call(this, null, e)
  18. } else if (arguments.length === 2) {
  19. const boundaryNodeRule = arguments[0], e = arguments[1]
  20. EdgeEnd.constructor_.call(this, e.getEdge(), e.getCoordinate(), e.getDirectedCoordinate(), new Label(e.getLabel()))
  21. this.insert(e)
  22. }
  23. }
  24. insert(e) {
  25. this._edgeEnds.add(e)
  26. }
  27. print(out) {
  28. out.println('EdgeEndBundle--> Label: ' + this._label)
  29. for (let it = this.iterator(); it.hasNext(); ) {
  30. const ee = it.next()
  31. ee.print(out)
  32. out.println()
  33. }
  34. }
  35. iterator() {
  36. return this._edgeEnds.iterator()
  37. }
  38. getEdgeEnds() {
  39. return this._edgeEnds
  40. }
  41. computeLabelOn(geomIndex, boundaryNodeRule) {
  42. let boundaryCount = 0
  43. let foundInterior = false
  44. for (let it = this.iterator(); it.hasNext(); ) {
  45. const e = it.next()
  46. const loc = e.getLabel().getLocation(geomIndex)
  47. if (loc === Location.BOUNDARY) boundaryCount++
  48. if (loc === Location.INTERIOR) foundInterior = true
  49. }
  50. let loc = Location.NONE
  51. if (foundInterior) loc = Location.INTERIOR
  52. if (boundaryCount > 0)
  53. loc = GeometryGraph.determineBoundary(boundaryNodeRule, boundaryCount)
  54. this._label.setLocation(geomIndex, loc)
  55. }
  56. computeLabelSide(geomIndex, side) {
  57. for (let it = this.iterator(); it.hasNext(); ) {
  58. const e = it.next()
  59. if (e.getLabel().isArea()) {
  60. const loc = e.getLabel().getLocation(geomIndex, side)
  61. if (loc === Location.INTERIOR) {
  62. this._label.setLocation(geomIndex, side, Location.INTERIOR)
  63. return null
  64. } else if (loc === Location.EXTERIOR) {
  65. this._label.setLocation(geomIndex, side, Location.EXTERIOR)
  66. }
  67. }
  68. }
  69. }
  70. getLabel() {
  71. return this._label
  72. }
  73. computeLabelSides(geomIndex) {
  74. this.computeLabelSide(geomIndex, Position.LEFT)
  75. this.computeLabelSide(geomIndex, Position.RIGHT)
  76. }
  77. updateIM(im) {
  78. Edge.updateIM(this._label, im)
  79. }
  80. computeLabel(boundaryNodeRule) {
  81. let isArea = false
  82. for (let it = this.iterator(); it.hasNext(); ) {
  83. const e = it.next()
  84. if (e.getLabel().isArea()) isArea = true
  85. }
  86. if (isArea) this._label = new Label(Location.NONE, Location.NONE, Location.NONE); else this._label = new Label(Location.NONE)
  87. for (let i = 0; i < 2; i++) {
  88. this.computeLabelOn(i, boundaryNodeRule)
  89. if (isArea) this.computeLabelSides(i)
  90. }
  91. }
  92. }