-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometryutils.h
More file actions
47 lines (36 loc) · 2.14 KB
/
Copy pathgeometryutils.h
File metadata and controls
47 lines (36 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef GEOMETRYUTILS_H
#define GEOMETRYUTILS_H
#include <QObject>
#include <QQmlEngine>
#include <QPoint>
#include <QVector2D>
class GeometryUtils : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
explicit GeometryUtils(QObject *parent = nullptr);
Q_INVOKABLE static qreal lerp(qreal from, qreal to, qreal t);
// Calculate a transition between two given points, mapping position onto a nearest perpendicular point on a line between start and end points.
// Returns a number clamped into [0; 1] range.
Q_INVOKABLE static qreal linearPosition(QPointF start, QPointF end, QPointF position);
// Calculate a transition between three given points in normalized coordinates.
// Returns a Point where both coordinates are clamped into [0; 1] range:
// - x corresponds to the position between the start and end points,
// - y corresponds to the position on a perpendicular between the third (zero) point and a line between start and end points.
Q_INVOKABLE static QPointF planarPosition(QPointF start, QPointF end, QPointF zero, QPointF position);
// If the point is inside the triangle, do nothing and return the point.
// Otherwise, find the closest vertex or a perpendicular projection on the perimeter.
Q_INVOKABLE static QPointF snapPointToTriangle(QPointF vertexA, QPointF vertexB, QPointF vertexC, QPointF position);
Q_INVOKABLE static QVector2D snapVectorToTriangle(QVector2D vertexA, QVector2D vertexB, QVector2D vertexC, QVector2D position);
// Generate a random triangle (three vertices) whose bounds are a unit square.
Q_INVOKABLE static QList<QPointF> randomUnitTriangle();
// Generate an SVG path for an outline of a triangle with rounded corners.
// Vertices are centers of circles for the rounded corners,
// so the all edges are offset outward by the radius.
Q_INVOKABLE static QString roundedTriangleOutlineSvgPath(QPointF vertexA, QPointF vertexB, QPointF vertexC, qreal cornerRadius);
// Multiply each point by the given scale factor.
Q_INVOKABLE static QList<QPointF> scaledPoints(const QList<QPointF> &points, QSizeF scale);
};
#endif // GEOMETRYUTILS_H