DirectedEdge.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import Orientation from '../algorithm/Orientation'
  2. import Comparable from '../../../../java/lang/Comparable'
  3. import ArrayList from '../../../../java/util/ArrayList'
  4. import Quadrant from '../geomgraph/Quadrant'
  5. import GraphComponent from './GraphComponent'
  6. export default class DirectedEdge extends GraphComponent {
  7. constructor() {
  8. super()
  9. DirectedEdge.constructor_.apply(this, arguments)
  10. }
  11. static constructor_() {
  12. this._parentEdge = null
  13. this._from = null
  14. this._to = null
  15. this._p0 = null
  16. this._p1 = null
  17. this._sym = null
  18. this._edgeDirection = null
  19. this._quadrant = null
  20. this._angle = null
  21. if (arguments.length === 0) {} else if (arguments.length === 4) {
  22. const from = arguments[0], to = arguments[1], directionPt = arguments[2], edgeDirection = arguments[3]
  23. this._from = from
  24. this._to = to
  25. this._edgeDirection = edgeDirection
  26. this._p0 = from.getCoordinate()
  27. this._p1 = directionPt
  28. const dx = this._p1.x - this._p0.x
  29. const dy = this._p1.y - this._p0.y
  30. this._quadrant = Quadrant.quadrant(dx, dy)
  31. this._angle = Math.atan2(dy, dx)
  32. }
  33. }
  34. static toEdges(dirEdges) {
  35. const edges = new ArrayList()
  36. for (let i = dirEdges.iterator(); i.hasNext(); )
  37. edges.add(i.next()._parentEdge)
  38. return edges
  39. }
  40. isRemoved() {
  41. return this._parentEdge === null
  42. }
  43. compareDirection(e) {
  44. if (this._quadrant > e._quadrant) return 1
  45. if (this._quadrant < e._quadrant) return -1
  46. return Orientation.index(e._p0, e._p1, this._p1)
  47. }
  48. getCoordinate() {
  49. return this._from.getCoordinate()
  50. }
  51. print(out) {
  52. const className = this.getClass().getName()
  53. const lastDotPos = className.lastIndexOf('.')
  54. const name = className.substring(lastDotPos + 1)
  55. out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + this._angle)
  56. }
  57. getDirectionPt() {
  58. return this._p1
  59. }
  60. getAngle() {
  61. return this._angle
  62. }
  63. compareTo(obj) {
  64. const de = obj
  65. return this.compareDirection(de)
  66. }
  67. getFromNode() {
  68. return this._from
  69. }
  70. getSym() {
  71. return this._sym
  72. }
  73. setEdge(parentEdge) {
  74. this._parentEdge = parentEdge
  75. }
  76. remove() {
  77. this._sym = null
  78. this._parentEdge = null
  79. }
  80. getEdge() {
  81. return this._parentEdge
  82. }
  83. getQuadrant() {
  84. return this._quadrant
  85. }
  86. setSym(sym) {
  87. this._sym = sym
  88. }
  89. getToNode() {
  90. return this._to
  91. }
  92. getEdgeDirection() {
  93. return this._edgeDirection
  94. }
  95. get interfaces_() {
  96. return [Comparable]
  97. }
  98. }