about summary refs log tree commit diff
path: root/converter/other/pamtosvg/point.c
blob: 0e10b6b60068c733e7cf4c259d2e453db916bfd6 (plain) (blame)
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
#include <stdbool.h>
#include <math.h>

#include "epsilon.h"

#include "point.h"



/* Operations on points with real coordinates.  It is not orthogonal,
   but more convenient, to have the subtraction operator return a
   vector, and the addition operator return a point.
*/



Point
point_make(float const x,
           float const y,
           float const z) {

    Point retval;

    retval.x = x;
    retval.y = y;
    retval.z = z;

    return retval;
}



bool
point_equal(Point const comparand,
            Point const comparator) {

    return
        epsilon_equal(comparand.x, comparator.x)
        &&
        epsilon_equal(comparand.y, comparator.y)
        &&
        epsilon_equal(comparand.z, comparator.z)
        ;
}



Point
point_sum(Point const coord1,
          Point const coord2) {

    Point retval;

    retval.x = coord1.x + coord2.x;
    retval.y = coord1.y + coord2.y;
    retval.z = coord1.z + coord2.z;

    return retval;
}



Point
point_scaled(Point const coord,
             float const r) {

    Point retval;

    retval.x = coord.x * r;
    retval.y = coord.y * r;
    retval.z = coord.z * r;

    return retval;
}



float
point_distance(Point const p1,
               Point const p2) {
/*----------------------------------------------------------------------------
  Return the Euclidean distance between 'p1' and 'p2'.
-----------------------------------------------------------------------------*/
    float const x = p1.x - p2.x, y = p1.y - p2.y, z = p1.z - p2.z;

    return (float) sqrt(SQR(x) + SQR(y) + SQR(z));
}