Frage

I'm trying to use google closure to write an application that covers a region of a plane with non-overlapping rectangles. One requirement I have is to be able to take a point on the plane (potentially with any floating-point coordinates) and identify the single rectangle that covers that point. Unfortunately, this has led to a problem using closure's rectangle class.

Consider, for example, the two unit-dimensioned rectangles whose top-left corners are located at (0,0) and (1,1). I would usually consider these rectangles to be non-overlapping, but closure's rectangle class tells me that both contain the point (1,1).

Is there a way I can make closure consider these rectangles to not overlap? Or another way to generate rectangles that do include all possible coordinates but which do not overlap (e.g. a way of specifying that the size of one side of a rectangle is the largest number which is smaller than 1)?

War es hilfreich?

Lösung

To your questions: You can not make closure consider these rectangles to not overlap. And you can not generate rectangles that cover all the space but to not overlap.

But you are going on this the wrong way. Just define which of the edges belong to which square – e.g. each square owns its top and left border. Now use closure to get all rectangles which touch a give point and ignore those where the point is part of the bottom or right corner.

Some notes though: The squares can’t own their full left border, as two squares share a pixel on that border. So a square does not own its bottom-left pixel. The way I explained the steps handles that, though. You also need to think about what you want to happen on the bottom right of your covered space. If your space is a multiple of your rectangle size, then you either have to add exceptions at the right and bottom corner or the rectangles there will be just lines, the one in the bottom right corner even only a single point.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top