pcbnew.SEG and missing handling for OPT_VECTOR2I?

Hello,
I’m trying to get intersection point of two segments.
There is:

https://docs.kicad.org/doxygen-python-8.0/classpcbnew_1_1SEG.html#a922a1fc1a5a0258fc0dd80dd30af5f25

 def Intersect(self, aSeg, aIgnoreEndpoints=False, aLines=False):
 r"""Intersect(SEG self, SEG aSeg, bool aIgnoreEndpoints=False, bool aLines=False) -> OPT_VECTOR2I"""
 return _pcbnew.SEG_Intersect(self, aSeg, aIgnoreEndpoints, aLines)

but it returns OPT_VECTOR2I which I think is missing swig handling and can’t be used from python (or am I missing something?)

Something like this:

seg1 = pcbnew.SEG(pos1, pos2)
seg2 = pcbnew.SEG(pos3, pos4)
result = seg1.Intersect(seg2)

produces following message in terminal:

swig/python detected a memory leak of type 'std::optional< VECTOR2< int > > *', no destructor found.

You are right on the diagnosis.
Your options are to file an issue on the kicad gitlab issue tracker asking for OPT_VECTOR2I to be mapped in swig and wait for the fix or implement intersection logic yourself. It’s just a few lines.

yes, I used my own intersection calculation, will open gitlab ticket anyway

update: if anyone interested: python: pcbnew.SEG and missing handling for OPT_VECTOR2I (#17991) · Issues · KiCad / KiCad Source Code / kicad · GitLab

1 Like