(* arbre 2-dimensionnel *)

let d = 2;; 

type point = float array;; (* tableaux de longueur d *)

type kdtree = V | N of kdtree * point * kdtree;; 

let pt_test = [|
[| 3.3 ; 0.9 |];
[| 2.0 ; 4.5 |];
[| 3.7 ; 5.1 |];
[| 8.4 ; 6.0 |];
[| 2.7 ; 1.8 |];
[| 1.2 ; 4.4 |];
[| 5.1 ; 3.6 |];
[| 5.7 ; 1.8 |];
[| 4.0 ; 1.4 |];
[| 6.6 ; 2.4 |];
[| 6.4 ; 0.7 |];
[| 7.9 ; 5.5 |];
|];;


let affiche_kdtree tree =
  let rec affiche_espace n = 
    if n > 0 then begin print_string " "; affiche_espace (n-1) end
  in
  let rec affiche_aux decalage tree =  match tree with
    | V -> ()
    | N (ag, pt, ad) -> begin
        affiche_aux (decalage + 3) ag;
        affiche_espace decalage; Printf.printf "(%f,%f) \n" pt.(0) pt.(1);
        affiche_aux (decalage + 3) ad;
    end
  in
  affiche_aux 0 tree
;;