RoundedPolygon



The RoundedPolygon class allows simple construction of polygonal shapes with optional rounding at the vertices. Polygons can be constructed with either the number of vertices desired or an ordered list of vertices.

Summary

Nested types

Public functions

FloatArray
calculateBounds(bounds: FloatArray, approximate: Boolean)

Calculates the axis-aligned bounds of the object.

Cmn
FloatArray

Like calculateBounds, this function calculates the axis-aligned bounds of the object and returns that rectangle.

Cmn
open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
RoundedPolygon

Creates a new RoundedPolygon, moving and resizing this one, so it's completely inside the (0, 0) -> (1, 1) square, centered if there extra space in one direction

Cmn
open String
Cmn
RoundedPolygon

Transforms (scales/translates/etc.) this RoundedPolygon with the given PointTransformer and returns a new RoundedPolygon.

Cmn

Public properties

Float
Cmn
Float
Cmn
List<Cubic>

A flattened version of the Features, as a List.

Cmn

Extension functions

Path

Returns a Path that is remembered across compositions for this RoundedPolygon.

Cmn
Shape

Returns a Shape that is remembered across compositions for this RoundedPolygon.

Cmn
Path

Gets a Path representation for a RoundedPolygon shape.

android
RoundedPolygon

Transforms a RoundedPolygon by the given matrix.

android

Public functions

calculateBounds

fun calculateBounds(
    bounds: FloatArray = FloatArray(4),
    approximate: Boolean = true
): FloatArray

Calculates the axis-aligned bounds of the object.

Parameters
bounds: FloatArray = FloatArray(4)

a buffer to hold the results. If not supplied, a temporary buffer will be created.

approximate: Boolean = true

when true, uses a faster calculation to create the bounding box based on the min/max values of all anchor and control points that make up the shape. Default value is true.

Returns
FloatArray

The axis-aligned bounding box for this object, where the rectangles left, top, right, and bottom values will be stored in entries 0, 1, 2, and 3, in that order.

calculateMaxBounds

fun calculateMaxBounds(bounds: FloatArray = FloatArray(4)): FloatArray

Like calculateBounds, this function calculates the axis-aligned bounds of the object and returns that rectangle. But this function determines the max dimension of the shape (by calculating the distance from its center to the start and midpoint of each curve) and returns a square which can be used to hold the object in any rotation. This function can be used, for example, to calculate the max size of a UI element meant to hold this shape in any rotation.

Parameters
bounds: FloatArray = FloatArray(4)

a buffer to hold the results. If not supplied, a temporary buffer will be created.

Returns
FloatArray

The axis-aligned max bounding box for this object, where the rectangles left, top, right, and bottom values will be stored in entries 0, 1, 2, and 3, in that order.

equals

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

hashCode

open fun hashCode(): Int

normalized

fun normalized(): RoundedPolygon

Creates a new RoundedPolygon, moving and resizing this one, so it's completely inside the (0, 0) -> (1, 1) square, centered if there extra space in one direction

toString

open fun toString(): String

transformed

fun transformed(f: PointTransformer): RoundedPolygon

Transforms (scales/translates/etc.) this RoundedPolygon with the given PointTransformer and returns a new RoundedPolygon. This is a low level API and there should be more platform idiomatic ways to transform a RoundedPolygon provided by the platform specific wrapper.

Parameters
f: PointTransformer

The PointTransformer used to transform this RoundedPolygon

Public properties

centerX

val centerXFloat

centerY

val centerYFloat

cubics

val cubicsList<Cubic>

A flattened version of the Features, as a List.

Extension functions

@ExperimentalMaterial3ExpressiveApi
@Composable
fun RoundedPolygon.toPath(startAngle: Int = 0): Path

Returns a Path that is remembered across compositions for this RoundedPolygon.

Parameters
startAngle: Int = 0

the angle (in degrees) from which to begin drawing the generated path. By default, it is set to 0 degrees, meaning the Path begins drawing at the 3 o'clock position. The returned path is rotated by this angle around the RoundedPolygon's centroid (centerX, centerY).

@ExperimentalMaterial3ExpressiveApi
@Composable
fun RoundedPolygon.toShape(startAngle: Int = 0): Shape

Returns a Shape that is remembered across compositions for this RoundedPolygon.

Parameters
startAngle: Int = 0

the angle (in degrees) from which to begin drawing the generated shape's path. By default, it is set to 0 degrees, meaning the shape's path begins drawing at the 3 o'clock position. The returned path is rotated by this angle around the RoundedPolygon's centroid (centerX, centerY).

fun RoundedPolygon.toPath(path: Path = Path()): Path

Gets a Path representation for a RoundedPolygon shape. Note that there is some rounding happening (to the nearest thousandth), to work around rendering artifacts introduced by some points being just slightly off from each other (far less than a pixel). This also allows for a more optimal path, as redundant curves (usually a single point) can be detected and not added to the resulting path.

Parameters
path: Path = Path()

an optional Path object which, if supplied, will avoid the function having to create a new Path object

transformed

fun RoundedPolygon.transformed(matrix: Matrix): RoundedPolygon

Transforms a RoundedPolygon by the given matrix.

Parameters
matrix: Matrix

The matrix by which the polygon is to be transformed