FORS Pipeline Reference Manual  4.12.5
fors_point.c
1 /* $Id: fors_point.c,v 1.3 2010-09-14 07:49:30 cizzo Exp $
2  *
3  * This file is part of the FORS library
4  * Copyright (C) 2002-2010 European Southern Observatory
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author: cizzo $
23  * $Date: 2010-09-14 07:49:30 $
24  * $Revision: 1.3 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <fors_point.h>
33 
34 #include <fors_utils.h>
35 
42 #define LIST_DEFINE
43 #undef LIST_ELEM
44 #define LIST_ELEM fors_point
45 #include <list.h>
46 
53 fors_point *fors_point_new(double x, double y)
54 {
55  fors_point *p = cpl_malloc(sizeof(*p));
56 
57  p->x = x;
58  p->y = y;
59 
60  return p;
61 }
62 
63 #undef cleanup
64 #define cleanup
65 
70 fors_point *fors_point_duplicate(const fors_point *p)
71 {
72  fors_point *p2 = NULL;
73 
74  assure( p != NULL, return p2, NULL );
75 
76  p2 = cpl_malloc(sizeof(*p2));
77  p2->x = p->x;
78  p2->y = p->y;
79 
80  return p2;
81 }
82 
87 void fors_point_delete(fors_point **p)
88 {
89  if (p && *p) {
90  cpl_free(*p); *p = NULL;
91  }
92  return;
93 }
94 
95 #undef cleanup
96 #define cleanup
97 
103 double fors_point_distsq(const fors_point *p,
104  const fors_point *q)
105 {
106  assure( p != NULL, return -1, NULL );
107  assure( q != NULL, return -1, NULL );
108 
109  return (
110  (p->x - q->x)*(p->x - q->x) +
111  (p->y - q->y)*(p->y - q->y));
112 }
113 
120 bool fors_point_equal(const fors_point *p,
121  const fors_point *q)
122 {
123  return fors_point_distsq(p, q) <= DBL_EPSILON;
124 }
125 
126 
fors_point * fors_point_new(double x, double y)
Constructor.
Definition: fors_point.c:53
#define assure(EXPR)
Definition: list.c:101
void fors_point_delete(fors_point **p)
Destructor.
Definition: fors_point.c:87
fors_point * fors_point_duplicate(const fors_point *p)
Copy constructor.
Definition: fors_point.c:70
bool fors_point_equal(const fors_point *p, const fors_point *q)
Equality.
Definition: fors_point.c:120
double fors_point_distsq(const fors_point *p, const fors_point *q)
Metric.
Definition: fors_point.c:103