|
Boost : |
From: Sérgio Vale e Pace (svpace.forum_at_[hidden])
Date: 2005-06-20 10:24:55
graphical libraries usually are incompatible and sometimes even
"unusual" for a reason, performance, when you´re processing lots and
lots of points per second, the simple act of calling a non inline
function is too much overhead. Don´t take me wrong I also believe that
a "unique" implementation for points would be great, but such
implementation is not trivial. I´m not sure about the internals of
your implementation, but I implemented something with a similar
interface sometime ago and the overhead caused by the function
forwarding was unacceptable. A template solution was the fastest I
could get, something like:
point<2, int> my_point;
If you´re intested in it take a look at http://osl.iu.edu/~tveldhui/
especially in the blitz++ library
On 5/20/04, Anis Benylloul <benyelloul_at_[hidden]> wrote:
> Hi !
>
> It is very common for graphical libraries to declare some rectangle and
> point classes.
> In fact, all of them do that: SDL has SDL_Rect, X has XRectangle and XPoint,
> Qt has QRect and QPoint, Window$ has POINT and RECT (and POINTF and RECTF),
> rect, Rect, Rectangle, point, Point2D, Point3D, point<float> ..... etc ....
>
> And you know what ? they all are incompatible, both interface and
> implementation. Time to have a look at this, heu ?
>
> After few months of work here is what I have:
>
> // Code Start
> int main()
> {
> // point_xy is an implementation type it contains
> // "some implementation" of the point abtraction
> // Other implementaions include point_xyz<>, for 3D points
> typedef geom::point_xy<double> point_xy;
>
> // point<> is a wrapper class, in which you "plug" implementation types
> // to obtain a working ``point''
> typedef geom::point<point_xy> point; // Plug, then save the result
> in ``point''
>
> point pt=point_xy(3.4, 3.0),
> pt2=point_xy(0.2, 1.4);
>
> // Cool property access
> pt.x()++;
> pt.y()=pt2.rho();
> pt.theta()+=3*pt2.y();
>
> // Handy operator overloads
> pt+=pt2*4;
>
> // std::complex<> is also a possible implementation
> geom::point< std::complex<double> > pt_cplx=std::complex<double>(4, 6);
>
> pt2=pt_cplx-pt; // Mixed-implementation computations
>
> // point::impl() extracts the implementation out of its wrapper
> std::complex<double>& impl=pt_cplx.impl();
>
>
> // Now for Boxes. Boxes are some generalization of rectanlges that
> are not always
> // ``flat''
>
> typedef geom::box_xywh<int> box_xywh; // Implementation type ..
> typedef geom::box<box_xywh> box; // .. being plugged in a wrapper
>
> box bx, bx2;
>
> bx.xmin()=bx2.x2();
> bx.width()=bx2.height();
> bx.y2()=bx2.height();
>
> // Accessing corners
> bx.corner< geom::x1, geom::y1>()=pt; // Displace
> bx.corner< geom::xmin, geom::ymax >()=bx2.corner<geom::x2, geom::y1,
> geom::z1>();
>
> // Accessing the center
> bx.center()=bx2.center()+pt;
> bx2.x1()=bx.center().x();
>
> // .....
> }
> // Code End
>
> So, wadda you say ?
>
> -- Anis Benyelloul
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk