Geometry helpers

## Geometry helpers Geometry helpers |

## Synopsis

    typedef             GOGeometryAABR;
                        GOGeometryOBR;
    enum                GOGeometryRotationType;
    enum                GOGeometrySide;
    #define             GO_GEOMETRY_ANGLE_TOLERANCE
    enum                GODirection;
    char const *        go_direction_get_name               (GODirection d);
    gboolean            go_direction_is_forward             (GODirection d);
    gboolean            go_direction_is_horizontal          (GODirection d);
    void                go_geometry_AABR_add                (GOGeometryAABR *aabr0,
                                                             GOGeometryAABR const *aabr1);
    void                go_geometry_OBR_to_AABR             (GOGeometryOBR const *obr,
                                                             GOGeometryAABR *aabr);
    GOGeometrySide      go_geometry_calc_label_anchor       (GOGeometryOBR *obr,
                                                             double alpha);
    GOGeometrySide      go_geometry_calc_label_position     (GOGeometryOBR *obr,
                                                             double alpha,
                                                             double offset,
                                                             GOGeometrySide side,
                                                             GOGeometrySide anchor);
    void                go_geometry_cartesian_to_polar      (double x,
                                                             double y,
                                                             double *rho,
                                                             double *theta);
    GOGeometryRotationType go_geometry_get_rotation_type    (double alpha);
    double              go_geometry_point_to_segment        (double xp,
                                                             double yp,
                                                             double xs,
                                                             double ys,
                                                             double w,
                                                             double h);
    gboolean            go_geometry_test_OBR_overlap        (GOGeometryOBR const *obr0,
                                                             GOGeometryOBR const *obr1);

## Object Hierarchy

      GEnum
       +----GODirection

## Description

## Details

### GOGeometryAABR

    typedef struct _GogViewAllocation GOGeometryAABR;

### GOGeometryOBR

    typedef struct {
            double x, y;
            double w, h;
            double alpha;
    } GOGeometryOBR;

double `x`; | horizontal position of the center.
double `y`; | vertical position of the center.
double `w`; | width of edge.
double `h`; | height of edge.
double `alpha`; | Aangle from x axis to w edge, in radians.

### enum GOGeometryRotationType

    typedef enum {
    	GO_ROTATE_NONE = 0,
    	GO_ROTATE_COUNTERCLOCKWISE = 1,
    	GO_ROTATE_UPSIDEDOWN = 2,
    	GO_ROTATE_CLOCKWISE = 3,
    	GO_ROTATE_FREE = 4
    } GOGeometryRotationType;

`GO_ROTATE_NONE` | no rotation.
`GO_ROTATE_COUNTERCLOCKWISE` | counter clockwise.
`GO_ROTATE_UPSIDEDOWN` | upside down.
`GO_ROTATE_CLOCKWISE` | clockwise.
`GO_ROTATE_FREE` | free rotation.

### enum GOGeometrySide

    typedef enum {
    	GO_SIDE_LEFT		= 1 << 0,
    	GO_SIDE_RIGHT		= 1 << 1,
    	GO_SIDE_LEFT_RIGHT = 3 << 0,
    	GO_SIDE_TOP		= 1 << 2,
    	GO_SIDE_BOTTOM		= 1 << 3,
    	GO_SIDE_TOP_BOTTOM = 3 << 2,
    	GO_SIDE_AUTO		= 15
    } GOGeometrySide;

`GO_SIDE_LEFT` | left.
`GO_SIDE_RIGHT` | right.
`GO_SIDE_LEFT_RIGHT` | left or right.
`GO_SIDE_TOP` | top.
`GO_SIDE_BOTTOM` | bottom.
`GO_SIDE_TOP_BOTTOM` | top or bottom.
`GO_SIDE_AUTO` | auto.

### GO_GEOMETRY_ANGLE_TOLERANCE

    #define GO_GEOMETRY_ANGLE_TOLERANCE 1E-3

### enum GODirection

    typedef enum {
    	GO_DIRECTION_UP    = 0,
    	GO_DIRECTION_DOWN  = 1,
    	GO_DIRECTION_LEFT  = 2,
    	GO_DIRECTION_RIGHT = 3,
    	GO_DIRECTION_NONE  = 4
    } GODirection;

