1 /*
2  *	v_centre.cc
3  *	AYM 1998-11-22
4  */
5 
6 
7 /*
8 This file is part of Yadex.
9 
10 Yadex incorporates code from DEU 5.21 that was put in the public domain in
11 1994 by Rapha�l Quinet and Brendon Wyber.
12 
13 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
14 
15 This program is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any later
18 version.
19 
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
26 Place, Suite 330, Boston, MA 02111-1307, USA.
27 */
28 
29 
30 #include "yadex.h"
31 #include "bitvec.h"
32 #include "levels.h"
33 #include "selectn.h"
34 #include "v_centre.h"
35 
36 
37 /*
38  *	centre_of_vertices
39  *	Return the coordinates of the centre of a group of vertices.
40  */
centre_of_vertices(SelPtr list,int * x,int * y)41 void centre_of_vertices (SelPtr list, int *x, int *y)
42 {
43 SelPtr cur;
44 int nitems;
45 long x_sum;
46 long y_sum;
47 
48 x_sum = 0;
49 y_sum = 0;
50 for (nitems = 0, cur = list; cur; cur = cur->next, nitems++)
51    {
52    x_sum += Vertices[cur->objnum].x;
53    y_sum += Vertices[cur->objnum].y;
54    }
55 if (nitems == 0)
56    {
57    *x = 0;
58    *y = 0;
59    }
60 else
61    {
62    *x = (int) (x_sum / nitems);
63    *y = (int) (y_sum / nitems);
64    }
65 }
66 
67 
68 /*
69  *	centre_of_vertices
70  *	Return the coordinates of the centre of a group of vertices.
71  */
centre_of_vertices(const bitvec_c & bv,int & x,int & y)72 void centre_of_vertices (const bitvec_c &bv, int &x, int &y)
73 {
74 long x_sum = 0;
75 long y_sum = 0;
76 int nmax = bv.nelements ();
77 int nvertices = 0;
78 for (int n = 0; n < nmax; n++)
79    {
80    if (bv.get (n))
81       {
82       x_sum += Vertices[n].x;
83       y_sum += Vertices[n].y;
84       nvertices++;
85       }
86    }
87 if (nvertices == 0)
88    {
89    x = 0;
90    y = 0;
91    }
92 else
93    {
94    x = (int) (x_sum / nvertices);
95    y = (int) (y_sum / nvertices);
96    }
97 }
98 
99 
100