libgeda

m_bounds.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 #include <libgeda_priv.h>
00022 
00028 void m_bounds_init(BOUNDS *bounds)
00029 {
00030   bounds->min_x = G_MAXINT;
00031   bounds->min_y = G_MAXINT;
00032   bounds->max_x = G_MININT;
00033   bounds->max_y = G_MININT;
00034 }
00035 
00047 void m_bounds_of_points(BOUNDS *bounds, sPOINT points[], gint count)
00048 {
00049   gint index;
00050 
00051   m_bounds_init(bounds);
00052 
00053   for (index=0; index<count; index++) {
00054     gint x = points[index].x;
00055     gint y = points[index].y;
00056 
00057     if (x < bounds->min_x) {
00058       bounds->min_x = x;
00059     }
00060 
00061     if (y < bounds->min_y) {
00062       bounds->min_y = y;
00063     }
00064 
00065     if (x > bounds->max_x) {
00066       bounds->max_x = x;
00067     }
00068 
00069     if (y > bounds->max_y) {
00070       bounds->max_y = y;
00071     }
00072   }
00073 }
00074 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines