Hi, nice style. However I do not understand where Your mentioned issue is.
That seems to work as expected.
Regarding Your suggestion:
"condition to check whether a vertex is between two segments with different material IDs "
I agree that this would be great option to have. I will add this to new features list.