# PolygonShapeGeometry

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.PolygonShapeGeometry) Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01) Common/All
- Cmn

  ```
  class PolygonShapeGeometry
  ```

*** ** * ** ***

Defines a polygon's `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()`, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#center()`, and corner rounding.

Coordinates are in layout pixels (`(0f, 0f)` to `(size.width, size.height)`). You can also define `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()` in a custom coordinate space (such as a `[0f, 1f]` unit square) and scale them to the layout bounds using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope#scaleToFit(androidx.compose.ui.layout.ContentScale,androidx.compose.ui.Alignment)`. Because custom `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()` do not have a circle radius, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding#fraction(kotlin.Float,kotlin.Float)` sets the corner radius as a fraction of the polygon's smaller dimension (`min(width, height)`).

```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.foundation.shape.PolygonShapeGeometry
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

// A kite authored in the unit square [0..1] with per-vertex rounding as fractions of the
// bounds, scaled and centered into the container via transform { scaleToFit() }.
val kite = remember {
    val geometry =
        PolygonShapeGeometry(
            vertices =
                listOf(Offset(0.5f, 0f), Offset(1f, 0.4f), Offset(0.5f, 1f), Offset(0f, 0.4f)),
            perVertexRounding =
                listOf(
                    CornerRounding.fraction(0.1f),
                    CornerRounding.fraction(0.15f),
                    CornerRounding.fraction(0.05f),
                    CornerRounding.fraction(0.15f),
                ),
        )
    PolygonShape { geometry }.apply { transform { scaleToFit() } }
}

Box(Modifier.size(width = 120.dp, height = 84.dp).clip(kite).background(Color(0xFF673AB7)))
```

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#PolygonShapeGeometry(kotlin.collections.List,androidx.compose.ui.geometry.Offset,androidx.compose.foundation.shape.CornerRounding)( vertices: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset>, center: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, rounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding )` Creates polygon geometry with uniform `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,androidx.compose.ui.geometry.Offset,androidx.compose.foundation.shape.CornerRounding)` at every vertex. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#PolygonShapeGeometry(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)( vertices: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset>, perVertexRounding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding>, center: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset )` Creates polygon geometry with per-vertex `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)`. | Cmn |

| ### Public functions |
|---|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#hashCode()()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#center()` polygon center in pixels, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` when computed from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding>?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#perVertexRounding()` optional per-vertex rounding matching `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()` in size | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#rounding()` uniform vertex rounding, or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding#Unrounded()` when using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#perVertexRounding()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset>` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()` vertex positions in pixels (or custom coordinates scaled with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope#scaleToFit(androidx.compose.ui.layout.ContentScale,androidx.compose.ui.Alignment)`), at least 3 | Cmn |

## Public constructors

### PolygonShapeGeometry

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

```
PolygonShapeGeometry(
    vertices: List<Offset>,
    center: Offset = Offset.Unspecified,
    rounding: CornerRounding = CornerRounding.Unrounded
)
```

Creates polygon geometry with uniform `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,androidx.compose.ui.geometry.Offset,androidx.compose.foundation.shape.CornerRounding)` at every vertex.

| Parameters |
|---|---|
| `vertices: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset>` | vertex positions in pixels (or custom coordinates scaled with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope#scaleToFit(androidx.compose.ui.layout.ContentScale,androidx.compose.ui.Alignment)`), at least 3 |
| `center: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset = Offset.Unspecified` | polygon center in pixels, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` to compute from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,androidx.compose.ui.geometry.Offset,androidx.compose.foundation.shape.CornerRounding)` |
| `rounding: https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding = CornerRounding.Unrounded` | corner rounding applied to every vertex |

| 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/PolygonShapeGeometry#(kotlin.collections.List,androidx.compose.ui.geometry.Offset,androidx.compose.foundation.shape.CornerRounding)` has fewer than 3 entries |

### PolygonShapeGeometry

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

```
PolygonShapeGeometry(
    vertices: List<Offset>,
    perVertexRounding: List<CornerRounding>,
    center: Offset = Offset.Unspecified
)
```

Creates polygon geometry with per-vertex `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)`.

| Parameters |
|---|---|
| `vertices: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset>` | vertex positions in pixels (or custom coordinates scaled with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope#scaleToFit(androidx.compose.ui.layout.ContentScale,androidx.compose.ui.Alignment)`), at least 3 |
| `perVertexRounding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding>` | rounding for each vertex, matching `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)` in size |
| `center: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset = Offset.Unspecified` | polygon center in pixels, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` to compute from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)` |

| 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/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)` has fewer than 3 entries or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)` differs from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#(kotlin.collections.List,kotlin.collections.List,androidx.compose.ui.geometry.Offset)` in size |

## Public functions

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

```
open fun hashCode(): Int
```

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### center

Cmn

```
val center: Offset
```

polygon center in pixels, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` when computed from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()`

### perVertexRounding

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

```
val perVertexRounding: List<CornerRounding>?
```

optional per-vertex rounding matching `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#vertices()` in size

### rounding

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

```
val rounding: CornerRounding
```

uniform vertex rounding, or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/CornerRounding#Unrounded()` when using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry#perVertexRounding()`

### vertices

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

```
val vertices: List<Offset>
```

vertex positions in pixels (or custom coordinates scaled with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope#scaleToFit(androidx.compose.ui.layout.ContentScale,androidx.compose.ui.Alignment)`), at least 3