11
11
#include "py/runtime.h"
12
12
#include "py/binary.h"
13
13
14
+ #if CIRCUITPY_ULAB
15
+ #include "extmod/ulab/code/ulab.h"
16
+ #include "extmod/ulab/code/ndarray.h"
17
+ #endif
18
+
14
19
#include "shared-module/_eve/__init__.h"
15
20
#include "shared-bindings/_eve/__init__.h"
16
21
@@ -844,6 +849,19 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(vertex2ii_obj, 3, 5, _vertex2ii);
844
849
845
850
// }
846
851
852
+ #if CIRCUITPY_ULAB
853
+ static bool is_vector (mp_obj_t a ) {
854
+ if (!mp_obj_is_type (a , & ulab_ndarray_type )) {
855
+ return false;
856
+ }
857
+ ndarray_obj_t * ndarray = MP_OBJ_TO_PTR (a );
858
+ if (!ndarray_is_dense (ndarray )) {
859
+ mp_raise_TypeError (MP_ERROR_TEXT ("input must be an ndarray" ));
860
+ }
861
+ return true;
862
+ }
863
+ #endif
864
+
847
865
// Hand-written functions {
848
866
849
867
//| def Vertex2f(self, b: float) -> None:
@@ -853,6 +871,18 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(vertex2ii_obj, 3, 5, _vertex2ii);
853
871
//| :param float y: pixel y-coordinate"""
854
872
//| ...
855
873
static mp_obj_t _vertex2f (mp_obj_t self , mp_obj_t a0 , mp_obj_t a1 ) {
874
+ #if CIRCUITPY_ULAB
875
+ if (is_vector (a0 ) && is_vector (a1 )) {
876
+ ndarray_obj_t * v0 = MP_OBJ_TO_PTR (a0 );
877
+ ndarray_obj_t * v1 = MP_OBJ_TO_PTR (a1 );
878
+ mp_float_t * p0 = (mp_float_t * )v0 -> array ;
879
+ mp_float_t * p1 = (mp_float_t * )v1 -> array ;
880
+ for (size_t i = 0 ; i < v0 -> len ; i ++ , p0 ++ , p1 ++ ) {
881
+ common_hal__eve_Vertex2f (EVEHAL (self ), * p0 , * p1 );
882
+ }
883
+ return mp_const_none ;
884
+ }
885
+ #endif
856
886
mp_float_t x = mp_obj_get_float (a0 );
857
887
mp_float_t y = mp_obj_get_float (a1 );
858
888
common_hal__eve_Vertex2f (EVEHAL (self ), x , y );
0 commit comments