SegmentNode.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Coordinate from '../geom/Coordinate'
  2. import SegmentPointComparator from './SegmentPointComparator'
  3. import Comparable from '../../../../java/lang/Comparable'
  4. export default class SegmentNode {
  5. constructor() {
  6. SegmentNode.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. this._segString = null
  10. this.coord = null
  11. this.segmentIndex = null
  12. this._segmentOctant = null
  13. this._isInterior = null
  14. const segString = arguments[0], coord = arguments[1], segmentIndex = arguments[2], segmentOctant = arguments[3]
  15. this._segString = segString
  16. this.coord = new Coordinate(coord)
  17. this.segmentIndex = segmentIndex
  18. this._segmentOctant = segmentOctant
  19. this._isInterior = !coord.equals2D(segString.getCoordinate(segmentIndex))
  20. }
  21. getCoordinate() {
  22. return this.coord
  23. }
  24. print(out) {
  25. out.print(this.coord)
  26. out.print(' seg # = ' + this.segmentIndex)
  27. }
  28. compareTo(obj) {
  29. const other = obj
  30. if (this.segmentIndex < other.segmentIndex) return -1
  31. if (this.segmentIndex > other.segmentIndex) return 1
  32. if (this.coord.equals2D(other.coord)) return 0
  33. if (!this._isInterior) return -1
  34. if (!other._isInterior) return 1
  35. return SegmentPointComparator.compare(this._segmentOctant, this.coord, other.coord)
  36. }
  37. isEndPoint(maxSegmentIndex) {
  38. if (this.segmentIndex === 0 && !this._isInterior) return true
  39. if (this.segmentIndex === maxSegmentIndex) return true
  40. return false
  41. }
  42. toString() {
  43. return this.segmentIndex + ':' + this.coord.toString()
  44. }
  45. isInterior() {
  46. return this._isInterior
  47. }
  48. get interfaces_() {
  49. return [Comparable]
  50. }
  51. }