public final class Morph


This class is used to animate between start and end polygons objects.

Morphing between arbitrary objects can be problematic because it can be difficult to determine how the points of a given shape map to the points of some other shape. Morph simplifies the problem by only operating on RoundedPolygon objects, which are known to have similar, contiguous structures. For one thing, the shape of a polygon is contiguous from start to end (compared to an arbitrary Path object, which could have one or more moveTo operations in the shape). Also, all edges of a polygon shape are represented by Cubic objects, thus the start and end shapes use similar operations. Two Polygon shapes then only differ in the quantity and placement of their curves. The morph works by determining how to map the curves of the two shapes together (based on proximity and other information, such as distance to polygon vertices and concavity), and splitting curves when the shapes do not have the same number of curves or when the curve placement within the shapes is very different.

Summary

Public constructors

Public methods

final @NonNull List<@NonNull Cubic>
asCubics(float progress)

Returns a representation of the morph object at a given progress value as a list of Cubics.

final void
@<Error class: unknown class>
forEachCubic(
    float progress,
    @NonNull MutableCubic mutableCubic,
    @NonNull Function1<@NonNull MutableCubicUnit> callback
)

Returns a representation of the morph object at a given progress value, iterating over the cubics and calling the callback.

Extension functions

final @NonNull Path
ShapesKt.toPath(
    @NonNull Morph receiver,
    float progress,
    @NonNull Path path
)

Public constructors

Morph

Added in 1.0.0-alpha05
public Morph(@NonNull RoundedPolygon start, @NonNull RoundedPolygon end)

Public methods

asCubics

Added in 1.0.0-alpha05
public final @NonNull List<@NonNull CubicasCubics(float progress)

Returns a representation of the morph object at a given progress value as a list of Cubics. Note that this function causes a new list to be created and populated, so there is some overhead.

Parameters
float progress

a value from 0 to 1 that determines the morph's current shape, between the start and end shapes provided at construction time. A value of 0 results in the start shape, a value of 1 results in the end shape, and any value in between results in a shape which is a linear interpolation between those two shapes. The range is generally 0..1 and values outside could result in undefined shapes, but values close to (but outside) the range can be used to get an exaggerated effect (e.g., for a bounce or overshoot animation).

forEachCubic

Added in 1.0.0-alpha05
@<Error class: unknown class>
public final void forEachCubic(
    float progress,
    @NonNull MutableCubic mutableCubic,
    @NonNull Function1<@NonNull MutableCubicUnit> callback
)

Returns a representation of the morph object at a given progress value, iterating over the cubics and calling the callback. This function is faster than asCubics, since it doesn't allocate new Cubic instances, but to do this it reuses the same MutableCubic instance during iteration.

Parameters
float progress

a value from 0 to 1 that determines the morph's current shape, between the start and end shapes provided at construction time. A value of 0 results in the start shape, a value of 1 results in the end shape, and any value in between results in a shape which is a linear interpolation between those two shapes. The range is generally 0..1 and values outside could result in undefined shapes, but values close to (but outside) the range can be used to get an exaggerated effect (e.g., for a bounce or overshoot animation).

@NonNull MutableCubic mutableCubic

An instance of MutableCubic that will be used to set each cubic in time.

@NonNull Function1<@NonNull MutableCubicUnit> callback

The function to be called for each Cubic

Extension functions

public final @NonNull Path ShapesKt.toPath(
    @NonNull Morph receiver,
    float progress,
    @NonNull Path path
)