Hello everyone! :wave: I just released a Kotlin M...
# feed
s
Hello everyone! 👋 I just released a Kotlin Multiplatform port of polybool-java! 👉 https://github.com/stefanOltmann/polybool-kotlin PolyBool is a library for performing boolean operations on 2D polygons - useful, for example, when merging overlapping SVG shapes. Over the past few months, I’ve been using polybool-java to union adjacent biome regions in my seed browser for _Oxygen Not Included_, which helped me save space in the worlds snapshot file. The downside was that it depended on a single Java library with no Kotlin equivalent, keeping me from going fully Kotlin/Native. That’s no longer an issue. 😄
💯 7
👀 2
👍 1
👏 1
And I already put that into production for the ONI seed browser backend. 🙂 https://github.com/StefanOltmann/oni-seed-browser-backend/commit/f25881592251bc7e65c5222ad4ae64a633fd1108
m
Does this library have any method to determine whether a given coordinate lies inside a polygon or not? I couldn’t find one 😢.
s
Not for a given coordinate, but I believe if you calculate an intersection with it that should answer the question. 🤔 https://github.com/velipso/polybool?tab=readme-ov-file#example
So if they don’t intersect you get an empty result, I guess. Didn’t try. The only thing I can verify for the original lib is that union works pretty good. If the other methods are broken I wouldn’t know. 🫣
I hope that the maker of polybool-java checked back with polybooljs to ensure the same results like I did with his lib. As the Java version has no unit tests at all this is unknown.
I guess when I find time I will create some proper test data to check that. A visualizer would make it easy to tell if the results are correct or not.
Could be something that draws images like this from test data.
I don’t think that I can add any methods to this library for you as the math involved is beyond my understanding.
m
I don’t think you can compute the intersection of a point with a polygon with this lib. You would have to create an artificial very small polygon for the point. Although this might work it would be very inefficient and error prone. What actually is small? Actually computing the intersection is more time consuming than just computing the boolean whether the point is inside or not. I have some code for this of my own but I am not so sure about all implementation details of this lib. (Handling multi-polygons, polygons with holes, inverted polygons, …)
s
Yes, creating a small polygon for that point was my suggestion, but I agree with you that it’s probably an inefficient calculation.
Maybe the maker of polybool-java or some other math experts will like to pick up this library and develop it further. I can’t. I’ll just maintain it to be compatible with KMP, so I can use polybool union in my KMP pet project. That’s why I made it.
m
Maybe you can just convert JTS to KMP for me. Then all my problems with geometries are solved 😉.
s
Wow, that library is huge… 👀 I… err… add that to my backlog. 😉
I hope you answered in the current developer survey that JTS is missing in the stdlib. 😄
m
LOL 😇🤔