util.C

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 #include "util.h"
00029 
00030 double AutoSkl(double dl){
00031   double dp=floor(log10(dl));
00032   if(dp!=0.)
00033     dl/=pow(10.,dp);
00034   if(dl>4) dl=5;
00035   else if(dl>1) dl=2;
00036   else dl=1;
00037   if(dp!=0.)
00038     dl*=pow(10.,dp);
00039   return dl;
00040 }
00041 
00042 double AutoNext(double x0, double dl){
00043   return(ceil(x0/dl)*dl);
00044 }
00045 
00046 void hsv2rgb(SPACOLOR *c){
00047   double i,f,h,m,n,k,v;
00048   if(c->s == 0.)
00049     c->r = c->g = c->b = c->v;
00050   else{
00051     if(c->h >= 360.) h=0.;
00052     else h = c->h/60.;
00053     i = floor(h);
00054     v = c->v;
00055     f = h-i;
00056     m = v*(1.-c->s);
00057     n = v*(1.-c->s*f);
00058     k = v*(1.-c->s*(1.-f));
00059     switch((int)h){
00060     case 0: c->r = v; c->g = k; c->b = m; break;
00061     case 1: c->r = n; c->g = v; c->b = m; break;
00062     case 2: c->r = m; c->g = v; c->b = k; break;
00063     case 3: c->r = m; c->g = n; c->b = v; break;
00064     case 4: c->r = k; c->g = m; c->b = v; break;
00065     case 5: c->r = v; c->g = m; c->b = n; break;
00066     }
00067   }
00068 }

Generated on Sat Apr 1 09:04:05 2006 for GXSM by  doxygen 1.4.6