-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathrect_impl.h
2862 lines (2564 loc) · 81.9 KB
/
rect_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
pygame - Python Game Library
Copyright (C) 2000-2001 Pete Shinners
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Pete Shinners
pete@shinners.org
*/
/*
* Python Rect Object -- useful 2d rectangle class
* a template like file that works with defines and it implements the Rect
* object
*/
#define PYGAMEAPI_RECT_INTERNAL
#include "pygame.h"
#include "structmember.h"
#include "pgcompat.h"
#include <limits.h>
// #region RectExport
#ifndef RectExport_init
#error RectExport_init needs to be defined
#endif
#ifndef RectExport_subtypeNew4
#error RectExport_subtypeNew4 needs to be defined
#endif
#ifndef RectExport_new
#error RectExport_new needs to be defined
#endif
#ifndef RectExport_dealloc
#error RectExport_dealloc needs to be defined
#endif
#ifndef RectExport_normalize
#error RectExport_normalize needs to be defined
#endif
#ifndef RectExport_pgTwoValuesFromFastcallArgs
#error RectExport_pgTwoValuesFromFastcallArgs needs to be defined
#endif
#ifndef RectExport_move
#error RectExport_move needs to be defined
#endif
#ifndef RectExport_moveIp
#error RectExport_moveIp needs to be defined
#endif
#ifndef RectExport_moveTo
#error RectExport_moveTo needs to be defined
#endif
#ifndef RectExport_inflate
#error RectExport_inflate needs to be defined
#endif
#ifndef RectExport_inflateIp
#error RectExport_inflateIp needs to be defined
#endif
#ifndef RectExport_scalebyIp
#error RectExport_scalebyIp needs to be defined
#endif
#ifndef RectExport_scaleby
#error RectExport_scaleby needs to be defined
#endif
#ifndef RectExport_update
#error RectExport_update needs to be defined
#endif
#ifndef RectExport_union
#error RectExport_union needs to be defined
#endif
#ifndef RectExport_unionIp
#error RectExport_unionIp needs to be defined
#endif
#ifndef RectExport_unionall
#error RectExport_unionall needs to be defined
#endif
#ifndef RectExport_unionallIp
#error RectExport_unionallIp needs to be defined
#endif
#ifndef RectExport_collidepoint
#error RectExport_collidepoint needs to be defined
#endif
#ifndef RectExport_colliderect
#error RectExport_colliderect needs to be defined
#endif
#ifndef RectExport_collidelist
#error RectExport_collidelist needs to be defined
#endif
#ifndef RectExport_collidelistall
#error RectExport_collidelistall needs to be defined
#endif
#ifndef RectExport_collideobjectsall
#error RectExport_collideobjectsall needs to be defined
#endif
#ifndef RectExport_collideobjects
#error RectExport_collideobjects needs to be defined
#endif
#ifndef RectExport_RectFromObjectAndKeyFunc
#error RectExport_RectFromObjectAndKeyFunc needs to ne defined
#endif
#ifndef RectExport_collidedict
#error RectExport_collidedict needs to be defined
#endif
#ifndef RectExport_collidedictall
#error RectExport_collidedictall needs to be defined
#endif
#ifndef RectExport_clip
#error RectExport_clip needs to be defined
#endif
#ifndef RectExport_clipline
#error RectExport_clipline needs to be defined
#endif
#ifndef RectExport_RectFromObject
#error RectExport_RectFromObject needs to be defined
#endif
#ifndef RectExport_RectFromFastcallArgs
#error RectExport_RectFromFastcallArgs needs to be defined
#endif
#ifndef RectExport_RectNew
#error RectExport_RectNew needs to be defined
#endif
#ifndef RectExport_do_rects_intresect
#error RectExport_do_rects_intresect needs to be Defined
#endif
#ifndef RectExport_RectNew4
#error RectExport_RectNew4 needs to be defined
#endif
#ifndef RectExport_Normalize
#error RectExport_Normalize needs to be defined
#endif
#ifndef RectExport_contains_internal
#error RectExport_contains_internal needs to be defined
#endif
#ifndef RectExport_contains
#error RectExport_contains needs to be defined
#endif
#ifndef RectExport_containsSeq
#error RectExport_containsSeq needs to be defined
#endif
#ifndef RectExport_clamp
#error RectExport_clamp needs to be defined
#endif
#ifndef RectExport_fit
#error RectExport_fit needs to be defined
#endif
#ifndef RectExport_clampIp
#error RectExport_clampIp needs to be defined
#endif
#ifndef RectExport_reduce
#error RectExport_reduce needs to be defined
#endif
#ifndef RectExport_copy
#error RectExport_copy needs to be defined
#endif
#ifndef RectExport_item
#error RectExport_item needs to be defined
#endif
#ifndef RectExport_assItem
#error RectExport_assItem needs to be defined
#endif
#ifndef RectExport_subscript
#error RectExport_subscript needs to be defined
#endif
#ifndef RectExport_assSubscript
#error RectExport_assSubscript needs to be defined
#endif
#ifndef RectExport_bool
#error RectExport_bool needs to be defined
#endif
#ifndef RectExport_richcompare
#error RectExport_richcompare needs to be defined
#endif
#ifndef RectExport_getwidth
#error RectExport_getwidth needs to be defined
#endif
#ifndef RectExport_setwidth
#error RectExport_setwidth needs to be defined
#endif
#ifndef RectExport_getheight
#error RectExport_getheight needs to be defined
#endif
#ifndef RectExport_setheight
#error RectExport_setheight needs to be defined
#endif
#ifndef RectExport_gettop
#error RectExport_gettop needs to be defined
#endif
#ifndef RectExport_settop
#error RectExport_settop needs to be defined
#endif
#ifndef RectExport_getleft
#error RectExport_getleft needs to be defined
#endif
#ifndef RectExport_setleft
#error RectExport_setleft needs to be defined
#endif
#ifndef RectExport_getright
#error RectExport_getright needs to be defined
#endif
#ifndef RectExport_setright
#error RectExport_setright needs to be defined
#endif
#ifndef RectExport_getbottom
#error RectExport_getbottom needs to be defined
#endif
#ifndef RectExport_setbottom
#error RectExport_setbottom needs to be defined
#endif
#ifndef RectExport_getcenterx
#error RectExport_getcenterx needs to be defined
#endif
#ifndef RectExport_setcenterx
#error RectExport_setcenterx needs to be defined
#endif
#ifndef RectExport_getcentery
#error RectExport_getcentery needs to be defined
#endif
#ifndef RectExport_setcentery
#error RectExport_setcentery needs to be defined
#endif
#ifndef RectExport_gettopleft
#error RectExport_gettopleft needs to be defined
#endif
#ifndef RectExport_settopleft
#error RectExport_settopleft needs to be defined
#endif
#ifndef RectExport_gettopright
#error RectExport_gettopright needs to be defined
#endif
#ifndef RectExport_settopright
#error RectExport_settopright needs to be defined
#endif
#ifndef RectExport_getbottomleft
#error RectExport_getbottomleft needs to be defined
#endif
#ifndef RectExport_setbottomleft
#error RectExport_setbottomleft needs to be defined
#endif
#ifndef RectExport_getbottomright
#error RectExport_getbottomright needs to be defined
#endif
#ifndef RectExport_setbottomright
#error RectExport_setbottomright needs to be defined
#endif
#ifndef RectExport_getmidtop
#error RectExport_getmidtop needs to be defined
#endif
#ifndef RectExport_setmidtop
#error RectExport_setmidtop needs to be defined
#endif
#ifndef RectExport_getmidleft
#error RectExport_getmidleft needs to be defined
#endif
#ifndef RectExport_setmidleft
#error RectExport_setmidleft needs to be defined
#endif
#ifndef RectExport_getmidbottom
#error RectExport_getmidbottom needs to be defined
#endif
#ifndef RectExport_setmidbottom
#error RectExport_setmidbottom needs to be defined
#endif
#ifndef RectExport_getmidright
#error RectExport_getmidright needs to be defined
#endif
#ifndef RectExport_setmidright
#error RectExport_setmidright needs to be defined
#endif
#ifndef RectExport_getcenter
#error RectExport_getcenter needs to be defined
#endif
#ifndef RectExport_setcenter
#error RectExport_setcenter needs to be defined
#endif
#ifndef RectExport_getsize
#error RectExport_getsize needs to be defined
#endif
#ifndef RectExport_setsize
#error RectExport_setsize needs to be defined
#endif
#ifndef RectExport_iterator
#error RectExpor_iterator needs to be defined
#endif
// #endregion
// #region RectImport
#ifndef RectImport_PythonNumberCheck
#error RectImport_PythonNumberCheck
#endif
#ifndef RectImport_PythonNumberAsPrimitiveType
#error RectImport_PythonNumberAsPrimitiveType
#endif
#ifndef RectImport_PrimitiveTypeAsPythonNumber
#error RectImport_PrimitiveTypeAsPythonNumber
#endif
#ifndef RectImport_ObjectName
#error RectImport_ObjectName needs to be defined
#endif
#ifndef RectImport_IntersectRectAndLine
#error RectImport_IntersectRectAndLine needs to be defined
#endif
#ifndef RectImport_RectCheck
#error RectImport_RectCheck needs to be Defined
#endif
#ifndef RectImport_OtherRectCheck
#error RectImport_OtherRectCheck needs to be defined
#endif
#ifndef RectImport_RectCheckExact
#error RectImport_RectCheckExact needs to be Defined
#endif
#ifndef RectImport_primitiveType
#error RectImport_primitiveType needs to be defined
#endif
#ifndef RectImport_innerRectStruct
#error RectImport_innerRectStruct needs to be defined
#endif
#ifndef RectImport_otherInnerRectStruct
#error RectImport_otherInnerRectStruct needs to be defined
#endif
#ifndef RectImport_innerPointStruct
#error RectImport_innerPointStruct needs to be defined
#endif
#ifndef RectImport_fourPrimiviteFromObj
#error RectImport_fourPrimiviteFromObj needs to be defined
#endif
#ifndef RectImport_RectObject
#error RectImport_RectObject needs to be defined
#endif
#ifndef RectImport_OtherRectObject
#error RectImport_OtherRectObject needs to be defined
#endif
#ifndef RectImport_TypeObject
#error RectImport_TypeObject needs to be Defined
#endif
#ifndef RectImport_primitiveFromObjIndex
#error RectImport_primitiveFromObjIndex needs to be defined
#endif
#ifndef RectImport_twoPrimitivesFromObj
#error RectImport_twoPrimitivesFromObj needs to be Defined
#endif
#ifndef RectImport_PrimitiveFromObj
#error RectImport_PrimitiveFromObj needs to be defined
#endif
#ifndef RectImport_PyBuildValueFormat
#error RectImport_PyBuildValueFormat needs to be defined
#endif
// #endregion
// #region RectOptional
#ifdef RectOptional_FREELIST
#ifndef PYPY_VERSION
#error freelist is currently only supported for PyPy
#endif
#ifndef RectOptional_FreelistlimitNumberName
#error RectOptional_FreelistlimitNumberName needs to be defined as RectOptional_FREELIST is defined
#endif
#ifndef RectOptional_FreelistlimitNumber
#error RectOptional_FreelistlimitNumber needs to be defined as RectOptional_FREELIST is defined
#endif
#ifndef RectOptional_FreelistFreelistName
#error RectOptional_FreelistFreelistName needs to be defined as RectOptional_FREELIST is defined
#endif
#ifndef RectOptional_Freelist_Num
#error RectOptional_Freelist_Num needs to be defined as RectOptional_FREELIST is defined
#endif
#endif // RectOptional_FREELIST
// #endregion RectOptional
#define PrimitiveType RectImport_primitiveType
#define RectObject RectImport_RectObject
#define OtherRectObject RectImport_OtherRectObject
#define TypeObject RectImport_TypeObject
#define InnerRect RectImport_innerRectStruct
#define OtherInnerRect RectImport_otherInnerRectStruct
#define InnerPoint RectImport_innerPointStruct
#define RectCheck RectImport_RectCheck
#define OtherRectCheck RectImport_OtherRectCheck
#define RectFromObject RectExport_RectFromObject
#define RectFromFastcallArgs RectExport_RectFromFastcallArgs
#define subtype_new4 RectExport_subtypeNew4
#define primitiveFromObjIndex RectImport_primitiveFromObjIndex
#define pgTwoValuesFromFastcallArgs RectExport_pgTwoValuesFromFastcallArgs
#define twoPrimitivesFromObj RectImport_twoPrimitivesFromObj
#define fourPrimivitesFromObj RectImport_fourPrimiviteFromObj
#define PrimitiveFromObj RectImport_PrimitiveFromObj
#define TypeFMT RectImport_PyBuildValueFormat
#define ObjectName RectImport_ObjectName
#define PythonNumberCheck RectImport_PythonNumberCheck
#define PythonNumberAsPrimitiveType RectImport_PythonNumberAsPrimitiveType
#define PythonNumberFromPrimitiveType RectImport_PrimitiveTypeAsPythonNumber
#define PrimitiveTypeAsPythonNumber RectImport_PrimitiveTypeAsPythonNumber
#define pgRectAsRect(x) (((RectObject *)x)->r)
static int
RectExport_do_rects_intresect(InnerRect *A, InnerRect *B)
{
if (A->w == 0 || A->h == 0 || B->w == 0 || B->h == 0) {
// zero sized rects should not collide with anything #1197
return 0;
}
// A.left < B.right &&
// A.top < A.bottom &&
// A.right > B.left &&
// A.bottom > b.top
return (MIN(A->x, A->x + A->w) < MAX(B->x, B->x + B->w) &&
MIN(A->y, A->y + A->h) < MAX(B->y, B->y + B->h) &&
MAX(A->x, A->x + A->w) > MIN(B->x, B->x + B->w) &&
MAX(A->y, A->y + A->h) > MIN(B->y, B->y + B->h));
}
#define _pg_do_rects_intersect RectExport_do_rects_intresect
static InnerRect *
RectExport_RectFromObject(PyObject *obj, InnerRect *temp);
static InnerRect *
RectExport_RectFromFastcallArgs(PyObject *const *args, Py_ssize_t nargs,
InnerRect *temp);
static PyObject *
RectExport_subtypeNew4(PyTypeObject *type, PrimitiveType x, PrimitiveType y,
PrimitiveType w, PrimitiveType h);
static PyObject *
RectExport_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
static void
RectExport_dealloc(RectObject *self);
static int
RectExport_init(RectObject *self, PyObject *args, PyObject *kwds);
static PyObject *
RectExport_RectNew(InnerRect *r);
static PyObject *
RectExport_RectNew4(PrimitiveType x, PrimitiveType y, PrimitiveType w,
PrimitiveType h);
static void
RectExport_Normalize(InnerRect *rect);
static PyObject *
RectExport_normalize(RectObject *self, PyObject *args);
static int
RectExport_pgTwoValuesFromFastcallArgs(PyObject *const *args, Py_ssize_t nargs,
PrimitiveType *x, PrimitiveType *y);
static PyObject *
RectExport_move(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_moveIp(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_moveTo(RectObject *self, PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames);
static PyObject *
RectExport_inflate(RectObject *self, PyObject *args);
static PyObject *
RectExport_inflateIp(RectObject *self, PyObject *args);
static PyObject *
RectExport_scalebyIp(RectObject *self, PyObject *args, PyObject *kwargs);
static PyObject *
RectExport_scaleby(RectObject *self, PyObject *args, PyObject *kwargs);
static PyObject *
RectExport_update(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_union(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_unionIp(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_unionall(RectObject *self, PyObject *args);
static PyObject *
RectExport_unionallIp(RectObject *self, PyObject *args);
static PyObject *
RectExport_collidepoint(RectObject *self, PyObject *const *args,
Py_ssize_t nargs);
static InnerRect *
RectExport_RectFromObjectAndKeyFunc(PyObject *obj, PyObject *keyfunc,
InnerRect *temp);
static PyObject *
RectExport_colliderect(RectObject *self, PyObject *const *args,
Py_ssize_t nargs);
static PyObject *
RectExport_collidelist(RectObject *self, PyObject *args);
static PyObject *
RectExport_collidelistall(RectObject *self, PyObject *args);
static PyObject *
RectExport_collideobjectsall(RectObject *self, PyObject *args,
PyObject *kwargs);
static PyObject *
RectExport_collideobjects(RectObject *self, PyObject *args, PyObject *kwargs);
static PyObject *
RectExport_collidedict(RectObject *self, PyObject *args, PyObject *kwargs);
static PyObject *
RectExport_collidedictall(RectObject *self, PyObject *args, PyObject *kwargs);
static PyObject *
RectExport_clip(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static int
RectExport_contains_internal(RectObject *self, PyObject *const *args,
Py_ssize_t nargs);
static PyObject *
RectExport_contains(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static int
RectExport_containsSeq(RectObject *self, PyObject *arg);
static PyObject *
RectExport_clamp(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_fit(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_clampIp(RectObject *self, PyObject *const *args, Py_ssize_t nargs);
static PyObject *
RectExport_reduce(RectObject *self, PyObject *args);
static PyObject *
RectExport_copy(RectObject *self, PyObject *args);
static PyObject *
RectExport_item(RectObject *self, Py_ssize_t i);
static int
RectExport_assItem(RectObject *self, Py_ssize_t i, PyObject *v);
static PyObject *
RectExport_subscript(RectObject *self, PyObject *op);
static int
RectExport_assSubscript(RectObject *self, PyObject *op, PyObject *value);
static int
RectExport_bool(RectObject *self);
static PyObject *
RectExport_richcompare(PyObject *o1, PyObject *o2, int opid);
static PyObject *
RectExport_getwidth(RectObject *self, void *closure);
static int
RectExport_setwidth(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getheight(RectObject *self, void *closure);
static int
RectExport_setheight(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_gettop(RectObject *self, void *closure);
static int
RectExport_settop(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getleft(RectObject *self, void *closure);
static int
RectExport_setleft(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getright(RectObject *self, void *closure);
static int
RectExport_setright(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getbottom(RectObject *self, void *closure);
static int
RectExport_setbottom(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getcenterx(RectObject *self, void *closure);
static int
RectExport_setcenterx(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getcentery(RectObject *self, void *closure);
static int
RectExport_setcentery(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_gettopleft(RectObject *self, void *closure);
static int
RectExport_settopleft(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_gettopright(RectObject *self, void *closure);
static int
RectExport_settopright(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getbottomleft(RectObject *self, void *closure);
static int
RectExport_setbottomleft(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getbottomright(RectObject *self, void *closure);
static int
RectExport_setbottomright(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getmidtop(RectObject *self, void *closure);
static int
RectExport_setmidtop(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getmidleft(RectObject *self, void *closure);
static int
RectExport_setmidleft(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getmidbottom(RectObject *self, void *closure);
static int
RectExport_setmidbottom(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getmidright(RectObject *self, void *closure);
static int
RectExport_setmidright(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getcenter(RectObject *self, void *closure);
static int
RectExport_setcenter(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_getsize(RectObject *self, void *closure);
static int
RectExport_setsize(RectObject *self, PyObject *value, void *closure);
static PyObject *
RectExport_iterator(RectObject *self);
#ifdef RectOptional_FREELIST
const int RectOptional_FreelistlimitNumberName =
RectOptional_FreelistlimitNumber;
static RectObject
*RectOptional_FreelistFreelistName[RectOptional_FreelistlimitNumber];
int RectOptional_Freelist_Num = -1;
#endif
static InnerRect *
RectExport_RectFromObject(PyObject *obj, InnerRect *temp)
{
Py_ssize_t length;
if (RectCheck(obj)) {
return &((RectObject *)obj)->r;
}
if (OtherRectCheck(obj)) {
OtherInnerRect rect = ((OtherRectObject *)obj)->r;
temp->x = (PrimitiveType)rect.x;
temp->y = (PrimitiveType)rect.y;
temp->w = (PrimitiveType)rect.w;
temp->h = (PrimitiveType)rect.h;
return temp;
}
if (pgSequenceFast_Check(obj)) {
length = PySequence_Fast_GET_SIZE(obj);
PyObject **items = PySequence_Fast_ITEMS(obj);
if (length == 4) {
if (!PrimitiveFromObj(items[0], &temp->x) ||
!PrimitiveFromObj(items[1], &temp->y) ||
!PrimitiveFromObj(items[2], &temp->w) ||
!PrimitiveFromObj(items[3], &temp->h)) {
return NULL;
}
return temp;
}
else if (length == 2) {
if (!twoPrimitivesFromObj(items[0], &temp->x, &temp->y) ||
!twoPrimitivesFromObj(items[1], &temp->w, &temp->h)) {
return NULL;
}
return temp;
}
else if (PyTuple_Check(obj) && length == 1) {
return RectExport_RectFromObject(items[0], temp);
}
else {
return NULL;
}
}
else if (PySequence_Check(obj)) {
PyObject *item;
if ((length = PySequence_Size(obj)) == -1) {
PyErr_Clear();
return NULL;
}
if (length == 4) {
item = PySequence_ITEM(obj, 0);
if (!PrimitiveFromObj(item, &temp->x)) {
Py_XDECREF(item);
return NULL;
}
Py_DECREF(item);
item = PySequence_ITEM(obj, 1);
if (!PrimitiveFromObj(item, &temp->y)) {
Py_XDECREF(item);
return NULL;
}
Py_DECREF(item);
item = PySequence_ITEM(obj, 2);
if (!PrimitiveFromObj(item, &temp->w)) {
Py_XDECREF(item);
return NULL;
}
Py_DECREF(item);
item = PySequence_ITEM(obj, 3);
if (!PrimitiveFromObj(item, &temp->h)) {
Py_XDECREF(item);
return NULL;
}
Py_DECREF(item);
return temp;
}
else if (length == 2) {
item = PySequence_ITEM(obj, 0);
if (!twoPrimitivesFromObj(item, &temp->x, &temp->y)) {
Py_XDECREF(item);
return NULL;
}
Py_DECREF(item);
item = PySequence_ITEM(obj, 1);
if (!twoPrimitivesFromObj(item, &temp->w, &temp->h)) {
Py_XDECREF(item);
return NULL;
}
Py_DECREF(item);
return temp;
}
/*looks like an arg?*/
else if (PyTuple_Check(obj) && length == 1) {
if (!(item = PyTuple_GET_ITEM(obj, 0))) {
return NULL;
}
InnerRect *returnrect = RectExport_RectFromObject(item, temp);
return returnrect;
}
}
/* Try to get the rect attribute */
PyObject *rectattr;
if (!(rectattr = PyObject_GetAttrString(obj, "rect"))) {
PyErr_Clear();
return NULL;
}
InnerRect *returnrect;
/*call if it's a method*/
if (PyCallable_Check(rectattr)) {
PyObject *rectresult = PyObject_CallObject(rectattr, NULL);
Py_DECREF(rectattr);
if (rectresult == NULL) {
PyErr_Clear();
return NULL;
}
rectattr = rectresult;
}
returnrect = RectExport_RectFromObject(rectattr, temp);
Py_DECREF(rectattr);
return returnrect;
}
static InnerRect *
RectExport_RectFromFastcallArgs(PyObject *const *args, Py_ssize_t nargs,
InnerRect *temp)
{
/* This function converts a sequence of arguments coming from a fastcall
* call into a Rect or FRect.
* */
if (nargs == 1) {
return RectFromObject(args[0], temp);
}
else if (nargs == 4) {
if (!PrimitiveFromObj(args[0], &temp->x) ||
!PrimitiveFromObj(args[1], &temp->y) ||
!PrimitiveFromObj(args[2], &temp->w) ||
!PrimitiveFromObj(args[3], &temp->h)) {
return NULL;
}
return temp;
}
else if (nargs == 2) {
if (!twoPrimitivesFromObj(args[0], &temp->x, &temp->y) ||
!twoPrimitivesFromObj(args[1], &temp->w, &temp->h)) {
return NULL;
}
return temp;
}
return NULL;
}
static PyObject *
RectExport_subtypeNew4(PyTypeObject *type, PrimitiveType x, PrimitiveType y,
PrimitiveType w, PrimitiveType h)
{
RectObject *rect;
rect = (RectObject *)TypeObject.tp_new(type, NULL, NULL);
if (rect) {
rect->r.x = x;
rect->r.y = y;
rect->r.w = w;
rect->r.h = h;
}
return (PyObject *)rect;
}
static PyObject *
RectExport_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
RectObject *self;
#ifdef RectOptional_FREELIST
/* Only instances of the base pygame.Rect class are allowed in the
* current freelist implementation (subclasses are not allowed) */
if (RectOptional_Freelist_Num > -1 && type == &RectImport_TypeObject) {
self = RectOptional_FreelistFreelistName[RectOptional_Freelist_Num];
Py_INCREF(self);
/* This is so that pypy garbage collector thinks it is a new obj
TODO: May be a hack. Is a hack.
See https://github.com/pygame/pygame/issues/430
*/
((PyObject *)(self))->ob_pypy_link = 0;
RectOptional_Freelist_Num--;
}
else {
self = (RectObject *)type->tp_alloc(type, 0);
}
#else
self = (RectObject *)type->tp_alloc(type, 0);
#endif
if (self != NULL) {
self->r.x = self->r.y = (PrimitiveType)0;
self->r.w = self->r.h = (PrimitiveType)0;
self->weakreflist = NULL;
}
return (PyObject *)self;
}
static void
RectExport_dealloc(RectObject *self)
{
if (self->weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject *)self);
}
#ifdef PYPY_VERSION
/* Only instances of the base pygame.Rect class are allowed in the
* current freelist implementation (subclasses are not allowed) */
if (RectOptional_Freelist_Num < RectOptional_FreelistlimitNumberName - 1 &&
RectImport_RectCheckExact(self)) {
RectOptional_Freelist_Num++;
RectOptional_FreelistFreelistName[RectOptional_Freelist_Num] = self;
}
else {
Py_TYPE(self)->tp_free((PyObject *)self);
}
#else
Py_TYPE(self)->tp_free((PyObject *)self);
#endif
}
static int
RectExport_init(RectObject *self, PyObject *args, PyObject *kwds)
{
InnerRect *argrect, temp;
if (!(argrect = RectFromObject(args, &temp))) {
PyErr_SetString(PyExc_TypeError, "Argument must be rect style object");
return -1;
}
self->r = *argrect;
return 0;
}
static PyObject *
RectExport_RectNew(InnerRect *r)
{
return subtype_new4(&TypeObject, r->x, r->y, r->w, r->h);
}
static PyObject *
RectExport_RectNew4(PrimitiveType x, PrimitiveType y, PrimitiveType w,
PrimitiveType h)
{
return subtype_new4(&TypeObject, x, y, w, h);
}
static void
RectExport_Normalize(InnerRect *rect)
{
if (rect->w < 0) {
rect->x += rect->w;
rect->w = -rect->w;
}
if (rect->h < 0) {
rect->y += rect->h;
rect->h = -rect->h;
}
}
static PyObject *
RectExport_normalize(RectObject *self, PyObject *args)
{
RectExport_Normalize(&pgRectAsRect(self));
Py_RETURN_NONE;
}
static int
RectExport_pgTwoValuesFromFastcallArgs(PyObject *const *args, Py_ssize_t nargs,
PrimitiveType *x, PrimitiveType *y)
{
/*Check if there is only one argument*/
if (nargs == 1) {
/*Attempt to convert the argument to two floats/integers*/
if (!twoPrimitivesFromObj(args[0], x, y)) {
if (!PySequence_Check(args[0])) {
PyErr_Format(
PyExc_TypeError,
"Invalid argument. Expected a sequence but got: '%s'",
Py_TYPE(args[0])->tp_name);
return 0;
}
Py_ssize_t size = PySequence_Size(args[0]);
if (size != 2) {
PyErr_Format(
PyExc_TypeError,
"Invalid sequence size. Expected size 2 but got: %d",
(int)size);
return 0;
}
PyObject *xobj, *yobj;
if (!(xobj = PySequence_GetItem(args[0], 0))) {
return 0;
}
if (!(yobj = PySequence_GetItem(args[0], 1))) {
Py_DECREF(xobj);
return 0;
}
PyErr_Format(PyExc_TypeError,
"Invalid sequence values. Expected two numeric "
"values but got: '%s', '%s'",
Py_TYPE(xobj)->tp_name, Py_TYPE(yobj)->tp_name);
Py_DECREF(xobj);
Py_DECREF(yobj);
return 0;
}
return 1;
}
/*Check if there are two arguments*/
else if (nargs == 2) {
/*Attempt to convert the first argument to an float/integer*/
if (!PrimitiveFromObj(args[0], x)) {
PyErr_Format(PyExc_TypeError,
"The first argument must be numeric (got: '%s')",
Py_TYPE(args[0])->tp_name);
return 0;
}
/*Attempt to convert the second argument to a float/integer*/
if (!PrimitiveFromObj(args[1], y)) {
PyErr_Format(PyExc_TypeError,
"The second argument must be numeric (got: '%s')",
Py_TYPE(args[1])->tp_name);
return 0;
}
return 1;
}
/*Raise a TypeError for invalid number of arguments*/
PyErr_Format(PyExc_TypeError,
"Function takes at most 2 arguments (%d given)", (int)nargs);
return 0;
}
static PyObject *
RectExport_move(RectObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PrimitiveType x, y;
if (!pgTwoValuesFromFastcallArgs(args, nargs, &x, &y)) {
return NULL;
}
return RectExport_subtypeNew4(Py_TYPE(self), self->r.x + x, self->r.y + y,
self->r.w, self->r.h);
}
static PyObject *
RectExport_moveIp(RectObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PrimitiveType x, y;
if (!pgTwoValuesFromFastcallArgs(args, nargs, &x, &y)) {
return NULL;
}
self->r.x += x;
self->r.y += y;
Py_RETURN_NONE;
}
static PyObject *
RectExport_moveTo(RectObject *self, PyObject *const *args, Py_ssize_t nargs,
PyObject *kwnames)
{
PyObject *rect = RectExport_copy(self, NULL);
if (!rect) {
return NULL;