[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.Matrix44
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
import org.openrndr.math.transforms.buildTransform
|
import org.openrndr.math.transforms.buildTransform
|
||||||
|
import kotlin.contracts.ExperimentalContracts
|
||||||
|
import kotlin.contracts.contract
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The [Camera2D] extension enables panning, rotating, and zooming the view
|
* 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`.
|
* @param function the drawing function to be applied within the isolated scope of the `Drawer`.
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
fun isolated(function: Drawer.() -> Unit) {
|
fun isolated(function: Drawer.() -> Unit) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(function, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
program.drawer.isolated {
|
program.drawer.isolated {
|
||||||
program.drawer.ortho(RenderTarget.active)
|
program.drawer.ortho(RenderTarget.active)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import org.openrndr.events.Event
|
|||||||
import org.openrndr.math.Matrix44
|
import org.openrndr.math.Matrix44
|
||||||
import org.openrndr.math.Spherical
|
import org.openrndr.math.Spherical
|
||||||
import org.openrndr.math.Vector3
|
import org.openrndr.math.Vector3
|
||||||
|
import kotlin.contracts.ExperimentalContracts
|
||||||
|
import kotlin.contracts.InvocationKind
|
||||||
|
import kotlin.contracts.contract
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
@@ -423,15 +426,20 @@ class OrbitalCamera(
|
|||||||
* in the same program.
|
* in the same program.
|
||||||
* @param function the function that is called in the isolation
|
* @param function the function that is called in the isolation
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
fun OrbitalCamera.isolated(drawer: Drawer, function: Drawer.() -> Unit) {
|
fun OrbitalCamera.isolated(drawer: Drawer, function: Drawer.() -> Unit) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(function, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
drawer.pushTransforms()
|
drawer.pushTransforms()
|
||||||
drawer.pushStyle()
|
drawer.pushStyle()
|
||||||
|
try {
|
||||||
applyTo(drawer)
|
applyTo(drawer)
|
||||||
function(drawer)
|
function(drawer)
|
||||||
|
} finally {
|
||||||
drawer.popStyle()
|
drawer.popStyle()
|
||||||
drawer.popTransforms()
|
drawer.popTransforms()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user