FORS Pipeline Reference Manual 4.9.9
|
00001 /* $Id: fors_point.c,v 1.3 2010/09/14 07:49:30 cizzo Exp $ 00002 * 00003 * This file is part of the FORS library 00004 * Copyright (C) 2002-2010 European Southern Observatory 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 St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 /* 00022 * $Author: cizzo $ 00023 * $Date: 2010/09/14 07:49:30 $ 00024 * $Revision: 1.3 $ 00025 * $Name: fors-4_9_9 $ 00026 */ 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include <config.h> 00030 #endif 00031 00032 #include <fors_point.h> 00033 00034 #include <fors_utils.h> 00035 00042 #define LIST_DEFINE 00043 #undef LIST_ELEM 00044 #define LIST_ELEM fors_point 00045 #include <list.h> 00046 00053 fors_point *fors_point_new(double x, double y) 00054 { 00055 fors_point *p = cpl_malloc(sizeof(*p)); 00056 00057 p->x = x; 00058 p->y = y; 00059 00060 return p; 00061 } 00062 00063 #undef cleanup 00064 #define cleanup 00065 00070 fors_point *fors_point_duplicate(const fors_point *p) 00071 { 00072 fors_point *p2 = NULL; 00073 00074 assure( p != NULL, return p2, NULL ); 00075 00076 p2 = cpl_malloc(sizeof(*p2)); 00077 p2->x = p->x; 00078 p2->y = p->y; 00079 00080 return p2; 00081 } 00082 00087 void fors_point_delete(fors_point **p) 00088 { 00089 if (p && *p) { 00090 cpl_free(*p); *p = NULL; 00091 } 00092 return; 00093 } 00094 00095 #undef cleanup 00096 #define cleanup 00097 00103 double fors_point_distsq(const fors_point *p, 00104 const fors_point *q) 00105 { 00106 assure( p != NULL, return -1, NULL ); 00107 assure( q != NULL, return -1, NULL ); 00108 00109 return ( 00110 (p->x - q->x)*(p->x - q->x) + 00111 (p->y - q->y)*(p->y - q->y)); 00112 } 00113 00120 bool fors_point_equal(const fors_point *p, 00121 const fors_point *q) 00122 { 00123 return fors_point_distsq(p, q) <= DBL_EPSILON; 00124 } 00125 00126