Sunday 15 September 2013

F# - how to group previous, this and next elements in circular Seq -


Like best sequence in F # seq [0; 1; 2; 3; 4] in a sequence of tuples like seq [4,0,1; 0,1,2; 1,2,3; 2,3,4; 3,4,0] ?

In addition to this: My compress represents the circular data. In this case the corner of a closed polyline requires the neighboring elements to calculate the angle of each corner.

I will do this: / P>

  Neighbors xs = match array With OFF SEK XS | [||] - & gt; [||] | [| X | - - & gt; [| X, X, X |] | XS - & gt; Let n = xs.Length [| Yield xs [N-1], XS. [0], XS. [1] I generate xs from 1 to n-2. [I-1], xs. [I], xs. [I + 1] yield xs [N-2], xs. [N-1], xs [0] |]   

To make it faster than modulo integer arithmetic comparison faster, assign array and use sequence expression Fill in the elements instead.

No comments:

Post a Comment