From 045f65608ad108fc7206ae1111cf0513f5a15e81 Mon Sep 17 00:00:00 2001
From: Alex Shvartzkop <dudesuchamazing@gmail.com>
Date: Tue, 23 Apr 2024 23:37:42 +0300
Subject: [PATCH] Add VECTOR2L to Swig.

---
 common/swig/math.i         | 33 +++++++++++++++++++++++++++++++++
 pcbnew/python/swig/units.i | 16 ++++++++--------
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/common/swig/math.i b/common/swig/math.i
index bc532b2d8e..9279958f4c 100644
--- a/common/swig/math.i
+++ b/common/swig/math.i
@@ -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; }
diff --git a/pcbnew/python/swig/units.i b/pcbnew/python/swig/units.i
index de4ec380f2..e28f743985 100644
--- a/pcbnew/python/swig/units.i
+++ b/pcbnew/python/swig/units.i
@@ -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)