Hosted by
|
package body Cubics is
function Create
(To : in Vector;
Control_A : in Vector;
Control_B : in Vector)
return Line_Access is
begin
return new Cubic'(To => To,
Control_A => Control_A,
Control_B => Control_B,
Length => 0.0);
end Create;
function Length
(Start : in Vector;
This : access Cubic)
return Real is
begin
if This.Length = 0.0 then
This.Length := abs(This.To - Start);
end if;
return This.Length;
end Length;
procedure Scale
(This : access Cubic;
Factor : in Real) is
begin
This.To := This.To * Factor;
This.Control_A := This.Control_A * Factor;
This.Control_B := This.Control_B * Factor;
This.Length := This.Length * Factor;
end Scale;
procedure Translate
(This : access Cubic;
Offset : in Vector) is
begin
This.To := This.To + Offset;
This.Control_A := This.Control_A + Offset;
This.Control_B := This.Control_B + Offset;
end Translate;
function Way_Point
(Start : in Vector;
This : access Cubic;
Part : in Real)
return Vector
is
Part_1 : Real := 1.0 - Part;
begin
return Start * Cube(Part_1) +
This.Control_A * 3.0 * Square(Part_1) * Part +
This.Control_B * 3.0 * Part_1 * Square(Part) +
This.To * Cube(Part);
end Way_Point;
function To_SVG
(This : access Cubic;
Tolerance : in Real)
return String is
begin
return "C " &
To_String(This.Control_A, Tolerance) & " " &
To_String(This.Control_B, Tolerance) & " " &
To_String(This.To, Tolerance);
end To_SVG;
function To_Postscript
(This : access Cubic;
Tolerance : in Real)
return String is
begin
return
To_String(Mirror_Y(This.Control_A), Tolerance) & " " &
To_String(Mirror_Y(This.Control_B), Tolerance) & " " &
To_String(Mirror_Y(This.To), Tolerance) & " curveto";
end To_Postscript;
end Cubics;
|