# PolygonShape

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/shape/PolygonShape.kt+class:androidx.compose.foundation.shape.PolygonShape) Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01) Common/All
- Cmn

  ```
  sealed class PolygonShape : Shape
  ```

*** ** * ** ***

Defines a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape` built from rounded polygon geometry.

Create instances with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` or companion factories like `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#regularPolygon(kotlin.Int,androidx.compose.foundation.shape.CornerRounding)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#star(kotlin.Int,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)`.

- Call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)` to rotate, translate, scale, apply a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Matrix`, or fit the geometry into the layout bounds in place.

- Call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#copy()` before mutating a shared shape to keep the original unchanged.

Note: Caches the resolved `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` for the most recent layout size, and shares returned `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` instances across callers. Do not mutate the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` returned by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#createOutline(androidx.compose.ui.geometry.Size,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.Density)`.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#absoluteRectangle(androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)( topLeftRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, topRightRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, bottomRightRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, bottomLeftRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding )` Creates a rectangular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with fixed left/right corner roundings. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#circle(kotlin.Int)(numVertices: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 3) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a circular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` approximated by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#circle(kotlin.Int)` rounded vertices. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#pill(kotlin.Float)(smoothing: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Creates a pill `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with rounded ends along the shorter container sides. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#pillStar(kotlin.Int,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)( numPoints: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, innerRadiusRatio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, vertexSpacing: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, startLocation: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, outerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, innerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding )` Creates a star `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with vertices distributed along a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#pill(kotlin.Float)` outline. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#rectangle(androidx.compose.foundation.shape.CornerRounding)(rounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding)` Creates a rectangular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` filling the layout bounds with uniform `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#rectangle(androidx.compose.foundation.shape.CornerRounding)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#rectangle(androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)( topStartRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, topEndRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, bottomEndRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, bottomStartRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding )` Creates a rectangular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with independent layout-direction-aware corners. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#regularPolygon(kotlin.Int,androidx.compose.foundation.shape.CornerRounding)( numVertices: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 3) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, rounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding )` Creates a regular polygon `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` inscribed in the container's smaller dimension. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#star(kotlin.Int,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)( numPoints: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, innerRadiusRatio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, outerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding, innerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding )` Creates a star `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` inscribed in the container's smaller dimension. | Cmn |

| ### Protected constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#PolygonShape()()` | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/RememberInComposition https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#copy()()` Creates an independent copy of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` and its transformations. | Cmn |
| `final https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#createOutline(androidx.compose.ui.geometry.Size,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.Density)( size: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size, layoutDirection: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection, density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density )` Creates `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` of this shape for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape#createOutline(androidx.compose.ui.geometry.Size,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.Density)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/RememberInComposition https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)(block: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Transforms this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape`'s geometry in place using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)`. | Cmn |

## Public companion functions

### absoluteRectangle

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun absoluteRectangle(
    topLeftRounding: CornerRounding = CornerRounding.Unrounded,
    topRightRounding: CornerRounding = CornerRounding.Unrounded,
    bottomRightRounding: CornerRounding = CornerRounding.Unrounded,
    bottomLeftRounding: CornerRounding = CornerRounding.Unrounded
): PolygonShape
```

Creates a rectangular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with fixed left/right corner roundings.

Corner roundings do not mirror with `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection`.

| Parameters |
|---|---|
| `topLeftRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | top-left corner rounding, resolved against the layout bounds |
| `topRightRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | top-right corner rounding, resolved against the layout bounds |
| `bottomRightRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | bottom-right corner rounding, resolved against the layout bounds |
| `bottomLeftRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | bottom-left corner rounding, resolved against the layout bounds |

### circle

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun circle(numVertices: @IntRange(from = 3) Int = 8): PolygonShape
```

Creates a circular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` approximated by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#circle(kotlin.Int)` rounded vertices.

| Parameters |
|---|---|
| `numVertices: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 3) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 8` | number of vertices approximating the circle, at least 3 |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#circle(kotlin.Int)` is less than 3 |

### pill

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun pill(smoothing: @FloatRange(from = 0.0, to = 1.0) Float = 0.0f): PolygonShape
```

Creates a pill `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with rounded ends along the shorter container sides.

| Parameters |
|---|---|
| `smoothing: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | transition smoothness between the endcap arcs and straight edges, in `0f..1f` (`0f` keeps a purely circular arc) |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#pill(kotlin.Float)` is outside `0f..1f` |

### pillStar

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun pillStar(
    numPoints: @IntRange(from = 2) Int,
    innerRadiusRatio: @FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) Float = 0.5f,
    vertexSpacing: @FloatRange(from = 0.0, to = 1.0) Float = 0.5f,
    startLocation: @FloatRange(from = 0.0, to = 1.0) Float = 0.0f,
    outerRounding: CornerRounding = CornerRounding.Unrounded,
    innerRounding: CornerRounding = outerRounding
): PolygonShape
```

Creates a star `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with vertices distributed along a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#pill(kotlin.Float)` outline.

`https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#pillStar(kotlin.Int,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` controls how vertices are spaced around the curved ends:

- `0f`: spaces inner vertices evenly along the curved ends

- `1f`: spaces outer vertices evenly along the curved ends

- `0.5f` (default): averages inner and outer spacing symmetrically

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CornerRounding
import androidx.compose.foundation.shape.PolygonShape
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// An elongated star outline distributed along a pill container, creating a decorative badge.
val pillStar = remember {
    PolygonShape.pillStar(
        numPoints = 8,
        innerRadiusRatio = 0.6f,
        outerRounding = CornerRounding.fraction(0.2f, smoothing = 0.5f),
    )
}
Box(Modifier.size(width = 140.dp, height = 64.dp).clip(pillStar).background(Color(0xFFE91E63)))
```

| Parameters |
|---|---|
| `numPoints: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | number of star tips, at least 2 |
| `innerRadiusRatio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.5f` | ratio of inner radius to outer radius, in `(0f, 1f)` |
| `vertexSpacing: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.5f` | curved-end vertex spacing policy, in `0f..1f` |
| `startLocation: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | perimeter offset where the outline starts, in `0f..1f` |
| `outerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | rounding for outer tips, resolved against the star's outer radius |
| `innerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = outerRounding` | rounding for inner corners, resolved against the star's outer radius |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#pillStar(kotlin.Int,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` is less than 2, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#pillStar(kotlin.Int,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` is outside `(0f, 1f)`, or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#pillStar(kotlin.Int,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#pillStar(kotlin.Int,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` is outside `0f..1f` |

### rectangle

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun rectangle(rounding: CornerRounding): PolygonShape
```

Creates a rectangular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` filling the layout bounds with uniform `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#rectangle(androidx.compose.foundation.shape.CornerRounding)`.

| Parameters |
|---|---|
| `rounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding` | corner rounding for all 4 corners, resolved against the layout bounds |

### rectangle

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun rectangle(
    topStartRounding: CornerRounding = CornerRounding.Unrounded,
    topEndRounding: CornerRounding = CornerRounding.Unrounded,
    bottomEndRounding: CornerRounding = CornerRounding.Unrounded,
    bottomStartRounding: CornerRounding = CornerRounding.Unrounded
): PolygonShape
```

Creates a rectangular `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with independent layout-direction-aware corners.

Corner roundings mirror automatically in `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection#Rtl`.

| Parameters |
|---|---|
| `topStartRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | top-start corner rounding, resolved against the layout bounds |
| `topEndRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | top-end corner rounding, resolved against the layout bounds |
| `bottomEndRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | bottom-end corner rounding, resolved against the layout bounds |
| `bottomStartRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | bottom-start corner rounding, resolved against the layout bounds |

