mission2.adb

with Gada.Text_IO ;

procedure Mission2 is

   package Txt renames Gada.Text_IO ;

   type T_Intervalle is record
      Inf : Float ;
      Sup  : Float ;
   end record ;
   
   function Intervalle_Image(A : T_Intervalle) return String is
   begin
      return "[" & Integer'Image(Integer(A.Inf)) & "," & Integer'Image(Integer(A.Sup)) & "]" ;
   end Intervalle_Image ;

   -- A est inclus dans B <=> les bornes de A sont comprises entre les bornes de B.
   function Est_Inclus (A : T_Intervalle ; B : T_Intervalle) return Boolean is
   begin
      return A.Inf >= B.Inf and A.Sup <= B.Sup ;
   end Est_Inclus ;

   -- A et B disjoints <=> A est situé avant B ou A est situé après B.
   function Disjoints (A : T_Intervalle ; B : T_Intervalle) return Boolean is
   begin
      return A.Sup < B.Inf or A.Inf > B.Sup ;
   end Disjoints ;

   procedure Afficher_Relation (A : T_Intervalle ; B : T_Intervalle) is
   begin
      if Est_Inclus(A, B) then
         Txt.Put_Line(Intervalle_Image(A) & " est inclus dans " & Intervalle_Image(B)) ;
      elsif Est_Inclus(B,A) then
         Txt.Put_Line(Intervalle_Image(B) & " est inclus dans " & Intervalle_Image(A)) ;
      elsif Disjoints(A,B) then
         Txt.Put_Line(Intervalle_Image(A) & " et " & Intervalle_Image(B) & " sont disjoints.") ;
      else
         Txt.Put_Line(Intervalle_Image(A) & " et " & Intervalle_Image(B) & " ne sont pas disjoints.") ;
      end if ;
   end Afficher_Relation ;

   type T_Prod is record
      Gauche : T_Intervalle ;
      Droite : T_Intervalle ;
   end record ;
   
   function Prod_Image(A : T_Prod) return String is
   begin
      return Intervalle_Image(A.Gauche) & " x " & Intervalle_Image(A.Droite) ;
   end Prod_Image ;
   
   
   -- A1xA2 est inclus dans B1xB2 <=> A1 inclus dans B1 et A2 inclus dans B2
   function Prod_Est_Inclus (A : T_Prod ; B : T_Prod) return Boolean is
   begin
      return Est_Inclus (A.Gauche, B.Gauche) and Est_Inclus(A.Droite, B.Droite) ;
   end Prod_Est_Inclus ;

   -- A1xA2 disjoint de B1xB2 <=> A1 disjoint de B1 ou A2 disjoint de B2
   function Prod_Disjoints (A : T_Prod ; B : T_Prod) return Boolean is
   begin
      return Disjoints(A.Gauche, B.Gauche) or Disjoints(A.Droite, B.Droite) ;
   end Prod_Disjoints ;

   procedure Prod_Afficher_Relation (A : T_Prod ; B : T_Prod) is
   begin
      if Prod_Est_Inclus(A, B) then
         Txt.Put_Line(Prod_Image(A) &  " est inclus dans " & Prod_Image(B)) ;
      elsif Prod_Est_Inclus(B,A) then
         Txt.Put_Line(Prod_Image(B) &  " est inclus dans " & Prod_Image(A)) ;
      elsif Prod_Disjoints(A,B) then
         Txt.Put_Line(Prod_Image(A) & " et " & Prod_Image(B) & " sont disjoints.") ;
      else
	 Txt.Put_Line(Prod_Image(A) & " et " & Prod_Image(B) & " ne sont pas disjoints.") ;
      end if ;
   end Prod_Afficher_Relation ;

   C : constant T_Intervalle := (5.0, 10.0) ;
   D : constant T_Intervalle := (7.0, 8.0) ;
   E : constant T_Intervalle := (4.0, 6.0) ;

begin
      Afficher_Relation(C,D) ;
      Afficher_Relation(D,C) ;
      Afficher_Relation(C,E) ;
      Afficher_Relation(D,E) ;

      Prod_Afficher_Relation((C, C), (D, D)) ;
      Prod_Afficher_Relation((C, D), (D, C)) ;
      Prod_Afficher_Relation((D, C), (E, C)) ;
end Mission2 ;