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 |
boolean |
|
final float |
|
final float |
|
final @NonNull List<@NonNull Cubic> |
A flattened version of the |
final @NonNull List<@NonNull Feature> |
|
int |
hashCode() |
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 |
toString() |
final @NonNull RoundedPolygon |
Transforms (scales/translates/etc.) this |
Extension functions |
|
|---|---|
final @NonNull Path |
Gets a |
final @NonNull RoundedPolygon |
ShapesKt.transformed(Transforms a |
Public methods
calculateBounds
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
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. |
getCubics
public final @NonNull List<@NonNull Cubic> getCubics()
A flattened version of the Features, as a List
normalized
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
transformed
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 |
Extension functions
ShapesKt.toPath
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.
ShapesKt.transformed
public final @NonNull RoundedPolygon ShapesKt.transformed(
@NonNull RoundedPolygon receiver,
@NonNull Matrix matrix
)
Transforms a RoundedPolygon by the given matrix.