EdgeEnd.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import Orientation from '../algorithm/Orientation'
  2. import Comparable from '../../../../java/lang/Comparable'
  3. import Quadrant from './Quadrant'
  4. import Assert from '../util/Assert'
  5. export default class EdgeEnd {
  6. constructor() {
  7. EdgeEnd.constructor_.apply(this, arguments)
  8. }
  9. static constructor_() {
  10. this._edge = null
  11. this._label = null
  12. this._node = null
  13. this._p0 = null
  14. this._p1 = null
  15. this._dx = null
  16. this._dy = null
  17. this._quadrant = null
  18. if (arguments.length === 1) {
  19. const edge = arguments[0]
  20. this._edge = edge
  21. } else if (arguments.length === 3) {
  22. const edge = arguments[0], p0 = arguments[1], p1 = arguments[2]
  23. EdgeEnd.constructor_.call(this, edge, p0, p1, null)
  24. } else if (arguments.length === 4) {
  25. const edge = arguments[0], p0 = arguments[1], p1 = arguments[2], label = arguments[3]
  26. EdgeEnd.constructor_.call(this, edge)
  27. this.init(p0, p1)
  28. this._label = label
  29. }
  30. }
  31. compareDirection(e) {
  32. if (this._dx === e._dx && this._dy === e._dy) return 0
  33. if (this._quadrant > e._quadrant) return 1
  34. if (this._quadrant < e._quadrant) return -1
  35. return Orientation.index(e._p0, e._p1, this._p1)
  36. }
  37. getDy() {
  38. return this._dy
  39. }
  40. getCoordinate() {
  41. return this._p0
  42. }
  43. setNode(node) {
  44. this._node = node
  45. }
  46. print(out) {
  47. const angle = Math.atan2(this._dy, this._dx)
  48. const className = this.getClass().getName()
  49. const lastDotPos = className.lastIndexOf('.')
  50. const name = className.substring(lastDotPos + 1)
  51. out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label)
  52. }
  53. compareTo(obj) {
  54. const e = obj
  55. return this.compareDirection(e)
  56. }
  57. getDirectedCoordinate() {
  58. return this._p1
  59. }
  60. getDx() {
  61. return this._dx
  62. }
  63. getLabel() {
  64. return this._label
  65. }
  66. getEdge() {
  67. return this._edge
  68. }
  69. getQuadrant() {
  70. return this._quadrant
  71. }
  72. getNode() {
  73. return this._node
  74. }
  75. toString() {
  76. const angle = Math.atan2(this._dy, this._dx)
  77. const className = this.getClass().getName()
  78. const lastDotPos = className.lastIndexOf('.')
  79. const name = className.substring(lastDotPos + 1)
  80. return ' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label
  81. }
  82. computeLabel(boundaryNodeRule) {}
  83. init(p0, p1) {
  84. this._p0 = p0
  85. this._p1 = p1
  86. this._dx = p1.x - p0.x
  87. this._dy = p1.y - p0.y
  88. this._quadrant = Quadrant.quadrant(this._dx, this._dy)
  89. Assert.isTrue(!(this._dx === 0 && this._dy === 0), 'EdgeEnd with identical endpoints found')
  90. }
  91. get interfaces_() {
  92. return [Comparable]
  93. }
  94. }