Krita Source Code Documentation
Loading...
Searching...
No Matches
KoPolygonUtils.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2011 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "KoPolygonUtils.h"
8#include <boost/polygon/polygon.hpp>
9#include <QPolygon>
10#include <QList>
11
12namespace boost { namespace polygon {
13 // QPoint wrapper
14 template <>
15 struct geometry_concept<QPoint> {
16 typedef point_concept type;
17 };
18
19 template <>
20 struct point_traits<QPoint> {
21 typedef int coordinate_type;
22
23 static inline coordinate_type get(const QPoint& point,
24 orientation_2d orient) {
25 if(orient == HORIZONTAL)
26 return point.x();
27 return point.y();
28 }
29 };
30
31 template <>
32 struct point_mutable_traits<QPoint> {
33 static inline void set(QPoint& point, orientation_2d orient, int value) {
34 if(orient == HORIZONTAL)
35 point.rx() = value;
36 else
37 point.ry() = value;
38 }
39 static inline QPoint construct(int x_value, int y_value) {
40 QPoint retval;
41 retval.rx() = x_value;
42 retval.ry() = y_value;
43 return retval;
44 }
45 };
46
47 // QPolygon wrapper
48 template <>
49 struct geometry_concept<QPolygon>{ typedef polygon_concept type; };
50
51 template <>
52 struct polygon_traits<QPolygon> {
53 typedef int coordinate_type;
54 typedef QPolygon::const_iterator iterator_type;
55 typedef QPoint point_type;
56
57 static inline iterator_type begin_points(const QPolygon& t) {
58 return t.begin();
59 }
60
61 static inline iterator_type end_points(const QPolygon& t) {
62 return t.end();
63 }
64
65 static inline std::size_t size(const QPolygon& t) {
66 return t.size();
67 }
68
69 static inline winding_direction winding(const QPolygon& t) {
70 Q_UNUSED(t);
71 return unknown_winding;
72 }
73 };
74
75 template <>
76 struct polygon_mutable_traits<QPolygon> {
77 template <typename iT>
78 static inline QPolygon& set_points(QPolygon& t,
79 iT input_begin, iT input_end) {
80 t.clear();
81
82 for(iT iter = input_begin; iter != input_end; iter++) {
83 t.push_back(QPoint(iter->x(), iter->y()));
84 }
85 return t;
86 }
87
88 };
89} }
90
91typedef std::vector<QPolygon> PolygonSet;
92
93
94
95QPolygon KoPolygonUtils::offsetPolygon(const QPolygon &polygon, int offset, bool rounded, int circleSegments)
96{
97 PolygonSet polygonSet;
98 polygonSet.push_back(polygon);
99 boost::polygon::resize(polygonSet, offset, rounded, circleSegments);
100 return polygonSet[0];
101}
102
103QList<QPolygon> KoPolygonUtils::offsetPolygons(const QList<QPolygon> polygons, int offset, bool rounded, int circleSegments)
104{
105 PolygonSet polygonSet;
106 Q_FOREACH(QPolygon polygon, polygons) {
107 polygonSet.push_back(polygon);
108 }
109 boost::polygon::resize(polygonSet, offset, rounded, circleSegments);
110
111 QList<QPolygon> finalPolygons;
112 for (int i=0; i < int(polygonSet.size()); i++) {
113 finalPolygons.append(polygonSet.at(i));
114 }
115 return finalPolygons;
116}
117
float value(const T *src, size_t ch)
std::vector< QPolygon > PolygonSet
static QPolygon offsetPolygon(const QPolygon &polygon, int offset, bool rounded=true, int circleSegments=16)
offsetPolygon This offsets a single polygon, using the winding/nonzero fill-rule to determine inside ...
static QList< QPolygon > offsetPolygons(const QList< QPolygon > polygons, int offset, bool rounded=true, int circleSegments=16)
static void set(QPoint &point, orientation_2d orient, int value)
static QPoint construct(int x_value, int y_value)
static coordinate_type get(const QPoint &point, orientation_2d orient)
static QPolygon & set_points(QPolygon &t, iT input_begin, iT input_end)
static std::size_t size(const QPolygon &t)
static iterator_type begin_points(const QPolygon &t)
static iterator_type end_points(const QPolygon &t)
static winding_direction winding(const QPolygon &t)