On Thu, Jan 3, 2013 at 3:14 PM, Peter Kasting <pkast...@google.com> wrote:
> On Thu, Jan 3, 2013 at 11:36 AM, Shawn Singh <shawnsi...@chromium.org>wrote: > >> Cons of making a separate vector class: >> - "offsets" are sometimes treated as relative point locations, and >> other times treated as vectors that can be added to points. Deciding when >> to use which one could become just as confusing as using Point vs Size is >> right now. >> > > Yeah, this is a real danger. It's sort of mitigated if you have no way to > add/subtract two points, only a point and a vector, because that kind of > forces you to always use your vector class for offsets, otherwise you can't > do much with them. However, you do still end up needing things like > "PointAtOffsetFromOrigin(const vector&)" that basically just convert a > vector directly to a point, so there is still the possibility for confusion. > > PK > The homogenous coordinate issue is the primary reason why it matters whether you are using (x,y) to represent a point or a direction. We seem to be begging for bugs by failing to clearly distinguish between the two cases. Not everyone learns this stuff, so here the summary. Say you have a transformation T(..) that transforms points, and it's using homogeneous coordinates. It is desirable to have T(a-b) == T(a) - T(b). To do so requires storing a-b, which is really a direction or offset, with a zero homogeneous coordinate. I would support adding "offset" and enforcing the mathematical definitions through parameter and return types, which is basically what Peter is suggesting. I think it makes the code much more self-documenting and will reduce the chance of bugs. Cheers, Stephen.Stephen Chenney | Software Engineer | schen...@google.com | 404-314-1809
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo/webkit-dev