How can I group an array of rectangles into “Islands” of connected regions?

前端 未结 8 2129
难免孤独
难免孤独 2021-02-04 08:12

The problem

I have an array of java.awt.Rectangles. For those who are not familiar with this class, the important piece of information is that they provid

8条回答
  •  轮回少年
    2021-02-04 08:39

    Connected components.

    Alternatively, because you only have rectangles you may be able to design an very efficient sweep line algorithm.

    I would expect the best algorithm to take at least O( n^2 ) time because given n rectangles there are O( n^2 ) possible intersections, and any algorithm to compute what you want would need to consider all intersections at some point.

提交回复
热议问题