我正在查看PathMetric.extractPath方法。我很困惑到底什么是'结束'参数应该是什么?我不知道路径长度是什么,我只知道我想提取百分之八十的路径。这是如何实现的?
rjee0c151#
end参数指定要停止提取的路径位置。在PathMetric类中,您可以访问路径length。因此,如果您想要80%的路径,可以用途:Path extractedPath = pathMetric.extractPath(0, pathMetric.length * 0.8);如果你的路径是封闭的,你想从路径的末端提取一部分,它与路径的开始部分重叠。你可以提取路径到末端,然后对于重叠部分,从开始部分提取另一条路径。然后将两者合并。
end
PathMetric
length
Path extractedPath = pathMetric.extractPath(0, pathMetric.length * 0.8);
double extraRemainingFromEnd = end - pathMetric.length; Path extractionToEnd = pathMetric.extractPath(start, pathMetric.length); Path overlapFromBeginning = pathMetric.extractPath(0, extraRemainingFromEnd); Path newPath = extractionToEnd..addPath(overlapFromBeginning , const Offset(0, 0));
或者更好的是,您可以在PathMetric上进行扩展:
extension on PathMetric { Path extractPathfromClosed(double start, double end) { if (end <= length || !isClosed) return extractPath(start, end); Path overlapFromBeginning = extractPath(0, end - length); return extractPath(start, length)..addPath(overlapFromBeginning, const Offset(0, 0)); } }
现在你可以直接从你的PathMetric示例使用extractPathfromClosed。
extractPathfromClosed
1条答案
按热度按时间rjee0c151#
end
参数指定要停止提取的路径位置。在
PathMetric
类中,您可以访问路径length
。因此,如果您想要80%的路径,可以用途:Path extractedPath = pathMetric.extractPath(0, pathMetric.length * 0.8);
如果你的路径是封闭的,你想从路径的末端提取一部分,它与路径的开始部分重叠。你可以提取路径到末端,然后对于重叠部分,从开始部分提取另一条路径。然后将两者合并。
或者更好的是,您可以在
PathMetric
上进行扩展:现在你可以直接从你的
PathMetric
示例使用extractPathfromClosed
。