Skip to content

Commit

Permalink
DefaultNode: optimize code readability in getMaximumBoundingBox
Browse files Browse the repository at this point in the history
  • Loading branch information
smlpt committed Jan 30, 2025
1 parent c0d9e09 commit 26ba645
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/kotlin/graphics/scenery/DefaultNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,24 @@ open class DefaultNode(name: String = "Node") : Node, Networkable {
}

override fun getMaximumBoundingBox(): OrientedBoundingBox {
if(boundingBox == null && children.size == 0) {
return OrientedBoundingBox(this,0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)
if (boundingBox == null && children.size == 0) {
return OrientedBoundingBox(this, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)
}

if(children.none { it !is BoundingGrid }) {
return OrientedBoundingBox(this,boundingBox?.min ?: Vector3f(0.0f, 0.0f, 0.0f), boundingBox?.max ?: Vector3f(0.0f, 0.0f, 0.0f))
if (children.none { it !is BoundingGrid }) {
return OrientedBoundingBox(
this,
boundingBox?.min ?: Vector3f(0.0f, 0.0f, 0.0f),
boundingBox?.max ?: Vector3f(0.0f, 0.0f, 0.0f)
)
}

return children
.filter { it !is BoundingGrid }.map { it.getMaximumBoundingBox().translate(it.spatialOrNull()?.position ?: Vector3f(0f, 0f, 0f)) }
.fold(boundingBox ?: OrientedBoundingBox(this, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), { lhs, rhs -> lhs.expand(lhs, rhs) })
.filter { it !is BoundingGrid }
.map { it.getMaximumBoundingBox().translate(it.spatialOrNull()?.position ?: Vector3f(0f, 0f, 0f)) }
.fold(
boundingBox ?: OrientedBoundingBox(this, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)
) { lhs, rhs -> lhs.expand(lhs, rhs) }
}

override fun runRecursive(func: (Node) -> Unit) {
Expand Down

0 comments on commit 26ba645

Please sign in to comment.