Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
d67046f0
Commit
d67046f0
authored
Sep 16, 2017
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small improvements to stroke simplifying
parent
5f65292d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
UBGraphicsStroke.cpp
src/domain/UBGraphicsStroke.cpp
+13
-17
No files found.
src/domain/UBGraphicsStroke.cpp
View file @
d67046f0
...
...
@@ -244,8 +244,6 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
while
(
b_it
+
1
!=
points
.
end
())
{
qreal
angle
=
qFabs
(
180
-
(
UBGeometryUtils
::
angle
(
it
->
first
,
b_it
->
first
,
(
b_it
+
1
)
->
first
)));
qreal
widthRatio
=
qMax
(
it
->
second
,
b_it
->
second
)
/
qMin
(
it
->
second
,
b_it
->
second
);
if
(
widthRatio
>
thresholdWidthDifference
)
qDebug
()
<<
"Width ratio: "
<<
widthRatio
;
if
(
angle
<
thresholdAngle
&&
widthRatio
<
thresholdWidthDifference
)
b_it
=
points
.
erase
(
b_it
);
...
...
@@ -259,7 +257,8 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
it
=
b_it
;
}
// Next, we iterate over the new points to build the polygons that make up the stroke
// Next, we iterate over the new points to build the polygons that make up the stroke.
// A new polygon is created every time drawCurve is true.
QList
<
UBGraphicsPolygonItem
*>
newPolygons
;
QList
<
strokePoint
>
newStrokePoints
;
...
...
@@ -270,29 +269,26 @@ UBGraphicsStroke* UBGraphicsStroke::simplify()
newStrokePoints
<<
points
[
i
];
// When a polygon is transparent and it overlaps with itself, it is *sometimes* filled incorrectly.
// Limiting the size of the polygons, and creating new ones when the angle between consecutive points is above a
// certain threshold helps mitigate this issue.
// TODO: fix fill issue
// Limiting the size of the polygons, and creating new ones when there is a sharp angle between
// consecutive point helps with two issues:
// 1. When a polygon is transparent and it overlaps with itself, it is *sometimes* filled incorrectly.
// 2. This way of simplifying strokes resuls in sharp, rather than rounded, corners when there is a sharp angle
// in the stroke
if
(
hasAlpha
())
{
if
(
newStrokePoints
.
size
()
>
1
&&
i
<
points
.
size
()
-
1
)
{
qreal
angle
=
qFabs
(
UBGeometryUtils
::
angle
(
points
[
i
-
1
].
first
,
points
[
i
].
first
,
points
[
i
+
1
].
first
));
if
(
angle
>
40
&&
angle
<
320
)
drawCurve
=
true
;
}
if
(
newStrokePoints
.
size
()
%
20
==
0
)
if
(
newStrokePoints
.
size
()
>
1
&&
i
<
points
.
size
()
-
1
)
{
qreal
angle
=
qFabs
(
UBGeometryUtils
::
angle
(
points
[
i
-
1
].
first
,
points
[
i
].
first
,
points
[
i
+
1
].
first
));
if
(
angle
<
150
)
// arbitrary threshold, change if necessary
drawCurve
=
true
;
}
if
(
hasAlpha
()
&&
newStrokePoints
.
size
()
%
20
==
0
)
drawCurve
=
true
;
if
(
drawCurve
)
{
UBGraphicsPolygonItem
*
poly
=
mScene
->
polygonToPolygonItem
(
UBGeometryUtils
::
curveToPolygon
(
newStrokePoints
,
true
,
true
));
//poly->setColor(QColor(rand()%256, rand()%256, rand()%256, poly->brush().color().alpha()));
//poly->setColor(QColor(rand()%256, rand()%256, rand()%256, poly->brush().color().alpha()));
// useful for debugging
// Subtract overlapping polygons if the stroke is translucent
if
(
!
poly
->
brush
().
isOpaque
())
{
foreach
(
UBGraphicsPolygonItem
*
prev
,
newPolygons
)
poly
->
subtract
(
prev
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment