Debian Codegraph @

src/lib/CDRTypes.cpp

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libcdr project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #include "CDRTypes.h"
11
12 #include "CDRPath.h"
13
14 void libcdr::CDRPolygon::create(libcdr::CDRPath &path) const
15 {
16 if (m_numAngles == 0)
17 return;
18
19 libcdr::CDRPath tmpPath(path);
20 double step = 2*M_PI / (double)m_numAngles;
21 if (m_nextPoint && m_numAngles % m_nextPoint)
22 {
23 libcdr::CDRTransform tmpTrafo(cos(m_nextPoint*step), sin(m_nextPoint*step), 0.0, -sin(m_nextPoint*step), cos(m_nextPoint*step), 0.0);
24 for (unsigned i = 1; i < m_numAngles; ++i)
25 {
26 tmpPath.transform(tmpTrafo);
27 path.appendPath(tmpPath);
28 }
29 }
30 else
31 {
32 libcdr::CDRTransform tmpTrafo(cos(m_nextPoint*step), sin(m_nextPoint*step), 0.0, -sin(m_nextPoint*step), cos(m_nextPoint*step), 0.0);
33 libcdr::CDRTransform tmpShift(cos(step), sin(step), 0.0, -sin(step), cos(step), 0.0);
34 for (unsigned i = 0; i < m_nextPoint; ++i)
35 {
36 if (i)
37 {
38 tmpPath.transform(tmpShift);
39 path.appendPath(tmpPath);
40 }
41 for (unsigned j=1; j < m_numAngles / m_nextPoint; ++j)
42 {
43 tmpPath.transform(tmpTrafo);
44 path.appendPath(tmpPath);
45 }
46 path.appendClosePath();
47 }
48 }
49 path.appendClosePath();
50 libcdr::CDRTransform trafo(m_rx, 0.0, m_cx, 0.0, m_ry, m_cy);
51 path.transform(trafo);
52 }
53
54 void libcdr::CDRSplineData::create(libcdr::CDRPath &path) const
55 {
56 if (points.empty() || knotVector.empty())
57 return;
58 path.appendMoveTo(points[0].first, points[0].second);
59 std::vector<std::pair<double, double> > tmpPoints;
60 tmpPoints.push_back(points[0]);
61 for (unsigned i = 1; i<points.size() && i<knotVector.size(); ++i)
62 {
63 tmpPoints.push_back(points[i]);
64 if (knotVector[i])
65 {
66 if (tmpPoints.size() == 2)
67 path.appendLineTo(tmpPoints[1].first, tmpPoints[1].second);
68 else if (tmpPoints.size() == 3)
69 path.appendQuadraticBezierTo(tmpPoints[1].first, tmpPoints[1].second,
70 tmpPoints[2].first, tmpPoints[2].second);
71 else
72 path.appendSplineTo(tmpPoints);
73 tmpPoints.clear();
74 tmpPoints.push_back(points[i]);
75 }
76 }
77 if (tmpPoints.size() == 2)
78 path.appendLineTo(tmpPoints[1].first, tmpPoints[1].second);
79 else if (tmpPoints.size() == 3)
80 path.appendQuadraticBezierTo(tmpPoints[1].first, tmpPoints[1].second,
81 tmpPoints[2].first, tmpPoints[2].second);
82 else if (tmpPoints.size() > 3)
83 path.appendSplineTo(tmpPoints);
84 }
85
86
87 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */