Skip to content

Commit

Permalink
Use the geometric center for shape first vertex
Browse files Browse the repository at this point in the history
instead of the bounding box center.
The bounding box center can be on an edge (consider a right triangle).
Having the first vertex on an edge can make outline computation wrong by
failing to determine if an edge normal points inward or outward. The
geometric center being stricly inside the shape and not on an edge,
using it instead makes outline computation correct.
  • Loading branch information
kimci86 committed Oct 22, 2023
1 parent 6aabb75 commit 71826de
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/SFML/Graphics/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ void Shape::update()
m_vertices[0] = m_vertices[1]; // so that the result of getBounds() is correct
m_insideBounds = m_vertices.getBounds();

// Compute the center and make it the first vertex
m_vertices[0].position.x = m_insideBounds.left + m_insideBounds.width / 2;
m_vertices[0].position.y = m_insideBounds.top + m_insideBounds.height / 2;
// Compute the geometric center and make it the first vertex
m_vertices[0].position = getGeometricCenter();

// Color
updateFillColors();
Expand Down

0 comments on commit 71826de

Please sign in to comment.