1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA
25 #include "libgeda_priv.h"
27 #ifdef HAVE_LIBDMALLOC
32 /*! \brief Set the contraints for the current page.
33 * \par Function Description
34 * This function will set the current page constraints.
36 * \param [in] toplevel The TOPLEVEL object.
37 * \param [in,out] page The PAGE object to set constraints on.
38 * \param [in] xmin The minimum x coordinate for the page.
39 * \param [in] xmax The maximum x coordinate for the page.
40 * \param [in] ymin The minimum y coordinate for the page.
41 * \param [in] ymax The maximum y coordinate for the page.
43 void set_window(TOPLEVEL
*toplevel
, PAGE
*page
,
44 int xmin
, int xmax
, int ymin
, int ymax
)
54 /* now do the constant setups */
60 page
->to_screen_x_constant
= fs
/ (f1
- f0
);
65 fs
= toplevel
->height
;
66 page
->to_screen_y_constant
= fs
/ (f1
- f0
);
72 page
->to_world_x_constant
= (fw1
- fw0
) / fw
;
77 fw
= toplevel
->height
;
78 page
->to_world_y_constant
= (fw1
- fw0
) / fw
;
82 /*! \brief Rotate a point by an arbitrary angle.
83 * \par Function Description
84 * This function will rotate a point coordinate by an arbitrary angle
85 * and return the new coordinate in the newx and newy parameters.
87 * \param [in] x Input point x coordinate.
88 * \param [in] y Input point y coordinate.
89 * \param [in] angle Angle to rotate in degrees.
90 * \param [out] newx Output point x coordinate.
91 * \param [out] newy Output point y coordinate.
93 void rotate_point(int x
, int y
, int angle
, int *newx
, int *newy
)
95 double costheta
, sintheta
;
103 *newx
= x
* costheta
- y
* sintheta
;
104 *newy
= x
* sintheta
+ y
* costheta
;
107 /*! \brief Rotate point in 90 degree increments only.
108 * \par Function Description
109 * This function takes a point coordinate and rotates it by
110 * 90 degrees at a time. The new point coordinate is returned
113 * \param [in] x Input point x coordinate.
114 * \param [in] y Input point y coordinate.
115 * \param [in] angle Angle to rotate by (90 degree increments only).
116 * \param [out] newx Output point x coordinate.
117 * \param [out] newy Output point y coordinate.
119 void rotate_point_90(int x
, int y
, int angle
, int *newx
, int *newy
)
124 /* I could have used sine/cosine for this, but I want absolute
150 *newx
= x
* costheta
- y
* sintheta
;
151 *newy
= x
* sintheta
+ y
* costheta
;
155 /*! \brief Convert Paper size to World coordinates.
156 * \par Function Description
157 * This function takes the paper size and converts it to
158 * world coordinates. It supports landscape with a fixed aspect ratio.
160 * \param [in] width Paper width. (units?)
161 * \param [in] height Paper height. (units?)
162 * \param [in] border Paper border size. (units?)
163 * \param [out] right Right world coordinate. (units?)
164 * \param [out] bottom Bottom world coordinate. (units?)
166 * \todo Support more modes than just landscape only mode.
168 void PAPERSIZEtoWORLD(int width
, int height
, int border
, int *right
, int *bottom
)
172 aspect
= (float) width
/ (float) height
;
175 printf("%f\n", aspect
);
178 if (aspect
< 1.333333333) {
179 /* is this lrint really needed? */
181 *right
= lrint (width
+border
+ ((height
+border
)*1.33333333 - (width
+border
)));
183 *right
= (int) width
+border
+
184 ((height
+border
)*1.33333333 - (width
+border
));
186 *bottom
= height
+border
;
188 *right
= (int) width
+border
;
189 *bottom
= (int) height
+border
+ ((width
+border
)/1.33333333 - (height
+border
));
193 aspect
= (float) *right
/ (float) *bottom
;
194 printf("%f\n", aspect
);