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

前端 未结 8 2036
难免孤独
难免孤独 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:49

    (this is too long for a comment)

    A quick drawing does NOT show that A intersects B: A has an height of 4 while B start at an Y position of 5, how could they intersect!?

    You can verify it with the following that prints out 'false':

    System.out.println( new Rectangle(0, 0, 2, 4).intersects( new Rectangle(1, 5, 4, 2) ) );
    

    Then your method signature are incomplete so is your code example.

    If you clarify a bit your problem and give a working, correct, example, then I've got a very nice solution for you.

    0 讨论(0)
  • 2021-02-04 08:52

    You cannot remove an object from a list your iterating through, iterator object or not, you will need to find another way

    0 讨论(0)
提交回复
热议问题