~centralelyon2010/inkscape/imagelinks2

4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
1
#define __PROJ_PT_C__
2
3
/*
4
 * 3x4 transformation matrix to map points from projective 3-space into the projective plane
5
 *
6
 * Authors:
7
 *   Maximilian Albert <Anhalter42@gmx.de>
8
 *
9
 * Copyright (C) 2007  Authors
10
 *
11
 * Released under GNU GPL, read the file 'COPYING' for more information
12
 */
13
14
#include "proj_pt.h"
15
#include "svg/stringstream.h"
16
17
namespace Proj {
18
19
Pt2::Pt2(const gchar *coord_str) {
20
    if (!coord_str) {
21
        pt[0] = 0.0;
22
        pt[1] = 0.0;
23
        pt[2] = 1.0;
24
        g_warning ("Coordinate string is empty. Creating default Pt2\n");
25
        return;
26
    }
27
    gchar **coords = g_strsplit(coord_str, ":", 0);
28
    if (coords[0] == NULL || coords[1] == NULL || coords[2] == NULL) {
29
        g_strfreev (coords);
30
        g_warning ("Malformed coordinate string.\n");
31
        return;
32
    }
33
34
    pt[0] = g_ascii_strtod(coords[0], NULL);
35
    pt[1] = g_ascii_strtod(coords[1], NULL);
36
    pt[2] = g_ascii_strtod(coords[2], NULL);
37
}
38
39
void
40
Pt2::normalize() {
41
    if (fabs(pt[2]) < 1E-6 || pt[2] == 1.0)
42
        return;
43
    pt[0] /= pt[2];
44
    pt[1] /= pt[2];
45
    pt[2] = 1.0;
46
}
47
6837 by cilix42
More NR::Point ==> Geom::Point
48
Geom::Point
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
49
Pt2::affine() {
50
  if (fabs(pt[2]) < epsilon) {
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
51
    return Geom::Point (Geom::infinity(), Geom::infinity());
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
52
  }
6837 by cilix42
More NR::Point ==> Geom::Point
53
  return Geom::Point (pt[0]/pt[2], pt[1]/pt[2]);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
54
}
55
56
gchar *
57
Pt2::coord_string() {
58
    Inkscape::SVGOStringStream os;
59
    os << pt[0] << " : "
60
       << pt[1] << " : "
61
       << pt[2];
62
    return g_strdup(os.str().c_str());
63
}
64
65
Pt3::Pt3(const gchar *coord_str) {
66
    if (!coord_str) {
67
        pt[0] = 0.0;
68
        pt[1] = 0.0;
69
        pt[2] = 0.0;
70
        pt[3] = 1.0;
71
        g_warning ("Coordinate string is empty. Creating default Pt2\n");
72
        return;
73
    }
74
    gchar **coords = g_strsplit(coord_str, ":", 0);
75
    if (coords[0] == NULL || coords[1] == NULL ||
76
        coords[2] == NULL || coords[3] == NULL) {
77
        g_strfreev (coords);
78
        g_warning ("Malformed coordinate string.\n");
79
        return;
80
    }
81
82
    pt[0] = g_ascii_strtod(coords[0], NULL);
83
    pt[1] = g_ascii_strtod(coords[1], NULL);
84
    pt[2] = g_ascii_strtod(coords[2], NULL);
85
    pt[3] = g_ascii_strtod(coords[3], NULL);
86
}
87
88
void
89
Pt3::normalize() {
90
    if (fabs(pt[3]) < 1E-6 || pt[3] == 1.0)
91
        return;
92
    pt[0] /= pt[3];
93
    pt[1] /= pt[3];
94
    pt[2] /= pt[3];
95
    pt[3] = 1.0;
96
}
97
98
gchar *
99
Pt3::coord_string() {
100
    Inkscape::SVGOStringStream os;
101
    os << pt[0] << " : "
102
       << pt[1] << " : "
103
       << pt[2] << " : "
104
       << pt[3];
105
    return g_strdup(os.str().c_str());
106
}
107
108
} // namespace Proj
109
110
/*
111
  Local Variables:
112
  mode:c++
113
  c-file-style:"stroustrup"
114
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
115
  indent-tabs-mode:nil
116
  fill-column:99
117
  End:
118
*/
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
119
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :