Add VECTOR2L to Swig.

This commit is contained in:
Alex Shvartzkop 2024-04-23 23:37:42 +03:00
parent cf6d30706b
commit 045f65608a
2 changed files with 41 additions and 8 deletions

View File

@ -44,6 +44,7 @@
%include <math/box2.h>
%template(VECTOR2I) VECTOR2<int>;
%template(VECTOR2L) VECTOR2<long long>;
%template(VECTOR2I_EXTENDED_TYPE) VECTOR2_TRAITS<int>;
%template(VECTOR3D) VECTOR3<double>;
%template(BOX2I) BOX2<VECTOR2I>;
@ -80,6 +81,38 @@
%}
}
%extend VECTOR2<long long>
{
void Set(long long x, long long y) { self->x = x; self->y = y; }
PyObject* Get()
{
PyObject* tup = PyTuple_New(2);
PyTuple_SET_ITEM(tup, 0, PyLong_FromLongLong(self->x));
PyTuple_SET_ITEM(tup, 1, PyLong_FromLongLong(self->y));
return tup;
}
%pythoncode
%{
def __eq__(self,other): return (self.x==other.x and self.y==other.y)
def __ne__(self,other): return not (self==other)
def __str__(self): return str(self.Get())
def __repr__(self): return 'VECTOR2L'+str(self.Get())
def __len__(self): return len(self.Get())
def __getitem__(self, index): return self.Get()[index]
def __setitem__(self, index, val):
if index == 0:
self.x = val
elif index == 1:
self.y = val
else:
raise IndexError
def __nonzero__(self): return self.Get() != (0,0)
%}
}
%extend VECTOR3<double>
{
void Set(double x, double y, double z) { self->x = x; self->y = y; self->z = z; }

View File

@ -34,34 +34,34 @@
def ToMM(iu):
if type(iu) in [int,float]:
return float(iu) / float(pcbIUScale.IU_PER_MM)
elif type(iu) in [wxPoint,wxSize,VECTOR2I]:
elif type(iu) in [wxPoint,wxSize,VECTOR2I,VECTOR2L]:
return tuple(map(ToMM,iu))
else:
raise TypeError("ToMM() expects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(iu)))
raise TypeError("ToMM() expects int, float, wxPoint, wxSize, VECTOR2I or VECTOR2L, instead got type " + str(type(iu)))
def FromMM(mm):
if type(mm) in [int,float]:
return int(float(mm) * float(pcbIUScale.IU_PER_MM))
elif type(mm) in [wxPoint,wxSize,VECTOR2I]:
elif type(mm) in [wxPoint,wxSize,VECTOR2I,VECTOR2L]:
return tuple(map(FromMM,mm))
else:
raise TypeError("FromMM() expects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(mm)))
raise TypeError("FromMM() expects int, float, wxPoint, wxSize, VECTOR2I or VECTOR2L, instead got type " + str(type(mm)))
def ToMils(iu):
if type(iu) in [int,float]:
return float(iu) / float(pcbIUScale.IU_PER_MILS)
elif type(iu) in [wxPoint,wxSize,VECTOR2I]:
elif type(iu) in [wxPoint,wxSize,VECTOR2I,VECTOR2L]:
return tuple(map(ToMils,iu))
else:
raise TypeError("ToMils() expects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(iu)))
raise TypeError("ToMils() expects int, float, wxPoint, wxSize, VECTOR2I or VECTOR2L, instead got type " + str(type(iu)))
def FromMils(mils):
if type(mils) in [int,float]:
return int(float(mils)*float(pcbIUScale.IU_PER_MILS))
elif type(mils) in [wxPoint,wxSize,VECTOR2I]:
elif type(mils) in [wxPoint,wxSize,VECTOR2I,VECTOR2L]:
return tuple(map(FromMils,mils))
else:
raise TypeError("FromMils() expects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(mils)))
raise TypeError("FromMils() expects int, float, wxPoint, wxSize, VECTOR2I or VECTOR2L, instead got type " + str(type(mils)))
def PutOnGridMM(value, gridSizeMM):
thresh = FromMM(gridSizeMM)