Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking up a Path to contours

Tags:

android

path

I'm trying to break down a complex Path in Android into its subcontours. Currently I came up with this code:

public static ArrayList<Path> splitToContours(Path path) {
ArrayList<Path> list = new ArrayList<Path>();
PathMeasure pm = new PathMeasure(path, true);
float segment = 0;
Path tempPath;
do {
    tempPath = new Path();
    tempPath.rewind();
    pm.getSegment(segment, segment + pm.getLength(), tempPath, true);
    segment += pm.getLength();
    tempPath.close();
    list.add(tempPath);
} while (pm.nextContour());
return list;
}

However it seems to me that the last point in a contour also starts the next contour. Can anyone help me out? Perhaps there's a simpler, more elegant way to do this? I've been banging my head against the wall for the last two weeks about that and I'm kinda lost here.

like image 932
scf Avatar asked Mar 05 '26 00:03

scf


1 Answers

Not sure what your exact problem is, but I use something like this to create a drawing style animation. You seem to be on the right track, maybe don't close the paths?

 List<Path> segmentPath(Path path, float segmentLength, float scale,
            float dx, float dy) {
        PathMeasure pm = new PathMeasure(path, false);
        float length = pm.getLength();

        float start = 0;
        float delta = segmentLength;

        List<Path> segments = new ArrayList<Path>();
        while (start <= length) {
            float end = start + delta;
            if (end > length) {
                end = length;
            }

            Path segment = new Path();
            pm.getSegment(start, end, segment, true);

            segments.add(segment);
            start += delta;
        }

        return segments;
    }
like image 110
Nikolay Elenkov Avatar answered Mar 06 '26 14:03

Nikolay Elenkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!