Zones: wxPoint/VECTOR2I warnings no longer needed
In the past, the ZONE_CONTAINER::GetPosition() member
returned a reference to a wxPoint, in accordance with the
BOARD_ITEM interface. This meant that ZONE_CONTAINER had
to reinterpret_cast a VECTOR2I (its internal position data) to wxPoint,
which was possible only due to fortunate memory layout.
This interface was changed to return wxPoints by value in
commit a4528988ca
, and the normal (wxPoint) cast was used instead.
Thus, we can now also remove the dire warnings and static_asserts
used to ensure the now-unused old method was correct.
This commit is contained in:
parent
e8afb14046
commit
b1a2c5d7c5
|
@ -79,15 +79,6 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Function GetPosition
|
||||
*
|
||||
* Returns a reference to the first corner of the polygon set.
|
||||
*
|
||||
* \warning The implementation of this function relies on the fact that wxPoint and VECTOR2I
|
||||
* have the same layout. If you intend to use the returned reference directly, please note
|
||||
* that you are _only_ allowed to use members x and y. Any use on anything that is not one of
|
||||
* these members will have undefined behaviour.
|
||||
*
|
||||
* @return a wxPoint, position of the first point of the outline
|
||||
*/
|
||||
const wxPoint GetPosition() const override;
|
||||
|
@ -770,43 +761,6 @@ private:
|
|||
std::vector<int> m_insulatedIslands;
|
||||
|
||||
bool m_hv45; // constrain edges to horizontal, vertical or 45º
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
typedef union {
|
||||
wxPoint wx;
|
||||
VECTOR2I vector;
|
||||
} WX_VECTOR_CONVERTER;
|
||||
|
||||
// Sanity check: assure that the conversion VECTOR2I->wxPoint using the previous union is
|
||||
// correct, making sure that the access for x and y attributes is still safe.
|
||||
static_assert(offsetof(wxPoint,x) == offsetof(VECTOR2I,x),
|
||||
"wxPoint::x and VECTOR2I::x have different offsets");
|
||||
|
||||
static_assert(offsetof(wxPoint,y) == offsetof(VECTOR2I,y),
|
||||
"wxPoint::y and VECTOR2I::y have different offsets");
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue