"unit" means "line of F# imperative code". If you see the error you saw then it may be an indication that you're mixing up imperative code and functional code.

In your code you're only returning a result from your function on one branch of your if/then/else. If you want your function to return a new array then you want something like this. Note I've replaced you array-of-arrays with array-of-pairs, and added several more "let" bindings to help make your long lines a bit shorter - this is just a matter of taste, as is using "atan2" instead of Math.Atan2. I've also changed the code to return an array rather than a linked list - I'm pretty sure that's what you want. And finally I'm not too sure why you were using "filter" - you can just chop ou tthe array you're interested in using "Array.sub".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/// Functional version - creates a new "ths" array 

let adjustBoundaries (path:(float*float)[]) (ths:float[]) closed =
    if not closed then
        let x0,y0 = path.[0]
        let x1,y1 = path.[1]
        let xNm2,yNm2 = path.[path.Length-2]
        let xNm1,yNm1 = path.[path.Length-1]
        let adjust dx dy th = 2.0 * atan2 dy dx - th
        let first = adjust (x1-x0) (y1-y0) ths.[1]
        let last = adjust (xNm1-xNm2) (yNm1-yNm2) ths.[ths.Length - 2]
        Array.concat [ [| first |]; Array.sub ths 1 (ths.Length-2); [| last |] ]
    else
        ths
1
2
3
4
5
6
7
8
9
10
11
12
13
/// Imperative version - mutates "ths" in place

let adjustBoundaries(path:(float*float)[]) (ths:float[]) closed =
    if not closed then
        let x0,y0 = path.[0]
        let x1,y1 = path.[1]
        let xNm2,yNm2 = path.[path.Length-2]
        let xNm1,yNm1 = path.[path.Length-1]
        let adjust dx dy th = 2.0 * atan2 dy dx - th
        let first = adjust (x1-x0) (y1-y0) ths.[1]
        let last = adjust (xNm1-xNm2) (yNm1-yNm2) ths.[ths.Length - 2]
        ths.[0] <- first;
        ths.[ths.Length-1] <- last

Regards

don

By on 7/25/2007 3:52 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper