File : generic_vector_operations.adb


------------------------------------------------------------------------------
--
--  package Generic_Vector_Operations (body)
--
------------------------------------------------------------------------------
--  Update information:
--
--  1995.12.27 (Jacob Sparre Andersen)
--    Written.
--
--  1996.06.25 (Jacob Sparre Andersen)
--    Reformatted the header.
--    Corrected a few bugs.
--
--  (Insert additional update information above this line.)
------------------------------------------------------------------------------

with Ada.Numerics.Generic_Elementary_Functions;

package body Generic_Vector_Operations is

   ---------------------------------------------------------------------------
   --  package Elementary_Functions:

   package Elementary_Functions is new
     Ada.Numerics.Generic_Elementary_Functions(Float_Type => Scalar);
   
   ---------------------------------------------------------------------------
   --  Length:

   ---------------------------------------------------------------------
   --  function Length:

   function Length (Item : in Vector) return Scalar is

   begin --  Length
      return Elementary_Functions.Sqrt (Squared_Length (Item));
   end Length;

   ---------------------------------------------------------------------
   --  function Squared_Length:

   function Squared_Length (Item : in Vector) return Scalar is

   begin --  Squared_Length
      return Item * Item;
   end Squared_Length;

   ---------------------------------------------------------------------------
   --  Normalization:

   ---------------------------------------------------------------------
   --  procedure Normalize:

   procedure Normalize (Item : in out Vector) is
   begin
      Item := Item / Length (Item);
   end Normalize;

   ---------------------------------------------------------------------
   --  function Unit_Vector:

   function Unit_Vector (Item : in Vector) return Vector is

   begin --  Unit_Vector
      return Item / Length (Item);
   end Unit_Vector;
   
   ---------------------------------------------------------------------------
   --  Manipulations:

   ---------------------------------------------------------------------
   --  function Projection:

   function Projection (Item : in Vector;
                        On   : in Vector) return Vector is

   begin --  Projection
      return On * (Item * On) / Squared_Length (On);
   end Projection;

   ---------------------------------------------------------------------
   --  function Mirror:

   function Mirror (Ray            : in Vector;
                    Surface_Normal : in Vector) return Vector is

   begin --  Mirror
      return Ray - 2.0 * Projection (Item => Ray, On => Surface_Normal);
   end Mirror;

   ---------------------------------------------------------------------------

end Generic_Vector_Operations;