KiCad PCB EDA Suite
Union to handle conversion between references to wxPoint and to VECTOR2I.
The function GetPosition(), that returns a reference to a wxPoint, needs some existing wxPoint object that it can point to. The header of this function cannot be changed, as it overrides the function from the base class BOARD_ITEM. This made sense when ZONE_CONTAINER was implemented using the legacy CPolyLine class, that worked with wxPoints. However, m_Poly is now a SHAPE_POLY_SET, whose corners are objects of type VECTOR2I, not wxPoint. Thus, we cannot directly reference the first corner of m_Poly, so a modified version of it that can be read as a wxPoint needs to be handled. Taking advantage of the fact that both wxPoint and VECTOR2I have the same memory layout (two integers: x, y), this union let us convert a reference to a VECTOR2I into a reference to a wxPoint.
The idea is the following: in GetPosition(), m_Poly->GetCornerPosition( 0 ) returns a reference to the first corner of the polygon set. If we retrieve its memory direction, we can tell the compiler to cast that pointer to a WX_VECTOR_CONVERTER pointer. We can finally shape that memory layout as a wxPoint picking the wx member of the union.
Although this solution is somewhat unstable, as it relies on the fact that the memory layout is exactly the same, it is the best attempt to keep backwards compatibility while using the new SHAPE_POLY_SET.