Node.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Location from '../geom/Location'
  2. import Label from './Label'
  3. import GraphComponent from './GraphComponent'
  4. export default class Node extends GraphComponent {
  5. constructor() {
  6. super()
  7. Node.constructor_.apply(this, arguments)
  8. }
  9. static constructor_() {
  10. this._coord = null
  11. this._edges = null
  12. const coord = arguments[0], edges = arguments[1]
  13. this._coord = coord
  14. this._edges = edges
  15. this._label = new Label(0, Location.NONE)
  16. }
  17. isIncidentEdgeInResult() {
  18. for (let it = this.getEdges().getEdges().iterator(); it.hasNext(); ) {
  19. const de = it.next()
  20. if (de.getEdge().isInResult()) return true
  21. }
  22. return false
  23. }
  24. isIsolated() {
  25. return this._label.getGeometryCount() === 1
  26. }
  27. getCoordinate() {
  28. return this._coord
  29. }
  30. print(out) {
  31. out.println('node ' + this._coord + ' lbl: ' + this._label)
  32. }
  33. computeIM(im) {}
  34. computeMergedLocation(label2, eltIndex) {
  35. let loc = Location.NONE
  36. loc = this._label.getLocation(eltIndex)
  37. if (!label2.isNull(eltIndex)) {
  38. const nLoc = label2.getLocation(eltIndex)
  39. if (loc !== Location.BOUNDARY) loc = nLoc
  40. }
  41. return loc
  42. }
  43. setLabel() {
  44. if (arguments.length === 2 && (Number.isInteger(arguments[1]) && Number.isInteger(arguments[0]))) {
  45. const argIndex = arguments[0], onLocation = arguments[1]
  46. if (this._label === null)
  47. this._label = new Label(argIndex, onLocation)
  48. else this._label.setLocation(argIndex, onLocation)
  49. } else {
  50. return super.setLabel.apply(this, arguments)
  51. }
  52. }
  53. getEdges() {
  54. return this._edges
  55. }
  56. mergeLabel() {
  57. if (arguments[0] instanceof Node) {
  58. const n = arguments[0]
  59. this.mergeLabel(n._label)
  60. } else if (arguments[0] instanceof Label) {
  61. const label2 = arguments[0]
  62. for (let i = 0; i < 2; i++) {
  63. const loc = this.computeMergedLocation(label2, i)
  64. const thisLoc = this._label.getLocation(i)
  65. if (thisLoc === Location.NONE) this._label.setLocation(i, loc)
  66. }
  67. }
  68. }
  69. add(e) {
  70. this._edges.insert(e)
  71. e.setNode(this)
  72. }
  73. setLabelBoundary(argIndex) {
  74. if (this._label === null) return null
  75. let loc = Location.NONE
  76. if (this._label !== null) loc = this._label.getLocation(argIndex)
  77. let newLoc = null
  78. switch (loc) {
  79. case Location.BOUNDARY:
  80. newLoc = Location.INTERIOR
  81. break
  82. case Location.INTERIOR:
  83. newLoc = Location.BOUNDARY
  84. break
  85. default:
  86. newLoc = Location.BOUNDARY
  87. break
  88. }
  89. this._label.setLocation(argIndex, newLoc)
  90. }
  91. }