Calculating borders of a rectangle

37 Views Asked by At

My question is a bit of definition related.

Let's say we have got a rectangle with its top-left corner at (0,0) and width=100px height=200px. My question is: how we compute the last pixels that belong to the rectangle? Specifically I want to know the x coords of the left and right border and y coords of top and bottom border that contains pixels belonging to the rectangle.

I tried to simply left=origin x, right=origin x + width, top=origin y, bottom=origin y - height, but during tests I found out that when rectangles are next to each other the above equations results in pixels that belongs to more than one rectangle at once (they shouldn't). So, I wish to know how to calculate them properly.

1

There are 1 best solutions below

0
fana On BEST ANSWER

enter image description here

In this figure,

  • Orange rect : (left,top) = (1,2), width=3, height=2
  • Green rect : (left,top) = (4,3), width=2, height=2

I think, this is the ordinal definition for pixel world.

In this example, no pixels belong to both.