[orx-shapes] Fix Rectangle.grid rounding error (#252)

This commit is contained in:
Abe Pazos
2022-08-10 20:18:33 +00:00
committed by GitHub
parent dfa1f922f5
commit ee9c5e0f70

View File

@@ -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()