19#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
20#include <QStringConverter>
24const quint8
quint8_MAX = std::numeric_limits<quint8>::max();
25const quint16
quint16_MAX = std::numeric_limits<quint16>::max();
27const qint16
qint16_MIN = std::numeric_limits<qint16>::min();
28const qint16
qint16_MAX = std::numeric_limits<qint16>::max();
29const qint32
qint32_MAX = std::numeric_limits<qint32>::max();
30const qint32
qint32_MIN = std::numeric_limits<qint32>::min();
37constexpr inline const T &
kisBoundFast(
const T &min,
const T &val,
const T &max)
50 return qMax(min, qMin(max, val));
103#define INTENT_PERCEPTUAL 0
104#define INTENT_RELATIVE_COLORIMETRIC 1
105#define INTENT_SATURATION 2
106#define INTENT_ABSOLUTE_COLORIMETRIC 3
111#define M_PI 3.14159265358979323846
120typename std::enable_if<std::is_floating_point<T>::value, T>::type
123 a = T(2 *
M_PI) + std::fmod(a, T(2 *
M_PI));
126 return a >= T(2 *
M_PI) ? std::fmod(a, T(2 *
M_PI)) : a;
131typename std::enable_if<std::is_floating_point<T>::value, T>::type
134 a = T(360.0) + std::fmod(a, T(360.0));
137 return a >= T(360.0) ? std::fmod(a, T(360.0)) : a;
141 qreal dist = fmod(qAbs(a - b), 2 *
M_PI);
142 if (dist >
M_PI) dist = 2 *
M_PI - dist;
154 return d1 < d2 ? b1 : b2;
177 return degrees *
M_PI / 180.0;
182 return radians * 180.0 /
M_PI;
185template<
class T,
typename U>
187 return rect.adjusted(-offset, -offset, offset, offset);
191 return std::sqrt(
pow2(pt1.x() - pt2.x()) +
pow2(pt1.y() - pt2.y()));
195 return pow2(pt1.x() - pt2.x()) +
pow2(pt1.y() - pt2.y());
198template<
typename Po
intType>
200 if (qAbs(
P.x()) < qAbs(
P.y())) {
208template<
typename Po
intType>
212 const QPointF lineVector = point - startPoint;
213 qreal lineAngle = std::atan2(lineVector.y(), lineVector.x());
216 lineAngle += 2 *
M_PI;
219 const quint32 constrainedLineIndex =
static_cast<quint32
>((lineAngle / angle) + 0.5);
220 const qreal constrainedLineAngle = constrainedLineIndex * angle;
222 const qreal lineLength =
kisDistance(lineVector, QPointF());
224 const QPointF constrainedLineVector(lineLength * std::cos(constrainedLineAngle), lineLength * std::sin(constrainedLineAngle));
226 const QPointF result = startPoint + constrainedLineVector;
236 const QPointF &
p1 = line.p1();
237 const QPointF &
p2 = line.p2();
247 qreal
B = - (
p1.x() -
p2.x()) / (
p1.y() -
p2.y());
248 qreal
C = -
p1.x() -
B *
p1.y();
258 const qreal prod = base.x() *
v.x() + base.y() *
v.y();
259 const qreal lengthSq =
pow2(base.x()) +
pow2(base.y());
260 qreal coeff = prod / lengthSq;
269 if(rc.right() >
bounds.right()) {
270 rc.translate(
bounds.right() - rc.right(), 0);
273 if(rc.left() <
bounds.left()) {
274 rc.translate(
bounds.left() - rc.left(), 0);
277 if(rc.bottom() >
bounds.bottom()) {
278 rc.translate(0,
bounds.bottom() - rc.bottom());
281 if(rc.top() <
bounds.top()) {
282 rc.translate(0,
bounds.top() - rc.top());
290 QPointF trimmedOrigin = toTakeFrom.topLeft();
291 QSize trimmedSize = QSize(width, toTakeFrom.height());
292 toTakeFrom.setWidth(toTakeFrom.width() - width);
293 toTakeFrom.translate(width, 0);
294 return QRectF(trimmedOrigin, trimmedSize);
299 QRectF converted = QRectF(toTakeFrom);
301 toTakeFrom = converted.toAlignedRect();
302 return toReturn.toAlignedRect();
307 QPointF trimmedOrigin = toTakeFrom.topLeft();
308 QSize trimmedSize = QSize(toTakeFrom.width(), height);
309 toTakeFrom.setHeight(toTakeFrom.height() - height);
310 toTakeFrom.translate(0, height);
311 return QRectF(trimmedOrigin, trimmedSize);
316 QRectF converted = QRectF(toTakeFrom);
317 QRectF toReturn =
kisTrimTop(height, converted);
318 toTakeFrom = converted.toAlignedRect();
319 return toReturn.toAlignedRect();
323#include <type_traits>
330 static_assert(std::is_integral<T>::value,
"Value has to be an integral number");
331 using base_type =
typename std::conditional<
sizeof(T) ==
sizeof(quint64), quint64, quint32>::type;
332 using common_type =
typename std::conditional<std::is_signed<T>::value,
typename std::make_signed<base_type>::type,
typename std::make_unsigned<base_type>::type>::type;
333 return static_cast<T
>(qNextPowerOfTwo(
static_cast<common_type
>(
v)));
qreal distance(const QPointF &p1, const QPointF &p2)
static bool qFuzzyCompare(half p1, half p2)
const double PRESSURE_DEFAULT
qreal incrementInDirection(qreal a, qreal inc, qreal direction)
const quint8 SELECTION_THRESHOLD
qreal kisDistance(const QPointF &pt1, const QPointF &pt2)
const double PRESSURE_THRESHOLD
@ OLD_CURSOR_STYLE_OUTLINE_TRIANGLE_RIGHTHANDED
@ OLD_CURSOR_STYLE_OUTLINE
@ OLD_CURSOR_STYLE_OUTLINE_CENTER_CROSS
@ OLD_CURSOR_STYLE_CROSSHAIR
@ OLD_CURSOR_STYLE_NO_CURSOR
@ OLD_CURSOR_STYLE_TOOLICON
@ OLD_CURSOR_STYLE_TRIANGLE_LEFTHANDED
@ OLD_CURSOR_STYLE_POINTER
@ OLD_CURSOR_STYLE_OUTLINE_CENTER_DOT
@ OLD_CURSOR_STYLE_OUTLINE_TRIANGLE_LEFTHANDED
@ OLD_CURSOR_STYLE_TRIANGLE_RIGHTHANDED
@ OLD_CURSOR_STYLE_SMALL_ROUND
T kisGrowRect(const T &rect, U offset)
T kisRadiansToDegrees(T radians)
constexpr const T & kisBoundFast(const T &min, const T &val, const T &max)
PointType snapToClosestNiceAngle(PointType point, PointType startPoint, qreal angle=(2 *M_PI)/24)
const quint8 MAX_SELECTED
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngleDegrees(T a)
const quint16 quint16_MAX
qreal shortestAngularDistance(qreal a, qreal b)
T kisDegreesToRadians(T degrees)
constexpr const char * currentUnderlyingStyleNameProperty
qreal kisDistanceToLine(const QPointF &m, const QLineF &line)
qreal kisSquareDistance(const QPointF &pt1, const QPointF &pt2)
const double PRESSURE_MAX
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngle(T a)
qreal bisectorAngle(qreal a, qreal b)
const quint8 MIN_SELECTED
QPointF kisProjectOnVector(const QPointF &base, const QPointF &v)
QRectF kisTrimTop(int height, QRectF &toTakeFrom)
QRect kisEnsureInRect(QRect rc, const QRect &bounds)
QRectF kisTrimLeft(int width, QRectF &toTakeFrom)
PointType snapToClosestAxis(PointType P)
const double PRESSURE_MIN
@ CURSOR_STYLE_SMALL_ROUND
@ CURSOR_STYLE_TRIANGLE_RIGHTHANDED
@ CURSOR_STYLE_WHITE_PIXEL
@ CURSOR_STYLE_BLACK_PIXEL
@ CURSOR_STYLE_TRIANGLE_LEFTHANDED