KD Chart API Documentation
3.1
Loading...
Searching...
No Matches
source
src
KDChart
Ternary
TernaryPoint.cpp
Go to the documentation of this file.
1
/****************************************************************************
2
**
3
** This file is part of the KD Chart library.
4
**
5
** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6
**
7
** SPDX-License-Identifier: MIT
8
**
9
****************************************************************************/
10
11
#include "
TernaryPoint.h
"
12
#include "
TernaryConstants.h
"
13
14
#include <limits>
15
16
#include <QChar>
17
#include <QTextStream>
18
19
TernaryPoint::TernaryPoint
()
20
{
21
Q_ASSERT(!
isValid
());
22
}
23
24
TernaryPoint::TernaryPoint
(qreal a, qreal b)
25
{
26
set
(
a
,
b
);
27
}
28
29
void
TernaryPoint::set
(qreal a, qreal b)
30
{
31
if
(
a
>= 0.0 &&
a
<= 1.0
32
&&
b
>= 0.0 &&
b
<= 1.0
33
&& 1.0 -
a
-
b
>= -2.0 * std::numeric_limits<qreal>::epsilon()) {
34
m_a =
a
;
35
m_b =
b
;
36
Q_ASSERT(
isValid
());
// more a test for isValid
37
}
else
{
38
m_a = -1.0;
39
m_b = -1.0;
40
Q_ASSERT(!
isValid
());
41
}
42
}
43
44
bool
TernaryPoint::isValid
()
const
45
{
46
return
m_a >= 0.0 && m_a <= 1.0
47
&& m_b >= 0.0 && m_b <= 1.0
48
&& 1.0 - m_a + m_b >= -std::numeric_limits<qreal>::epsilon();
49
}
50
51
QDebug
operator<<
(
QDebug
stream,
const
TernaryPoint
&point)
52
{
53
QString
string;
54
QTextStream
text(&
string
);
55
text <<
"[TernaryPoint: "
;
56
if
(point.
isValid
()) {
57
text.
setFieldWidth
(2);
58
text.
setPadChar
(
QLatin1Char
(
'0'
));
59
text << ( int )(point.
a
() * 100.0) <<
"%|"
60
<< (
int
)(point.
b
() * 100.0) <<
"%|"
61
<< (
int
)(point.
c
() * 100.0) <<
"%]"
;
62
}
else
{
63
text <<
"a="
<< point.
a
() <<
" - b="
<< point.
b
() <<
" - INVALID]"
;
64
}
65
stream << string;
66
return
stream;
67
}
68
69
QPointF
translate
(
const
TernaryPoint
&point)
70
{
71
if
(point.
isValid
()) {
72
// the position is calculated by
73
// - first moving along the B-C line to the function that b
74
// selects
75
// - then traversing the selected function until we meet with
76
// the function that A selects (which is a parallel of the B-C
77
// line)
78
QPointF
bPosition(1.0 - point.
b
(), 0.0);
79
QPointF
aPosition(point.
a
() *
AxisVector_C_A
);
80
QPointF
result(bPosition + aPosition);
81
return
result;
82
}
else
{
83
qWarning() <<
"TernaryPoint::translate(TernaryPoint): cannot translate invalid ternary points:"
84
<< point;
85
return
QPointF
();
86
}
87
}
TernaryConstants.h
AxisVector_C_A
const QPointF AxisVector_C_A
operator<<
QDebug operator<<(QDebug stream, const TernaryPoint &point)
Definition
TernaryPoint.cpp:51
translate
QPointF translate(const TernaryPoint &point)
Definition
TernaryPoint.cpp:69
TernaryPoint.h
TernaryPoint
TernaryPoint defines a point within a ternary coordinate plane.
Definition
TernaryPoint.h:22
TernaryPoint::set
void set(qreal a, qreal b)
Definition
TernaryPoint.cpp:29
TernaryPoint::a
qreal a() const
Definition
TernaryPoint.h:27
TernaryPoint::b
qreal b() const
Definition
TernaryPoint.h:31
TernaryPoint::TernaryPoint
TernaryPoint()
Definition
TernaryPoint.cpp:19
TernaryPoint::isValid
bool isValid() const
Definition
TernaryPoint.cpp:44
TernaryPoint::c
qreal c() const
Definition
TernaryPoint.h:35
QDebug
QLatin1Char
QPointF
QString
QTextStream
QTextStream::setFieldWidth
void setFieldWidth(int width)
QTextStream::setPadChar
void setPadChar(QChar ch)
© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Fri Apr 26 2024 00:04:57 for KD Chart API Documentation by doxygen 1.9.8