From: Anis Benylloul (benyelloul_at_[hidden])
Date: 2005-06-20 04:03:31
It is very common for graphical libraries to declare some rectangle and
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
// 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
point pt=point_xy(3.4, 3.0),
// Cool property access
// Handy operator overloads
// 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
// Now for Boxes. Boxes are some generalization of rectanlges that
are not always
typedef geom::box_xywh<int> box_xywh; // Implementation type ..
typedef geom::box<box_xywh> box; // .. being plugged in a wrapper
box bx, bx2;
// Accessing corners
bx.corner< geom::x1, geom::y1>()=pt; // Displace
bx.corner< geom::xmin, geom::ymax >()=bx2.corner<geom::x2, geom::y1,
// Accessing the center
// Code End
So, wadda you say ?
-- Anis Benyelloul
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk