-- $Date: 2004/02/02 09:01:43 $
-- $Revision: 1.15 $
-- $Author: jcrocholl $

with Real_Numbers; use Real_Numbers;
with Real_Vectors; use Real_Vectors;
with Lines; use Lines;

-- Cubic bezier curves.
package Cubics is

   -- Cubic bezier curve. Extends Line with two control points.
   type Cubic is new Line with record
      Control_A, Control_B : Vector;
   end record;

   -- Access type for cubic bezier curves.
   type Cubic_Access is access all Cubic;

   -- Create a cubic bezier curve.
   function Create
     (To        : in Vector-- End point of the curve.
      Control_A : in Vector-- First control point of curve.
      Control_B : in Vector-- Second control point of curve.
     return Line_Access;     -- The newly created curve.

   -- Calculate the arc length of this curve. Results are cached for
   -- reuse. So make sure the starting point always remains the same
   -- between calls.
   function Length
     (Start : in Vector;    -- Starting point of the curve.
      This  : access Cubic-- Get this curve's arc length.
     return Real;           -- The length of the arc.

   -- Scale a curve by a given factor.
   procedure Scale
     (This   : access Cubic-- Scale this curve.
      Factor : in Real);     -- Scaling factor.

   -- Translate a curve by a given offset.
   procedure Translate
     (This   : access Cubic-- Translate this curve.
      Offset : in Vector);   -- Translating offset.

   -- Get one point from the cubic bezier curve.
   function Way_Point
     (Start : in Vector;    -- Starting point of the curve.
      This  : access Cubic-- Definition of the curve.
      Part  : in Real)      -- Parametrization variable from 0 to 1.
     return Vector;         -- The point on the curve.

   -- Format a cubic bezier curve for Scalable Vector Graphics output.
   function To_SVG
     (This      : access Cubic-- Format this curve.
      Tolerance : in Real)      -- Tolerance level.
     return String;             -- The resulting SVG code.

   -- Format a cubic bezier curve for postscript output.
   function To_Postscript
     (This      : access Cubic-- Format this curve.
      Tolerance : in Real)      -- Tolerance level.
     return String;             -- The resulting Postscript code.

end Cubics;