Add length approximation from sampled points.#10
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
===========================================
+ Coverage 51.46% 76.19% +24.73%
===========================================
Files 2 2
Lines 581 605 +24
===========================================
+ Hits 299 461 +162
+ Misses 282 144 -138 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
61b692d to
6f9ccdf
Compare
|
Sorry, I missed this until now. I'm curious what your use-case is for this? My gut feeling is that since it's not related to the purpose of parsing or rendering SVG paths, and because it's relatively simple to implement it yourself by calling the existing |
4e64d63 to
dc424c3
Compare
|
Yes, I just have the same extension in multiple projects/packages. It's why I guess I will stay with my own fork of this project. I animate the strokes of kanji and I use this extension to generate the length of the paths for animation timing |
|
If you want to pass on it, that's fine. I guess I could make a small svgpath-length swift package to augment it. |
|
Perhaps if I could see a worked example of how you are using it? I guess where I'm struggling is how this would be useful on its own. For your Kanji animation example, wouldn't you also need a bunch of other functions for slicing up and interpolating paths? and those would all need to be repeated in every project that used that animation as well, so the path length calculation seems like the most trivial part. Also, it seems quite inefficient to calculate the length by generating points and then throwing them away, only to generate them again later when you need the actual point positions. It seems like it would make more sense to have a method like: extension [SVGPoint] {
var length: Double { ... }
}So that you don't need to calculate the points twice. But then again it illustrates why it seems odd for this to be part of the SVGPath library, because this could equally be an extension of |
|
I guess I don't completely understand your reasoning, but it's totally ok, you are the author and steward of the project. I can understand if you want to keep the project as single responsibility as possible. I am not a mathematics and graphics programming whiz. CGPath does not provide a built-in method to return sampled or interpolated points along the path. My sources are SVG path data from the start and to even get to a CGPath I am going through the parsing of SVGPath. The fact that you have an implementation for sampling points is wonderful. I was able to use that walk through the points and approximate the path length and store it. The trigonometry is dead simple and easily reproducible. I just thought other people might also benefit from the method. It's just as much a utility method as the points sampling function. Thank you for also exposing the aspect fill transform directly in the initializer. Another small, not exactly necessary thing that I also have code for that I can delete now. Probably my implementation can be cleaned up more anyway by adding something like extension SVGPoint {
func distance(to other: SVGPoint) -> Double {
hypot(x - other.x, y - other.y)
}
}and using that in the length. The point (in my mind) are that if these functions are generic and useful, why not include them for convenience. So shall we close this or clean it up? |
|
Let's close it for now. Thanks |
Another small extension to the project. It simply adds an extension on Collection where Element == SVGPoint to calculate the length between all the points, and then uses that extension to calculate the length from the existing point sampling function.