Function

transformed

Returns a new PolygonShape with rotation and translation applied to the underlying geometry.

TransformedPolygonShapeSample

@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(percent = 15)) }
            .transformed(rotation = 45f, contentScale = ContentScale.Fit)
    }
    Box(Modifier.size(96.dp).clip(diamond).background(Color(0xFFE91E63)))
}

RuntimeTransformedPolygonShapeSample

@Sampled
@Composable
fun RuntimeTransformedPolygonShapeSample() {
    // Pre-creates the unrotated and rotated badge shape values. The runtime decision toggles
    // between shape instances without rebuilding or recomputing geometry on state flips.
    val badge = remember {
        PolygonShape.star(
            numPoints = 8,
            innerRadiusRatio = 0.75f,
            outerRounding = CornerRounding(percent = 40),
        )
    }
    val selectedBadge = remember(badge) { badge.transformed(rotation = 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
        }
    )
}

Content updated: