diff --git a/include/CSFML/Graphics/CircleShape.h b/include/CSFML/Graphics/CircleShape.h index 1d946ef..6cc695e 100644 --- a/include/CSFML/Graphics/CircleShape.h +++ b/include/CSFML/Graphics/CircleShape.h @@ -292,6 +292,36 @@ CSFML_GRAPHICS_API void sfCircleShape_setOutlineColor(sfCircleShape* shape, sfCo //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfCircleShape_setOutlineThickness(sfCircleShape* shape, float thickness); +//////////////////////////////////////////////////////////// +/// \brief Set the limit on the ratio between miter length and outline thickness of a circle shape +/// +/// Outline segments around each corner are joined either +/// with a miter or a bevel join. +/// - A miter join is formed by extending outline segments until +/// they intersect. The distance between the point of +/// intersection and the shape's corner is the miter length. +/// - A bevel join is formed by connecting outline segments with +/// a straight line perpendicular to the corner's bisector. +/// +/// The miter limit is used to determine whether outline segments +/// around a corner are joined with a bevel or a miter. +/// When the ratio between the miter length and outline thickness +/// exceeds the miter limit, a bevel is used instead of a miter. +/// +/// The miter limit is linked to the maximum inner angle of a +/// corner below which a bevel is used by the following formula: +/// +/// miterLimit = 1 / sin(angle / 2) +/// +/// The miter limit must be greater than or equal to 1. +/// By default, the miter limit is 10. +/// +/// \param shape Shape object +/// \param miterLimit New miter limit +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfCircleShape_setMiterLimit(sfCircleShape* shape, float miterLimit); + //////////////////////////////////////////////////////////// /// \brief Get the source texture of a circle shape /// @@ -346,6 +376,16 @@ CSFML_GRAPHICS_API sfColor sfCircleShape_getOutlineColor(const sfCircleShape* sh //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API float sfCircleShape_getOutlineThickness(const sfCircleShape* shape); +//////////////////////////////////////////////////////////// +/// \brief Get the limit on the ratio between miter length and outline thickness of a circle shape +/// +/// \param shape Shape object +/// +/// \return Limit on the ratio between miter length and outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API float sfCircleShape_getMiterLimit(const sfCircleShape* shape); + //////////////////////////////////////////////////////////// /// \brief Get the total number of points of a circle shape /// diff --git a/include/CSFML/Graphics/ConvexShape.h b/include/CSFML/Graphics/ConvexShape.h index aca5c39..d8f1d78 100644 --- a/include/CSFML/Graphics/ConvexShape.h +++ b/include/CSFML/Graphics/ConvexShape.h @@ -292,6 +292,36 @@ CSFML_GRAPHICS_API void sfConvexShape_setOutlineColor(sfConvexShape* shape, sfCo //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfConvexShape_setOutlineThickness(sfConvexShape* shape, float thickness); +//////////////////////////////////////////////////////////// +/// \brief Set the limit on the ratio between miter length and outline thickness of a convex shape +/// +/// Outline segments around each corner are joined either +/// with a miter or a bevel join. +/// - A miter join is formed by extending outline segments until +/// they intersect. The distance between the point of +/// intersection and the shape's corner is the miter length. +/// - A bevel join is formed by connecting outline segments with +/// a straight line perpendicular to the corner's bisector. +/// +/// The miter limit is used to determine whether outline segments +/// around a corner are joined with a bevel or a miter. +/// When the ratio between the miter length and outline thickness +/// exceeds the miter limit, a bevel is used instead of a miter. +/// +/// The miter limit is linked to the maximum inner angle of a +/// corner below which a bevel is used by the following formula: +/// +/// miterLimit = 1 / sin(angle / 2) +/// +/// The miter limit must be greater than or equal to 1. +/// By default, the miter limit is 10. +/// +/// \param shape Shape object +/// \param miterLimit New miter limit +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfConvexShape_setMiterLimit(sfConvexShape* shape, float miterLimit); + //////////////////////////////////////////////////////////// /// \brief Get the source texture of a convex shape /// @@ -346,6 +376,16 @@ CSFML_GRAPHICS_API sfColor sfConvexShape_getOutlineColor(const sfConvexShape* sh //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API float sfConvexShape_getOutlineThickness(const sfConvexShape* shape); +//////////////////////////////////////////////////////////// +/// \brief Get the limit on the ratio between miter length and outline thickness of a convex shape +/// +/// \param shape Shape object +/// +/// \return Limit on the ratio between miter length and outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API float sfConvexShape_getMiterLimit(const sfConvexShape* shape); + //////////////////////////////////////////////////////////// /// \brief Get the total number of points of a convex shape /// diff --git a/include/CSFML/Graphics/RectangleShape.h b/include/CSFML/Graphics/RectangleShape.h index 2834a5f..784ec87 100644 --- a/include/CSFML/Graphics/RectangleShape.h +++ b/include/CSFML/Graphics/RectangleShape.h @@ -292,6 +292,36 @@ CSFML_GRAPHICS_API void sfRectangleShape_setOutlineColor(sfRectangleShape* shape //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRectangleShape_setOutlineThickness(sfRectangleShape* shape, float thickness); +//////////////////////////////////////////////////////////// +/// \brief Set the limit on the ratio between miter length and outline thickness of a rectangle shape +/// +/// Outline segments around each corner are joined either +/// with a miter or a bevel join. +/// - A miter join is formed by extending outline segments until +/// they intersect. The distance between the point of +/// intersection and the shape's corner is the miter length. +/// - A bevel join is formed by connecting outline segments with +/// a straight line perpendicular to the corner's bisector. +/// +/// The miter limit is used to determine whether outline segments +/// around a corner are joined with a bevel or a miter. +/// When the ratio between the miter length and outline thickness +/// exceeds the miter limit, a bevel is used instead of a miter. +/// +/// The miter limit is linked to the maximum inner angle of a +/// corner below which a bevel is used by the following formula: +/// +/// miterLimit = 1 / sin(angle / 2) +/// +/// The miter limit must be greater than or equal to 1. +/// By default, the miter limit is 10. +/// +/// \param shape Shape object +/// \param miterLimit New miter limit +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRectangleShape_setMiterLimit(sfRectangleShape* shape, float miterLimit); + //////////////////////////////////////////////////////////// /// \brief Get the source texture of a rectangle shape /// @@ -346,6 +376,16 @@ CSFML_GRAPHICS_API sfColor sfRectangleShape_getOutlineColor(const sfRectangleSha //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API float sfRectangleShape_getOutlineThickness(const sfRectangleShape* shape); +//////////////////////////////////////////////////////////// +/// \brief Get the limit on the ratio between miter length and outline thickness of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Limit on the ratio between miter length and outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API float sfRectangleShape_getMiterLimit(const sfRectangleShape* shape); + //////////////////////////////////////////////////////////// /// \brief Get the total number of points of a rectangle shape /// diff --git a/include/CSFML/Graphics/Shape.h b/include/CSFML/Graphics/Shape.h index d844ca6..be09ea4 100644 --- a/include/CSFML/Graphics/Shape.h +++ b/include/CSFML/Graphics/Shape.h @@ -291,6 +291,36 @@ CSFML_GRAPHICS_API void sfShape_setOutlineColor(sfShape* shape, sfColor color); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfShape_setOutlineThickness(sfShape* shape, float thickness); +//////////////////////////////////////////////////////////// +/// \brief Set the limit on the ratio between miter length and outline thickness of a shape +/// +/// Outline segments around each corner are joined either +/// with a miter or a bevel join. +/// - A miter join is formed by extending outline segments until +/// they intersect. The distance between the point of +/// intersection and the shape's corner is the miter length. +/// - A bevel join is formed by connecting outline segments with +/// a straight line perpendicular to the corner's bisector. +/// +/// The miter limit is used to determine whether outline segments +/// around a corner are joined with a bevel or a miter. +/// When the ratio between the miter length and outline thickness +/// exceeds the miter limit, a bevel is used instead of a miter. +/// +/// The miter limit is linked to the maximum inner angle of a +/// corner below which a bevel is used by the following formula: +/// +/// miterLimit = 1 / sin(angle / 2) +/// +/// The miter limit must be greater than or equal to 1. +/// By default, the miter limit is 10. +/// +/// \param shape Shape object +/// \param miterLimit New miter limit +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfShape_setMiterLimit(sfShape* shape, float miterLimit); + //////////////////////////////////////////////////////////// /// \brief Get the source texture of a shape /// @@ -345,6 +375,16 @@ CSFML_GRAPHICS_API sfColor sfShape_getOutlineColor(const sfShape* shape); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API float sfShape_getOutlineThickness(const sfShape* shape); +//////////////////////////////////////////////////////////// +/// \brief Get the limit on the ratio between miter length and outline thickness of a shape +/// +/// \param shape Shape object +/// +/// \return Limit on the ratio between miter length and outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API float sfShape_getMiterLimit(const sfShape* shape); + //////////////////////////////////////////////////////////// /// \brief Get the total number of points of a shape /// diff --git a/src/CSFML/Graphics/CircleShape.cpp b/src/CSFML/Graphics/CircleShape.cpp index 240702d..701ea9a 100644 --- a/src/CSFML/Graphics/CircleShape.cpp +++ b/src/CSFML/Graphics/CircleShape.cpp @@ -207,6 +207,14 @@ void sfCircleShape_setOutlineThickness(sfCircleShape* shape, float thickness) } +//////////////////////////////////////////////////////////// +void sfCircleShape_setMiterLimit(sfCircleShape* shape, float miterLimit) +{ + assert(shape); + shape->setMiterLimit(miterLimit); +} + + //////////////////////////////////////////////////////////// const sfTexture* sfCircleShape_getTexture(const sfCircleShape* shape) { @@ -247,6 +255,14 @@ float sfCircleShape_getOutlineThickness(const sfCircleShape* shape) } +//////////////////////////////////////////////////////////// +float sfCircleShape_getMiterLimit(const sfCircleShape* shape) +{ + assert(shape); + return shape->getMiterLimit(); +} + + //////////////////////////////////////////////////////////// size_t sfCircleShape_getPointCount(const sfCircleShape* shape) { diff --git a/src/CSFML/Graphics/ConvexShape.cpp b/src/CSFML/Graphics/ConvexShape.cpp index 5809371..a232a77 100644 --- a/src/CSFML/Graphics/ConvexShape.cpp +++ b/src/CSFML/Graphics/ConvexShape.cpp @@ -204,6 +204,14 @@ void sfConvexShape_setOutlineThickness(sfConvexShape* shape, float thickness) } +//////////////////////////////////////////////////////////// +void sfConvexShape_setMiterLimit(sfConvexShape* shape, float miterLimit) +{ + assert(shape); + shape->setMiterLimit(miterLimit); +} + + //////////////////////////////////////////////////////////// const sfTexture* sfConvexShape_getTexture(const sfConvexShape* shape) { @@ -244,6 +252,14 @@ float sfConvexShape_getOutlineThickness(const sfConvexShape* shape) } +//////////////////////////////////////////////////////////// +float sfConvexShape_getMiterLimit(const sfConvexShape* shape) +{ + assert(shape); + return shape->getMiterLimit(); +} + + //////////////////////////////////////////////////////////// size_t sfConvexShape_getPointCount(const sfConvexShape* shape) { diff --git a/src/CSFML/Graphics/RectangleShape.cpp b/src/CSFML/Graphics/RectangleShape.cpp index 9563e7c..2ba840a 100644 --- a/src/CSFML/Graphics/RectangleShape.cpp +++ b/src/CSFML/Graphics/RectangleShape.cpp @@ -204,6 +204,14 @@ void sfRectangleShape_setOutlineThickness(sfRectangleShape* shape, float thickne } +//////////////////////////////////////////////////////////// +void sfRectangleShape_setMiterLimit(sfRectangleShape* shape, float miterLimit) +{ + assert(shape); + shape->setMiterLimit(miterLimit); +} + + //////////////////////////////////////////////////////////// const sfTexture* sfRectangleShape_getTexture(const sfRectangleShape* shape) { @@ -244,6 +252,14 @@ float sfRectangleShape_getOutlineThickness(const sfRectangleShape* shape) } +//////////////////////////////////////////////////////////// +float sfRectangleShape_getMiterLimit(const sfRectangleShape* shape) +{ + assert(shape); + return shape->getMiterLimit(); +} + + //////////////////////////////////////////////////////////// size_t sfRectangleShape_getPointCount(const sfRectangleShape* shape) { diff --git a/src/CSFML/Graphics/Shape.cpp b/src/CSFML/Graphics/Shape.cpp index 243f2f2..c14df10 100644 --- a/src/CSFML/Graphics/Shape.cpp +++ b/src/CSFML/Graphics/Shape.cpp @@ -196,6 +196,14 @@ void sfShape_setOutlineThickness(sfShape* shape, float thickness) } +//////////////////////////////////////////////////////////// +void sfShape_setMiterLimit(sfShape* shape, float miterLimit) +{ + assert(shape); + shape->setMiterLimit(miterLimit); +} + + //////////////////////////////////////////////////////////// const sfTexture* sfShape_getTexture(const sfShape* shape) { @@ -236,6 +244,14 @@ float sfShape_getOutlineThickness(const sfShape* shape) } +//////////////////////////////////////////////////////////// +float sfShape_getMiterLimit(const sfShape* shape) +{ + assert(shape); + return shape->getMiterLimit(); +} + + //////////////////////////////////////////////////////////// size_t sfShape_getPointCount(const sfShape* shape) { diff --git a/test/Graphics/Shape.test.cpp b/test/Graphics/Shape.test.cpp index e43ee42..8d20c6f 100644 --- a/test/Graphics/Shape.test.cpp +++ b/test/Graphics/Shape.test.cpp @@ -47,6 +47,7 @@ TEST_CASE("[Graphics] sfShape") CHECK(outlineColor.b == sfWhite.b); CHECK(outlineColor.a == sfWhite.a); CHECK(sfShape_getOutlineThickness(shape) == 0); + CHECK(sfShape_getMiterLimit(shape) == 10); CHECK(sfShape_getPointCount(shape) == 3); const sfVector2f point = sfShape_getPoint(shape, 0); CHECK(point.x == 0); @@ -104,4 +105,12 @@ TEST_CASE("[Graphics] sfShape") CHECK(origin.y == 90); sfShape_destroy(shape); } + + SECTION("Set/get miter limit") + { + sfShape* shape = sfShape_create(getPointCount, getPoint, &points); + sfShape_setMiterLimit(shape, 2); + CHECK(sfShape_getMiterLimit(shape) == 2); + sfShape_destroy(shape); + } }