Hint:
The handling of special cases such as a vertex on an edge or two overlapping edges is an uneasy topic as the configurations are varied and cases can telescope (think of several collinear edges that overlap).
My best advice is to enforce coherence by assigning every vertex an inside or outside state (wrt the other polygon). Then when you intersect an edge with the other polygon, the parity of the number of intersections must match the change in the endpoint state (same state => even number of intersections).
I am not specifying in what way you assign the states, this will depend on your particular algorithm (in practice states are assigned as you go). What matters is that when a state is tested you may not change it anymore.
In case a anomaly appears (parity of number of intersections not matching the change of state), you must fix that, either by sacrificing an intersection or by duplicating one (or any other rule that you find appropriate).
Example:
In this sample case, the green dots denote vertices considered external to the blue polygon, and the digits indicate acceptable numbers of intersections assigned to the corresponding edges.
The black outline below represents the union polygon that would result from this assignment of states.
