---
title: "PolygonShapeTransformScope"
description: "Transforms a [PolygonShape]'s geometry inside [PolygonShape.transform]."
type: "interface"
lastmod: "2026-10-07"
---
## API Reference

> Source set: Common

```kotlin
public sealed interface PolygonShapeTransformScope : Density
```

Transforms a [PolygonShape](/jetpack-compose/androidx.compose.foundation/foundation/functions/PolygonShape/api)'s geometry inside `PolygonShape.transform`.

Exposes the layout resolution inputs ([size](/jetpack-compose/androidx.compose.foundation/foundation/functions/size/api), `layoutDirection`, and `Density`). Operations
(`rotate`, `translate`, [scale](/jetpack-compose/androidx.compose.foundation/foundation/functions/scale/api), `transform`, and `scaleToFit`) concatenate onto the
transformation matrix in the exact order they are called (for example, [scale](/jetpack-compose/androidx.compose.foundation/foundation/functions/scale/api) followed by
`translate` differs from `translate` followed by [scale](/jetpack-compose/androidx.compose.foundation/foundation/functions/scale/api)).

## Properties

### size

> Source set: Common

```kotlin
public val size: Size
```

Size of the shape's layout container in pixels.

### layoutDirection

> Source set: Common

```kotlin
public val layoutDirection: LayoutDirection
```

Layout direction of the shape.

## Functions

### rotate

> Source set: Common

```kotlin
public fun rotate(degrees: Float, pivot: Offset = Offset.Unspecified)
```

Rotates the polygon clockwise by `degrees` around `pivot`.

#### Parameters

| | |
| --- | --- |
| degrees | clockwise rotation in degrees |
| pivot | rotation center in pixels, or `Offset.Unspecified` for the polygon's center |

### translate

> Source set: Common

```kotlin
public fun translate(x: Float = 0f, y: Float = 0f)
```

Translates the polygon by (`x`, `y`) pixels.

#### Parameters

| | |
| --- | --- |
| x | horizontal offset in pixels |
| y | vertical offset in pixels |

### scale

> Source set: Common

```kotlin
public fun scale(
        scaleX: Float,
        scaleY: Float = scaleX,
        pivot: Offset = Offset.Unspecified,
    )
```

Scales the polygon by `scaleX` horizontally and `scaleY` vertically around `pivot`.

#### Parameters

| | |
| --- | --- |
| scaleX | horizontal scale factor |
| scaleY | vertical scale factor, defaults to `scaleX` for uniform scaling |
| pivot | scale center in pixels, or `Offset.Unspecified` for the polygon's center |

### transform

> Source set: Common

```kotlin
public fun transform(matrix: Matrix)
```

Multiplies the current transformation by the affine `matrix` around the polygon's center.

Linear components (rotation, scale, skew) pivot around the polygon's center, while
translation components offset the polygon directly.

#### Parameters

| | |
| --- | --- |
| matrix | affine transformation matrix to multiply |

#### Throws: IllegalArgumentException

if [matrix](/jetpack-compose/androidx.compose.ui/ui-graphics/classes/Matrix) contains perspective components

### scaleToFit

> Source set: Common

```kotlin
public fun scaleToFit(
        contentScale: ContentScale = ContentScale.Fit,
        alignment: Alignment = Alignment.Center,
    )
```

Scales and aligns the polygon's bounding box into [size](/jetpack-compose/androidx.compose.foundation/foundation/functions/size/api) in call order.

- Call before `rotate`, [scale](/jetpack-compose/androidx.compose.foundation/foundation/functions/scale/api), or `translate` to fit the unrotated polygon first, then
transform it around its fitted center.
- Call after `rotate` or `transform` to fit the transformed bounding box into [size](/jetpack-compose/androidx.compose.foundation/foundation/functions/size/api).
- `ContentScale.Fit` (default) scales uniformly to fit within bounds, preserving aspect ratio
- `ContentScale.FillBounds` stretches each axis independently to fill the bounds
- `ContentScale.Crop` fills the bounds, preserving aspect ratio and clipping overflow
- `ContentScale.None` applies no scaling

#### Parameters

| | |
| --- | --- |
| contentScale | policy for scaling the polygon's bounding box into the layout bounds |
| alignment | placement of the scaled polygon within the layout bounds |

## Code Examples

### TransformedPolygonShapeSample

```kotlin
@Sampled
@Composable
fun TransformedPolygonShapeSample() {
    // A square polygon rotated 45 degrees around its center and scaled into the layout bounds in a
    // single pass so the rotated diamond stays inscribed without clipping.
    val diamond = remember {
        PolygonShape { polygon(numVertices = 4, rounding = CornerRounding.fraction(0.15f)) }
            .apply {
                transform {
                    rotate(degrees = 45f)
                    scaleToFit(contentScale = ContentScale.Fit)
                }
            }
    }
    Box(Modifier.size(96.dp).clip(diamond).background(Color(0xFFE91E63)))
}
```

### RuntimeTransformedPolygonShapeSample

```kotlin
@Sampled
@Composable
fun RuntimeTransformedPolygonShapeSample() {
    // Creates an unrotated badge shape and an independent rotated copy using copy() + transform {}.
    val badge = remember {
        PolygonShape.star(
            numPoints = 8,
            innerRadiusRatio = 0.75f,
            outerRounding = CornerRounding.fraction(0.4f),
        )
    }
    val selectedBadge =
        remember(badge) { badge.copy().apply { transform { rotate(degrees = 22.5f) } } }
    var selected by remember { mutableStateOf(false) }
    val shape = if (selected) selectedBadge else badge
    Box(
        Modifier.size(96.dp).clip(shape).background(Color(0xFF00695C)).clickable {
            selected = !selected
        }
    )
}
```
