Boost logo

Boost :

Subject: Re: [boost] A design for geometric objects
From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2008-11-14 10:46:01


Hello,

>> polygon_90_concept is the base most type of polygon. It's corners are
>> restricted to multiples of 90 degrees and its edges are axis-parallel. It
>> is the base most type because it is the most restricted.

That's exactly what I thought while reading Luke's explanation.

> You may want to read that article on Wikipedia:
> http://en.wikipedia.org/wiki/Circle-ellipse_problem
>
> Basically, inheriting an Ellipse from a Circle is always wrong, and
> inheriting a Circle from an Ellipse is wrong if the Ellipse view of the
> Circle is mutable.

Wouldn't a typically C++-like approach be to use traits to ask each
shape to present itself as an ellipse if it can?

ellipse_traits<X>::get_length() and ellipse_traits<X>::get_width()
would give the length and width that X has when viewed as an ellipse.
ellipse_traits<ellipse> would simply define them as being its length and width.
ellipse_traits<circle> would define them as both being its radius.
specialization ellipse_traits<rectangle> would not exist, meaning that
a rectangle is-not-an ellipse.
ellipse and circle would obviously be 2 completely separated classes.

Do you think this approach is valid and could be generalized to all
geometric shapes?

Bruno


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk