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
1a075c05
Commit
1a075c05
authored
7 years ago
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved bezier calculations to UBGeometryUtils
-> also deleted obsolete UBInterpolator classes
parent
123ebf1d
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
52 additions
and
120 deletions
+52
-120
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+5
-6
UBGraphicsStroke.cpp
src/domain/UBGraphicsStroke.cpp
+14
-10
UBGraphicsStroke.h
src/domain/UBGraphicsStroke.h
+1
-2
UBGeometryUtils.cpp
src/frameworks/UBGeometryUtils.cpp
+28
-0
UBGeometryUtils.h
src/frameworks/UBGeometryUtils.h
+2
-0
UBInterpolator.cpp
src/frameworks/UBInterpolator.cpp
+0
-53
UBInterpolator.h
src/frameworks/UBInterpolator.h
+0
-45
frameworks.pri
src/frameworks/frameworks.pri
+2
-4
No files found.
src/domain/UBGraphicsScene.cpp
View file @
1a075c05
...
@@ -37,7 +37,6 @@
...
@@ -37,7 +37,6 @@
#include "frameworks/UBGeometryUtils.h"
#include "frameworks/UBGeometryUtils.h"
#include "frameworks/UBPlatformUtils.h"
#include "frameworks/UBPlatformUtils.h"
#include "frameworks/UBInterpolator.h"
#include "core/UBApplication.h"
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "core/UBSettings.h"
...
@@ -552,13 +551,13 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
...
@@ -552,13 +551,13 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
drawLineTo
(
position
,
width
,
true
);
drawLineTo
(
position
,
width
,
true
);
}
}
else
{
else
{
UBInterpolator
::
InterpolationMethod
interpolator
=
UBInterpolator
::
NoInterpolation
;
bool
interpolate
=
false
;
if
((
currentTool
==
UBStylusTool
::
Pen
&&
UBSettings
::
settings
()
->
boardInterpolatePenStrokes
->
get
().
toBool
())
if
((
currentTool
==
UBStylusTool
::
Pen
&&
UBSettings
::
settings
()
->
boardInterpolatePenStrokes
->
get
().
toBool
())
||
(
currentTool
==
UBStylusTool
::
Marker
&&
UBSettings
::
settings
()
->
boardInterpolateMarkerStrokes
->
get
().
toBool
()))
||
(
currentTool
==
UBStylusTool
::
Marker
&&
UBSettings
::
settings
()
->
boardInterpolateMarkerStrokes
->
get
().
toBool
()))
{
{
interpolat
or
=
UBInterpolator
::
Bezier
;
interpolat
e
=
true
;
}
}
...
@@ -572,14 +571,14 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
...
@@ -572,14 +571,14 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
mDistanceFromLastStrokePoint
+=
distance
;
mDistanceFromLastStrokePoint
+=
distance
;
if
(
mDistanceFromLastStrokePoint
>
MIN_DISTANCE
)
{
if
(
mDistanceFromLastStrokePoint
>
MIN_DISTANCE
)
{
QList
<
QPair
<
QPointF
,
qreal
>
>
newPoints
=
mCurrentStroke
->
addPoint
(
scenePos
,
width
,
interpolat
or
);
QList
<
QPair
<
QPointF
,
qreal
>
>
newPoints
=
mCurrentStroke
->
addPoint
(
scenePos
,
width
,
interpolat
e
);
if
(
newPoints
.
length
()
>
1
)
if
(
newPoints
.
length
()
>
1
)
drawCurve
(
newPoints
);
drawCurve
(
newPoints
);
mDistanceFromLastStrokePoint
=
0
;
mDistanceFromLastStrokePoint
=
0
;
}
}
if
(
interpolat
or
==
UBInterpolator
::
Bezier
)
{
if
(
interpolat
e
)
{
// Bezier curves aren't drawn all the way to the scenePos (they stop halfway between the previous and
// Bezier curves aren't drawn all the way to the scenePos (they stop halfway between the previous and
// current scenePos), so we add a line from the last drawn position in the stroke and the
// current scenePos), so we add a line from the last drawn position in the stroke and the
// scenePos, to make the drawing feel more responsive. This line is then deleted if a new segment is
// scenePos, to make the drawing feel more responsive. This line is then deleted if a new segment is
...
...
This diff is collapsed.
Click to expand it.
src/domain/UBGraphicsStroke.cpp
View file @
1a075c05
...
@@ -77,9 +77,17 @@ QList<UBGraphicsPolygonItem*> UBGraphicsStroke::polygons() const
...
@@ -77,9 +77,17 @@ QList<UBGraphicsPolygonItem*> UBGraphicsStroke::polygons() const
/**
/**
* @brief Add a point to the curve, interpolating extra points if required
* @brief Add a point to the curve, interpolating extra points if required
* @return The points (or point, if none were interpolated) that were added
* @param point The position of the point to add
* @param width The width of the stroke at that point.
* @param interpolate If true, a Bézier curve will be drawn rather than a straight line
* @return A list containing the last point drawn plus the point(s) that were added
*
* This method should be called when a new point is given by the input method (mouse, pen or other), and the points that are returned
* should be used to draw the actual stroke on-screen. This is because if interpolation (bézier curves) are to be used, the points to draw
* do not correspond to the points that were given by the input method.
*
*/
*/
QList
<
QPair
<
QPointF
,
qreal
>
>
UBGraphicsStroke
::
addPoint
(
const
QPointF
&
point
,
qreal
width
,
UBInterpolator
::
InterpolationMethod
interpolationMethod
)
QList
<
QPair
<
QPointF
,
qreal
>
>
UBGraphicsStroke
::
addPoint
(
const
QPointF
&
point
,
qreal
width
,
bool
interpolate
)
{
{
strokePoint
newPoint
(
point
,
width
);
strokePoint
newPoint
(
point
,
width
);
...
@@ -88,17 +96,17 @@ QList<QPair<QPointF, qreal> > UBGraphicsStroke::addPoint(const QPointF& point, q
...
@@ -88,17 +96,17 @@ QList<QPair<QPointF, qreal> > UBGraphicsStroke::addPoint(const QPointF& point, q
if
(
n
==
0
)
{
if
(
n
==
0
)
{
mReceivedPoints
<<
newPoint
;
mReceivedPoints
<<
newPoint
;
mDrawnPoints
<<
newPoint
;
mDrawnPoints
<<
newPoint
;
return
QList
<
strokePoint
>
();
return
QList
<
strokePoint
>
()
<<
newPoint
;
}
}
if
(
interpolationMethod
==
UBInterpolator
::
NoInterpolation
)
{
if
(
!
interpolate
)
{
strokePoint
lastPoint
=
mReceivedPoints
.
last
();
strokePoint
lastPoint
=
mReceivedPoints
.
last
();
mReceivedPoints
<<
newPoint
;
mReceivedPoints
<<
newPoint
;
mDrawnPoints
<<
newPoint
;
mDrawnPoints
<<
newPoint
;
return
QList
<
strokePoint
>
()
<<
lastPoint
<<
newPoint
;
return
QList
<
strokePoint
>
()
<<
lastPoint
<<
newPoint
;
}
}
else
if
(
interpolationMethod
==
UBInterpolator
::
Bezier
)
{
else
{
// The curve we are interpolating is not between two drawn points;
// The curve we are interpolating is not between two drawn points;
// it is between the midway points of the second-to-last and last point, and last and current point.
// it is between the midway points of the second-to-last and last point, and last and current point.
...
@@ -118,14 +126,10 @@ QList<QPair<QPointF, qreal> > UBGraphicsStroke::addPoint(const QPointF& point, q
...
@@ -118,14 +126,10 @@ QList<QPair<QPointF, qreal> > UBGraphicsStroke::addPoint(const QPointF& point, q
QPointF
p1
=
mReceivedPoints
[
mReceivedPoints
.
size
()
-
1
].
first
;
QPointF
p1
=
mReceivedPoints
[
mReceivedPoints
.
size
()
-
1
].
first
;
QPointF
p2
=
point
;
QPointF
p2
=
point
;
UBQuadraticBezier
bz
;
QPointF
startPoint
=
(
p1
+
p0
)
/
2.0
;
QPointF
startPoint
=
(
p1
+
p0
)
/
2.0
;
QPointF
endPoint
=
(
p2
+
p1
)
/
2.0
;
QPointF
endPoint
=
(
p2
+
p1
)
/
2.0
;
bz
.
setPoints
(
startPoint
,
p1
,
endPoint
);
QList
<
QPointF
>
calculated
=
UBGeometryUtils
::
quadraticBezier
(
startPoint
,
p1
,
endPoint
,
10
);
QList
<
QPointF
>
calculated
=
bz
.
getPoints
(
10
);
QList
<
strokePoint
>
newPoints
;
QList
<
strokePoint
>
newPoints
;
qreal
startWidth
=
mDrawnPoints
.
last
().
second
;
qreal
startWidth
=
mDrawnPoints
.
last
().
second
;
...
...
This diff is collapsed.
Click to expand it.
src/domain/UBGraphicsStroke.h
View file @
1a075c05
...
@@ -33,7 +33,6 @@
...
@@ -33,7 +33,6 @@
#include <QtGui>
#include <QtGui>
#include "core/UB.h"
#include "core/UB.h"
#include "frameworks/UBInterpolator.h"
...
@@ -60,7 +59,7 @@ class UBGraphicsStroke
...
@@ -60,7 +59,7 @@ class UBGraphicsStroke
void
clear
();
void
clear
();
QList
<
QPair
<
QPointF
,
qreal
>
>
addPoint
(
const
QPointF
&
point
,
qreal
width
,
UBInterpolator
::
InterpolationMethod
interpolationMethod
=
UBInterpolator
::
NoInterpolation
);
QList
<
QPair
<
QPointF
,
qreal
>
>
addPoint
(
const
QPointF
&
point
,
qreal
width
,
bool
interpolate
=
false
);
const
QList
<
QPair
<
QPointF
,
qreal
>
>&
points
()
{
return
mDrawnPoints
;
}
const
QList
<
QPair
<
QPointF
,
qreal
>
>&
points
()
{
return
mDrawnPoints
;
}
...
...
This diff is collapsed.
Click to expand it.
src/frameworks/UBGeometryUtils.cpp
View file @
1a075c05
...
@@ -447,3 +447,31 @@ qreal UBGeometryUtils::angle(const QPointF& p1, const QPointF& p2, const QPointF
...
@@ -447,3 +447,31 @@ qreal UBGeometryUtils::angle(const QPointF& p1, const QPointF& p2, const QPointF
return
180.
*
beta
/
3.14159
;
return
180.
*
beta
/
3.14159
;
}
}
/**
* @brief Calculate a quadratic Bézier curve and return it in the form of a list of points
* @param p0 The start point of the curve
* @param p1 The control point of the curve
* @param p2 The end point of the curve
* @param nPoints The number of points by which to approximate the curve, i.e. the length of the returned list
* @return A list of points that can be used to draw the curve.
*/
QList
<
QPointF
>
UBGeometryUtils
::
quadraticBezier
(
const
QPointF
&
p0
,
const
QPointF
&
p1
,
const
QPointF
&
p2
,
unsigned
int
nPoints
)
{
QPainterPath
path
(
p0
);
path
.
quadTo
(
p1
,
p2
);
QList
<
QPointF
>
points
;
if
(
nPoints
<=
1
)
return
points
;
for
(
unsigned
int
i
(
0
);
i
<=
nPoints
;
++
i
)
{
qreal
percent
=
qreal
(
i
)
/
qreal
(
nPoints
);
points
<<
path
.
pointAtPercent
(
percent
);
}
return
points
;
}
This diff is collapsed.
Click to expand it.
src/frameworks/UBGeometryUtils.h
View file @
1a075c05
...
@@ -57,6 +57,8 @@ class UBGeometryUtils
...
@@ -57,6 +57,8 @@ class UBGeometryUtils
static
qreal
angle
(
const
QPointF
&
p1
,
const
QPointF
&
p2
,
const
QPointF
&
p3
);
static
qreal
angle
(
const
QPointF
&
p1
,
const
QPointF
&
p2
,
const
QPointF
&
p3
);
static
QList
<
QPointF
>
quadraticBezier
(
const
QPointF
&
p0
,
const
QPointF
&
p1
,
const
QPointF
&
p2
,
unsigned
int
nPoints
);
const
static
int
centimeterGraduationHeight
;
const
static
int
centimeterGraduationHeight
;
const
static
int
halfCentimeterGraduationHeight
;
const
static
int
halfCentimeterGraduationHeight
;
const
static
int
millimeterGraduationHeight
;
const
static
int
millimeterGraduationHeight
;
...
...
This diff is collapsed.
Click to expand it.
src/frameworks/UBInterpolator.cpp
deleted
100644 → 0
View file @
123ebf1d
#include "UBInterpolator.h"
UBInterpolator
::
UBInterpolator
()
{
}
UBInterpolator
::~
UBInterpolator
()
{
}
UBQuadraticBezier
::
UBQuadraticBezier
()
{
mPath
=
0
;
}
UBQuadraticBezier
::~
UBQuadraticBezier
()
{
if
(
mPath
)
delete
mPath
;
}
void
UBQuadraticBezier
::
setPoints
(
QList
<
QPointF
>
points
)
{
setPoints
(
points
[
0
],
points
[
1
],
points
[
2
]);
}
void
UBQuadraticBezier
::
setPoints
(
QPointF
start
,
QPointF
control
,
QPointF
end
)
{
mPath
=
new
QPainterPath
(
start
);
mPath
->
quadTo
(
control
,
end
);
}
/**
* @brief Return n points along the curve, including start and end points (thus n should be larger than or equal to 2).
*
* The higher n, the more accurate the resulting curve will be.
*/
QList
<
QPointF
>
UBQuadraticBezier
::
getPoints
(
int
n
)
{
QList
<
QPointF
>
points
;
if
(
n
<=
1
)
return
points
;
for
(
int
i
(
0
);
i
<=
n
;
++
i
)
{
qreal
percent
=
qreal
(
i
)
/
qreal
(
n
);
points
<<
mPath
->
pointAtPercent
(
percent
);
}
return
points
;
}
This diff is collapsed.
Click to expand it.
src/frameworks/UBInterpolator.h
deleted
100644 → 0
View file @
123ebf1d
#ifndef UBINTERPOLATOR_H
#define UBINTERPOLATOR_H
#include <QtGui>
class
UBInterpolator
{
/* Abstract class representing an interpolator */
public
:
enum
InterpolationMethod
{
NoInterpolation
,
//SimpleSpline,
//CatmullRom,
Bezier
};
UBInterpolator
();
virtual
~
UBInterpolator
();
virtual
void
setPoints
(
QList
<
QPointF
>
points
)
=
0
;
//virtual double y(double x) {}
};
class
UBQuadraticBezier
:
public
UBInterpolator
{
public
:
UBQuadraticBezier
();
virtual
~
UBQuadraticBezier
();
virtual
void
setPoints
(
QList
<
QPointF
>
points
);
void
setPoints
(
QPointF
start
,
QPointF
control
,
QPointF
end
);
//virtual double y(double x);
QList
<
QPointF
>
getPoints
(
int
n
);
private
:
QPainterPath
*
mPath
;
};
#endif // UBINTERPOLATOR_H
This diff is collapsed.
Click to expand it.
src/frameworks/frameworks.pri
View file @
1a075c05
...
@@ -6,8 +6,7 @@ HEADERS += src/frameworks/UBGeometryUtils.h \
...
@@ -6,8 +6,7 @@ HEADERS += src/frameworks/UBGeometryUtils.h \
src/frameworks/UBVersion.h \
src/frameworks/UBVersion.h \
src/frameworks/UBCoreGraphicsScene.h \
src/frameworks/UBCoreGraphicsScene.h \
src/frameworks/UBCryptoUtils.h \
src/frameworks/UBCryptoUtils.h \
src/frameworks/UBBase32.h \
src/frameworks/UBBase32.h
$$PWD/UBInterpolator.h
SOURCES += src/frameworks/UBGeometryUtils.cpp \
SOURCES += src/frameworks/UBGeometryUtils.cpp \
src/frameworks/UBPlatformUtils.cpp \
src/frameworks/UBPlatformUtils.cpp \
...
@@ -16,8 +15,7 @@ SOURCES += src/frameworks/UBGeometryUtils.cpp \
...
@@ -16,8 +15,7 @@ SOURCES += src/frameworks/UBGeometryUtils.cpp \
src/frameworks/UBVersion.cpp \
src/frameworks/UBVersion.cpp \
src/frameworks/UBCoreGraphicsScene.cpp \
src/frameworks/UBCoreGraphicsScene.cpp \
src/frameworks/UBCryptoUtils.cpp \
src/frameworks/UBCryptoUtils.cpp \
src/frameworks/UBBase32.cpp \
src/frameworks/UBBase32.cpp
$$PWD/UBInterpolator.cpp
win32 {
win32 {
...
...
This diff is collapsed.
Click to expand it.
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