Hosted by
|
package body Vectors is
function "+"
(A : in Vector)
return Vector is
begin
return A;
end "+";
function "-"
(A : in Vector)
return Vector is
begin
return (-A.X, -A.Y);
end "-";
function "+"
(A, B : in Vector)
return Vector is
begin
return (A.X + B.X, A.Y + B.Y);
end "+";
function "-"
(A, B : in Vector)
return Vector is
begin
return (A.X - B.X, A.Y - B.Y);
end "-";
function "*"
(A, B : in Vector)
return Vector is
begin
return (A.X * B.X, A.Y * B.Y);
end "*";
function "*"
(A : in Vector;
B : in Number)
return Vector is
begin
return (A.X * B, A.Y * B);
end "*";
function "*"
(A : in Number;
B : in Vector)
return Vector is
begin
return (A * B.X, A * B.Y);
end "*";
function "/"
(A : in Vector;
B : in Number)
return Vector is
begin
return (A.X / B, A.Y / B);
end "/";
function "abs"
(A : in Vector)
return Number
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";
function Mirror_Y
(A : in Vector)
return Vector is
begin
return (A.X, -A.Y);
end Mirror_Y;
function To_String
(A : in Vector)
return String is
begin
return To_String(A.X) & " " & To_String(A.Y);
end To_String;
function To_String
(A : in Vector;
Tolerance : in Number)
return String is
begin
return To_String(A.X, Tolerance) & " " & To_String(A.Y, Tolerance);
end To_String;
function Max
(A, B : in Rectangle)
return Rectangle is
begin
return (
Min(A.Left, B.Left), Min(A.Top, B.Top),
Max(A.Right, B.Right), Max(A.Bottom, B.Bottom));
end Max;
function "+"
(A : in Rectangle;
B : in Vector)
return Rectangle is
begin
return (
A.Left + B.X, A.Top + B.Y,
A.Right + B.X, A.Bottom + B.Y);
end "+";
function Get_Width
(This : in Rectangle)
return Number is
begin
return This.Right - This.Left;
end Get_Width;
pragma Inline(Get_Width);
function Get_Height
(This : in Rectangle)
return Number is
begin
return This.Bottom - This.Top;
end Get_Height;
pragma Inline(Get_Height);
function Get_Bottom_Left
(This : in Rectangle)
return Vector is
begin
return Vector'(This.Left, This.Bottom);
end Get_Bottom_Left;
function Get_Top_Right
(This : in Rectangle)
return Vector is
begin
return Vector'(This.Right, This.Top);
end Get_Top_Right;
function Get_Bottom_Right
(This : in Rectangle)
return Vector is
begin
return Vector'(This.Right, This.Bottom);
end Get_Bottom_Right;
function Get_Top_Left
(This : in Rectangle)
return Vector is
begin
return Vector'(This.Left, This.Top);
end Get_Top_Left;
function To_String
(This : in Rectangle)
return String is
begin
return
To_String(This.Left) & " " &
To_String(This.Top) & " " &
To_String(This.Right) & " " &
To_String(This.Bottom);
end To_String;
function To_String
(This : in Rectangle;
Tolerance : in Number)
return String is
begin
return
To_String(This.Left, Tolerance) & " " &
To_String(This.Top, Tolerance) & " " &
To_String(This.Right, Tolerance) & " " &
To_String(This.Bottom, Tolerance);
end To_String;
end Vectors;
|