[orx-camera] Add explicit contract checks for lambdas in Camera2D and OrbitalCamera
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
try {
|
||||
applyTo(drawer)
|
||||
function(drawer)
|
||||
|
||||
} finally {
|
||||
drawer.popStyle()
|
||||
drawer.popTransforms()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user