Boost logo

Boost :

Subject: Re: [boost] [geometry] area, length, centroid, behavior
From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2009-02-24 11:31:23


On Tue, Feb 24, 2009 at 7:29 AM, Barend Gehrels <barend_at_[hidden]> wrote:
>
> 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

I can't decide between compiler error and 0. To be formally correct,
I believe it should be compiler error because it doesn't exist, but 0
also signals non-existance.

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

Compiler error. Provide functions like perimeter, chord_length,
length_along_axis, or whatever else.

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

To be formally correct, I believe linestring should be compiler error.
 Centroid is the point on which it would balance when placed on a
needle, and obviously that doesn't often happen with a non-straight
linestring.

You could provide average_point (not sure I like the name) that
returns the average of the points and have centroid call it, only with
a stricter interface.

> 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)

This is a much bigger question than you ask. Where do you want the
error checking to occur? Do you provide an is_closed, or
is_overlapped, or things of that nature for checking the validity of a
polygon? Is a valid polygon a precondition of all functions that work
on polygons, or do you intend to check for validity in every function?

If I *know* my polygon is valid, I don't want to pay for the error checking.

--Michael Fawcett


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