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

前端 未结 7 2273
轻奢々
轻奢々 2021-02-08 13:45

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:26

    If the rectangles all have the same angle; then the following might me more efficient and easier to program:

    Determine for every y coordinate which rectangles cover that y coordinate (you only have to do this for y coordinates at which the covering changes;i.e. that correspond to the upper or lower limit of a rectangle). Once you know that, solve the problem for each such y coordinate (i.e. check whether all x values are covered by the rectangles that are "active" for that Y coordinate).

    Edit: I think this is O(n^2 log(n)^2) complexity, as two sorts are all the hard work you have to do

提交回复
热议问题