Index

Package: Directions

Description

package Directions is

Types

Axis_Direction

subtype Axis_Direction is Integer range -1..1;

Direction_Type

type Direction_Type is
        record
            x, y : Axis_Direction;
        end record;
A record capable of expressing eight directions with x, y axis. It is useful because direction arithmetic can be performed on a Direction_Type.

Cardinal_Direction

type Cardinal_Direction is (Left, Right, Up, Down);
Enumeration of the four cardinal directions.

Direction_8

type Direction_8 is (D8_Left,    D8_Right,    D8_Up,        D8_Down,
                         D8_Up_Left, D8_Up_Right, D8_Down_Left, D8_Down_Right);
Enumeration of eight directions at 45 degree angles.

Direction_Booleans

type Direction_Booleans is array (Cardinal_Direction) of Boolean;
An array of Booleans indexed by cardinal direction.

Constants & Global variables

Subprograms & Entries

+

function "+"
( l: Direction_Type;
r: Cardinal_Direction ) return Direction_Type;
Returns a combined direction. If the direction of 'r' is directly opposite the matching component of the 'l' direction, then 'r' will override the matching component of 'l' in the resultant direction. (ex: Dir_Left + Right = Dir_Right)

-

function "-"
( l: Direction_Type;
r: Cardinal_Direction ) return Direction_Type;
Zeros the component of direction 'l' that matches 'r'. Note that the returned direction will have at least one non-zero component because a direction with no components is illegal.

and

function "and"
( l: Direction_Type;
r: Cardinal_Direction ) return Boolean;
Returns true if cardinal direction 'r' is a component of direction 'l'. Example: "<Up+Right> and Up = True", "<Down+Right> and Up = False"

To_D8

function To_D8
( dir: Direction_Type ) return Direction_8;
Converts dir to a Direction_8 type. If dir doesn't have a component in any axis then a Constraint_Error is raised.

To_D8

function To_D8
( dir: Cardinal_Direction ) return Direction_8;
Converts dir to a Direction_8 type.

To_X

function To_X
( dir: Direction_Type ) return Direction_8;
Returns only the X component of dir as a Direction_8. If dir doesn't have an X component then Left is returned as a default.

To_Y

function To_Y
( dir: Direction_Type ) return Direction_8;
Returns only the Y component of dir as a Direction_8. If dir doesn't have any Y component then Up is returned as a default.

To_Y

function To_Y
( dir: Direction_Type ) return Cardinal_Direction;
Returns only the Y component of dir as a cardinal direction. If dir doesn't have any Y component then Up is returned as a default.

not

function "not"
( db: Direction_Booleans ) return Boolean;
Returns true if all of the Booleans in the array are False.

Opposite

function Opposite
( dir: Cardinal_Direction ) return Cardinal_Direction;
Returns the opposite of the given direction.

To_Direction

function To_Direction
( dir: Cardinal_Direction ) return Direction_Type;
Converts a Cardinal_Direction to a general Direction_Type.

To_Direction

function To_Direction
( dir: Direction_8 ) return Direction_Type;
Converts a Direction_8 to a general Direction_Type.

To_String

function To_String
( dir: Direction_Type ) return String;