[orx-shapes] Add extensions for creating sub-shapes and positioning boxes

Introduce `Rectangle.sub` and `Box.sub` functions to derive sub-rectangles and sub-boxes from existing shapes using relative dimensions. Add `Box.place` to position a box relative to another using customizable anchors.
This commit is contained in:
Edwin Jakobs
2025-02-26 21:58:17 +01:00
parent bd310d7014
commit 6ad584a262
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package org.openrndr.extra.shapes.primitives
import org.openrndr.math.Vector3
import org.openrndr.shape.Box
fun Box.place(item: Box, anchor: Vector3 = Vector3(0.5, 0.5, 0.5), itemAnchor: Vector3 = anchor): Box {
return Box(
corner = corner + (dimensions * anchor - item.dimensions * itemAnchor),
width = item.width,
height = item.height,
depth = item.depth
)
}

View File

@@ -0,0 +1,21 @@
package org.openrndr.extra.shapes.primitives
import org.openrndr.shape.Box
/**
* Creates a sub-box from the current box using the dimensions
* defined by another box.
*
* @param uvw The box defining the dimensions (relative to this box)
* to create the sub-box. Its position and size are used to compute the
* resulting sub-box.
*/
fun Box.sub(uvw: Box) =
sub(
uvw.corner.x,
uvw.corner.y,
uvw.corner.z,
uvw.corner.x + uvw.width,
uvw.corner.y + uvw.height,
uvw.corner.z + uvw.depth
)

View File

@@ -0,0 +1,13 @@
package org.openrndr.extra.shapes.primitives
import org.openrndr.shape.Rectangle
/**
* Creates a sub-rectangle from the current rectangle using the dimensions
* defined by another rectangle.
*
* @param uv The rectangle defining the dimensions (relative to this rectangle)
* to create the sub-rectangle. Its position and size are used to compute the
* resulting sub-rectangle.
*/
fun Rectangle.sub(uv: Rectangle) = sub(uv.x, uv.y, uv.x + uv.width, uv.y + uv.height)