PreparedPolygonIntersects.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import SegmentStringUtil from '../../noding/SegmentStringUtil'
  2. import PreparedPolygonPredicate from './PreparedPolygonPredicate'
  3. export default class PreparedPolygonIntersects extends PreparedPolygonPredicate {
  4. constructor() {
  5. super()
  6. PreparedPolygonIntersects.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. const prepPoly = arguments[0]
  10. PreparedPolygonPredicate.constructor_.call(this, prepPoly)
  11. }
  12. static intersects(prep, geom) {
  13. const polyInt = new PreparedPolygonIntersects(prep)
  14. return polyInt.intersects(geom)
  15. }
  16. intersects(geom) {
  17. const isInPrepGeomArea = this.isAnyTestComponentInTarget(geom)
  18. if (isInPrepGeomArea) return true
  19. if (geom.getDimension() === 0) return false
  20. const lineSegStr = SegmentStringUtil.extractSegmentStrings(geom)
  21. if (lineSegStr.size() > 0) {
  22. const segsIntersect = this._prepPoly.getIntersectionFinder().intersects(lineSegStr)
  23. if (segsIntersect) return true
  24. }
  25. if (geom.getDimension() === 2) {
  26. const isPrepGeomInArea = this.isAnyTargetComponentInAreaTest(geom, this._prepPoly.getRepresentativePoints())
  27. if (isPrepGeomInArea) return true
  28. }
  29. return false
  30. }
  31. }