libgeda

m_basic.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 
00022 #include <stdio.h>
00023 #include <math.h>
00024 
00025 #include "libgeda_priv.h"
00026 
00027 #ifdef HAVE_LIBDMALLOC
00028 #include <dmalloc.h>
00029 #endif
00030 
00031 
00043 void set_window(TOPLEVEL *toplevel, PAGE *page,
00044                 int xmin, int xmax, int ymin, int ymax)
00045 {
00046   double fs,f0,f1;
00047   double fw0,fw1,fw;
00048 
00049   page->left   = xmin;
00050   page->right  = xmax;
00051   page->top    = ymin; 
00052   page->bottom = ymax;
00053 
00054   /* now do the constant setups */
00055 
00056   /* pix_x */
00057   f0 = page->left;
00058   f1 = page->right;
00059   fs = toplevel->width;
00060   page->to_screen_x_constant = fs / (f1 - f0);
00061 
00062   /* pix_y */
00063   f0 = page->top;
00064   f1 = page->bottom;
00065   fs = toplevel->height;
00066   page->to_screen_y_constant = fs / (f1 - f0); 
00067 
00068   /* mil_x */
00069   fw1 = page->right;
00070   fw0 = page->left;
00071   fw  = toplevel->width;
00072   page->to_world_x_constant = (fw1 - fw0) / fw;
00073 
00074   /* mil_y */
00075   fw1 = page->bottom;
00076   fw0 = page->top;
00077   fw  = toplevel->height;
00078   page->to_world_y_constant = (fw1 - fw0) / fw;
00079 }
00080 
00081 
00093 void rotate_point(int x, int y, int angle, int *newx, int *newy)
00094 {
00095   double costheta, sintheta;
00096   double rad;
00097 
00098   rad = angle*M_PI/180;
00099 
00100   costheta = cos(rad);
00101   sintheta = sin(rad);
00102 
00103   *newx = x * costheta - y * sintheta;
00104   *newy = x * sintheta + y * costheta;
00105 }
00106 
00119 void rotate_point_90(int x, int y, int angle, int *newx, int *newy)
00120 {
00121   double costheta=1; 
00122   double sintheta=0;
00123 
00124   /* I could have used sine/cosine for this, but I want absolute 
00125    * accuracy */
00126   switch(angle) {
00127 
00128     case(0):
00129       *newx = x;
00130       *newy = y; 
00131       return;
00132       break;
00133         
00134     case(90):
00135       costheta = 0;
00136       sintheta = 1;
00137       break;
00138         
00139     case(180):
00140       costheta = -1;
00141       sintheta = 0;
00142       break;
00143         
00144     case(270):
00145       costheta = 0;
00146       sintheta = -1;
00147       break;
00148   }
00149 
00150   *newx = x * costheta - y * sintheta;
00151   *newy = x * sintheta + y * costheta;
00152 }
00153 
00154 
00168 void PAPERSIZEtoWORLD(int width, int height, int border, int *right, int *bottom)
00169 {
00170   float aspect;
00171 
00172   aspect = (float) width / (float) height;
00173 
00174 #if DEBUG   
00175   printf("%f\n", aspect);
00176 #endif
00177 
00178   if (aspect < 1.333333333) {
00179     /* is this lrint really needed? */
00180 #ifdef HAVE_LRINT
00181     *right = lrint (width+border + ((height+border)*1.33333333 - (width+border)));
00182 #else 
00183     *right = (int) width+border + 
00184       ((height+border)*1.33333333 - (width+border));
00185 #endif
00186     *bottom = height+border;
00187   } else {
00188     *right = (int) width+border;    
00189     *bottom = (int) height+border + ((width+border)/1.33333333 - (height+border));
00190   }
00191     
00192 #if DEBUG
00193   aspect = (float) *right / (float) *bottom;
00194   printf("%f\n", aspect);
00195 #endif
00196 
00197 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines