# Iterate the points around the edge of a rectangle

With an arbitrary starting location, that can be any point along the edge of a rectangle, how would you iterate over every point in a clockwise order? So for example if the starting point happens to be (1, 0) like in the image below, how would you iterate over all the points, shown as green squares, around the rectangle. I can probably do a simple brute force method by figuring out which edge of the rectangle the starting point is on and moving the position along that edge until the max x or y is reached and then follow along the next edge until the starting point is reached again, but I'm just curious if there is a more elegant solution.

I forgot to add that the data I have to work with is the top-left position of the rectangle, its size, and the starting point along the edge.

-
How are you given the data of the "rectangle"? The coordinates of its four corners? A list of the lattice point it intersects? the coordinates of two opposite corners? – Vhailor Mar 8 '12 at 1:39
@Vhailor That's a good point. I forgot to include that. I'll edit the post. – Shenjoku Mar 8 '12 at 2:18