box.c 2.24 KB
Newer Older
Ercan Ersoy's avatar
Ercan Ersoy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/*
 BOX.H

 License CC0 PUBLIC DOMAIN

 To the extent possible under law, Mark J. Olesen has waived all copyright 
 and related or neighboring rights to FDOSTUI Library. This work is published 
 from: United States.
*/
#include "box.h"

extern int
box_contains(
    int const                           i_pos_x,
    int const                           i_pos_y,
    struct box const*                   i_box)
{
    int                                 l_hit;
    int                                 l_right;
    int                                 l_bottom;

    l_hit= 0;

    do
    {

        if (0 == (*i_box).m_len_x)
        {
            break;
        }

        if (0 == (*i_box).m_len_y)
        {
            break;
        }

        if (i_pos_x < (*i_box).m_pos_x)
        {
            break;
        }

        if (i_pos_y < (*i_box).m_pos_y)
        {
            break;
        }

        l_right= ((*i_box).m_pos_x + (*i_box).m_len_x) - 1;

        if (i_pos_x > l_right)
        {
            break;
        }

        l_bottom= ((*i_box).m_pos_y + (*i_box).m_len_y) - 1;

        if (i_pos_y > l_bottom)
        {
            break;
        }

        l_hit= 1;

    }while(0);

    return l_hit;
}

extern int
box_contains_box(
    struct box const*                   i_box1,
    struct box const*                   i_box2)
{
    int                                 l_hit;

    l_hit= (
        ((*i_box2).m_pos_x >= (*i_box1).m_pos_x) &&
        ((*i_box2).m_pos_y >= (*i_box1).m_pos_y) &&
        ((int)((*i_box2).m_pos_x+(*i_box2).m_len_x) <=
        (int)((*i_box1).m_pos_x+(*i_box1).m_len_x)) &&
        ((int)((*i_box2).m_pos_y+(*i_box2).m_len_y) <=
        (int)((*i_box1).m_pos_y+(*i_box1).m_len_y))
            );

    return l_hit;
}

extern int
box_equal(
    struct box const*                   i_box1,
    struct box const*                   i_box2)
{
    int                                 l_equal;

    l_equal= (
        ((*i_box1).m_pos_x == (*i_box2).m_pos_x) &&
        ((*i_box1).m_pos_y == (*i_box2).m_pos_y) &&
        ((*i_box1).m_len_x == (*i_box2).m_len_x) &&
        ((*i_box1).m_len_y == (*i_box2).m_len_y)
            );

    return l_equal;
}