commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <gil...@harfang.homelinux.org>
Subject Re: [math] geometry algorithms
Date Mon, 15 Oct 2012 22:08:34 GMT
Hello.

> >> [...]
> >>
> >> public interface ConvexHull<S extends Space> {
> >>     Vector<S>[] generate(Vector<S>[] points);
> >> }
> > 
> > I think that you should use "List" instead of arrays (even "Iterable"
> > whenever possible); it will be plainly more flexible. Just a little
> > thought...
> 
> I have now several implementations of at least 2D algorithms with this
> interface:
> 
> Iterable<Vector2D> generate(Iterable<Vector2D> points)
> 
> which works, but I find it quite cumbersome for the following reasons:
> 
>  * Iterable obviously does not provide a size() method which is quite
>    handy in the algorithms
> 
>  * the addAll() method of collections is not defined for Iterable, but
>    only for Collection

If the algorithm needs some API to perform decently, it's fair to require
it.

> 
> So I would better opt for an interface like:
> 
> Iterable<Vector2D> generate(Collection<Vector2D> points)
> 
> The output may be an Iterable as it is ordered, a Collection might give
> a wrong impression to the user (a Collection is not sorted per se,
> although the same is true for Iterable, hmm)

I don't understand; should the output be sortable?

> What do you think?

Not mixing different types makes the API simpler; the prototype could be
  Collection<Vector2D> generate(Collection<Vector2D> points)
or
  List<Vector2D> generate(List<Vector2D> points)

[Also, usability is enhanced by arguments as abstract as possible, but the
returned value's concreteness is only limited by the developer's willingness
to not be tied to a specific data structure.]

If the answer to the above question is yes, then the second prototype makes
more sense.


Regards,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message