libgeda

m_circle.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 
00026 #include <config.h>
00027 #include <math.h>
00028 #include <stdio.h>
00029 
00030 #include "libgeda_priv.h"
00031 
00032 #ifdef HAVE_LIBDMALLOC
00033 #include <dmalloc.h>
00034 #endif
00035 
00036 
00049 double m_circle_shortest_distance (CIRCLE *circle, int x, int y, int solid)
00050 {
00051   double shortest_distance;
00052   double distance_to_center;
00053   double dx, dy;
00054 
00055   g_return_val_if_fail (circle != NULL, G_MAXDOUBLE);
00056 
00057   dx = ((double)x) - ((double)circle->center_x);
00058   dy = ((double)y) - ((double)circle->center_y);
00059 
00060   distance_to_center = sqrt ((dx * dx) + (dy * dy));
00061 
00062   if (solid) {
00063     shortest_distance = max (distance_to_center - circle->radius, 0);
00064   } else {
00065     shortest_distance = fabs (distance_to_center - circle->radius);
00066   }
00067 
00068   return shortest_distance;
00069 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines