Skip to content

Commit

Permalink
[orx-shapes] Fix Rectangle.grid rounding error (openrndr#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid committed Aug 17, 2022
1 parent 54aca03 commit 9fa93a2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions orx-shapes/src/commonMain/kotlin/RectangleGrid.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9fa93a2

Please sign in to comment.