Hello,
My two cents on it is that you need to preprocess geometry data to:
- duplicate vertexes that connect to more than two vertexes;
- for each of the resulting pairs, set the connectivity of the two collocated vertexes such that you have two closed polygons and not a single self intersecting one.
Not a trivial task though, so I suggest refering to these:
https://doi.org/10.1016/j.tcs.2020.07.040 (research paper)
algorithms - Divide self-intersecting polygon into simple polygons - Computer Science Stack Exchange
algorithm - How divide self-intersecting polygon into simple polygons? - Stack Overflow
algorithm - A decomposition of the polygon with self intersections - Stack Overflow
Libraries you can try:
Overview (Clipper2, a small library with an algorithm that does what you need for C++, C# and Delphi).
CGAL 5.5.1 - 2D Arrangements: User Manual (CGAL, a massive C/C++ library of industry-level, high-performing and accurate computational geometry algorithms that has what you need).
take care,
Paulo