2015-04-07 22:13:15 -07:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2015 Subhransu Mohanty
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EINA_BEZIER_H
|
|
|
|
#define EINA_BEZIER_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Floating point cubic bezier curve
|
|
|
|
*/
|
|
|
|
typedef struct _Eina_Bezier Eina_Bezier;
|
|
|
|
|
|
|
|
struct _Eina_Bezier
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
double x; /**< x coordinate of start point */
|
|
|
|
double y; /**< y coordinate of start point */
|
|
|
|
} start;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
double x; /**< x coordinate of 1st control point */
|
|
|
|
double y; /**< y coordinate of 1st control point */
|
|
|
|
} ctrl_start;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
double x; /**< coordinate of 2nd control point */
|
|
|
|
double y; /**< y coordinate of 2nd control point */
|
|
|
|
} ctrl_end;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
double x; /**< x coordinate of end point */
|
|
|
|
double y; /**< y coordinate of end point */
|
|
|
|
} end;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Sets the values of the points of the given floating
|
2015-04-07 22:13:15 -07:00
|
|
|
* point cubic bezier curve.
|
|
|
|
*
|
2018-07-18 23:51:53 -07:00
|
|
|
* @param[out] b The floating point bezier.
|
|
|
|
* @param[in] start_x The x coordinate of the start point.
|
|
|
|
* @param[in] start_y The y coordinate of the start point.
|
|
|
|
* @param[in] ctrl_start_x The x coordinate of the 1st control point.
|
|
|
|
* @param[in] ctrl_start_y The y coordinate of the 1st control point.
|
|
|
|
* @param[in] ctrl_end_x The X coordinate of the 2nd control point.
|
|
|
|
* @param[in] ctrl_end_y The Y coordinate of the 2nd control point.
|
|
|
|
* @param[in] end_x The X coordinate of the end point.
|
|
|
|
* @param[in] end_y The Y coordinate of the end point.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
|
|
|
* @p b. No check is done on @p b.
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI void eina_bezier_values_set(Eina_Bezier *b, double start_x, double start_y, double ctrl_start_x, double ctrl_start_y, double ctrl_end_x, double ctrl_end_y, double end_x, double end_y) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Gets the values of the points of the given floating
|
2015-04-07 22:13:15 -07:00
|
|
|
* point cubic bezier curve.
|
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[out] start_x x coordinate of start point.
|
|
|
|
* @param[out] start_y y coordinate of start point.
|
|
|
|
* @param[out] ctrl_start_x x coordinate of 1st control point.
|
|
|
|
* @param[out] ctrl_start_y y coordinate of 1st control point.
|
|
|
|
* @param[out] ctrl_end_x x coordinate of 2nd control point.
|
|
|
|
* @param[out] ctrl_end_y y coordinate of 2nd control point.
|
|
|
|
* @param[out] end_x x coordinate of end point.
|
|
|
|
* @param[out] end_y y coordinate of end point.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
|
|
|
* @p b. No check is done on @p b.
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI void eina_bezier_values_get(const Eina_Bezier *b, double *start_x, double *start_y, double *ctrl_start_x, double *ctrl_start_y, double *ctrl_end_x, double *ctrl_end_y, double *end_x, double *end_y) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2018-05-02 16:45:35 -07:00
|
|
|
* @brief Calculates the approximate length of the given floating point
|
|
|
|
* cubic bezier curve.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
2018-05-02 16:45:35 -07:00
|
|
|
* @return The bezier's length.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* The curve length is approximated using the Alpha max plus beta min algorithm,
|
|
|
|
* which is designed to give fast results with a maximum error of less than 7%
|
|
|
|
* compared with the correct value.
|
|
|
|
*
|
|
|
|
* No check is done on @p b.
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI double eina_bezier_length_get(const Eina_Bezier *b) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2018-02-14 12:00:44 -08:00
|
|
|
* @brief Returns the relative position on a bezier at a given length.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[in] len The length along the bezier curve.
|
2018-05-02 16:45:35 -07:00
|
|
|
* @return The relative position from 0.0 to 1.0.
|
2018-02-14 12:00:44 -08:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* Calculates the proportional location on @p b as a number from 0.0 to
|
|
|
|
* 1.0 that corresponds to a distance @p len along it. Returns 1.0 if
|
|
|
|
* @p len is equal or greater than the bezier's length.
|
|
|
|
*
|
|
|
|
* No check is done on @p b.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI double eina_bezier_t_at(const Eina_Bezier *b, double len) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2018-02-14 12:00:44 -08:00
|
|
|
* @brief Gets the point on the bezier curve at position t.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[in] t The floating point position between 0.0 and 1.0.
|
2018-02-14 12:00:44 -08:00
|
|
|
* @param[out] px The corresponding point's X coordinate.
|
|
|
|
* @param[out] py The corresponding point's Y coordinate.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* No check is done on @p b.
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI void eina_bezier_point_at(const Eina_Bezier *b, double t, double *px, double *py) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2018-02-14 12:00:44 -08:00
|
|
|
* @brief Determines the slope of the bezier at a given position.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[out] t The position along the bezier between 0.0 and 1.0.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* No check is done on @p b.
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI double eina_bezier_angle_at(const Eina_Bezier *b, double t) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2018-02-14 12:00:44 -08:00
|
|
|
* @brief Splits the bezier at a given length.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[in] len The length along the bezier to make the split.
|
2018-02-14 12:00:44 -08:00
|
|
|
* @param[out] left The resultant split's left portion of the bezier.
|
|
|
|
* @param[out] right The resultant split's right portion of the bezier.
|
2015-04-07 22:13:15 -07:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* No check is done on @p b.
|
2015-08-07 05:41:56 -07:00
|
|
|
* @since 1.16
|
2015-04-07 22:13:15 -07:00
|
|
|
*/
|
|
|
|
EAPI void eina_bezier_split_at_length(const Eina_Bezier *b, double len, Eina_Bezier *left, Eina_Bezier *right) EINA_ARG_NONNULL(1);
|
|
|
|
|
2015-11-09 20:22:19 -08:00
|
|
|
/**
|
2018-05-02 16:45:35 -07:00
|
|
|
* @brief Calculates the bounding box for the bezier.
|
2015-11-09 20:22:19 -08:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[out] x The X coordinate of the bounding box.
|
|
|
|
* @param[out] y The Y coordinate of the bounding box.
|
|
|
|
* @param[out] w The width of the bounding box.
|
|
|
|
* @param[out] h The height of the bounding box.
|
2015-11-09 20:22:19 -08:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* No check is done on @p b.
|
2016-01-06 06:31:48 -08:00
|
|
|
* @since 1.17
|
2015-11-09 20:22:19 -08:00
|
|
|
*/
|
|
|
|
EAPI void eina_bezier_bounds_get(const Eina_Bezier *b, double *x, double *y, double *w, double *h) EINA_ARG_NONNULL(1);
|
|
|
|
|
2015-11-24 21:09:59 -08:00
|
|
|
/**
|
2018-02-14 12:00:44 -08:00
|
|
|
* @brief Finds the bezier between the given interval.
|
2015-11-24 21:09:59 -08:00
|
|
|
*
|
2018-03-06 16:58:44 -08:00
|
|
|
* @param[in] b The floating point bezier.
|
|
|
|
* @param[in] t0 The start of the interval.
|
|
|
|
* @param[in] t1 The end of the interval.
|
|
|
|
* @param[out] result The resulting bezier.
|
2015-11-24 21:09:59 -08:00
|
|
|
*
|
2018-05-02 16:45:35 -07:00
|
|
|
* No check is done on @p b.
|
2016-01-06 06:31:48 -08:00
|
|
|
* @since 1.17
|
2015-11-24 21:09:59 -08:00
|
|
|
*/
|
|
|
|
EAPI void eina_bezier_on_interval(Eina_Bezier *b, double t0, double t1, Eina_Bezier *result);
|
|
|
|
|
2015-04-07 22:13:15 -07:00
|
|
|
#endif // EINA_BEZIER_H
|