---
title: "constrain"
description: "Takes [otherConstraints] and returns the result of coercing them in the current constraints. Note
this means that any size satisfying the resulting constraints will satisfy the current
constraints, but they might not satisfy the [otherConstraints] when the two set of constraints
are disjoint. Examples (showing only width, height works the same): (minWidth=2,
maxWidth=10).constrain(minWidth=7, maxWidth=12) -> (minWidth = 7, maxWidth = 10) (minWidth=2,
maxWidth=10).constrain(minWidth=11, maxWidth=12) -> (minWidth=10, maxWidth=10) (minWidth=2,
maxWidth=10).constrain(minWidth=5, maxWidth=7) -> (minWidth=5, maxWidth=7)"
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Constraints.constrain(otherConstraints: Constraints): Constraints
```


Takes `otherConstraints` and returns the result of coercing them in the current constraints. Note
this means that any size satisfying the resulting constraints will satisfy the current
constraints, but they might not satisfy the `otherConstraints` when the two set of constraints
are disjoint. Examples (showing only width, height works the same): (minWidth=2,
maxWidth=10).constrain(minWidth=7, maxWidth=12) -> (minWidth = 7, maxWidth = 10) (minWidth=2,
maxWidth=10).constrain(minWidth=11, maxWidth=12) -> (minWidth=10, maxWidth=10) (minWidth=2,
maxWidth=10).constrain(minWidth=5, maxWidth=7) -> (minWidth=5, maxWidth=7)



<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Constraints.constrain(size: IntSize) =
    IntSize(
        width = size.width.fastCoerceIn(minWidth, maxWidth),
        height = size.height.fastCoerceIn(minHeight, maxHeight),
    )
```


Takes a size and returns the closest size to it that satisfies the constraints.



