From 9fa93a2a64f259cdb9109f596d8f8c5aea5a2eca Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Wed, 10 Aug 2022 20:18:33 +0000 Subject: [PATCH] [orx-shapes] Fix Rectangle.grid rounding error (#252) --- orx-shapes/src/commonMain/kotlin/RectangleGrid.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/orx-shapes/src/commonMain/kotlin/RectangleGrid.kt b/orx-shapes/src/commonMain/kotlin/RectangleGrid.kt index 45fb92730..c31faf0d7 100644 --- a/orx-shapes/src/commonMain/kotlin/RectangleGrid.kt +++ b/orx-shapes/src/commonMain/kotlin/RectangleGrid.kt @@ -1,6 +1,7 @@ package org.openrndr.extra.shapes import org.openrndr.shape.Rectangle +import kotlin.math.round /** * Splits [Rectangle] into a grid of [Rectangle]s @@ -51,8 +52,8 @@ fun Rectangle.grid( val cellSpaceX = cellWidth + gutterX val cellSpaceY = cellHeight + gutterY - val columns = ((availableWidth + gutterX) / cellSpaceX).toInt() - val rows = ((availableHeight + gutterY) / cellSpaceY).toInt() + val columns = round((availableWidth + gutterX) / cellSpaceX).toInt() + val rows = round((availableHeight + gutterY) / cellSpaceY).toInt() if (columns == 0 || rows == 0) { return emptyList()