PreparedPolygonPredicate.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Location from '../Location'
  2. import ComponentCoordinateExtracter from '../util/ComponentCoordinateExtracter'
  3. import SimplePointInAreaLocator from '../../algorithm/locate/SimplePointInAreaLocator'
  4. export default class PreparedPolygonPredicate {
  5. constructor() {
  6. PreparedPolygonPredicate.constructor_.apply(this, arguments)
  7. }
  8. static constructor_() {
  9. this._prepPoly = null
  10. this._targetPointLocator = null
  11. const prepPoly = arguments[0]
  12. this._prepPoly = prepPoly
  13. this._targetPointLocator = prepPoly.getPointLocator()
  14. }
  15. isAnyTargetComponentInAreaTest(testGeom, targetRepPts) {
  16. const piaLoc = new SimplePointInAreaLocator(testGeom)
  17. for (let i = targetRepPts.iterator(); i.hasNext(); ) {
  18. const p = i.next()
  19. const loc = piaLoc.locate(p)
  20. if (loc !== Location.EXTERIOR) return true
  21. }
  22. return false
  23. }
  24. isAllTestComponentsInTarget(testGeom) {
  25. const coords = ComponentCoordinateExtracter.getCoordinates(testGeom)
  26. for (let i = coords.iterator(); i.hasNext(); ) {
  27. const p = i.next()
  28. const loc = this._targetPointLocator.locate(p)
  29. if (loc === Location.EXTERIOR) return false
  30. }
  31. return true
  32. }
  33. isAnyTestComponentInTargetInterior(testGeom) {
  34. const coords = ComponentCoordinateExtracter.getCoordinates(testGeom)
  35. for (let i = coords.iterator(); i.hasNext(); ) {
  36. const p = i.next()
  37. const loc = this._targetPointLocator.locate(p)
  38. if (loc === Location.INTERIOR) return true
  39. }
  40. return false
  41. }
  42. isAllTestComponentsInTargetInterior(testGeom) {
  43. const coords = ComponentCoordinateExtracter.getCoordinates(testGeom)
  44. for (let i = coords.iterator(); i.hasNext(); ) {
  45. const p = i.next()
  46. const loc = this._targetPointLocator.locate(p)
  47. if (loc !== Location.INTERIOR) return false
  48. }
  49. return true
  50. }
  51. isAnyTestComponentInTarget(testGeom) {
  52. const coords = ComponentCoordinateExtracter.getCoordinates(testGeom)
  53. for (let i = coords.iterator(); i.hasNext(); ) {
  54. const p = i.next()
  55. const loc = this._targetPointLocator.locate(p)
  56. if (loc !== Location.EXTERIOR) return true
  57. }
  58. return false
  59. }
  60. }