diff --git a/orx-shapes/src/commonMain/kotlin/primitives/BoxPlace.kt b/orx-shapes/src/commonMain/kotlin/primitives/BoxPlace.kt new file mode 100644 index 00000000..b2de3584 --- /dev/null +++ b/orx-shapes/src/commonMain/kotlin/primitives/BoxPlace.kt @@ -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 + ) +} \ No newline at end of file diff --git a/orx-shapes/src/commonMain/kotlin/primitives/BoxSub.kt b/orx-shapes/src/commonMain/kotlin/primitives/BoxSub.kt new file mode 100644 index 00000000..43c70716 --- /dev/null +++ b/orx-shapes/src/commonMain/kotlin/primitives/BoxSub.kt @@ -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 + ) \ No newline at end of file diff --git a/orx-shapes/src/commonMain/kotlin/primitives/RectangleSub.kt b/orx-shapes/src/commonMain/kotlin/primitives/RectangleSub.kt new file mode 100644 index 00000000..93d038a8 --- /dev/null +++ b/orx-shapes/src/commonMain/kotlin/primitives/RectangleSub.kt @@ -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) \ No newline at end of file