Algorithm required to determine if a rectangle is completely covered by another set of rectangles

前端 未结 7 1080
时光说笑
时光说笑 2021-02-08 13:49

I am searching for an algorithm that will determine if a new rectangle is completely covered by a set of existing rectangles. Another way of putting the question, is does the ne

7条回答
  •  臣服心动
    2021-02-08 14:21

    If rectangles are aligned that's easy:

    Let's say you have rectangle A0 and want to know if it is fully covered by (B1, B2, B3...) = B

    A := (A0)
    while P := pop B
      for R in A
        if P fully covers R:
          remove R from A
        else if P and R does overlap:
          remove R from A
          break R in subrentangles S := (S1, S2, S3,...) following the intersections \
                                                         with P edges
          push S into A
    if A is empty:
       say B covers A0
    else:
       say B does not fully cover A0
    

提交回复
热议问题