compat/src/main/java/androidx/core/graphics/PathUtils.java
@RequiresApi(26)
    @NonNull
    public static Collection<PathSegment> flatten(@NonNull final Path path,
            @FloatRange(from = 0) final float error) {
        float[] pathData = path.approximate(error);
        int pointCount = pathData.length / 3;
        List<PathSegment> segments = new ArrayList<>(pointCount);
        for (int i = 1; i < pointCount; i++) {
            int index = i * 3;
            int prevIndex = (i - 1) * 3;

            float d = pathData[index];
            float x = pathData[index + 1];
            float y = pathData[index + 2];

            float pd = pathData[prevIndex];
            float px = pathData[prevIndex + 1];
            float py = pathData[prevIndex + 2];

            if (d != pd && (x != px || y != py)) {
                segments.add(new PathSegment(new PointF(px, py), pd, new PointF(x, y), d));
            }
        }
        return segments;
    }
/**
     * Flattens (or approximate) a {@link Path} with a series of line segments.
     *
     * <em>Note:</em> This method requires API 26 or newer.
     *
     * @param error The acceptable error for a line on the Path. Typically this would be
     *              0.5 so that the error is less than half a pixel.
     *
     * @see Path#approximate
     */
Flattens (or approximate) a  Path with a series of line segments.
Note: This method requires API 26 or newer.

@param error The acceptable error for a line on the Path. Typically this would be
0.5 so that the error is less than half a pixel.

@see Path#approximate
Flattens ( or approximate ) a Path with a series of line segments . Note : This method requires API 26 or newer . @param error The acceptable error for a line on the Path . Typically this would be 0 . 5 so that the error is less than half a pixel . @see Path#approximate
@RequiresApi(26)
    @NonNull
    public static Collection<PathSegment> flatten(@NonNull final Path path,
            @FloatRange(from = 0) final float error) {
        float[] pathData = path.approximate(error);
        int pointCount = pathData.length / 3;
        List<PathSegment> segments = new ArrayList<>(pointCount);
        for (int i = 1; i < pointCount; i++) {
            int index = i * 3;
            int prevIndex = (i - 1) * 3;
            float d = pathData[index];
            float x = pathData[index + 1];
            float y = pathData[index + 2];
            float pd = pathData[prevIndex];
            float px = pathData[prevIndex + 1];
            float py = pathData[prevIndex + 2];
            if (d != pd && (x != px || y != py)) {
                segments.add(new PathSegment(new PointF(px, py), pd, new PointF(x, y), d));
            }
        }
        return segments;
    }
@ RequiresApi ( 26 ) @ NonNull public static Collection < PathSegment > flatten ( @ NonNull final Path path , @ FloatRange ( from = 0 ) final float error ) { float [ ] pathData = path . approximate ( error ) ; int pointCount = pathData . length / 3 ; List < PathSegment > segments = new ArrayList < > ( pointCount ) ; for ( int i = 1 ; i < pointCount ; i ++ ) { int index = i * 3 ; int prevIndex = ( i - 1 ) * 3 ; float d = pathData [ index ] ; float x = pathData [ index + 1 ] ; float y = pathData [ index + 2 ] ; float pd = pathData [ prevIndex ] ; float px = pathData [ prevIndex + 1 ] ; float py = pathData [ prevIndex + 2 ] ; if ( d != pd && ( x != px || y != py ) ) { segments . add ( new PathSegment ( new PointF ( px , py ) , pd , new PointF ( x , y ) , d ) ) ; } } return segments ; }
Flattens (or approximate) a {@link Path} with a series of line segments.
Flattens ( or approximate ) a { @link Path } with a series of line segments .