











open Compatibility
open Types;;
open Constants;;


(* test_color : color -> color *)
let test_color (c : color) =
    let r , g , b = c
    in
       if (r < 0.0) or (r > 1.0)
       or (g < 0.0) or (g > 1.0)
       or (b < 0.0) or (b > 1.0)
       then raise (Failure "RGB items of color must be >= 0.0 and <= 1.0.")
       else c
;;

(* test_time : time -> time *)
let test_time (t : time) =
    if t < 0.0
    then raise (Failure "Time must be >= 0.0.")
    else t
;;

(* test_speed : float -> float *)
let test_speed s =
    if s < 0.0
    then raise (Failure "Speed must be >= 0.0.")
    else s
;;

(* test_size : vect3D -> vect3D *)
let test_size (s : vect3D) =
    let x , y , z = s
    in
       if (x > 0.0) & (y > 0.0) & (z > 0.0)
       then s
       else raise (Failure "Size items of a geometric must be > 0.0.")
;;

(* test_proximity_size : vect3D -> vect3D *)
let test_proximity_size (s : vect3D) =
    let x , y , z = s
    in
       if (x < 0.0) & (y < 0.0) & (z < 0.0)
       then raise (Failure "Size items of a proximity box must be >= 0.0.")
       else s
;;

(* test_radius : float -> float *)
let test_radius r =
    if r > 0.0
    then r
    else raise (Failure "Radius must be > 0.0.")
;;

(* test_height : float -> float *)
let test_height h =
    if h > 0.0
    then h
    else raise (Failure "Height must be > 0.0.")
;;

(* test_length : float -> float *)
let test_length l =
    if l < 0.0
    then raise (Failure "Length must be >= 0.0.")
    else l
;;

(* test_max_extent : float -> float *)
let test_max_extent m =
    if m < 0.0
    then raise (Failure "Max extent of text must be >= 0.0.")
    else m
;;


(* test_elevationGrid_dimension : int -> int *)
let test_elevationGrid_dimension d =
    if d > 1
    then d
    else raise
         (Failure "The dimensions of an elevation grid must be > 1.")
;;

(* test_elevationGrid_spacing : float -> float *)
let test_elevationGrid_spacing s =
    if s < 0.0
    then raise
         (Failure "The spacings of an elevation grid must be >= 0.0.")
    else s
;;

(* test_extrusion_scale : vect2D list  -> vect2D list *)
let test_extrusion_scale (scale : vect2D list) =
    let test (s : vect2D) =
        let x , y = s
        in
           if (x > 0.0) & (y > 0.0)
           then s
           else raise
                  (Failure 
                     "The scale list items of an extrusion must be > 0.0.")
    in
       map test scale
;;

(* test_material_ambient_intensity : float -> float *)
let test_material_ambient_intensity i =
     if (i < 0.0) or (i > 1.0)
     then raise
          (Failure
            "Ambient_intensity of a material must be >= 0.0 and <= 1.0.")
     else i
;;

(* test_material_shininess : float -> float *)
let test_material_shininess s =
     if (s < 0.0) or (s > 1.0)
     then raise
          (Failure "Shininess of a material must be >= 0.0 and <= 1.0.")
     else s
;;

(* test_material_transparency : float -> float *)
let test_material_transparency t =
     if (t < 0.0) or (t > 1.0)
     then raise
          (Failure "Transparency of a material must be >= 0.0 and <= 1.0.")
     else t
;;

(* test_attenuation : vect3D -> vect3D *)
let test_attenuation (a : vect3D) =
    let x , y , z = a
    in
       if (x < 0.0) or (y < 0.0) or (z < 0.0)
       then raise (Failure "Attenuation items of a light must be >= 0.0.")
       else a
;;

(* test_cut_off_angle : float -> float *)
let test_cut_off_angle a =
    if (a <= 0.0) or (a > (pi /. 2.0))
    then raise 
           (Failure
              "Cut-off angle of a spot light must be > 0.0 and <= pi/2.")
    else a
;;

(* test_beam_width : float -> float *)
let test_beam_width b =
    if (b <= 0.0) or (b > (pi /. 2.0))
    then raise
           (Failure
              "Beam width of a spot light must be > 0.0 and <= pi/2.")
    else b
;;

(* test_light_intensity : float -> float *)
let test_light_intensity i =
    if i < 0.0
    then raise (Failure "Intensity of a light must be >= 0.0")
    else i
;;

(* test_light_ambient_intensity : float -> float *)
let test_light_ambient_intensity i =
    if i < 0.0
    then raise (Failure "Ambient intensity of a light must be >= 0.0")
    else i
;;


(* test_field_of_view : float -> float *)
let test_field_of_view f =
    if (f > 0.0) & (f < pi)
    then f
    else raise
           (Failure
              "Field of view in a view point must be > 0.0 and < pi.")
;;

(* test_avatar_size : float -> float *)
let test_avatar_size s =
    if s < 0.0
    then raise (Failure "Avatar sizes must be >= 0.0.")
    else s
;;

(* test_visibility_limit : float -> float *)
let test_visibility_limit l =
    if l < 0.0
    then raise (Failure "Visibility limit of a view point must be >= 0.0.")
    else l
;;

(* test_sound_min_or_max : float -> float *)
let test_sound_min_or_max m =
    if m < 0.0
    then raise (Failure "All min and max of a sound must be >= 0.0.")
    else m
;;

(* test_sound_intensity : float -> float *)
let test_sound_intensity i =
    if (i < 0.0) or (i > 1.0)
    then raise (Failure "Sound intensity must be >= 0.0 and <= 1.0.")
    else i
;;

(* test_sound_priority : float -> float *)
let test_sound_priority p =
    if (p < 0.0) or (p > 1.0)
    then raise (Failure "Sound priority must be >= 0.0 and <= 1.0.")
    else p
;;

(* test_pitch : float -> float *)
let test_pitch p =
    if p > 0.0
    then p
    else raise (Failure "Sound pitch must be > 0.0.")
;;


(* test_background_angle : float -> float *)
let test_background_angle a =
    if (a < 0.0) or (a > pi)
    then raise (Failure "Background angles must be >= 0.0 and <= pi.")
    else a
;;


