From a4ed1966a98344d8d49b5afeefe8c98cd919c33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa?= Date: Sat, 23 Nov 2024 13:21:57 +0000 Subject: [PATCH] Avoid ranges on AABB --- .../minart/geometry/AxisAlignedBoundingBox.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/shared/src/main/scala/eu/joaocosta/minart/geometry/AxisAlignedBoundingBox.scala b/core/shared/src/main/scala/eu/joaocosta/minart/geometry/AxisAlignedBoundingBox.scala index c3770883..a6633847 100644 --- a/core/shared/src/main/scala/eu/joaocosta/minart/geometry/AxisAlignedBoundingBox.scala +++ b/core/shared/src/main/scala/eu/joaocosta/minart/geometry/AxisAlignedBoundingBox.scala @@ -92,11 +92,17 @@ final case class AxisAlignedBoundingBox( * * @param f side effect, receiving (x, y) points */ - def foreach(f: (Int, Int) => Unit): Unit = - for { - y <- (y1 until y2).iterator - x <- (x1 until x2).iterator - } f(x, y) + def foreach(f: (Int, Int) => Unit): Unit = { + var y = y1 + while (y < y2) { + var x = x1 + while (x < x2) { + f(x, y) + x = x + 1 + } + y = y + 1 + } + } } object AxisAlignedBoundingBox {