From: Johan E. <jbc...@sw...> - 2011-06-21 20:42:33
|
On 17-6-2011 22:49, Krzysztof Kosiński wrote: > Hello all > I'm writing an integer rectangle class which I will use in my GSoC > project, and since i need to also introduce integer points, I would > like to ask for your opinions about one thing related to all points: > Currently Geom::Point has the index operator as the only way of access > to the coordinates. However, this is often inconvenient, especially > when Geom::X and Geom::Y, and leads to hard to parse notation like > (a-b)[Geom::Y]. Here are the proposed solutions: > > 1. New methods > Coord&x(); Coord&y(); + const versions > This is OK, but I don't see much merit in having the extra parentheses > of a method call, since there is read-write access to the coordinates > anyway. > > 2. Public members in a transparent union > union { struct { Coord x; Coord y; }; Coord _pt[2]; } > Might not work on some compilers. > > 3. Replace _pt with public members > Coord x, y; > Could theoretically be lower performing, because we now have to use an > if for indexing, but in reality on anything more modern than Pentium > Pro both the if and the table access will be compiled to conditional > moves. I assume in option 3 that you keep operator[] ? I agree that [Geom::Y] is extremely annoying and much too verbose. Ciao, Johan |