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. ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With