mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
lazy bounding radius computing for shape_node (avoids O(n^2) deserialization)
This commit is contained in:
@@ -410,8 +410,7 @@ shape_node::merge( shape_node &Shape ) {
|
||||
m_data.vertices.insert(
|
||||
std::end( m_data.vertices ),
|
||||
std::begin( Shape.m_data.vertices ), std::end( Shape.m_data.vertices ) );
|
||||
// NOTE: we could recalculate radius with something other than brute force, but it'll do
|
||||
compute_radius();
|
||||
invalidate_radius();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -445,7 +444,16 @@ shape_node::compute_radius() {
|
||||
m_data.area.radius = static_cast<float>( std::sqrt( squaredradius ) );
|
||||
}
|
||||
|
||||
void shape_node::invalidate_radius() {
|
||||
m_data.area.radius = -1.0f;
|
||||
}
|
||||
|
||||
float shape_node::radius() {
|
||||
if (m_data.area.radius == -1.0f)
|
||||
compute_radius();
|
||||
|
||||
return m_data.area.radius;
|
||||
}
|
||||
|
||||
// sends content of the struct to provided stream
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user