[orx-camera] Add explicit contract checks for lambdas in Camera2D and OrbitalCamera

This commit is contained in:
Edwin Jakobs
2025-08-20 21:12:21 +02:00
parent 7541865e2c
commit ad31a9ab02
2 changed files with 20 additions and 6 deletions

View File

@@ -12,6 +12,8 @@ import org.openrndr.events.Event
import org.openrndr.math.Matrix44
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.buildTransform
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
/**
* The [Camera2D] extension enables panning, rotating, and zooming the view
@@ -78,7 +80,11 @@ class Camera2D : Extension, ChangeEvents {
*
* @param function the drawing function to be applied within the isolated scope of the `Drawer`.
*/
@OptIn(ExperimentalContracts::class)
fun isolated(function: Drawer.() -> Unit) {
contract {
callsInPlace(function, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
program.drawer.isolated {
program.drawer.ortho(RenderTarget.active)

View File

@@ -8,6 +8,9 @@ import org.openrndr.events.Event
import org.openrndr.math.Matrix44
import org.openrndr.math.Spherical
import org.openrndr.math.Vector3
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.pow
@@ -423,15 +426,20 @@ class OrbitalCamera(
* in the same program.
* @param function the function that is called in the isolation
*/
@OptIn(ExperimentalContracts::class)
fun OrbitalCamera.isolated(drawer: Drawer, function: Drawer.() -> Unit) {
contract {
callsInPlace(function, InvocationKind.EXACTLY_ONCE)
}
drawer.pushTransforms()
drawer.pushStyle()
applyTo(drawer)
function(drawer)
drawer.popStyle()
drawer.popTransforms()
try {
applyTo(drawer)
function(drawer)
} finally {
drawer.popStyle()
drawer.popTransforms()
}
}