### regularPolygon

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun regularPolygon(
    numVertices: @IntRange(from = 3) Int,
    rounding: CornerRounding = CornerRounding.Unrounded
): PolygonShape
```

Creates a regular polygon `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` inscribed in the container's smaller dimension.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CornerRounding
import androidx.compose.foundation.shape.PolygonShape
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// A pentagon whose corners round to a 0.2f fraction of its generating radius, so the rounding
// scales proportionally with the shape at any size.
val pentagon = remember {
    PolygonShape.regularPolygon(numVertices = 5, rounding = CornerRounding.fraction(0.2f))
}
Box(Modifier.size(96.dp).clip(pentagon).background(Color(0xFF009688)))
```

| Parameters |
|---|---|
| `numVertices: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 3) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | number of vertices, at least 3 |
| `rounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | corner rounding resolved against the polygon's radius |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#regularPolygon(kotlin.Int,androidx.compose.foundation.shape.CornerRounding)` is less than 3 |

### star

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
fun star(
    numPoints: @IntRange(from = 2) Int,
    innerRadiusRatio: @FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) Float = 0.5f,
    outerRounding: CornerRounding = CornerRounding.Unrounded,
    innerRounding: CornerRounding = outerRounding
): PolygonShape
```

Creates a star `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` inscribed in the container's smaller dimension.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CornerRounding
import androidx.compose.foundation.shape.PolygonShape
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// An eight-point star with smoothly rounded outer points.
val star =
    PolygonShape.star(
        numPoints = 8,
        innerRadiusRatio = 0.6f,
        outerRounding = CornerRounding.fraction(0.15f, smoothing = 0.5f),
    )
Box(Modifier.size(96.dp).clip(star).background(Color(0xFFFFC107)))
```

| Parameters |
|---|---|
| `numPoints: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | number of star tips, at least 2 |
| `innerRadiusRatio: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, fromInclusive = false, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.5f` | ratio of inner radius to outer radius, in `(0f, 1f)` |
| `outerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | rounding for outer tips, resolved against the star's outer radius |
| `innerRounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = outerRounding` | rounding for inner corners, resolved against the star's outer radius |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#star(kotlin.Int,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` is less than 2 or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape.Companion#star(kotlin.Int,kotlin.Float,androidx.compose.foundation.shape.CornerRounding,androidx.compose.foundation.shape.CornerRounding)` is outside `(0f, 1f)` |

## Protected constructors

### PolygonShape

Cmn

```
protected PolygonShape()
```

## Public functions

### copy

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
@RememberInComposition
fun copy(): PolygonShape
```

Creates an independent copy of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` and its transformations.

Subsequent in-place mutations via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)` on the returned copy do not affect this shape, and vice versa.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CornerRounding
import androidx.compose.foundation.shape.PolygonShape
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// 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
    }
)
```

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` | a new `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` with the same base geometry and transformation configuration |

### createOutline

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
final fun createOutline(
    size: Size,
    layoutDirection: LayoutDirection,
    density: Density
): Outline
```

Creates `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` of this shape for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape#createOutline(androidx.compose.ui.geometry.Size,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.Density)`.

| Parameters |
|---|---|
| `size: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | the size of the shape boundary. |
| `layoutDirection: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` | the current layout direction. |
| `density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` | the current density of the screen. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` of this shape for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shape#createOutline(androidx.compose.ui.geometry.Size,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.Density)`. |

### transform

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
@RememberInComposition
fun transform(block: PolygonShapeTransformScope.() -> Unit): Unit
```

Transforms this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape`'s geometry in place using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)`.

- Runs `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)` in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope` during outline resolution, deferring Compose state reads out of composition so animated transforms update without recomposition.

- Replaces any transformation block previously set on this shape via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)`.

- Mutates this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` in place; call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#copy()` first to keep a shared base shape unchanged.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CornerRounding
import androidx.compose.foundation.shape.PolygonShape
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp

// 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)))
```

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CornerRounding
import androidx.compose.foundation.shape.PolygonShape
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// 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
    }
)
```

| Parameters |
|---|---|
| `block: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | transformation block run in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope` at resolution time |