From e3299a51512dd2e16c0e7834c5534f9773e6ce59 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 20 Sep 2024 15:37:02 -0500 Subject: [PATCH] Implement `getGeometricCenter` --- include/CSFML/Graphics/CircleShape.h | 14 ++++++++++++++ include/CSFML/Graphics/ConvexShape.h | 14 ++++++++++++++ include/CSFML/Graphics/RectangleShape.h | 14 ++++++++++++++ include/CSFML/Graphics/Shape.h | 14 ++++++++++++++ src/CSFML/Graphics/CircleShape.cpp | 8 ++++++++ src/CSFML/Graphics/ConvexShape.cpp | 8 ++++++++ src/CSFML/Graphics/RectangleShape.cpp | 8 ++++++++ src/CSFML/Graphics/Shape.cpp | 8 ++++++++ 8 files changed, 88 insertions(+) diff --git a/include/CSFML/Graphics/CircleShape.h b/include/CSFML/Graphics/CircleShape.h index b9c9fc84..5fdf1f15 100644 --- a/include/CSFML/Graphics/CircleShape.h +++ b/include/CSFML/Graphics/CircleShape.h @@ -369,6 +369,20 @@ CSFML_GRAPHICS_API size_t sfCircleShape_getPointCount(const sfCircleShape* shape //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfVector2f sfCircleShape_getPoint(const sfCircleShape* shape, size_t index); +//////////////////////////////////////////////////////////// +/// \brief Get the geometric center of the circle +/// +/// The returned point is in local coordinates, that is, +/// the shape's transforms (position, rotation, scale) are +/// not taken into account. +/// +/// \param shape Shape object +/// +/// \return The geometric center of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfVector2f sfCircleShape_getGeometricCenter(const sfCircleShape* shape); + //////////////////////////////////////////////////////////// /// \brief Set the radius of a circle /// diff --git a/include/CSFML/Graphics/ConvexShape.h b/include/CSFML/Graphics/ConvexShape.h index 93830ce2..cdc46c56 100644 --- a/include/CSFML/Graphics/ConvexShape.h +++ b/include/CSFML/Graphics/ConvexShape.h @@ -369,6 +369,20 @@ CSFML_GRAPHICS_API size_t sfConvexShape_getPointCount(const sfConvexShape* shape //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfVector2f sfConvexShape_getPoint(const sfConvexShape* shape, size_t index); +//////////////////////////////////////////////////////////// +/// \brief Get the geometric center of a convex shape +/// +/// The returned point is in local coordinates, that is, +/// the shape's transforms (position, rotation, scale) are +/// not taken into account. +/// +/// \param shape Shape object +/// +/// \return The geometric center of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfVector2f sfConvexShape_getGeometricCenter(const sfConvexShape* shape); + //////////////////////////////////////////////////////////// /// \brief Set the number of points of a convex shap /// diff --git a/include/CSFML/Graphics/RectangleShape.h b/include/CSFML/Graphics/RectangleShape.h index 92cff7e3..0d019478 100644 --- a/include/CSFML/Graphics/RectangleShape.h +++ b/include/CSFML/Graphics/RectangleShape.h @@ -369,6 +369,20 @@ CSFML_GRAPHICS_API size_t sfRectangleShape_getPointCount(const sfRectangleShape* //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfVector2f sfRectangleShape_getPoint(const sfRectangleShape* shape, size_t index); +//////////////////////////////////////////////////////////// +/// \brief Get the geometric center of the rectangle +/// +/// The returned point is in local coordinates, that is, +/// the shape's transforms (position, rotation, scale) are +/// not taken into account. +/// +/// \param shape Shape object +/// +/// \return The geometric center of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfVector2f sfRectangleShape_getGeometricCenter(const sfRectangleShape* shape); + //////////////////////////////////////////////////////////// /// \brief Set the size of a rectangle shape /// diff --git a/include/CSFML/Graphics/Shape.h b/include/CSFML/Graphics/Shape.h index a8dfff46..3ec3f0b2 100644 --- a/include/CSFML/Graphics/Shape.h +++ b/include/CSFML/Graphics/Shape.h @@ -368,6 +368,20 @@ CSFML_GRAPHICS_API size_t sfShape_getPointCount(const sfShape* shape); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfVector2f sfShape_getPoint(const sfShape* shape, size_t index); +//////////////////////////////////////////////////////////// +/// \brief Get the geometric center of the shape +/// +/// The returned point is in local coordinates, that is, +/// the shape's transforms (position, rotation, scale) are +/// not taken into account. +/// +/// \param shape Shape object +/// +/// \return The geometric center of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfVector2f sfShape_getGeometricCenter(const sfShape* shape); + //////////////////////////////////////////////////////////// /// \brief Get the local bounding rectangle of a shape /// diff --git a/src/CSFML/Graphics/CircleShape.cpp b/src/CSFML/Graphics/CircleShape.cpp index eea6957e..7e7234c5 100644 --- a/src/CSFML/Graphics/CircleShape.cpp +++ b/src/CSFML/Graphics/CircleShape.cpp @@ -263,6 +263,14 @@ sfVector2f sfCircleShape_getPoint(const sfCircleShape* shape, size_t index) } +//////////////////////////////////////////////////////////// +sfVector2f sfCircleShape_getGeometricCenter(const sfCircleShape* shape) +{ + assert(shape); + return convertVector2(shape->This.getGeometricCenter()); +} + + //////////////////////////////////////////////////////////// void sfCircleShape_setRadius(sfCircleShape* shape, float radius) { diff --git a/src/CSFML/Graphics/ConvexShape.cpp b/src/CSFML/Graphics/ConvexShape.cpp index 52de3b7e..21dd2ca6 100644 --- a/src/CSFML/Graphics/ConvexShape.cpp +++ b/src/CSFML/Graphics/ConvexShape.cpp @@ -260,6 +260,14 @@ sfVector2f sfConvexShape_getPoint(const sfConvexShape* shape, size_t index) } +//////////////////////////////////////////////////////////// +sfVector2f sfConvexShape_getGeometricCenter(const sfConvexShape* shape) +{ + assert(shape); + return convertVector2(shape->This.getGeometricCenter()); +} + + //////////////////////////////////////////////////////////// void sfConvexShape_setPointCount(sfConvexShape* shape, size_t count) { diff --git a/src/CSFML/Graphics/RectangleShape.cpp b/src/CSFML/Graphics/RectangleShape.cpp index f704b331..29c1595a 100644 --- a/src/CSFML/Graphics/RectangleShape.cpp +++ b/src/CSFML/Graphics/RectangleShape.cpp @@ -260,6 +260,14 @@ sfVector2f sfRectangleShape_getPoint(const sfRectangleShape* shape, size_t index } +//////////////////////////////////////////////////////////// +sfVector2f sfRectangleShape_getGeometricCenter(const sfRectangleShape* shape) +{ + assert(shape); + return convertVector2(shape->This.getGeometricCenter()); +} + + //////////////////////////////////////////////////////////// void sfRectangleShape_setSize(sfRectangleShape* shape, sfVector2f size) { diff --git a/src/CSFML/Graphics/Shape.cpp b/src/CSFML/Graphics/Shape.cpp index af6621c8..43745f0f 100644 --- a/src/CSFML/Graphics/Shape.cpp +++ b/src/CSFML/Graphics/Shape.cpp @@ -252,6 +252,14 @@ sfVector2f sfShape_getPoint(const sfShape* shape, size_t index) } +//////////////////////////////////////////////////////////// +sfVector2f sfShape_getGeometricCenter(const sfShape* shape) +{ + assert(shape); + return convertVector2(shape->getGeometricCenter()); +} + + //////////////////////////////////////////////////////////// sfFloatRect sfShape_getLocalBounds(const sfShape* shape) {