RoundedPolygonKt

Added in 1.0.1

public final class RoundedPolygonKt


Summary

Public methods

static final @NonNull RoundedPolygon

Creates a copy of the given RoundedPolygon

static final @NonNull RoundedPolygon
RoundedPolygon(
    @NonNull float[] vertices,
    @NonNull CornerRounding rounding,
    List<@NonNull CornerRounding> perVertexRounding,
    float centerX,
    float centerY
)

This function takes the vertices (either supplied or calculated, depending on the constructor called), plus CornerRounding parameters, and creates the actual RoundedPolygon shape, rounding around the vertices (or not) as specified.

static final @NonNull RoundedPolygon
RoundedPolygon(
    @IntRange(from = 3) int numVertices,
    float radius,
    float centerX,
    float centerY,
    @NonNull CornerRounding rounding,
    List<@NonNull CornerRounding> perVertexRounding
)

This constructor takes the number of vertices in the resulting polygon.

Public methods

RoundedPolygon

public static final @NonNull RoundedPolygon RoundedPolygon(@NonNull RoundedPolygon source)

Creates a copy of the given RoundedPolygon

RoundedPolygon

public static final @NonNull RoundedPolygon RoundedPolygon(
    @NonNull float[] vertices,
    @NonNull CornerRounding rounding,
    List<@NonNull CornerRounding> perVertexRounding,
    float centerX,
    float centerY
)

This function takes the vertices (either supplied or calculated, depending on the constructor called), plus CornerRounding parameters, and creates the actual RoundedPolygon shape, rounding around the vertices (or not) as specified. The result is a list of Cubic curves which represent the geometry of the final shape.

Parameters
@NonNull float[] vertices

The list of vertices in this polygon specified as pairs of x/y coordinates in this FloatArray. This should be an ordered list (with the outline of the shape going from each vertex to the next in order of this list), otherwise the results will be undefined.

@NonNull CornerRounding rounding

The CornerRounding properties of all vertices. If some vertices should have different rounding properties, then use perVertexRounding instead. The default rounding value is CornerRounding.Unrounded, meaning that the polygon will use the vertices themselves in the final shape and not curves rounded around the vertices.

List<@NonNull CornerRounding> perVertexRounding

The CornerRounding properties of all vertices. If this parameter is not null, then it must have the same size as vertices. If this parameter is null, then the polygon will use the rounding parameter for every vertex instead. The default value is null.

float centerX

The X coordinate of the center of the polygon, around which all vertices will be placed. The default center is at (0,0).

float centerY

The Y coordinate of the center of the polygon, around which all vertices will be placed. The default center is at (0,0).

Throws
kotlin.IllegalArgumentException

if the number of vertices is less than 3 (the vertices parameter has less than 6 Floats). Or if the perVertexRounding parameter is not null and the size doesn't match the number vertices.

RoundedPolygon

public static final @NonNull RoundedPolygon RoundedPolygon(
    @IntRange(from = 3) int numVertices,
    float radius,
    float centerX,
    float centerY,
    @NonNull CornerRounding rounding,
    List<@NonNull CornerRounding> perVertexRounding
)

This constructor takes the number of vertices in the resulting polygon. These vertices are positioned on a virtual circle around a given center with each vertex positioned radius distance from that center, equally spaced (with equal angles between them). If no radius is supplied, the shape will be created with a default radius of 1, resulting in a shape whose vertices lie on a unit circle, with width/height of 2. That default polygon will probably need to be rescaled using transformed into the appropriate size for the UI in which it will be drawn.

The rounding and perVertexRounding parameters are optional. If not supplied, the result will be a regular polygon with straight edges and unrounded corners.

Parameters
@IntRange(from = 3) int numVertices

The number of vertices in this polygon.

float radius

The radius of the polygon, in pixels. This radius determines the initial size of the object, but it can be transformed later by using the transformed function.

float centerX

The X coordinate of the center of the polygon, around which all vertices will be placed. The default center is at (0,0).

float centerY

The Y coordinate of the center of the polygon, around which all vertices will be placed. The default center is at (0,0).

@NonNull CornerRounding rounding

The CornerRounding properties of all vertices. If some vertices should have different rounding properties, then use perVertexRounding instead. The default rounding value is CornerRounding.Unrounded, meaning that the polygon will use the vertices themselves in the final shape and not curves rounded around the vertices.

List<@NonNull CornerRounding> perVertexRounding

The CornerRounding properties of every vertex. If this parameter is not null, then it must have numVertices elements. If this parameter is null, then the polygon will use the rounding parameter for every vertex instead. The default value is null.

Throws
kotlin.IllegalArgumentException

If perVertexRounding is not null and its size is not equal to numVertices.

kotlin.IllegalArgumentException

numVertices must be at least 3.