-- $Date: 2004/01/11 00:59:06 $
-- $Revision: 1.7 $
-- $Author: jcrocholl $

package body Straights is

   -- Create a straight line.
   function Create
     (To : in Vector-- End point of the line.
     return Line is   -- The newly created straight line.
   begin
      return new Straight_Record'(To => To, Length => 0.0);
   end Create;

   -- Calculate the length of this line. Results are cached for
   -- reuse. So make sure the starting point always remain the same
   -- between calls.
   function Length
     (Start : in Vector;              -- Starting point of the line.
      This  : access Straight_Record-- Get this line's length.
     return Real is                   -- The distance from start to end point.
   begin
      if This.Length = 0.0 then
         This.Length := abs(This.To - Start);
      end if;
      return This.Length;
   end Length;

   -- Scale a line by a given factor.
   procedure Scale
     (This   : access Straight_Record;
      Factor : in Real) is
   begin
      This.To := This.To * Factor;
      This.Length := This.Length * Factor;
   end Scale;

   -- Translate a line by a given offset.
   procedure Translate
     (This   : access Straight_Record-- Translate this line.
      Offset : in Vector) is           -- Translating offset.
   begin
      This.To := This.To + Offset;
   end Translate;

   -- Get one point from a straight line.
   function Way_Point
     (Start : in Vector;              -- Starting point of the line.
      This  : access Straight_Record-- Definition of the line.
      Part  : in Real)                -- Parametrization variable from 0 to 1.
     return Vector is                 -- The point on the line.
   begin
      return Start + Part * (This.To - Start);
   end Way_Point;

   -- Format a straight line for postscript output.
   function Postscript
     (This : access Straight_Record-- Format this line.
     return String is                -- The resulting postscript code.
   begin
      return Postscript(This.To) & " lineto";
   end Postscript;

end Straights;