From 048abbf46f1654edd40bf2628d44474d5c8e1730 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Sat, 10 Dec 2011 14:51:40 +0100 Subject: [PATCH] Renamed GetOutlinePoint/GetOutlinePointsCount to GetPoint/GetPointsCount in sf::Shape, and made them public --- include/SFML/Graphics/CircleShape.hpp | 10 +++--- include/SFML/Graphics/ConvexShape.hpp | 26 ++------------- include/SFML/Graphics/RectangleShape.hpp | 8 ++--- include/SFML/Graphics/Shape.hpp | 42 ++++++++++-------------- src/SFML/Graphics/CircleShape.cpp | 6 ++-- src/SFML/Graphics/ConvexShape.cpp | 14 -------- src/SFML/Graphics/RectangleShape.cpp | 4 +-- src/SFML/Graphics/Shape.cpp | 5 ++- 8 files changed, 35 insertions(+), 80 deletions(-) diff --git a/include/SFML/Graphics/CircleShape.hpp b/include/SFML/Graphics/CircleShape.hpp index cb0ffed0..0c7b3f21 100644 --- a/include/SFML/Graphics/CircleShape.hpp +++ b/include/SFML/Graphics/CircleShape.hpp @@ -69,15 +69,13 @@ public : //////////////////////////////////////////////////////////// float GetRadius() const; -private : - //////////////////////////////////////////////////////////// - /// \brief Get the number of points defining the shape + /// \brief Get the number of points of the shape /// /// \return Number of points of the shape /// //////////////////////////////////////////////////////////// - virtual unsigned int GetOutlinePointsCount() const; + virtual unsigned int GetPointsCount() const; //////////////////////////////////////////////////////////// /// \brief Get a point of the shape @@ -87,7 +85,7 @@ private : /// \return Index-th point of the shape /// //////////////////////////////////////////////////////////// - virtual Vector2f GetOutlinePoint(unsigned int index) const; + virtual Vector2f GetPoint(unsigned int index) const; private : @@ -122,6 +120,6 @@ private : /// window.Draw(circle); /// \endcode /// -/// \see sf::Shape, sf::StarShape, sf::RectangleShape, sf::ConvexShape +/// \see sf::Shape, sf::RectangleShape, sf::ConvexShape /// //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/ConvexShape.hpp b/include/SFML/Graphics/ConvexShape.hpp index ed3ccd39..771f1521 100644 --- a/include/SFML/Graphics/ConvexShape.hpp +++ b/include/SFML/Graphics/ConvexShape.hpp @@ -68,7 +68,7 @@ public : /// \see SetPointsCount /// //////////////////////////////////////////////////////////// - unsigned int GetPointsCount() const; + virtual unsigned int GetPointsCount() const; //////////////////////////////////////////////////////////// /// \brief Set the position of a point @@ -94,27 +94,7 @@ public : /// \see SetPoint /// //////////////////////////////////////////////////////////// - Vector2f GetPoint(unsigned int index) const; - -private : - - //////////////////////////////////////////////////////////// - /// \brief Get the number of points defining the shape - /// - /// \return Number of points of the shape - /// - //////////////////////////////////////////////////////////// - virtual unsigned int GetOutlinePointsCount() const; - - //////////////////////////////////////////////////////////// - /// \brief Get a point of the shape - /// - /// \param index Index of the point to get - /// - /// \return Index-th point of the shape - /// - //////////////////////////////////////////////////////////// - virtual Vector2f GetOutlinePoint(unsigned int index) const; + virtual Vector2f GetPoint(unsigned int index) const; private : @@ -157,6 +137,6 @@ private : /// window.Draw(polygon); /// \endcode /// -/// \see sf::Shape, sf::StarShape, sf::RectangleShape, sf::CircleShape +/// \see sf::Shape, sf::RectangleShape, sf::CircleShape /// //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/RectangleShape.hpp b/include/SFML/Graphics/RectangleShape.hpp index 48e9f5d4..6d3b4c04 100644 --- a/include/SFML/Graphics/RectangleShape.hpp +++ b/include/SFML/Graphics/RectangleShape.hpp @@ -69,15 +69,13 @@ public : //////////////////////////////////////////////////////////// const Vector2f& GetSize() const; -private : - //////////////////////////////////////////////////////////// /// \brief Get the number of points defining the shape /// /// \return Number of points of the shape /// //////////////////////////////////////////////////////////// - virtual unsigned int GetOutlinePointsCount() const; + virtual unsigned int GetPointsCount() const; //////////////////////////////////////////////////////////// /// \brief Get a point of the shape @@ -87,7 +85,7 @@ private : /// \return Index-th point of the shape /// //////////////////////////////////////////////////////////// - virtual Vector2f GetOutlinePoint(unsigned int index) const; + virtual Vector2f GetPoint(unsigned int index) const; private : @@ -122,6 +120,6 @@ private : /// window.Draw(rectangle); /// \endcode /// -/// \see sf::Shape, sf::StarShape, sf::CircleShape, sf::ConvexShape +/// \see sf::Shape, sf::CircleShape, sf::ConvexShape /// //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/Shape.hpp b/include/SFML/Graphics/Shape.hpp index e38c1784..1b545b41 100644 --- a/include/SFML/Graphics/Shape.hpp +++ b/include/SFML/Graphics/Shape.hpp @@ -184,6 +184,24 @@ public : //////////////////////////////////////////////////////////// float GetOutlineThickness() const; + //////////////////////////////////////////////////////////// + /// \brief Get the total number of points of the shape + /// + /// \return Number of points of the shape + /// + //////////////////////////////////////////////////////////// + virtual unsigned int GetPointsCount() const = 0; + + //////////////////////////////////////////////////////////// + /// \brief Get a point of the shape + /// + /// \param index Index of the point to get, in range [0 .. GetPointsCount() - 1] + /// + /// \return Index-th point of the shape + /// + //////////////////////////////////////////////////////////// + virtual Vector2f GetPoint(unsigned int index) const = 0; + //////////////////////////////////////////////////////////// /// \brief Get the local bounding rectangle of the entity /// @@ -230,30 +248,6 @@ protected : //////////////////////////////////////////////////////////// void Update(); -private : - - //////////////////////////////////////////////////////////// - /// \brief Get the number of points defining the shape - /// - /// This function must be implemented in derived classes. - /// - /// \return Number of points of the shape - /// - //////////////////////////////////////////////////////////// - virtual unsigned int GetOutlinePointsCount() const = 0; - - //////////////////////////////////////////////////////////// - /// \brief Get a point of the shape - /// - /// This function must be implemented in derived classes. - /// - /// \param index Index of the point to get - /// - /// \return Index-th point of the shape - /// - //////////////////////////////////////////////////////////// - virtual Vector2f GetOutlinePoint(unsigned int index) const = 0; - private : //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index 4830e71f..cbf692dd 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -54,16 +54,16 @@ float CircleShape::GetRadius() const //////////////////////////////////////////////////////////// -unsigned int CircleShape::GetOutlinePointsCount() const +unsigned int CircleShape::GetPointsCount() const { return 30; } //////////////////////////////////////////////////////////// -Vector2f CircleShape::GetOutlinePoint(unsigned int index) const +Vector2f CircleShape::GetPoint(unsigned int index) const { - float angle = index * 2 * 3.141592654f / GetOutlinePointsCount(); + float angle = index * 2 * 3.141592654f / GetPointsCount(); float x = std::cos(angle) * myRadius; float y = std::sin(angle) * myRadius; diff --git a/src/SFML/Graphics/ConvexShape.cpp b/src/SFML/Graphics/ConvexShape.cpp index 6c6954f1..d60b583b 100644 --- a/src/SFML/Graphics/ConvexShape.cpp +++ b/src/SFML/Graphics/ConvexShape.cpp @@ -66,18 +66,4 @@ Vector2f ConvexShape::GetPoint(unsigned int index) const return myPoints[index]; } - -//////////////////////////////////////////////////////////// -unsigned int ConvexShape::GetOutlinePointsCount() const -{ - return GetPointsCount(); -} - - -//////////////////////////////////////////////////////////// -Vector2f ConvexShape::GetOutlinePoint(unsigned int index) const -{ - return GetPoint(index); -} - } // namespace sf diff --git a/src/SFML/Graphics/RectangleShape.cpp b/src/SFML/Graphics/RectangleShape.cpp index 3b9ffd77..0d49192d 100644 --- a/src/SFML/Graphics/RectangleShape.cpp +++ b/src/SFML/Graphics/RectangleShape.cpp @@ -54,14 +54,14 @@ const Vector2f& RectangleShape::GetSize() const //////////////////////////////////////////////////////////// -unsigned int RectangleShape::GetOutlinePointsCount() const +unsigned int RectangleShape::GetPointsCount() const { return 4; } //////////////////////////////////////////////////////////// -Vector2f RectangleShape::GetOutlinePoint(unsigned int index) const +Vector2f RectangleShape::GetPoint(unsigned int index) const { switch (index) { diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 3a0e87cb..656cc370 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -169,7 +169,7 @@ myBounds () void Shape::Update() { // Get the total number of points of the shape - unsigned int count = GetOutlinePointsCount(); + unsigned int count = GetPointsCount(); if (count < 3) { myVertices.Resize(0); @@ -180,9 +180,8 @@ void Shape::Update() myVertices.Resize(count + 2); // + 2 for center and repeated first point // Position - Vector2f offset(myOutlineThickness, myOutlineThickness); for (unsigned int i = 0; i < count; ++i) - myVertices[i + 1].Position = GetOutlinePoint(i) + offset; + myVertices[i + 1].Position = GetPoint(i); myVertices[count + 1].Position = myVertices[1].Position; // Update the bounding rectangle