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 #include <optional>
0011 #include "vector.hpp"
0012 
0013 namespace glaxnimate::math {
0014 
0015 /**
0016  * \brief Finds the closest point to a line
0017  * \param line_a Point to determine the line
0018  * \param line_b Second point to determine the line
0019  * \param p      Point to find the closest of
0020  * \returns The point on the line that is closest to \p p
0021  */
0022 QPointF line_closest_point(const QPointF& line_a, const QPointF& line_b, const QPointF& p);
0023 
0024 /**
0025  * \brief Gets the center of the circle passing through 3 points
0026  */
0027 QPointF circle_center(const QPointF& p1, const QPointF& p2, const QPointF& p3);
0028 
0029 /**
0030  * \brief Intersection point between two lines, each defined by two points
0031  * \note the intersection might lay outside the segments provided
0032  */
0033 std::optional<QPointF> line_intersection(const QPointF& start1, const QPointF& end1, const QPointF& start2, const QPointF& end2);
0034 
0035 } // namespace glaxnimate::math