DirectedEdge.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import Location from '../geom/Location'
  2. import EdgeEnd from './EdgeEnd'
  3. import Position from './Position'
  4. import TopologyException from '../geom/TopologyException'
  5. import Label from './Label'
  6. export default class DirectedEdge extends EdgeEnd {
  7. constructor() {
  8. super()
  9. DirectedEdge.constructor_.apply(this, arguments)
  10. }
  11. static constructor_() {
  12. this._isForward = null
  13. this._isInResult = false
  14. this._isVisited = false
  15. this._sym = null
  16. this._next = null
  17. this._nextMin = null
  18. this._edgeRing = null
  19. this._minEdgeRing = null
  20. this._depth = [0, -999, -999]
  21. const edge = arguments[0], isForward = arguments[1]
  22. EdgeEnd.constructor_.call(this, edge)
  23. this._isForward = isForward
  24. if (isForward) {
  25. this.init(edge.getCoordinate(0), edge.getCoordinate(1))
  26. } else {
  27. const n = edge.getNumPoints() - 1
  28. this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1))
  29. }
  30. this.computeDirectedLabel()
  31. }
  32. static depthFactor(currLocation, nextLocation) {
  33. if (currLocation === Location.EXTERIOR && nextLocation === Location.INTERIOR) return 1; else if (currLocation === Location.INTERIOR && nextLocation === Location.EXTERIOR) return -1
  34. return 0
  35. }
  36. getNextMin() {
  37. return this._nextMin
  38. }
  39. getDepth(position) {
  40. return this._depth[position]
  41. }
  42. setVisited(isVisited) {
  43. this._isVisited = isVisited
  44. }
  45. computeDirectedLabel() {
  46. this._label = new Label(this._edge.getLabel())
  47. if (!this._isForward) this._label.flip()
  48. }
  49. getNext() {
  50. return this._next
  51. }
  52. setDepth(position, depthVal) {
  53. if (this._depth[position] !== -999)
  54. if (this._depth[position] !== depthVal) throw new TopologyException('assigned depths do not match', this.getCoordinate())
  55. this._depth[position] = depthVal
  56. }
  57. isInteriorAreaEdge() {
  58. let isInteriorAreaEdge = true
  59. for (let i = 0; i < 2; i++)
  60. if (!(this._label.isArea(i) && this._label.getLocation(i, Position.LEFT) === Location.INTERIOR && this._label.getLocation(i, Position.RIGHT) === Location.INTERIOR))
  61. isInteriorAreaEdge = false
  62. return isInteriorAreaEdge
  63. }
  64. setNextMin(nextMin) {
  65. this._nextMin = nextMin
  66. }
  67. print(out) {
  68. super.print.call(this, out)
  69. out.print(' ' + this._depth[Position.LEFT] + '/' + this._depth[Position.RIGHT])
  70. out.print(' (' + this.getDepthDelta() + ')')
  71. if (this._isInResult) out.print(' inResult')
  72. }
  73. setMinEdgeRing(minEdgeRing) {
  74. this._minEdgeRing = minEdgeRing
  75. }
  76. isLineEdge() {
  77. const isLine = this._label.isLine(0) || this._label.isLine(1)
  78. const isExteriorIfArea0 = !this._label.isArea(0) || this._label.allPositionsEqual(0, Location.EXTERIOR)
  79. const isExteriorIfArea1 = !this._label.isArea(1) || this._label.allPositionsEqual(1, Location.EXTERIOR)
  80. return isLine && isExteriorIfArea0 && isExteriorIfArea1
  81. }
  82. setEdgeRing(edgeRing) {
  83. this._edgeRing = edgeRing
  84. }
  85. getMinEdgeRing() {
  86. return this._minEdgeRing
  87. }
  88. getDepthDelta() {
  89. let depthDelta = this._edge.getDepthDelta()
  90. if (!this._isForward) depthDelta = -depthDelta
  91. return depthDelta
  92. }
  93. setInResult(isInResult) {
  94. this._isInResult = isInResult
  95. }
  96. getSym() {
  97. return this._sym
  98. }
  99. isForward() {
  100. return this._isForward
  101. }
  102. getEdge() {
  103. return this._edge
  104. }
  105. printEdge(out) {
  106. this.print(out)
  107. out.print(' ')
  108. if (this._isForward) this._edge.print(out); else this._edge.printReverse(out)
  109. }
  110. setSym(de) {
  111. this._sym = de
  112. }
  113. setVisitedEdge(isVisited) {
  114. this.setVisited(isVisited)
  115. this._sym.setVisited(isVisited)
  116. }
  117. setEdgeDepths(position, depth) {
  118. let depthDelta = this.getEdge().getDepthDelta()
  119. if (!this._isForward) depthDelta = -depthDelta
  120. let directionFactor = 1
  121. if (position === Position.LEFT) directionFactor = -1
  122. const oppositePos = Position.opposite(position)
  123. const delta = depthDelta * directionFactor
  124. const oppositeDepth = depth + delta
  125. this.setDepth(position, depth)
  126. this.setDepth(oppositePos, oppositeDepth)
  127. }
  128. getEdgeRing() {
  129. return this._edgeRing
  130. }
  131. isInResult() {
  132. return this._isInResult
  133. }
  134. setNext(next) {
  135. this._next = next
  136. }
  137. isVisited() {
  138. return this._isVisited
  139. }
  140. }