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 To_String
(A : in Vector)
return String is
begin
return "(" &
To_String(A.X) & ", " &
To_String(A.Y) & ")";
end To_String;
function Get_Width
(This : in Box)
return Number is
begin
return This.Right - This.Left;
end Get_Width;
pragma Inline(Get_Width);
function Get_Height
(This : in Box)
return Number is
begin
return This.Top - This.Bottom;
end Get_Height;
pragma Inline(Get_Height);
function Get_Bottom_Left
(This : in Box)
return Vector is
begin
return Vector'(This.Left, This.Bottom);
end Get_Bottom_Left;
function Get_Top_Right
(This : in Box)
return Vector is
begin
return Vector'(This.Right, This.Top);
end Get_Top_Right;
end Vectors;
|