AbstractPreparedPolygonContains.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import hasInterface from '../../../../../hasInterface'
  2. import SegmentIntersectionDetector from '../../noding/SegmentIntersectionDetector'
  3. import SegmentStringUtil from '../../noding/SegmentStringUtil'
  4. import Polygonal from '../Polygonal'
  5. import PreparedPolygonPredicate from './PreparedPolygonPredicate'
  6. export default class AbstractPreparedPolygonContains extends PreparedPolygonPredicate {
  7. constructor() {
  8. super()
  9. AbstractPreparedPolygonContains.constructor_.apply(this, arguments)
  10. }
  11. static constructor_() {
  12. this._requireSomePointInInterior = true
  13. this._hasSegmentIntersection = false
  14. this._hasProperIntersection = false
  15. this._hasNonProperIntersection = false
  16. const prepPoly = arguments[0]
  17. PreparedPolygonPredicate.constructor_.call(this, prepPoly)
  18. }
  19. eval(geom) {
  20. const isAllInTargetArea = this.isAllTestComponentsInTarget(geom)
  21. if (!isAllInTargetArea) return false
  22. if (this._requireSomePointInInterior && geom.getDimension() === 0) {
  23. const isAnyInTargetInterior = this.isAnyTestComponentInTargetInterior(geom)
  24. return isAnyInTargetInterior
  25. }
  26. const properIntersectionImpliesNotContained = this.isProperIntersectionImpliesNotContainedSituation(geom)
  27. this.findAndClassifyIntersections(geom)
  28. if (properIntersectionImpliesNotContained && this._hasProperIntersection) return false
  29. if (this._hasSegmentIntersection && !this._hasNonProperIntersection) return false
  30. if (this._hasSegmentIntersection)
  31. return this.fullTopologicalPredicate(geom)
  32. if (hasInterface(geom, Polygonal)) {
  33. const isTargetInTestArea = this.isAnyTargetComponentInAreaTest(geom, this._prepPoly.getRepresentativePoints())
  34. if (isTargetInTestArea) return false
  35. }
  36. return true
  37. }
  38. findAndClassifyIntersections(geom) {
  39. const lineSegStr = SegmentStringUtil.extractSegmentStrings(geom)
  40. const intDetector = new SegmentIntersectionDetector()
  41. intDetector.setFindAllIntersectionTypes(true)
  42. this._prepPoly.getIntersectionFinder().intersects(lineSegStr, intDetector)
  43. this._hasSegmentIntersection = intDetector.hasIntersection()
  44. this._hasProperIntersection = intDetector.hasProperIntersection()
  45. this._hasNonProperIntersection = intDetector.hasNonProperIntersection()
  46. }
  47. isProperIntersectionImpliesNotContainedSituation(testGeom) {
  48. if (hasInterface(testGeom, Polygonal)) return true
  49. if (this.isSingleShell(this._prepPoly.getGeometry())) return true
  50. return false
  51. }
  52. isSingleShell(geom) {
  53. if (geom.getNumGeometries() !== 1) return false
  54. const poly = geom.getGeometryN(0)
  55. const numHoles = poly.getNumInteriorRing()
  56. if (numHoles === 0) return true
  57. return false
  58. }
  59. }