From 7dfc7f02029b039005fdb1868dccefa4e523d25c Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Wed, 2 Mar 2022 18:35:13 -0700 Subject: [PATCH] Use new sf::Vector2 utilities --- src/SFML/Graphics/Shape.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index a7726827..a46dca94 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -36,18 +36,12 @@ namespace // Compute the normal of a segment sf::Vector2f computeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2) { - sf::Vector2f normal(p1.y - p2.y, p2.x - p1.x); - float length = std::sqrt(normal.x * normal.x + normal.y * normal.y); + sf::Vector2f normal = (p2 - p1).perpendicular(); + float length = normal.length(); if (length != 0.f) normal /= length; return normal; } - - // Compute the dot product of two vectors - float dotProduct(const sf::Vector2f& p1, const sf::Vector2f& p2) - { - return p1.x * p2.x + p1.y * p2.y; - } } @@ -280,9 +274,9 @@ void Shape::updateOutline() // Make sure that the normals point towards the outside of the shape // (this depends on the order in which the points were defined) - if (dotProduct(n1, m_vertices[0].position - p1) > 0) + if (n1.dot(m_vertices[0].position - p1) > 0) n1 = -n1; - if (dotProduct(n2, m_vertices[0].position - p1) > 0) + if (n2.dot(m_vertices[0].position - p1) > 0) n2 = -n2; // Combine them to get the extrusion direction