summaryrefslogtreecommitdiff
path: root/lib/bounding-box.c
blob: 25f0b74328b96e8a97d8bd569c60f28356061801 (plain)
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
/* bounding-box.c: definitions for bounding box operations.

Copyright (C) 1992 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

#include "config.h"

#include "bounding-box.h"


/* See the comments at `get_character_bitmap' in gf_input.c for why the
   width and height are treated asymmetrically.  */

const bounding_box_type
dimensions_to_bb (dimensions_type dimensions)
{
  bounding_box_type answer;

  MIN_ROW (answer) = 0;
  MIN_COL (answer) = 0;
  MAX_ROW (answer) = MAX ((int) DIMENSIONS_HEIGHT (dimensions) - 1, 0);
  MAX_COL (answer) = MAX (DIMENSIONS_WIDTH (dimensions), 0);

  return answer;
}


/* Dimensions can't be negative, even though bounding boxes can, so we
   have to check.  */
   
const dimensions_type
bb_to_dimensions (bounding_box_type bb)
{
  dimensions_type d;
  
  DIMENSIONS_WIDTH (d) = MAX (BB_WIDTH (bb), 0);
  DIMENSIONS_HEIGHT (d) = MAX (BB_HEIGHT (bb), 0);
  
  return d;
}


/* If the point P lies outside of any of the current bounds in BB,
   update BB.  */

void
update_real_bounding_box (real_bounding_box_type *bb, real_coordinate_type p)
{
  if (p.x < MIN_COL (*bb)) MIN_COL (*bb) = p.x;
  if (p.x > MAX_COL (*bb)) MAX_COL (*bb) = p.x;
  if (p.y < MIN_ROW (*bb)) MIN_ROW (*bb) = p.y;
  if (p.y > MAX_ROW (*bb)) MAX_ROW (*bb) = p.y;
    
}


void
update_bounding_box (bounding_box_type *bb, coordinate_type p)
{
  if (p.x < MIN_COL (*bb)) MIN_COL (*bb) = p.x;
  if (p.x > MAX_COL (*bb)) MAX_COL (*bb) = p.x;
  if (p.y < MIN_ROW (*bb)) MIN_ROW (*bb) = p.y;
  if (p.y > MAX_ROW (*bb)) MAX_ROW (*bb) = p.y;
    
}