MCPcopy Create free account
hub / github.com/SFML/SFML / getBounds

Method getBounds

src/SFML/Graphics/VertexArray.cpp:101–132  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

99
100////////////////////////////////////////////////////////////
101FloatRect VertexArray::getBounds() const
102{
103 if (!m_vertices.empty())
104 {
105 float left = m_vertices[0].position.x;
106 float top = m_vertices[0].position.y;
107 float right = m_vertices[0].position.x;
108 float bottom = m_vertices[0].position.y;
109
110 for (std::size_t i = 1; i < m_vertices.size(); ++i)
111 {
112 const Vector2f position = m_vertices[i].position;
113
114 // Update left and right
115 if (position.x < left)
116 left = position.x;
117 else if (position.x > right)
118 right = position.x;
119
120 // Update top and bottom
121 if (position.y < top)
122 top = position.y;
123 else if (position.y > bottom)
124 bottom = position.y;
125 }
126
127 return {{left, top}, {right - left, bottom - top}};
128 }
129
130 // Array is empty
131 return {};
132}
133
134
135////////////////////////////////////////////////////////////

Callers 3

updateMethod · 0.80
updateOutlineMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected