[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:
13
orx-shapes/src/commonMain/kotlin/primitives/BoxPlace.kt
Normal file
13
orx-shapes/src/commonMain/kotlin/primitives/BoxPlace.kt
Normal 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
|
||||
)
|
||||
}
|
||||
21
orx-shapes/src/commonMain/kotlin/primitives/BoxSub.kt
Normal file
21
orx-shapes/src/commonMain/kotlin/primitives/BoxSub.kt
Normal 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
|
||||
)
|
||||
13
orx-shapes/src/commonMain/kotlin/primitives/RectangleSub.kt
Normal file
13
orx-shapes/src/commonMain/kotlin/primitives/RectangleSub.kt
Normal 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)
|
||||
Reference in New Issue
Block a user