Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
proj_pt.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
13#include <glib.h>
14
15#include "proj_pt.h"
16#include "svg/stringstream.h"
17
18namespace Proj {
19
20Pt2::Pt2(const char *coord_str) {
21 if (!coord_str) {
22 pt[0] = 0.0;
23 pt[1] = 0.0;
24 pt[2] = 1.0;
25 g_warning ("Coordinate string is empty. Creating default Pt2\n");
26 return;
27 }
28 char **coords = g_strsplit(coord_str, ":", 0);
29 if (coords[0] == nullptr || coords[1] == nullptr || coords[2] == nullptr) {
30 g_strfreev (coords);
31 g_warning ("Malformed coordinate string.\n");
32 return;
33 }
34
35 pt[0] = g_ascii_strtod(coords[0], nullptr);
36 pt[1] = g_ascii_strtod(coords[1], nullptr);
37 pt[2] = g_ascii_strtod(coords[2], nullptr);
38 g_strfreev (coords);
39}
40
41void
43 if (fabs(pt[2]) < 1E-6 || pt[2] == 1.0)
44 return;
45 pt[0] /= pt[2];
46 pt[1] /= pt[2];
47 pt[2] = 1.0;
48}
49
52 if (fabs(pt[2]) < epsilon) {
54 }
55 return Geom::Point (pt[0]/pt[2], pt[1]/pt[2]);
56}
57
58char *
61 os << pt[0] << " : "
62 << pt[1] << " : "
63 << pt[2];
64 return g_strdup(os.str().c_str());
65}
66
67Pt3::Pt3(const char *coord_str) {
68 if (!coord_str) {
69 pt[0] = 0.0;
70 pt[1] = 0.0;
71 pt[2] = 0.0;
72 pt[3] = 1.0;
73 g_warning ("Coordinate string is empty. Creating default Pt2\n");
74 return;
75 }
76 char **coords = g_strsplit(coord_str, ":", 0);
77 if (coords[0] == nullptr || coords[1] == nullptr ||
78 coords[2] == nullptr || coords[3] == nullptr) {
79 g_strfreev (coords);
80 g_warning ("Malformed coordinate string.\n");
81 return;
82 }
83
84 pt[0] = g_ascii_strtod(coords[0], nullptr);
85 pt[1] = g_ascii_strtod(coords[1], nullptr);
86 pt[2] = g_ascii_strtod(coords[2], nullptr);
87 pt[3] = g_ascii_strtod(coords[3], nullptr);
88}
89
90void
92 if (fabs(pt[3]) < 1E-6 || pt[3] == 1.0)
93 return;
94 pt[0] /= pt[3];
95 pt[1] /= pt[3];
96 pt[2] /= pt[3];
97 pt[3] = 1.0;
98}
99
100char *
103 os << pt[0] << " : "
104 << pt[1] << " : "
105 << pt[2] << " : "
106 << pt[3];
107 return g_strdup(os.str().c_str());
108}
109
110} // namespace Proj
111
112/*
113 Local Variables:
114 mode:c++
115 c-file-style:"stroustrup"
116 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117 indent-tabs-mode:nil
118 fill-column:99
119 End:
120*/
121// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :
Two-dimensional point that doubles as a vector.
Definition point.h:66
std::string str() const
char * coord_string()
Definition proj_pt.cpp:59
double pt[3]
Definition proj_pt.h:89
void normalize()
Definition proj_pt.cpp:42
Geom::Point affine()
Definition proj_pt.cpp:51
char * coord_string()
Definition proj_pt.cpp:101
double pt[4]
Definition proj_pt.h:156
void normalize()
Definition proj_pt.cpp:91
constexpr Coord infinity()
Get a value representing infinity.
Definition coord.h:88
Generic auxiliary routines for 3D axes.
const double epsilon
Definition proj_pt.h:21
TODO: insert short description here.