9
This is a question which came up several times in my career, and which splits me and my colleagues into two camps. I thought it might be best answered on this site, once and for all.
Almost all graphics UI libraries implement a Rectangle structure, but the way they do it usually divides along two possible options:
- The rectangle is defined as two 2D points within the same coordinate system, usually named p0 and p1, or with individual components, as x0, y0, x1, y1.
- The rectangle is defined as 2D origin and size vectors, usually named position and size, or, individually, x, y, width, height.
Now, say I were to write an UI library, which of the two choices should I take?
Update: The question concerns the implementation, not the interface. Of course the rectangle's interface could well support both approaches, but how would you store the data within the rectangle?