Navigation C API Pages Python bindings Applications

Bounding box

Bounding box is an rectangle combine with an offset.

Bounding box
#include <utils/gp_bbox.h>

typedef struct gp_bbox {
        gp_coord x;
        gp_coord y;
        gp_size w;
        gp_size h;
} gp_bbox;

int gp_bbox_empty(gp_bbox box);

gp_bbox gp_bbox_pack(gp_coord x, gp_coord y, gp_coord w, gp_coord h);

gp_bbox gp_bbox_merge(gp_bbox box1, gp_bbox box2);

gp_bbox gp_bbox_intersection(gp_bbox box1, gp_bbox box2);

int gp_bbox_intersects(gp_bbox box1, gp_bbox box2);

gp_bbox gp_bbox_move(gp_bbox box, gp_coord x, gp_coord y);

Bounding box is an absctraction for union and intersection of rectangles on a plane. This is mostly used by the widget library at the moment.

Bounding box example code
//SPDX-License-Identifier: LGPL-2.0-or-later

/*

   Copyright (c) 2014-2020 Cyril Hrubis <metan@ucw.cz>

 */

/*
 * Just a simple fun with bboxes.
 */

#include <utils/gp_bbox.h>

static void bboxes_intersect(gp_bbox box1, gp_bbox box2)
{
        printf(GP_BBOX_FMT " & " GP_BBOX_FMT " = %i\n",
               GP_BBOX_PARS(box1), GP_BBOX_PARS(box2),
               gp_bbox_intersects(box1, box2));
}

int main(void)
{
        gp_bbox bbox = gp_bbox_merge(gp_bbox_pack(0, 0, 1, 1), gp_bbox_pack(1, 1, 1, 1));

        bboxes_intersect(bbox, gp_bbox_pack(0, 0, 1, 1));
        bboxes_intersect(bbox, gp_bbox_pack(0, 3, 1, 1));
        bboxes_intersect(bbox, gp_bbox_pack(2, 0, 1, 1));
        bboxes_intersect(bbox, gp_bbox_pack(-1, -2, 1, 1));

        return 0;
}