Subject: Re: [boost] [geometry] area, length, centroid, behavior
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2009-02-24 12:21:42
Barend Gehrels wrote:
> What should the generic "area" algorithm return for point and linestring?
> What should the generic "length" algorithm return for polygon?
> What should the generic "centroid" algorithm return for point and
There are two cases I can think of here:
- Maybe I have a heterogeneous collection of geometric objects and I
want to do something involving one of these algorithms to each
element. I can't imagine doing this in a real scenario, so I have no
comment about what the behaviour should be.
- I have made a typo in my code. In this case I really want a compiler error.
> and for an invalid polygon (e.g. no points at all, or not closed)?
One option is to prohibit invalid polygons, i.e. to make it impossible
to construct one with too few points. I suspect that this would lead
to other problems though. So I suggest that you have a simple
is_valid() test that the user can call if they care about this case and
make centroid (etc) return an arbitrary answer like (0,0), but
guarantee not to crash (e.g. not divide by zero).