Template for vector<VECTOR2I> in swig
This commit is contained in:
parent
a0e424c2ac
commit
4bcfa8df1f
|
@ -154,6 +154,7 @@ typedef long time_t;
|
|||
|
||||
// Contains VECTOR2I
|
||||
%include math.i
|
||||
%template(VECTOR_VECTOR2I) std::vector<VECTOR2I>;
|
||||
|
||||
// ignore warning from nested classes
|
||||
#pragma SWIG nowarn=325
|
||||
|
@ -174,6 +175,7 @@ typedef long time_t;
|
|||
#include <utf8.h>
|
||||
%include <utf8.h>
|
||||
|
||||
|
||||
%extend UTF8
|
||||
{
|
||||
const char* Cast_to_CChar() { return (self->c_str()); }
|
||||
|
|
|
@ -34,3 +34,35 @@
|
|||
#include <math/vector2d.h>
|
||||
%include <math/vector2d.h>
|
||||
%template(VECTOR2I) VECTOR2<int>;
|
||||
|
||||
%extend VECTOR2<int>
|
||||
{
|
||||
void Set(long x, long y) { self->x = x; self->y = y; }
|
||||
|
||||
PyObject* Get()
|
||||
{
|
||||
PyObject* tup = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->x));
|
||||
PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(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 'VECTOR2I'+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)
|
||||
|
||||
%}
|
||||
}
|
||||
|
|
|
@ -34,34 +34,34 @@
|
|||
def ToMM(iu):
|
||||
if type(iu) in [int,float]:
|
||||
return float(iu) / float(IU_PER_MM)
|
||||
elif type(iu) in [wxPoint,wxSize]:
|
||||
elif type(iu) in [wxPoint,wxSize,VECTOR2I]:
|
||||
return tuple(map(ToMM,iu))
|
||||
else:
|
||||
raise TypeError("ToMM() excpects int, float, wxPoint or wxSize, instead got type " + str(type(iu)))
|
||||
raise TypeError("ToMM() excpects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(iu)))
|
||||
|
||||
def FromMM(mm):
|
||||
if type(mm) in [int,float]:
|
||||
return int(float(mm) * float(IU_PER_MM))
|
||||
elif type(mm) in [wxPoint,wxSize]:
|
||||
elif type(mm) in [wxPoint,wxSize,VECTOR2I]:
|
||||
return tuple(map(FromMM,mm))
|
||||
else:
|
||||
raise TypeError("FromMM() expects int, float, wxPoint or wxSize, instead got type " + str(type(mm)))
|
||||
raise TypeError("FromMM() expects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(mm)))
|
||||
|
||||
def ToMils(iu):
|
||||
if type(iu) in [int,float]:
|
||||
return float(iu) / float(IU_PER_MILS)
|
||||
elif type(iu) in [wxPoint,wxSize]:
|
||||
elif type(iu) in [wxPoint,wxSize,VECTOR2I]:
|
||||
return tuple(map(ToMils,iu))
|
||||
else:
|
||||
raise TypeError("ToMils() excpects int, float, wxPoint or wxSize, instead got type " + str(type(iu)))
|
||||
raise TypeError("ToMils() excpects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(iu)))
|
||||
|
||||
def FromMils(mils):
|
||||
if type(mils) in [int,float]:
|
||||
return int(float(mils)*float(IU_PER_MILS))
|
||||
elif type(mils) in [wxPoint,wxSize]:
|
||||
elif type(mils) in [wxPoint,wxSize,VECTOR2I]:
|
||||
return tuple(map(FromMils,mils))
|
||||
else:
|
||||
raise TypeError("FromMils() excpects int, float, wxPoint or wxSize, instead got type " + str(type(mils)))
|
||||
raise TypeError("FromMils() excpects int, float, wxPoint, wxSize or VECTOR2I, instead got type " + str(type(mils)))
|
||||
|
||||
def PutOnGridMM(value, gridSizeMM):
|
||||
thresh = FromMM(gridSizeMM)
|
||||
|
@ -83,6 +83,12 @@
|
|||
def wxPointMils(mmx,mmy):
|
||||
return wxPoint(FromMils(mmx),FromMils(mmy))
|
||||
|
||||
def VECTOR2I_MM(mmx,mmy):
|
||||
return VECTOR2I(FromMM(mmx),FromMM(mmy))
|
||||
|
||||
def VECTOR2I_Mils(mmx,mmy):
|
||||
return VECTOR2I(FromMils(mmx),FromMils(mmy))
|
||||
|
||||
def wxRectMM(x,y,wx,wy):
|
||||
x = int(FromMM(x))
|
||||
y = int(FromMM(y))
|
||||
|
|
Loading…
Reference in New Issue