LinearRing.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import LineString from './LineString'
  2. import Geometry from './Geometry'
  3. import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException'
  4. import CoordinateSequences from './CoordinateSequences'
  5. import Dimension from './Dimension'
  6. export default class LinearRing extends LineString {
  7. constructor() {
  8. super()
  9. LinearRing.constructor_.apply(this, arguments)
  10. }
  11. static constructor_() {
  12. const points = arguments[0], factory = arguments[1]
  13. LineString.constructor_.call(this, points, factory)
  14. this.validateConstruction()
  15. }
  16. copyInternal() {
  17. return new LinearRing(this._points.copy(), this._factory)
  18. }
  19. getBoundaryDimension() {
  20. return Dimension.FALSE
  21. }
  22. isClosed() {
  23. if (this.isEmpty())
  24. return true
  25. return super.isClosed.call(this)
  26. }
  27. reverseInternal() {
  28. const seq = this._points.copy()
  29. CoordinateSequences.reverse(seq)
  30. return this.getFactory().createLinearRing(seq)
  31. }
  32. getTypeCode() {
  33. return Geometry.TYPECODE_LINEARRING
  34. }
  35. validateConstruction() {
  36. if (!this.isEmpty() && !super.isClosed.call(this))
  37. throw new IllegalArgumentException('Points of LinearRing do not form a closed linestring')
  38. if (this.getCoordinateSequence().size() >= 1 && this.getCoordinateSequence().size() < LinearRing.MINIMUM_VALID_SIZE)
  39. throw new IllegalArgumentException('Invalid number of points in LinearRing (found ' + this.getCoordinateSequence().size() + ' - must be 0 or >= 4)')
  40. }
  41. getGeometryType() {
  42. return Geometry.TYPENAME_LINEARRING
  43. }
  44. }
  45. LinearRing.MINIMUM_VALID_SIZE = 4