Boost logo

Boost :

Subject: Re: [boost] [geometry] area, length, centroid, behavior
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-02-24 12:33:08


Barend Gehrels a écrit :
> I would like to hear the opinion of potential geometry users on the list
> about the following.
>
> For the three geometries, point, linestring (= sequence of points),
> polygon:
>
> What should the generic "area" algorithm return for point and linestring?
> - 0 (zero)
> - compiler error (so this function is not defined for them at all)
> - exception
> Personally I would feel for 0 (zero) because you can then request the
> "area" in a generic collection, regardless of what is inside.

0, indeed.

>
> What should the generic "length" algorithm return for polygon?
> - 0 (zero)
> - its perimeter
> - compiler error
> - exception

Rename length to perimeter, since that is more generic.

>
> What should the generic "centroid" algorithm return for point and
> linestring?
> - the point / the average its points
> - compiler error
> - exception

For all geometries, which are only sets of points, the centroid should
be the average point.

> and for an invalid polygon (e.g. no points at all, or not closed)?
> - exception
> - return "false" (if centroid is passed as a reference parameter)
> - ? (we've not always the compiler error option here because points are
> usually stored in a runtime collection)

Undefined behaviour.
An invalid polygon shouldn't be allowed in the first place.

Ideally, that should be prevented by the type system.


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