forked from CamDavidsonPilon/matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_transforms.cpp
More file actions
2483 lines (1922 loc) · 61.9 KB
/
_transforms.cpp
File metadata and controls
2483 lines (1922 loc) · 61.9 KB
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
#include <functional>
#include <limits>
#include <math.h>
#include "_transforms.h"
#include "mplutils.h"
#include "numpy/arrayobject.h"
#include "MPL_isnan.h"
Value::~Value() {
_VERBOSE("Value::~Value");
}
Py::Object
Value::set(const Py::Tuple & args) {
_VERBOSE("Value::set");
args.verify_length(1);
_val = Py::Float( args[0] );
return Py::Object();
}
Py::Object
Value::get(const Py::Tuple & args) {
_VERBOSE("Value::get");
args.verify_length(0);
return Py::Float( _val );
}
int
LazyValue::compare(const Py::Object &other) {
if (!check(other))
throw Py::TypeError("Can only compare LazyValues with LazyValues");
LazyValue* pother = static_cast<LazyValue*>(other.ptr());
double valself = val();
double valother = pother->val();
int ret;
if (valself<valother) ret=-1;
else if (valself==valother) ret=0;
else ret=1;
return ret;
}
Py::Object
LazyValue::number_add( const Py::Object &o ) {
_VERBOSE("LazyValue::number");
if (!LazyValue::check(o))
throw Py::TypeError("Can only add LazyValues with other LazyValues");
LazyValue* rhs = static_cast<LazyValue*>(o.ptr());
return Py::asObject(new BinOp(this, rhs, BinOp::ADD));
}
Py::Object
LazyValue::number_divide( const Py::Object &o ) {
_VERBOSE("LazyValue::number");
//std::cout << "initing divide" << std::endl;
if (!LazyValue::check(o))
throw Py::TypeError("Can only divide LazyValues with other LazyValues");
LazyValue* rhs = static_cast<LazyValue*>(o.ptr());
BinOp* op = new BinOp(this, rhs, BinOp::DIVIDE);
//std::cout << "initing divide done" << std::endl;
return Py::asObject(op);
}
Py::Object
LazyValue::number_multiply( const Py::Object &o ) {
_VERBOSE("LazyValue::number");
if (!LazyValue::check(o))
throw Py::TypeError("Can only multiply LazyValues with other LazyValues");
LazyValue* rhs = static_cast<LazyValue*>(o.ptr());
return Py::asObject(new BinOp(this, rhs, BinOp::MULTIPLY));
}
Py::Object
LazyValue::number_subtract( const Py::Object &o ) {
_VERBOSE("LazyValue::number");
if (!LazyValue::check(o))
throw Py::TypeError("Can only subtract LazyValues with other LazyValues");
LazyValue* rhs = static_cast<LazyValue*>(o.ptr());
return Py::asObject(new BinOp(this, rhs, BinOp::SUBTRACT));
}
BinOp::BinOp(LazyValue* lhs, LazyValue* rhs, int opcode) :
_lhs(lhs), _rhs(rhs), _opcode(opcode) {
_VERBOSE("BinOp::BinOp");
Py_INCREF(lhs);
Py_INCREF(rhs);
}
BinOp::~BinOp() {
_VERBOSE("BinOp::~BinOp");
Py_DECREF(_lhs);
Py_DECREF(_rhs);
}
Py::Object
BinOp::get(const Py::Tuple & args) {
_VERBOSE("BinOp::get");
args.verify_length(0);
double x = val();
return Py::Float( x );
}
Point::Point(LazyValue* x, LazyValue* y) : _x(x), _y(y) {
_VERBOSE("Point::Point");
Py_INCREF(x);
Py_INCREF(y);
}
Point::~Point()
{
_VERBOSE("Point::~Point");
Py_DECREF(_x);
Py_DECREF(_y);
}
Interval::Interval(LazyValue* val1, LazyValue* val2) :
_val1(val1), _val2(val2), _minpos(NULL) {
_VERBOSE("Interval::Interval");
Py_INCREF(val1);
Py_INCREF(val2);
};
Interval::~Interval() {
_VERBOSE("Interval::~Interval");
Py_DECREF(_val1);
Py_DECREF(_val2);
}
Py::Object
Interval::update(const Py::Tuple &args) {
_VERBOSE("Interval::update");
args.verify_length(2);
Py::SeqBase<Py::Object> vals = args[0];
//don't use current bounds when updating box if ignore==1
int ignore = Py::Int(args[1]);
size_t Nval = vals.length();
if (Nval==0) return Py::Object();
double minx = _val1->val();
double maxx = _val2->val();
int reversed = 0;
if (minx > maxx) {
reversed = 1;
double tmp = minx;
minx = maxx;
maxx = tmp;
}
double thisval;
thisval = Py::Float(vals[0]);
if (ignore) {
minx = thisval;
maxx = thisval;
}
for (size_t i=0; i<Nval; ++i) {
if (thisval<minx) minx = thisval;
if (thisval>maxx) maxx = thisval;
_minpos->update(thisval);
}
if (reversed) {
_val1->set_api(maxx);
_val2->set_api(minx);
} else {
_val1->set_api(minx);
_val2->set_api(maxx);
}
return Py::Object();
}
Bbox::Bbox(Point* ll, Point* ur) : _ll(ll), _ur(ur), _ignore(1) {
_VERBOSE("Bbox::Bbox");
Py_INCREF(ll);
Py_INCREF(ur);
};
Bbox::~Bbox() {
_VERBOSE("Bbox::~Bbox");
Py_DECREF(_ll);
Py_DECREF(_ur);
}
Py::Object
Bbox::_deepcopy() {
double minx = _ll->xval();
double miny = _ll->yval();
double maxx = _ur->xval();
double maxy = _ur->yval();
return Py::asObject( new Bbox( new Point(new Value(minx), new Value(miny) ),
new Point(new Value(maxx), new Value(maxy) )));
}
Py::Object
Bbox::deepcopy(const Py::Tuple &args) {
_VERBOSE("Bbox::deepcopy");
args.verify_length(0);
return _deepcopy();
}
Py::Object
Bbox::scale(const Py::Tuple &args) {
_VERBOSE("Bbox::scale");
args.verify_length(2);
double sx = Py::Float(args[0]);
double sy = Py::Float(args[1]);
double minx = _ll->xval();
double miny = _ll->yval();
double maxx = _ur->xval();
double maxy = _ur->yval();
double w = maxx-minx;
double h = maxy-miny;
double deltaw = (sx*w-w)/2.0;
double deltah = (sy*h-h)/2.0;
_ll->x_api()->set_api(minx-deltaw);
_ur->x_api()->set_api(maxx+deltaw);
_ll->y_api()->set_api(miny-deltah);
_ur->y_api()->set_api(maxy+deltah);
return Py::Object();
}
Py::Object
Bbox::get_bounds(const Py::Tuple & args) {
_VERBOSE("Bbox::get_bounds");
args.verify_length(0);
double minx = _ll->xval();
double miny = _ll->yval();
double maxx = _ur->xval();
double maxy = _ur->yval();
double width = maxx - minx;
double height = maxy - miny;
Py::Tuple ret(4);
ret[0] = Py::Float(minx);
ret[1] = Py::Float(miny);
ret[2] = Py::Float(width);
ret[3] = Py::Float(height);
return ret;
}
Py::Object
Bbox::count_contains(const Py::Tuple &args) {
_VERBOSE("Bbox::count_contains");
args.verify_length(1);
Py::SeqBase<Py::Object> xys = args[0];
size_t Nxys = xys.length();
long count = 0;
double minx = _ll->xval();
double miny = _ll->yval();
double maxx = _ur->xval();
double maxy = _ur->yval();
for(size_t i=0; i < Nxys; i++) {
Py::SeqBase<Py::Object> xy(xys[i]);
xy.verify_length(2);
double x = Py::Float(xy[0]);
double y = Py::Float(xy[1]);
int inx = ( (x>=minx) && (x<=maxx) || (x>=maxx) && (x<=minx) );
if (!inx) continue;
int iny = ( (y>=miny) && (y<=maxy) || (y>=maxy) && (y<=miny) );
if (!iny) continue;
count += 1;
}
return Py::Int(count);
}
Py::Object
Bbox::contains(const Py::Tuple &args) {
_VERBOSE("Bbox::contains");
args.verify_length(2);
double x = Py::Float(args[0]);
double y = Py::Float(args[1]);
double minx = _ll->xval();
double miny = _ll->yval();
double maxx = _ur->xval();
double maxy = _ur->yval();
int inx = ( (x>=minx) && (x<=maxx) || (x>=maxx) && (x<=minx) );
if (!inx) return Py::Int(0);
int iny = ( (y>=miny) && (y<=maxy) || (y>=maxy) && (y<=miny) );
return Py::Int(iny);
}
Py::Object
Bbox::overlaps(const Py::Tuple &args, const Py::Dict &kwargs) {
_VERBOSE("Bbox::overlaps");
args.verify_length(1);
if (! check(args[0]))
throw Py::TypeError("Expected a bbox");
int x = Py::Int( overlapsx(args, kwargs) );
int y = Py::Int( overlapsy(args, kwargs) );
return Py::Int(x&&y);
}
Py::Object
Bbox::ignore(const Py::Tuple &args) {
_VERBOSE("Bbox::ignore");
args.verify_length(1);
_ignore = Py::Int(args[0]);
return Py::Object();
}
Py::Object
Bbox::is_ignore(const Py::Tuple &args) {
_VERBOSE("Bbox::ignore");
args.verify_length(0);
return Py::Int(_ignore);
}
Py::Object
Bbox::overlapsx(const Py::Tuple &args, const Py::Dict &kwargs) {
_VERBOSE("Bbox::overlapsx");
args.verify_length(1);
if (! check(args[0]))
throw Py::TypeError("Expected a bbox");
int ignoreend = false;
if (kwargs.hasKey("ignoreend")) {
ignoreend = Py::Int(kwargs["ignoreend"]);
}
Bbox* other = static_cast<Bbox*>(args[0].ptr());
double minx = _ll->xval();
double maxx = _ur->xval();
double ominx = other->_ll->xval();
double omaxx = other->_ur->xval();
int b=0;
if (ignoreend) {
b = ( ( (ominx>minx) && (ominx<maxx)) ||
( (minx>ominx) && (minx<omaxx)) );
}
else{
b = ( ( (ominx>=minx) && (ominx<=maxx)) ||
( (minx>=ominx) && (minx<=omaxx)) );
}
return Py::Int(b);
}
Py::Object
Bbox::overlapsy(const Py::Tuple &args, const Py::Dict &kwargs) {
_VERBOSE("Bbox::overlapsy");
args.verify_length(1);
if (! check(args[0]))
throw Py::TypeError("Expected a bbox");
int ignoreend = false;
if (kwargs.hasKey("ignoreend")) {
ignoreend = Py::Int(kwargs["ignoreend"]);
}
Bbox* other = static_cast<Bbox*>(args[0].ptr());
double miny = _ll->yval();
double maxy = _ur->yval();
double ominy = other->_ll->yval();
double omaxy = other->_ur->yval();
int b=0;
if (ignoreend) {
b = ( ( (ominy>miny) && (ominy<maxy)) ||
( (miny>ominy) && (miny<omaxy)) );
}
else {
b = ( ( (ominy>=miny) && (ominy<=maxy)) ||
( (miny>=ominy) && (miny<=omaxy)) );
}
return Py::Int(b);
}
/*
As for how the datalim handling works, the syntax is
self.dataLim.update(xys, ignore)
Note this is different than the ax.update_datalim method, which calls
it. datalim is a bbox which has an ignore state variable (boolean).
The ignore argument to update datalim can take on three values
0: do not ignore the current limits and update them with the xys
1: ignore the current datalim limits and override with xys
-1: use the datalim ignore state to determine the ignore settings
This seems a bit complex but arose from experience. Basically a lot
of different objects want to add their data to the datalim. In most
use cases, you want the first object to add data to ignore the current
limits (which are just default values) and subsequent objects to add
to the datalim taking into account the previous limits. The default
behavior of datalim is to set ignore to 1, and after the first call
with -1 set ignore to 0. Thus everyone can call with -1 and have the
desired default behavior . I hope you are all confused now.
One can manually set the ignore state var with
datalim.ignore(1)
*/
Py::Object
Bbox::update(const Py::Tuple &args) {
_VERBOSE("Bbox::update");
args.verify_length(2);
Py::Object test = args[0];
if (test.hasAttr("shape")) return Bbox::update_numerix_xy(args);
Py::SeqBase<Py::Object> xys = args[0];
//don't use current bounds on first update
int ignore = Py::Int(args[1]);
if (ignore==-1) {
ignore = _ignore;
_ignore = 0; // don't ignore future updates
}
size_t Nx = xys.length();
if (Nx==0) return Py::Object();
double minx = _ll->xval();
double maxx = _ur->xval();
int xreversed = 0;
if (minx > maxx) {
xreversed = 1;
double tmp = minx;
minx = maxx;
maxx = tmp;
}
double miny = _ll->yval();
double maxy = _ur->yval();
int yreversed = 0;
if (miny > maxy) {
yreversed = 1;
double tmp = miny;
miny = maxy;
maxy = tmp;
}
Py::Tuple tup;
if (ignore) {
minx = miny = std::numeric_limits<double>::max();
maxx = maxy = std::numeric_limits<double>::min();
}
for (size_t i=0; i<Nx; ++i) {
tup = xys[i];
double x = Py::Float(tup[0]);
double y = Py::Float(tup[1]);
if (MPL_isnan64(x) || MPL_isnan64(y)) continue;
_posx.update(x);
_posy.update(y);
if (x<minx) minx=x;
if (x>maxx) maxx=x;
if (y<miny) miny=y;
if (y>maxy) maxy=y;
}
if (xreversed) {
_ll->x_api()->set_api(maxx);
_ur->x_api()->set_api(minx);
} else {
_ll->x_api()->set_api(minx);
_ur->x_api()->set_api(maxx);
}
if (yreversed) {
_ll->y_api()->set_api(maxy);
_ur->y_api()->set_api(miny);
} else {
_ll->y_api()->set_api(miny);
_ur->y_api()->set_api(maxy);
}
return Py::Object();
}
// Replace update with the following?
Py::Object
Bbox::update_numerix_xy(const Py::Tuple &args) {
//update the box from the numerix array xy
_VERBOSE("Bbox::update_numerix_xy");
args.verify_length(2);
Py::Object xyo = args[0];
PyArrayObject *xyin = (PyArrayObject *) PyArray_FromObject(xyo.ptr(),
PyArray_DOUBLE, 2, 2);
if (xyin==NULL)
throw Py::TypeError("Bbox::update_numerix_xy expected numerix array");
size_t Nxy = xyin->dimensions[0];
size_t N2 = xyin->dimensions[1];
if (N2 != 2)
throw Py::ValueError("xy array must have shape (N, 2)");
//don't use current bounds when updating box if ignore==1
if (Nxy==0) return Py::Object();
double minx = _ll->xval();
double maxx = _ur->xval();
int xreversed = 0;
if (minx > maxx) {
xreversed = 1;
double tmp = minx;
minx = maxx;
maxx = tmp;
}
double miny = _ll->yval();
double maxy = _ur->yval();
int yreversed = 0;
if (miny > maxy) {
yreversed = 1;
double tmp = miny;
miny = maxy;
maxy = tmp;
}
double thisx, thisy;
//don't use current bounds on first update
int ignore = Py::Int(args[1]);
if (ignore==-1) {
ignore = _ignore;
_ignore = 0; // don't ignore future updates
}
if (ignore) {
minx = miny = std::numeric_limits<double>::max();
maxx = maxy = -std::numeric_limits<double>::max();
}
int ngood = 0;
for (size_t i=0; i< Nxy; ++i) {
thisx = *(double *)(xyin->data + i*xyin->strides[0]);
thisy = *(double *)(xyin->data + i*xyin->strides[0] + xyin->strides[1]);
if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) continue;
_posx.update(thisx);
_posy.update(thisy);
if (thisx<minx) minx=thisx;
if (thisx>maxx) maxx=thisx;
if (thisy<miny) miny=thisy;
if (thisy>maxy) maxy=thisy;
ngood++;
}
Py_XDECREF(xyin);
if (ngood) {
if (xreversed) {
_ll->x_api()->set_api(maxx);
_ur->x_api()->set_api(minx);
} else {
_ll->x_api()->set_api(minx);
_ur->x_api()->set_api(maxx);
}
if (yreversed) {
_ll->y_api()->set_api(maxy);
_ur->y_api()->set_api(miny);
} else {
_ll->y_api()->set_api(miny);
_ur->y_api()->set_api(maxy);
}
}
return Py::Object();
}
Py::Object
Bbox::update_numerix(const Py::Tuple &args) {
//update the box from the numerix arrays x and y
_VERBOSE("Bbox::update_numerix");
args.verify_length(3);
Py::Object xo = args[0];
Py::Object yo = args[1];
PyArrayObject *x = (PyArrayObject *) PyArray_ContiguousFromObject(xo.ptr(), PyArray_DOUBLE, 1, 1);
if (x==NULL)
throw Py::TypeError("Bbox::update_numerix expected numerix array");
PyArrayObject *y = (PyArrayObject *) PyArray_ContiguousFromObject(yo.ptr(), PyArray_DOUBLE, 1, 1);
if (y==NULL)
throw Py::TypeError("Bbox::update_numerix expected numerix array");
size_t Nx = x->dimensions[0];
size_t Ny = y->dimensions[0];
if (Nx!=Ny)
throw Py::ValueError("x and y must be equal length sequences");
//don't use current bounds when updating box if ignore==1
if (Nx==0) return Py::Object();
double minx = _ll->xval();
double maxx = _ur->xval();
int xreversed = 0;
if (minx > maxx) {
xreversed = 1;
double tmp = minx;
minx = maxx;
maxx = tmp;
}
double miny = _ll->yval();
double maxy = _ur->yval();
int yreversed = 0;
if (miny > maxy) {
yreversed = 1;
double tmp = miny;
miny = maxy;
maxy = tmp;
}
double thisx, thisy;
//don't use current bounds on first update
int ignore = Py::Int(args[2]);
if (ignore==-1) {
ignore = _ignore;
_ignore = 0; // don't ignore future updates
}
if (ignore) {
minx = miny = std::numeric_limits<double>::max();
maxx = maxy = -std::numeric_limits<double>::max();
}
for (size_t i=0; i< Nx; ++i) {
thisx = *(double *)(x->data + i*x->strides[0]);
thisy = *(double *)(y->data + i*y->strides[0]);
if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) continue;
_posx.update(thisx);
_posy.update(thisy);
if (thisx<minx) minx=thisx;
if (thisx>maxx) maxx=thisx;
if (thisy<miny) miny=thisy;
if (thisy>maxy) maxy=thisy;
}
Py_XDECREF(x);
Py_XDECREF(y);
if (xreversed) {
_ll->x_api()->set_api(maxx);
_ur->x_api()->set_api(minx);
} else {
_ll->x_api()->set_api(minx);
_ur->x_api()->set_api(maxx);
}
if (yreversed) {
_ll->y_api()->set_api(maxy);
_ur->y_api()->set_api(miny);
} else {
_ll->y_api()->set_api(miny);
_ur->y_api()->set_api(maxy);
}
return Py::Object();
}
Func::~Func() {
_VERBOSE("Func::~Func");
}
Py::Object
Func::map(const Py::Tuple &args) {
_VERBOSE("Func::map");
args.verify_length(1);
double xin = Py::Float(args[0]);
double xout;
try {
xout = this->operator()(xin);
}
catch (const std::exception &e) {
throw Py::ValueError(e.what());
}
catch(...) {
throw Py::ValueError("Domain error on Func::map");
}
return Py::Float(xout);
};
Py::Object
Func::inverse(const Py::Tuple &args) {
_VERBOSE("Func::inverse");
args.verify_length(1);
double xin = Py::Float(args[0]);
double xout = this->inverse_api(xin);
return Py::Float(xout);
};
Py::Object
FuncXY::map(const Py::Tuple &args) {
_VERBOSE("FuncXY::map");
args.verify_length(2);
double xin = Py::Float(args[0]);
double yin = Py::Float(args[1]);
std::pair<double, double> xy;
try {
xy = this->operator()(xin, yin);
}
catch (const std::exception &e) {
throw Py::ValueError(e.what());
}
catch(...) {
throw Py::ValueError("Domain error on FuncXY nonlinear transform");
}
Py::Tuple ret(2);
double xout = xy.first;
double yout = xy.second;
ret[0] = Py::Float(xout);
ret[1] = Py::Float(yout);
return ret;
//return Py::Object();
};
Py::Object
FuncXY::inverse(const Py::Tuple &args) {
_VERBOSE("FuncXY::inverse");
args.verify_length(2);
double xin = Py::Float(args[0]);
double yin = Py::Float(args[1]);
std::pair<double, double> xy = this->inverse_api(xin, yin);
Py::Tuple ret(2);
double xout = xy.first;
double yout = xy.second;
ret[0] = Py::Float(xout);
ret[1] = Py::Float(yout);
return ret;
};
Transformation::~Transformation() {
_VERBOSE("Transformation::~Transformation");
if (_transOffset!=NULL) {
Py_DECREF(_transOffset);
}
}
Py::Object
Transformation::as_vec6(const Py::Tuple & args) {
_VERBOSE("Transformation::as_vec6");
throw Py::RuntimeError("This transformation does not support as_vec6");
return Py::Object();
}
Py::Object
Transformation::get_funcx(const Py::Tuple & args) {
_VERBOSE("Transformation::get_funcx");
throw Py::RuntimeError("This transformation does not support get_funcx");
return Py::Object();
}
Py::Object
Transformation::get_funcy(const Py::Tuple & args) {
_VERBOSE("Transformation::get_funcy");
throw Py::RuntimeError("This transformation does not support get_funcy");
return Py::Object();
}
Py::Object
Transformation::set_funcx(const Py::Tuple & args) {
_VERBOSE("Transformation::set_funcx");
throw Py::RuntimeError("This transformation does not support set_funcx");
return Py::Object();
}
Py::Object
Transformation::set_funcy(const Py::Tuple & args) {
_VERBOSE("Transformation::set_funcy");
throw Py::RuntimeError("This transformation does not support set_funcy");
return Py::Object();
}
Py::Object
Transformation::get_funcxy(const Py::Tuple & args) {
_VERBOSE("Transformation::get_funcxy");
throw Py::RuntimeError("This transformation does not support get_funcxy");
return Py::Object();
}
Py::Object
Transformation::set_funcxy(const Py::Tuple & args) {
_VERBOSE("Transformation::set_funcxy");
throw Py::RuntimeError("This transformation does not support set_funcxy");
return Py::Object();
}
Py::Object
Transformation::get_bbox1(const Py::Tuple & args) {
_VERBOSE("Transformation::get_bbox1");
throw Py::RuntimeError("This transformation does not support get_bbox1");
return Py::Object();
}
Py::Object
Transformation::get_bbox2(const Py::Tuple & args) {
_VERBOSE("Transformation::get_bbox2");
throw Py::RuntimeError("This transformation does not support get_bbox2");
return Py::Object();
}
Py::Object
Transformation::set_bbox1(const Py::Tuple & args) {
_VERBOSE("Transformation::set_bbox1");
throw Py::RuntimeError("This transformation does not support set_bbox1");
return Py::Object();
}
Py::Object
Transformation::set_bbox2(const Py::Tuple & args) {
_VERBOSE("Transformation::set_bbox2");
throw Py::RuntimeError("This transformation does not support set_bbox1");
return Py::Object();
}
Py::Object
Transformation::set_offset(const Py::Tuple & args) {
_VERBOSE("Transformation::set_offset");
args.verify_length(2);
Py::SeqBase<Py::Object> xy = args[0];
//std::cout << "checking args" << std::endl;
if (!check(args[1]))
throw Py::TypeError("Transformation::set_offset(xy,trans) requires trans to be a Transformation instance");
//std::cout << "getting x,y" << std::endl;
_usingOffset = 1;
_xo = Py::Float(xy[0]);
_yo = Py::Float(xy[1]);
//std::cout << "casting" << std::endl;
_transOffset = static_cast<Transformation*>(args[1].ptr());
//std::cout << "increffing" << std::endl;
Py_INCREF(_transOffset);
//std::cout << "returning" << std::endl;
return Py::Object();
}
Py::Object
Transformation::inverse_xy_tup(const Py::Tuple & args) {
_VERBOSE("Transformation::inverse_xy_tup");
args.verify_length(1);
Py::Tuple tup = args[0];
double xin = Py::Float(tup[0]);
double yin = Py::Float(tup[1]);
try {
if (!_frozen) eval_scalars();
}
catch (const std::exception &e) {
throw Py::ValueError(e.what());
}
catch(...) {
throw Py::ValueError("Domain error on inverse_xy_tup");
}
inverse_api(xin, yin);
Py::Tuple ret(2);
ret[0] = Py::Float(xy.first);
ret[1] = Py::Float(xy.second);
return ret;
}
Py::Object
Transformation::inverse_numerix_xy(const Py::Tuple & args) {
_VERBOSE("Transformation::inverse_numerix_xy");
args.verify_length(1);
Py::Object xyo = args[0];
PyArrayObject *xyin = (PyArrayObject *) PyArray_FromObject(xyo.ptr(),
PyArray_DOUBLE, 2, 2);
if (xyin==NULL)
throw Py::TypeError("Transformation::inverse_numerix_xy expected numerix array");
size_t Nxy = xyin->dimensions[0];
size_t N2 = xyin->dimensions[1];
if (N2!=2) {
Py_XDECREF(xyin);
throw Py::ValueError("xy must have shape (N,2)");
}
// evaluate the lazy objects
try {
if (!_frozen) eval_scalars();
}
catch (const std::exception &e) {
Py_XDECREF(xyin);
throw Py::ValueError(e.what());
}
catch(...) {
Py_XDECREF(xyin);