BasicPreparedGeometry.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import PointLocator from '../../algorithm/PointLocator'
  2. import ComponentCoordinateExtracter from '../util/ComponentCoordinateExtracter'
  3. import PreparedGeometry from './PreparedGeometry'
  4. export default class BasicPreparedGeometry {
  5. constructor() {
  6. BasicPreparedGeometry.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. this._baseGeom = null
  10. this._representativePts = null
  11. const geom = arguments[0]
  12. this._baseGeom = geom
  13. this._representativePts = ComponentCoordinateExtracter.getCoordinates(geom)
  14. }
  15. getRepresentativePoints() {
  16. return this._representativePts
  17. }
  18. containsProperly(g) {
  19. if (!this._baseGeom.getEnvelopeInternal().contains(g.getEnvelopeInternal())) return false
  20. return this._baseGeom.relate(g, 'T**FF*FF*')
  21. }
  22. getGeometry() {
  23. return this._baseGeom
  24. }
  25. envelopesIntersect(g) {
  26. if (!this._baseGeom.getEnvelopeInternal().intersects(g.getEnvelopeInternal())) return false
  27. return true
  28. }
  29. covers(g) {
  30. return this._baseGeom.covers(g)
  31. }
  32. intersects(g) {
  33. return this._baseGeom.intersects(g)
  34. }
  35. touches(g) {
  36. return this._baseGeom.touches(g)
  37. }
  38. within(g) {
  39. return this._baseGeom.within(g)
  40. }
  41. isAnyTargetComponentInTest(testGeom) {
  42. const locator = new PointLocator()
  43. for (let i = this._representativePts.iterator(); i.hasNext(); ) {
  44. const p = i.next()
  45. if (locator.intersects(p, testGeom)) return true
  46. }
  47. return false
  48. }
  49. coveredBy(g) {
  50. return this._baseGeom.coveredBy(g)
  51. }
  52. overlaps(g) {
  53. return this._baseGeom.overlaps(g)
  54. }
  55. toString() {
  56. return this._baseGeom.toString()
  57. }
  58. disjoint(g) {
  59. return !this.intersects(g)
  60. }
  61. crosses(g) {
  62. return this._baseGeom.crosses(g)
  63. }
  64. contains(g) {
  65. return this._baseGeom.contains(g)
  66. }
  67. envelopeCovers(g) {
  68. if (!this._baseGeom.getEnvelopeInternal().covers(g.getEnvelopeInternal())) return false
  69. return true
  70. }
  71. get interfaces_() {
  72. return [PreparedGeometry]
  73. }
  74. }