1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <libgeda_priv.h>
23 /*! \brief Initialize a bounds by setting it to empty
25 * \param bounds [in] The bounds to set to empty. This parameter must not
28 void m_bounds_init(BOUNDS
*bounds
)
30 bounds
->min_x
= G_MAXINT
;
31 bounds
->min_y
= G_MAXINT
;
32 bounds
->max_x
= G_MININT
;
33 bounds
->max_y
= G_MININT
;
36 /*! \brief Calculate the bounds of a set of points
38 * For an empty set of points, this function returns an empty bounds.
40 * \param bounds [out] The bounds of the given set of points. The bounds
41 * does not need to be initialized before calling this function, but this
42 * parameter must not be NULL.
43 * \param points [in] The given set of points. If the count is greater than
44 * zero, this parameter must not be NULL.
45 * \param count [in] The number of points in the set.
47 void m_bounds_of_points(BOUNDS
*bounds
, sPOINT points
[], gint count
)
51 m_bounds_init(bounds
);
53 for (index
=0; index
<count
; index
++) {
54 gint x
= points
[index
].x
;
55 gint y
= points
[index
].y
;
57 if (x
< bounds
->min_x
) {
61 if (y
< bounds
->min_y
) {
65 if (x
> bounds
->max_x
) {
69 if (y
> bounds
->max_y
) {