`GO_DIRECTION_UP` | up.
`GO_DIRECTION_DOWN` | down.
`GO_DIRECTION_LEFT` | left.
`GO_DIRECTION_RIGHT` | right.
`GO_DIRECTION_NONE` | no direction.

### go_direction_get_name ()

    char const *        go_direction_get_name               (GODirection d);

### go_direction_is_forward ()

    gboolean            go_direction_is_forward             (GODirection d);

`d` : | GODirection
Returns : | TRUE for GO_DIRECTION_DOWN or GO_DIRECTION_RIGHT.

### go_direction_is_horizontal ()

    gboolean            go_direction_is_horizontal          (GODirection d);

`d` : | GODirection
Returns : | TRUE for GO_DIRECTION_LEFT and GO_DIRECTION_RIGHT.

### go_geometry_AABR_add ()

    void                go_geometry_AABR_add                (GOGeometryAABR *aabr0,
                                                             GOGeometryAABR const *aabr1);

Computes the Axis Aligned Bounding Rectangle of aabr0 and aabr1, and stores result in aabr0.

`aabr0` : | a GOGeometryAABR
`aabr1` : | a GOGeometryAABR

### go_geometry_OBR_to_AABR ()

    void                go_geometry_OBR_to_AABR             (GOGeometryOBR const *obr,
                                                             GOGeometryAABR *aabr);

Stores Axis Aligned Bounding Rectangle of `obr` in `aabr`.

`obr` : | a GOGeometryOBR
`aabr` : | a GOGeometryAABR

### go_geometry_calc_label_anchor ()

    GOGeometrySide      go_geometry_calc_label_anchor       (GOGeometryOBR *obr,
                                                             double alpha);

`obr` : | bounding rectangle of label
`alpha` : | angle of axis
Returns : | computed label anchor, to be used by go_geometry_calc_label_position.

### go_geometry_calc_label_position ()

    GOGeometrySide      go_geometry_calc_label_position     (GOGeometryOBR *obr,
                                                             double alpha,
                                                             double offset,
                                                             GOGeometrySide side,
                                                             GOGeometrySide anchor);

Convenience routine that computes position of a label relative to an axis.

`obr` : | bounding rectangle of label
`alpha` : | angle of axis
`offset` : | minimum distance between label and axis
`side` : | side of label with respect to axis
`anchor` : | where to anchor the label
Returns : | the computed anchor if `anchor` == GO_SIDE_AUTO, or `anchor` value.

### go_geometry_cartesian_to_polar ()

    void                go_geometry_cartesian_to_polar      (double x,
                                                             double y,
                                                             double *rho,
                                                             double *theta);

Converts cartesion coordinates to polar coordinates.

`x` : | cartesian coordinate
`y` : | cartesian coordinate
`rho` : | polar coordinate
`theta` : | polar coordinate

### go_geometry_get_rotation_type ()

    GOGeometryRotationType go_geometry_get_rotation_type    (double alpha);

Calculates rotation type for handling of special angles (alpha = n * pi / 2)

`alpha` : | angle in radians
Returns : | a GOGeometryRotationType

### go_geometry_point_to_segment ()

    double              go_geometry_point_to_segment        (double xp,
                                                             double yp,
                                                             double xs,
                                                             double ys,
                                                             double w,
                                                             double h);

`xp` : | point coordinate
`yp` : | point coordinate
`xs` : | segment start coordinate
`ys` : | segment start coordinate
`w` : | extent of segment
`h` : | extent of segment
Returns : | the distance between a point and a segment.

### go_geometry_test_OBR_overlap ()

    gboolean            go_geometry_test_OBR_overlap        (GOGeometryOBR const *obr0,
                                                             GOGeometryOBR const *obr1);

Overlap test of Oriented Bounding Rectangles by the separating axis method.

`obr0` : | a GOGeometryOBR
`obr1` : | a GOGeometryOBR
Returns : | `TRUE` if OOBRs overlap