OffsetSegmentString.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import GeometryFactory from '../../geom/GeometryFactory'
  2. import Coordinate from '../../geom/Coordinate'
  3. import ArrayList from '../../../../../java/util/ArrayList'
  4. export default class OffsetSegmentString {
  5. constructor() {
  6. OffsetSegmentString.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. this._ptList = null
  10. this._precisionModel = null
  11. this._minimimVertexDistance = 0.0
  12. this._ptList = new ArrayList()
  13. }
  14. getCoordinates() {
  15. const coord = this._ptList.toArray(OffsetSegmentString.COORDINATE_ARRAY_TYPE)
  16. return coord
  17. }
  18. setPrecisionModel(precisionModel) {
  19. this._precisionModel = precisionModel
  20. }
  21. addPt(pt) {
  22. const bufPt = new Coordinate(pt)
  23. this._precisionModel.makePrecise(bufPt)
  24. if (this.isRedundant(bufPt)) return null
  25. this._ptList.add(bufPt)
  26. }
  27. reverse() {}
  28. addPts(pt, isForward) {
  29. if (isForward)
  30. for (let i = 0; i < pt.length; i++)
  31. this.addPt(pt[i])
  32. else
  33. for (let i = pt.length - 1; i >= 0; i--)
  34. this.addPt(pt[i])
  35. }
  36. isRedundant(pt) {
  37. if (this._ptList.size() < 1) return false
  38. const lastPt = this._ptList.get(this._ptList.size() - 1)
  39. const ptDist = pt.distance(lastPt)
  40. if (ptDist < this._minimimVertexDistance) return true
  41. return false
  42. }
  43. toString() {
  44. const fact = new GeometryFactory()
  45. const line = fact.createLineString(this.getCoordinates())
  46. return line.toString()
  47. }
  48. closeRing() {
  49. if (this._ptList.size() < 1) return null
  50. const startPt = new Coordinate(this._ptList.get(0))
  51. const lastPt = this._ptList.get(this._ptList.size() - 1)
  52. if (startPt.equals(lastPt)) return null
  53. this._ptList.add(startPt)
  54. }
  55. setMinimumVertexDistance(minimimVertexDistance) {
  56. this._minimimVertexDistance = minimimVertexDistance
  57. }
  58. }
  59. OffsetSegmentString.COORDINATE_ARRAY_TYPE = new Array(0).fill(null)