RoundedPolygon


public final class 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 static class RoundedPolygon.Companion

Public methods

final @NonNull float[]
calculateBounds(@NonNull float[] bounds, boolean approximate)

Calculates the axis-aligned bounds of the object.

final @NonNull float[]
calculateMaxBounds(@NonNull float[] bounds)

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

boolean
equals(Object other)
final float
final float
final @NonNull List<@NonNull Cubic>

A flattened version of the Features, as a List.

final @NonNull List<@NonNull Feature>
int
final @NonNull 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

@NonNull String
final @NonNull RoundedPolygon

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

Extension functions

final @NonNull Path

Gets a Path representation for a RoundedPolygon shape.

final @NonNull RoundedPolygon
ShapesKt.transformed(
    @NonNull RoundedPolygon receiver,
    @NonNull Matrix matrix
)

Transforms a RoundedPolygon by the given matrix.

Public methods

calculateBounds

Added in 1.0.0
public final @NonNull float[] calculateBounds(@NonNull float[] bounds, boolean approximate)

Calculates the axis-aligned bounds of the object.

Parameters
@NonNull float[] bounds

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

boolean approximate

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
@NonNull float[]

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

Added in 1.0.0
public final @NonNull float[] calculateMaxBounds(@NonNull float[] bounds)

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
@NonNull float[] bounds

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

Returns
@NonNull float[]

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

public boolean equals(Object other)

getCenterX

Added in 1.0.0
public final float getCenterX()

getCenterY

Added in 1.0.0
public final float getCenterY()

getCubics

Added in 1.0.0
public final @NonNull List<@NonNull CubicgetCubics()

A flattened version of the Features, as a List.

getFeatures

Added in 1.1.0-alpha01
public final @NonNull List<@NonNull FeaturegetFeatures()

hashCode

public int hashCode()

normalized

Added in 1.0.0
public final @NonNull RoundedPolygon normalized()

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

public @NonNull String toString()

transformed

Added in 1.0.0
public final @NonNull RoundedPolygon transformed(@NonNull PointTransformer f)

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
@NonNull PointTransformer f

The PointTransformer used to transform this RoundedPolygon

Extension functions

public final @NonNull Path ShapesKt.toPath(@NonNull RoundedPolygon receiver, @NonNull 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
@NonNull Path path

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

ShapesKt.transformed

public final @NonNull RoundedPolygon ShapesKt.transformed(
    @NonNull RoundedPolygon receiver,
    @NonNull Matrix matrix
)

Transforms a RoundedPolygon by the given matrix.

Parameters
@NonNull Matrix matrix

The matrix by which the polygon is to be transformed