-- $Date: 2004/01/10 11:49:40 $
-- $Revision: 1.6 $
-- $Author: jcrocholl $

package body Vectors is

   --------------------
   -- Vector Operations
   --------------------

   -- Unary plus: identity.
   function "+"
     (A : in Vector)  -- Copy this vector.
     return Vector is -- The same vector.
   begin
      return A;
   end "+";

   -- Unary minus: mirror a vector.
   function "-"
     (A : in Vector)  -- Mirror this vector.
     return Vector is -- The mirrored vector.
   begin
      return (-A.X, -A.Y);
   end "-";

   -- Vector addition.
   function "+"
     (A, B : in Vector-- Add these two vectors.
     return Vector is   -- The result vector.
   begin
      return (A.X + B.X, A.Y + B.Y);
   end "+";

   -- Vector subtraction.
   function "-"
     (A, B : in Vector-- Subtract B From A.
     return Vector is   -- The result vector.
   begin
      return (A.X - B.X, A.Y - B.Y);
   end "-";

   -- Multiplication for corresponding components.
   function "*"
     (A, B : in Vector-- Multiply components of these vectors.
     return Vector is   -- The result vector.
   begin
      return (A.X * B.X, A.Y * B.Y);
   end "*";

   -- Multiply a vector with a scalar number.
   function "*"
     (A : in Vector;  -- Scale this vector.
      B : in Number)  -- Scalar factor.
     return Vector is -- The result vector.
   begin
      return (A.X * B, A.Y * B);
   end "*";

   -- Multiply a vector with a scalar number.
   function "*"
     (A : in Number;  -- Scalar factor.
      B : in Vector)  -- Scale this vector.
     return Vector is -- The result vector.
   begin
      return (A * B.X, A * B.Y);
   end "*";

   -- Divide a vector by a scalar number.
   function "/"
     (A : in Vector;  -- Divide this vector.
      B : in Number)  -- Scalar divisor.
     return Vector is -- The result vector.
   begin
      return (A.X / B, A.Y / B);
   end "/";

   -- Calculate the length of a vector.
   function "abs"
     (A : in Vector-- Calculate length of this vector.
     return Number   -- The length of the vector.
   is
      S : Number := A.X * A.X + A.Y * A.Y;
   begin
      if S > Zero then
         return Sqrt(S);
      else
         return Zero;
      end if;
   end "abs";

   -- Convert a vector to a string.
   function To_String
     (A : in Vector)  -- Convert this vector.
     return String is -- The string representation.
   begin
      return "(" &
        To_String(A.X) & ", " &
        To_String(A.Y) & ")";
   end To_String;

   -----------------
   -- Box Operations
   -----------------

   -- Calculate the width of the box.
   function Get_Width
     (This : in Box)  -- Calculate width of this box.
     return Number is -- Difference between right and left.
   begin
      return This.Right - This.Left;
   end Get_Width;
   pragma Inline(Get_Width);

   -- Calculate the height of the box.
   function Get_Height
     (This : in Box)  -- Calculate height of this box.
     return Number is -- Difference between top and bottom.
   begin
      return This.Top - This.Bottom;
   end Get_Height;
   pragma Inline(Get_Height);

   -- Get the bottom left corner.
   function Get_Bottom_Left
     (This : in Box)  -- Get corner from this box.
     return Vector is -- A vector containing left and bottom.
   begin
      return Vector'(This.Left, This.Bottom);
   end Get_Bottom_Left;

   -- Get the top right corner.
   function Get_Top_Right
     (This : in Box)  -- Get corner from this box.
     return Vector is -- A vector containing right and top.
   begin
      return Vector'(This.Right, This.Top);
   end Get_Top_Right;

end Vectors;