File indexing completed on 2024-12-15 04:01:12

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 #include <utility>
0009 #include "bezier.hpp"
0010 
0011 namespace glaxnimate::math::bezier {
0012 
0013 /**
0014  * \brief Turns all points in the curve to smooth, sutomatically setting tangents
0015  */
0016 void auto_smooth(Bezier& curve, int start, int end);
0017 
0018 /**
0019  * \brief Reduces the number of points in a bezier curve
0020  */
0021 void simplify(Bezier& curve, qreal threshold);
0022 
0023 
0024 struct ProjectResult
0025 {
0026     int index = 0;
0027     qreal factor = 0;
0028     qreal distance = std::numeric_limits<qreal>::max();
0029     QPointF point = {};
0030 };
0031 
0032 /**
0033  * \brief Projects a point onto a bezier curve
0034  * \param curve The target bezier
0035  * \param p     The point to project
0036  * \returns ProjectResult with the point on \p curve closest to \p p
0037  */
0038 ProjectResult project(const Bezier& curve, const QPointF& p);
0039 
0040 ProjectResult project(const BezierSegment& segment, const QPointF& p);
0041 
0042 } // namespace glaxnimate::math