[webkit-dev] Int/FloatPoint and Int/FloatSize
Stephen Chenney
schenney at chromium.org
Thu Jan 3 14:55:21 PST 2013
On Thu, Jan 3, 2013 at 3:14 PM, Peter Kasting <pkasting at google.com> wrote:
> On Thu, Jan 3, 2013 at 11:36 AM, Shawn Singh <shawnsingh at 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 | schenney at google.com |
404-314-1809
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20130103/2b4dd1e7/attachment.html>
More information about the webkit-dev
mailing list