Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input a set of points to a clojure function

I am writing an algorithm in Clojure which takes in a set of points which represents an polygon. Another input is a point, and the output needs to be whether the point lies inside the polygon or not.

My question is how do I input the set of points to the function? What data structure in clojure would be most appropriate - A set, vector, list etc. ?

like image 849
Pranav Avatar asked Mar 02 '11 14:03

Pranav


1 Answers

Presumably the order of points matters, so that the shape ABCD is not the same as the shape ABDC?

In which case you need some sort of data structure which preserves order. This means that a list or vector is acceptable, but a set is not.

But you could also write your function to take anything seqable -- so that if you later want to change from vector to list or vice versa, you don't have to change your function. Program to an interface, not to an implementation.

like image 72
Philip Potter Avatar answered Nov 13 '22 10:11

Philip Potter