-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointops.c
103 lines (80 loc) · 1.99 KB
/
pointops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Ken Clarkson wrote this. Copyright (c) 1995 by AT&T..
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#include <float.h>
#include <math.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "points.h"
int pdim; /* point dimension */
#define NEARZERO(d) ((d) < FLT_EPSILON && (d) > -FLT_EPSILON)
Coord maxdist(int dim, point p1, point p2) {
Coord x,y,
d = 0;
int i = dim;
while (i--) {
x = *p1++;
y = *p2++;
d += (x<y) ? y-x : x-y ;
}
return d;
}
void print_point(FILE *F, int dim, point p) {
int j;
if (!p) {
fprintf(F, "NULL");
return;
}
for (j=0;j<dim;j++) fprintf(F, "%g ", *p++);
}
void print_point_int(FILE *F, int dim, point p) {
int j;
if (!p) {
fprintf(F, "NULL");
return;
}
for (j=0;j<dim;j++) fprintf(F, "%.20g ", *p++);
}
static int scale(int dim, point p) {
Coord max = 0;
int i;
Coord abs,val;
for (i=0;i<dim;i++) {
val = p[i];
abs = (val > 0) ? val: -val;
max = (abs > max) ? abs : max;
}
if (max< 100*DBL_EPSILON) {
fprintf(stderr, "fails to scale: ");
print_point(stderr, dim,p);fflush(stderr);
fprintf(stderr, "\n");
return 1;
}
for (i=0;i<dim;i++) p[i] /= max;
return 0;
}
/*
static int normalize(int dim, point p) {
Coord norm;
int i;
norm = norm2(dim,p);
if (norm < 3*FLT_EPSILON) {
fprintf(stderr, "fails to normalize: ");
print_point(dim,p);fflush(stdout);
fprintf(stderr, "\n");
return 1;
}
for (i=0;i<dim;i++) p[i] /= norm;
return 0;
}
*/