Hi to all!
 
I am trying to implement in OCaml version 3.07 the Delaunay triangulation contained in the program 'Triangle' of  J.R. Shewchuk for divide-and-conquer,  but the results differ from those produced by the
original program. After exhausting tests, I believe that the problem is related to the structure of pointers. Or either, with some moment the values of  'farleft' and 'farright' intervene one in another one. Please, it would like to know as to hinder collateral effect (improper propagation) provoked by pointers for the following situation:
 
type 'a pointer = Null | Pointer of 'a ref;;
let ( !^ ) = function
    | Null -> invalid_arg "Attempt to dereference the null pointer"
    | Pointer r -> !r;;
(*val ( !^ ) : 'a pointer -> 'a = <fun>*)
let ( ^:= ) p v =
    match p with
    | Null -> invalid_arg "Attempt to assign the null pointer"
    | Pointer r -> r := v;;
(*val ( ^:= ) : 'a pointer -> 'a -> unit = <fun>*)
let new_pointer x = Pointer (ref x);;
(*val new_pointer : 'a -> 'a pointer = <fun>*)
...
let dummytri = new_pointer ({tr_adjtri=(Array.init 3 (fun x -> {te_ptri=Null; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0});;
let dummypoint = new_pointer {po_x = 0.0; po_y = 0.0; po_marker = 0};;
let dummysh = new_pointer {sh_edg=(Array.init 2 (fun x -> Null)); sh_no=(Array.init 2 (fun x -> dummypoint)); sh_adjtri=(Array.init 2 (fun x -> Null)); sh_marker=0};;
let triangleloop = ref [||];;
...

...
let farleft  = ref (new_pointer {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0})
and farright = ref (new_pointer {te_tri={tr_adjtri=(Array.init 3 (fun x -> {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint)); tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}) in
...
maketriangle farleft;
maketriangle farright;
(* It has advanced, geometric primitives modify values of farleft and farright and connect they. *)
...
 

(* It adds an element to the 'triangleloop' array and returns a pointer for its last element *)
let maketriangle newtriedge =
   let l = Array.length !triangleloop in
   aumenteTriangulos triangleloop 1;
   newtriedge ^:= !triangleloop.(l);;
(*val maketriangle : triedge pointer -> unit = <fun>*)
 

(* It increases the size of  'triangleloop' *)
let aumenteTriangulos trianguloArray aumento =
   trianguloArray := Array.append !trianguloArray
                             (Array.init aumento (fun x -> {te_tri={tr_adjtri=(Array.init 3 (fun x ->
                             {te_ptri=dummytri; ta_orient=0})); tr_no=(Array.init 3 (fun x -> dummypoint));
                             tr_adjedg=(Array.init 3 (fun x -> dummysh)); tr_area=0.0}; te_orient=0}));;
(*val aumenteTriangulos : triedge array ref -> int -&! gt; unit = <fun>*)
 

Yours truly,
 
André Luiz Moura



Yahoo! GeoCities: a maneira mais fácil de criar seu web site grátis!