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

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 
0009 #include <QPointF>
0010 
0011 #include "bezier/bezier.hpp"
0012 
0013 namespace glaxnimate::math {
0014 
0015 class EllipseSolver
0016 {
0017 public:
0018     /**
0019      * \param center      2D vector, center of the ellipse
0020      * \param radii       2D vector, x/y radius of the ellipse
0021      * \param xrot        Angle between the main axis of the ellipse and the x axis (in radians)
0022      */
0023     EllipseSolver(const QPointF& center, const QPointF& radii, qreal xrot);
0024 
0025     QPointF point(qreal t) const;
0026 
0027     QPointF derivative(qreal t) const;
0028 
0029     bezier::Bezier to_bezier(qreal anglestart, qreal angle_delta);
0030 
0031     static bezier::Bezier from_svg_arc(
0032         QPointF start, qreal rx, qreal ry, qreal xrot,
0033         bool large, bool sweep, QPointF dest
0034     );
0035 
0036 private:
0037     static qreal _alpha(qreal step);
0038 
0039     static QPointF _matrix_mul(qreal phi, const QPointF p, qreal sin_mul=1);
0040 
0041     static qreal _angle(const QPointF& u, const QPointF& v);
0042 
0043     QPointF center;
0044     QPointF radii;
0045     qreal xrot;
0046 };
0047 
0048 } // namespace glaxnimate::math
0049