I think that matters are rather more complex than this.
For instance, I found 2 lines meet with each other at both ends. In this case, 2 intersections are both a point. One will find two lines form an enclosed area.
When 2 lines intersect or meet/touch more than 2 times, intersection will return more than 2 points. For instance, when two lines meet at 3 points, one would get 2 gap polygons.
Given 2 zigzagging lines, how to write a function to return overlaps and gaps is an interesting matter.
Regards,
David