5
* 3x4 transformation matrix to map points from projective 3-space into the projective plane
8
* Maximilian Albert <Anhalter42@gmx.de>
10
* Copyright (C) 2007 Authors
12
* Released under GNU GPL, read the file 'COPYING' for more information
15
#include "libnr/nr-point.h"
16
#include "libnr/nr-values.h"
21
const double epsilon = 1E-6;
23
// TODO: Catch the case when the constructors are called with only zeros
26
Pt2 () { pt[0] = 0; pt[1] = 0; pt[2] = 1.0; } // we default to (0 : 0 : 1)
27
Pt2 (double x, double y, double w) { pt[0] = x; pt[1] = y; pt[2] = w; }
28
Pt2 (NR::Point const &point) { pt[0] = point[NR::X]; pt[1] = point[NR::Y]; pt[2] = 1; }
29
Pt2 (const gchar *coord_str);
31
inline double operator[] (unsigned int index) const {
32
if (index > 2) { return NR_HUGE; }
35
inline double &operator[] (unsigned int index) {
36
// FIXME: How should we handle wrong indices?
37
//if (index > 2) { return NR_HUGE; }
40
inline bool operator== (Pt2 &rhs) {
43
return (fabs(pt[0] - rhs.pt[0]) < epsilon &&
44
fabs(pt[1] - rhs.pt[1]) < epsilon &&
45
fabs(pt[2] - rhs.pt[2]) < epsilon);
47
inline bool operator!= (Pt2 &rhs) {
48
return !((*this) == rhs);
51
/*** For convenience, we define addition/subtraction etc. as "affine" operators (i.e.,
52
the result for finite points is the same as if the affine points were addes ***/
53
inline Pt2 &operator+(Pt2 &rhs) const {
54
Pt2 *result = new Pt2 (*this);
57
for ( unsigned i = 0 ; i < 2 ; ++i ) {
58
result->pt[i] += rhs.pt[i];
63
inline Pt2 &operator-(Pt2 &rhs) const {
64
Pt2 *result = new Pt2 (*this);
67
for ( unsigned i = 0 ; i < 2 ; ++i ) {
68
result->pt[i] -= rhs.pt[i];
73
inline Pt2 &operator*(double const s) const {
74
Pt2 *result = new Pt2 (*this);
76
for ( unsigned i = 0 ; i < 2 ; ++i ) {
84
inline bool is_finite() { return pt[2] != 0; } // FIXME: Should we allow for some tolerance?
85
gchar *coord_string();
86
inline void print(gchar const *s) const { g_print ("%s(%8.2f : %8.2f : %8.2f)\n", s, pt[0], pt[1], pt[2]); }
95
Pt3 () { pt[0] = 0; pt[1] = 0; pt[2] = 0; pt[3] = 1.0; } // we default to (0 : 0 : 0 : 1)
96
Pt3 (double x, double y, double z, double w) { pt[0] = x; pt[1] = y; pt[2] = z; pt[3] = w; }
97
Pt3 (const gchar *coord_str);
99
inline bool operator== (Pt3 &rhs) {
102
return (fabs(pt[0] - rhs.pt[0]) < epsilon &&
103
fabs(pt[1] - rhs.pt[1]) < epsilon &&
104
fabs(pt[2] - rhs.pt[2]) < epsilon &&
105
fabs(pt[3] - rhs.pt[3]) < epsilon);
108
/*** For convenience, we define addition/subtraction etc. as "affine" operators (i.e.,
109
the result for finite points is the same as if the affine points were addes ***/
110
inline Pt3 &operator+(Pt3 &rhs) const {
111
Pt3 *result = new Pt3 (*this);
114
for ( unsigned i = 0 ; i < 3 ; ++i ) {
115
result->pt[i] += rhs.pt[i];
120
inline Pt3 &operator-(Pt3 &rhs) const {
121
Pt3 *result = new Pt3 (*this);
124
for ( unsigned i = 0 ; i < 3 ; ++i ) {
125
result->pt[i] -= rhs.pt[i];
130
inline Pt3 &operator*(double const s) const {
131
Pt3 *result = new Pt3 (*this);
133
for ( unsigned i = 0 ; i < 3 ; ++i ) {
139
inline double operator[] (unsigned int index) const {
140
if (index > 3) { return NR_HUGE; }
143
inline double &operator[] (unsigned int index) {
144
// FIXME: How should we handle wrong indices?
145
//if (index > 3) { return NR_HUGE; }
149
inline bool is_finite() { return pt[3] != 0; } // FIXME: Should we allow for some tolerance?
150
gchar *coord_string();
151
inline void print(gchar const *s) const {
152
g_print ("%s(%8.2f : %8.2f : %8.2f : %8.2f)\n", s, pt[0], pt[1], pt[2], pt[3]);
161
#endif /* __PROJ_PT_H__ */
166
c-file-style:"stroustrup"
167
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :