forked from HinTak/skia-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.cpp
1848 lines (1499 loc) · 67.5 KB
/
Matrix.cpp
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 "common.h"
#include <include/core/SkRSXform.h>
#include <include/core/SkPoint3.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/iostream.h>
// Static variables must be declared.
constexpr int SkMatrix::kMScaleX;
constexpr int SkMatrix::kMSkewX;
constexpr int SkMatrix::kMTransX;
constexpr int SkMatrix::kMSkewY;
constexpr int SkMatrix::kMScaleY;
constexpr int SkMatrix::kMTransY;
constexpr int SkMatrix::kMPersp0;
constexpr int SkMatrix::kMPersp1;
constexpr int SkMatrix::kMPersp2;
constexpr int SkMatrix::kAScaleX;
constexpr int SkMatrix::kASkewY;
constexpr int SkMatrix::kASkewX;
constexpr int SkMatrix::kAScaleY;
constexpr int SkMatrix::kATransX;
constexpr int SkMatrix::kATransY;
typedef py::array_t<SkScalar, py::array::c_style | py::array::forcecast> NumPy;
SkScalar GetItem(const SkMatrix& m, int index) {
if (index < 0 || 9 <= index)
throw std::out_of_range("Invalid index");
return m[index];
}
void SetItem(SkMatrix& m, int index, SkScalar value) {
if (index < 0 || 9 <= index)
throw std::out_of_range("Invalid index");
m[index] = value;
}
void initMatrix(py::module &m) {
py::enum_<SkApplyPerspectiveClip>(m, "ApplyPerspectiveClip")
.value("kNo", SkApplyPerspectiveClip::kNo,
"Don't pre-clip the geometry before applying the (perspective) matrix.")
.value("kYes", SkApplyPerspectiveClip::kYes,
"Do pre-clip the geometry before applying the (perspective) matrix.")
.export_values();
// Matrix
py::class_<SkMatrix> matrix(m, "Matrix", R"docstring(
:py:class:`Matrix` holds a 3x3 matrix for transforming coordinates.
This allows mapping :py:class:`Point` and vectors with translation, scaling,
skewing, rotation, and perspective.
:py:class:`Matrix` elements are in row major order. :py:class:`Matrix` does
not have a constructor, so it must be explicitly initialized.
:py:meth:`setIdentity` initializes :py:class:`Matrix` so it has no effect.
:py:meth:`setTranslate`, :py:meth:`setScale`, :py:meth:`setSkew`,
:py:meth:`setRotate`, :py:meth:`set9` and :py:meth:`setAll` initializes all
:py:class:`Matrix` elements with the corresponding mapping.
:py:class:`Matrix` includes a hidden variable that classifies the type of
matrix to improve performance. :py:class:`Matrix` is not thread safe unless
getType() is called first.
)docstring");
py::enum_<SkMatrix::ScaleToFit>(matrix, "ScaleToFit")
.value("kFill_ScaleToFit", SkMatrix::ScaleToFit::kFill_ScaleToFit,
"scales in x and y to fill destination SkRect")
.value("kStart_ScaleToFit", SkMatrix::ScaleToFit::kStart_ScaleToFit,
"scales and aligns to left and top")
.value("kCenter_ScaleToFit", SkMatrix::ScaleToFit::kCenter_ScaleToFit,
"scales and aligns to center")
.value("kEnd_ScaleToFit", SkMatrix::ScaleToFit::kEnd_ScaleToFit,
"scales and aligns to right and bottom")
.export_values();
py::enum_<SkMatrix::TypeMask>(matrix, "TypeMask")
.value("kIdentity_Mask", SkMatrix::TypeMask::kIdentity_Mask,
"identity SkMatrix; all bits clear")
.value("kTranslate_Mask", SkMatrix::TypeMask::kTranslate_Mask,
"translation SkMatrix")
.value("kScale_Mask", SkMatrix::TypeMask::kScale_Mask,
"scale SkMatrix")
.value("kAffine_Mask", SkMatrix::TypeMask::kAffine_Mask,
"skew or rotate SkMatrix")
.value("kPerspective_Mask", SkMatrix::TypeMask::kPerspective_Mask,
"perspective SkMatrix")
.export_values();
matrix
.def(py::init<>(),
R"docstring(
Creates an identity :py:class:`Matrix`::
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
)docstring")
.def(py::init(
[] (NumPy array) {
auto info = array.request();
size_t size = (info.ndim) ? info.shape[0] * info.strides[0] : 0;
if (size != (sizeof(SkScalar) * 9))
throw std::runtime_error("Incompatible array size");
SkMatrix matrix;
matrix.set9(reinterpret_cast<SkScalar*>(info.ptr));
return matrix;
}),
R"docstring(
Creates a :py:class:`Matrix` from 3x3 float32 NumPy array.
)docstring",
py::arg("array"))
.def("getType", &SkMatrix::getType,
R"docstring(
Returns a bit field describing the transformations the matrix may
perform.
The bit field is computed conservatively, so it may include false
positives. For example, when kPerspective_Mask is set, all other bits
are set.
:return: kIdentity_Mask, or combinations of: kTranslate_Mask,
kScale_Mask, kAffine_Mask, kPerspective_Mask
)docstring")
.def("isIdentity", &SkMatrix::isIdentity,
R"docstring(
Returns true if :py:class:`Matrix` is identity.
Identity matrix is::
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
:return: true if :py:class:`Matrix` has no effect
)docstring")
.def("isScaleTranslate", &SkMatrix::isScaleTranslate,
R"docstring(
Returns true if :py:class:`Matrix` at most scales and translates.
:py:class:`Matrix` may be identity, contain only scale elements, only
translate elements, or both. :py:class:`Matrix` form is::
| scale-x 0 translate-x |
| 0 scale-y translate-y |
| 0 0 1 |
:return: true if :py:class:`Matrix` is identity; or scales, translates,
or both
)docstring")
.def("isTranslate", &SkMatrix::isTranslate,
R"docstring(
Returns true if :py:class:`Matrix` is identity, or translates.
:py:class:`Matrix` form is::
| 1 0 translate-x | | 0 1 translate-y | | 0 0 1 |
:return: true if :py:class:`Matrix` is identity, or translates
)docstring")
.def("rectStaysRect", &SkMatrix::rectStaysRect,
R"docstring(
Returns true SkMatrix maps SkRect to another SkRect.
If true, :py:class:`Matrix` is identity, or scales, or rotates a
multiple of 90 degrees, or mirrors on axes. In all cases,
:py:class:`Matrix` may also have translation. :py:class:`Matrix` form is
either::
| scale-x 0 translate-x |
| 0 scale-y translate-y |
| 0 0 1 |
or::
| 0 rotate-x translate-x |
| rotate-y 0 translate-y |
| 0 0 1 |
for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
Also called :py:meth:`preservesAxisAlignment`; use the one that provides
better inline documentation.
:return: true if :py:class:`Matrix` maps one :py:class:`Rect` into
another
)docstring")
.def("preservesAxisAlignment", &SkMatrix::preservesAxisAlignment,
R"docstring(
Returns true :py:class:`Matrix` maps :py:class:`Rect` to another
:py:class:`Rect`.
If true, :py:class:`Matrix` is identity, or scales, or rotates a
multiple of 90 degrees, or mirrors on axes. In all cases,
:py:class:`Matrix` may also have translation. :py:class:`Matrix` form is
either::
| scale-x 0 translate-x |
| 0 scale-y translate-y |
| 0 0 1 |
or::
| 0 rotate-x translate-x |
| rotate-y 0 translate-y |
| 0 0 1 |
for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
Also called :py:meth:`rectStaysRect`; use the one that provides better
inline documentation.
:return: true if :py:class:`Matrix` maps one :py:class:`Rect` into
another
)docstring")
.def("hasPerspective", &SkMatrix::hasPerspective,
R"docstring(
Returns true if the matrix contains perspective elements.
:py:class:`Matrix` form is::
| – – – |
| – – – |
| perspective-x perspective-y perspective-scale |
where perspective-x or perspective-y is non-zero, or perspective-scale
is not one. All other elements may have any value.
:return: true if :py:class:`Matrix` is in most general form
)docstring")
.def("isSimilarity", &SkMatrix::isSimilarity,
R"docstring(
Returns true if :py:class:`Matrix` contains only translation, rotation,
reflection, and uniform scale.
Returns false if :py:class:`Matrix` contains different scales, skewing,
perspective, or degenerate forms that collapse to a line or point.
Describes that the :py:class:`Matrix` makes rendering with and without
the matrix are visually alike; a transformed circle remains a circle.
Mathematically, this is referred to as similarity of a Euclidean space,
or a similarity transformation.
Preserves right angles, keeping the arms of the angle equal lengths.
:param float tol: to be deprecated
:return: true if :py:class:`Matrix` only rotates, uniformly scales,
translates
)docstring",
py::arg("tol") = SK_ScalarNearlyZero)
.def("preservesRightAngles", &SkMatrix::preservesRightAngles,
R"docstring(
Returns true if :py:class:`Matrix` contains only translation, rotation,
reflection, and scale.
Scale may differ along rotated axes. Returns false if :py:class:`Matrix`
skewing, perspective, or degenerate forms that collapse to a line or
point.
Preserves right angles, but not requiring that the arms of the angle
retain equal lengths.
:param float tol: to be deprecated
:return: true if :py:class:`Matrix` only rotates, scales, translates
)docstring",
py::arg("tol") = SK_ScalarNearlyZero)
.def("__getitem__", &GetItem,
R"docstring(
Returns one matrix value.
Asserts if index is out of range and SK_DEBUG is defined.
:param int index: one of: kMScaleX, kMSkewX, kMTransX, kMSkewY,
kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
:return: value corresponding to index
)docstring",
py::arg("index"), py::is_operator())
.def("get", &GetItem,
R"docstring(
Returns one matrix value.
Asserts if index is out of range and SK_DEBUG is defined.
:param int index: one of: kMScaleX, kMSkewX, kMTransX, kMSkewY,
kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
:return: value corresponding to index
)docstring",
py::arg("index"))
.def("rc", &SkMatrix::rc,
R"docstring(
Returns one matrix value from a particular row/column. Asserts if index
is out of range and SK_DEBUG is defined.
:param r: matrix row to fetch
:param c: matrix column to fetch
:return: value at the given matrix position
)docstring",
py::arg("r"), py::arg("c"))
.def("getScaleX", &SkMatrix::getScaleX,
R"docstring(
Returns scale factor multiplied by x-axis input, contributing to x-axis
output.
With :py:meth:`mapPoints`, scales :py:class:`Point` along the x-axis.
:return: horizontal scale factor
)docstring")
.def("getScaleY", &SkMatrix::getScaleY,
R"docstring(
Returns scale factor multiplied by y-axis input, contributing to y-axis
output.
With :py:meth:`mapPoints`, scales :py:class:`Point` along the y-axis.
:return: vertical scale factor
)docstring")
.def("getSkewY", &SkMatrix::getSkewY,
R"docstring(
Returns scale factor multiplied by x-axis input, contributing to y-axis
output.
With :py:meth:`mapPoints`, skews :py:class:`Point` along the y-axis.
Skewing both axes can rotate :py:class:`Point`.
:return: vertical skew factor
)docstring")
.def("getSkewX", &SkMatrix::getSkewX,
R"docstring(
Returns scale factor multiplied by y-axis input, contributing to x-axis
output.
With :py:meth:`mapPoints`, skews :py:class:`Point` along the x-axis.
Skewing both axes can rotate :py:class:`Point`.
:return: horizontal scale factor
)docstring")
.def("getTranslateX", &SkMatrix::getTranslateX,
R"docstring(
Returns translation contributing to x-axis output.
With :py:meth:`mapPoints`, moves :py:class:`Point` along the x-axis.
:return: horizontal translation factor
)docstring")
.def("getTranslateY", &SkMatrix::getTranslateY,
R"docstring(
Returns translation contributing to y-axis output.
With :py:meth:`mapPoints`, moves :py:class:`Point` along the y-axis.
:return: vertical translation factor
)docstring")
.def("getPerspX", &SkMatrix::getPerspX,
R"docstring(
Returns factor scaling input x-axis relative to input y-axis.
:return: input x-axis perspective factor
)docstring")
.def("getPerspY", &SkMatrix::getPerspY,
R"docstring(
Returns factor scaling input y-axis relative to input x-axis.
:return: input y-axis perspective factor
)docstring")
.def("__setitem__", &SetItem,
R"docstring(
Returns writable :py:class:`Matrix` value.
Asserts if index is out of range and SK_DEBUG is defined. Clears
internal cache anticipating that caller will change :py:class:`Matrix`
value.
Next call to read :py:class:`Matrix` state may recompute cache;
subsequent writes to :py:class:`Matrix` value must be followed by
:py:meth:`dirtyMatrixTypeCache`.
:param int index: one of: kMScaleX, kMSkewX, kMTransX, kMSkewY,
kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
:param value: value to set
)docstring",
py::arg("index"), py::arg("value"), py::is_operator())
.def("set", &SetItem,
R"docstring(
Returns writable :py:class:`Matrix` value.
Asserts if index is out of range and SK_DEBUG is defined. Clears
internal cache anticipating that caller will change :py:class:`Matrix`
value.
Next call to read :py:class:`Matrix` state may recompute cache;
subsequent writes to :py:class:`Matrix` value must be followed by
:py:meth:`dirtyMatrixTypeCache`.
:param int index: one of: kMScaleX, kMSkewX, kMTransX, kMSkewY,
kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
:param value: value to set
)docstring",
py::arg("index"), py::arg("value"))
.def("setScaleX", &SkMatrix::setScaleX,
R"docstring(
Sets horizontal scale factor.
:param float v: horizontal scale factor to store
)docstring",
py::arg("v"))
.def("setScaleY", &SkMatrix::setScaleY,
R"docstring(
Sets vertical scale factor.
:param float v: vertical scale factor to store
)docstring",
py::arg("v"))
.def("setSkewY", &SkMatrix::setSkewY,
R"docstring(
Sets vertical skew factor.
:param v: vertical skew factor to store
)docstring",
py::arg("v"))
.def("setSkewX", &SkMatrix::setSkewX,
R"docstring(
Sets horizontal skew factor.
:param float v: horizontal skew factor to store
)docstring",
py::arg("v"))
.def("setTranslateX", &SkMatrix::setTranslateX,
R"docstring(
Sets horizontal translation.
:param float v: horizontal translation to store
)docstring",
py::arg("v"))
.def("setTranslateY", &SkMatrix::setTranslateY,
R"docstring(
Sets vertical translation.
:param float v: vertical translation to store
)docstring",
py::arg("v"))
.def("setPerspX", &SkMatrix::setPerspX,
R"docstring(
Sets input x-axis perspective factor, which causes mapXY() to vary input
x-axis values inversely proportional to input y-axis values.
:param float v: perspective factor
)docstring",
py::arg("v"))
.def("setPerspY", &SkMatrix::setPerspY,
R"docstring(
Sets input y-axis perspective factor, which causes mapXY() to vary input
y-axis values inversely proportional to input x-axis values.
:param float v: perspective factor
)docstring",
py::arg("v"))
.def("setAll", &SkMatrix::setAll,
R"docstring(
Sets all values from parameters.
Sets matrix to::
| scaleX skewX transX |
| skewY scaleY transY |
| persp0 persp1 persp2 |
:param float scaleX: horizontal scale factor to store
:param float skewX: horizontal skew factor to store
:param float transX: horizontal translation to store
:param float skewY: vertical skew factor to store
:param float scaleY: vertical scale factor to store
:param float transY: vertical translation to store
:param float persp0: input x-axis values perspective factor to store
:param float persp1: input y-axis values perspective factor to store
:param float persp2: perspective scale factor to store
)docstring",
py::arg("scaleX"), py::arg("skewX"), py::arg("transX"),
py::arg("skewY"), py::arg("scaleY"), py::arg("transY"),
py::arg("persp0"), py::arg("persp1"), py::arg("persp2"))
.def("get9",
[] (const SkMatrix& matrix) {
std::vector<SkScalar> buffer(9);
matrix.get9(&buffer[0]);
return buffer;
},
R"docstring(
Returns nine scalar values contained by :py:class:`Matrix` into list,
in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY,
kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.
)docstring")
.def("set9",
[] (SkMatrix& matrix, const std::vector<SkScalar> values) {
if (values.size() != 9)
throw std::runtime_error("values must have 9 elements");
return matrix.set9(&values[0]);
},
R"docstring(
Sets :py:class:`Matrix` to nine scalar values in values, in member value
ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY,
kMTransY, kMPersp0, kMPersp1, kMPersp2.
Sets matrix to::
| values[0] values[1] values[2] |
| values[3] values[4] values[5] |
| values[6] values[7] values[8] |
In the future, set9 followed by get9 may not return the same values.
Since :py:class:`Matrix` maps non-homogeneous coordinates, scaling all
nine values produces an equivalent transformation, possibly improving
precision.
:param values: nine scalar values
)docstring",
py::arg("buffer"))
.def("reset", &SkMatrix::reset,
R"docstring(
Sets :py:class:`Matrix` to identity; which has no effect on mapped
:py:class:`Point`.
Sets :py:class:`Matrix` to::
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
Also called :py:meth:`setIdentity`; use the one that provides better
inline documentation.
)docstring")
.def("setIdentity", &SkMatrix::setIdentity,
R"docstring(
Sets :py:class:`Matrix` to identity; which has no effect on mapped
:py:class:`Point`.
Sets :py:class:`Matrix` to::
| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
Also called :py:meth:`reset`; use the one that provides better inline
documentation.
)docstring")
.def("setTranslate",
py::overload_cast<SkScalar, SkScalar>(&SkMatrix::setTranslate),
R"docstring(
Sets :py:class:`Matrix` to translate by (dx, dy).
:dx: horizontal translation
:dy: vertical translation
)docstring",
py::arg("dx"), py::arg("dy"))
.def("setTranslate",
py::overload_cast<const SkVector&>(&SkMatrix::setTranslate),
R"docstring(
Sets :py:class:`Matrix` to translate by (v.fX, v.fY).
:v: vector containing horizontal and vertical
translation
)docstring",
py::arg("v"))
.def("setScale",
py::overload_cast<SkScalar, SkScalar, SkScalar, SkScalar>(
&SkMatrix::setScale),
R"docstring(
Sets :py:class:`Matrix` to scale by sx and sy, about a pivot point at
(px, py).
The pivot point is unchanged when mapped with :py:class:`Matrix`.
:sx: horizontal scale factor
:sy: vertical scale factor
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("sx"), py::arg("sy"), py::arg("px"), py::arg("py"))
.def("setScale",
py::overload_cast<SkScalar, SkScalar>(&SkMatrix::setScale),
R"docstring(
Sets :py:class:`Matrix` to scale by sx and sy about at pivot point at
(0, 0).
:sx: horizontal scale factor
:sy: vertical scale factor
)docstring",
py::arg("sx"), py::arg("sy"))
.def("setRotate",
py::overload_cast<SkScalar, SkScalar, SkScalar>(&SkMatrix::setRotate),
R"docstring(
Sets :py:class:`Matrix` to rotate by degrees about a pivot point at (px,
py).
The pivot point is unchanged when mapped with :py:class:`Matrix`.
Positive degrees rotates clockwise.
:degrees: angle of axes relative to upright axes
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("degrees"), py::arg("px"), py::arg("py"))
.def("setRotate", py::overload_cast<SkScalar>(&SkMatrix::setRotate),
R"docstring(
Sets :py:class:`Matrix` to rotate by degrees about a pivot point at (0,
0).
Positive degrees rotates clockwise.
:degrees: angle of axes relative to upright axes
)docstring",
py::arg("degrees"))
.def("setSinCos",
py::overload_cast<SkScalar, SkScalar, SkScalar, SkScalar>(
&SkMatrix::setSinCos),
R"docstring(
Sets :py:class:`Matrix` to rotate by sinValue and cosValue, about a
pivot point at (px, py).
The pivot point is unchanged when mapped with :py:class:`Matrix`.
Vector (sinValue, cosValue) describes the angle of rotation relative to
(0, 1). Vector length specifies scale.
:sinValue: rotation vector x-axis component
:cosValue: rotation vector y-axis component
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("sinValue"), py::arg("cosValue"), py::arg("px"), py::arg("py"))
.def("setSinCos",
py::overload_cast<SkScalar, SkScalar>(&SkMatrix::setSinCos),
R"docstring(
Sets :py:class:`Matrix` to rotate by sinValue and cosValue, about a
pivot point at (0, 0).
Vector (sinValue, cosValue) describes the angle of rotation relative to
(0, 1). Vector length specifies scale.
:sinValue: rotation vector x-axis component
:cosValue: rotation vector y-axis component
)docstring",
py::arg("sinValue"), py::arg("cosValue"))
.def("setRSXform", &SkMatrix::setRSXform,
R"docstring(
Sets :py:class:`Matrix` to rotate, scale, and translate using a
compressed matrix form.
Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation
relative to (0, 1). Vector length specifies scale. Mapped point is
rotated and scaled by vector, then translated by (rsxForm.fTx,
rsxForm.fTy).
:param skia.RSXform rsxForm: compressed :py:class:`RSXform` matrix
:return: reference to :py:class:`Matrix`
)docstring",
py::arg("rsxForm"))
.def("setSkew",
py::overload_cast<SkScalar, SkScalar, SkScalar, SkScalar>(
&SkMatrix::setSkew),
R"docstring(
Sets :py:class:`Matrix` to skew by kx and ky, about a pivot point at
(px, py).
The pivot point is unchanged when mapped with :py:class:`Matrix`.
:kx: horizontal skew factor
:ky: vertical skew factor
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("kx"), py::arg("ky"), py::arg("px"), py::arg("py"))
.def("setSkew", py::overload_cast<SkScalar, SkScalar>(&SkMatrix::setSkew),
R"docstring(
Sets :py:class:`Matrix` to skew by kx and ky, about a pivot point at
(0, 0).
:kx: horizontal skew factor
:ky: vertical skew factor
)docstring",
py::arg("kx"), py::arg("ky"))
.def("setConcat", &SkMatrix::setConcat,
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` a multiplied by
:py:class:`Matrix` b.
Either a or b may be this.
Given::
| A B C | | J K L |
a = | D E F |, b = | M N O |
| G H I | | P Q R |
sets :py:class:`Matrix` to::
| A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
| G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
:param skia.Matrix a: :py:class:`Matrix` on left side of multiply
expression
:param skia.Matrix b: :py:class:`Matrix` on right side of multiply
expression
)docstring",
py::arg("a"), py::arg("b"))
.def("preTranslate", &SkMatrix::preTranslate,
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from translation (dx, dy).
This can be thought of as moving the point to be mapped before applying
:py:class:`Matrix`.
Given::
| A B C | | 1 0 dx |
Matrix = | D E F |, T(dx, dy) = | 0 1 dy |
| G H I | | 0 0 1 |
sets :py:class:`Matrix` to::
| A B C | | 1 0 dx | | A B A*dx+B*dy+C |
Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F |
| G H I | | 0 0 1 | | G H G*dx+H*dy+I |
:param dx: x-axis translation before applying :py:class:`Matrix`
:param dy: y-axis translation before applying :py:class:`Matrix`
)docstring",
py::arg("dx"), py::arg("dy"))
.def("preScale",
py::overload_cast<SkScalar, SkScalar, SkScalar, SkScalar>(
&SkMatrix::preScale),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from scaling by (sx, sy) about pivot
point (px, py).
This can be thought of as scaling about a pivot point before applying
:py:class:`Matrix`.
Given::
| A B C | | sx 0 dx |
Matrix = | D E F |, S(sx, sy, px, py) = | 0 sy dy |
| G H I | | 0 0 1 |
where::
dx = px - sx * px
dy = py - sy * py
sets :py:class:`Matrix` to::
| A B C | | sx 0 dx | | A*sx B*sy A*dx+B*dy+C |
Matrix * S(sx, sy, px, py) = | D E F | | 0 sy dy | = | D*sx E*sy D*dx+E*dy+F |
| G H I | | 0 0 1 | | G*sx H*sy G*dx+H*dy+I |
:sx: horizontal scale factor
:sy: vertical scale factor
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("sx"), py::arg("sy"), py::arg("px"), py::arg("py"))
.def("preScale",
py::overload_cast<SkScalar, SkScalar>(&SkMatrix::preScale),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from scaling by (sx, sy) about pivot
point (0, 0).
This can be thought of as scaling about the origin before applying
:py:class:`Matrix`.
Given::
| A B C | | sx 0 0 |
Matrix = | D E F |, S(sx, sy) = | 0 sy 0 |
| G H I | | 0 0 1 |
sets :py:class:`Matrix` to::
| A B C | | sx 0 0 | | A*sx B*sy C |
Matrix * S(sx, sy) = | D E F | | 0 sy 0 | = | D*sx E*sy F |
| G H I | | 0 0 1 | | G*sx H*sy I |
:sx: horizontal scale factor
:sy: vertical scale factor
)docstring",
py::arg("sx"), py::arg("sy"))
.def("preRotate",
py::overload_cast<SkScalar, SkScalar, SkScalar>(&SkMatrix::preRotate),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from rotating by degrees about pivot
point (px, py).
This can be thought of as rotating about a pivot point before applying
:py:class:`Matrix`.
Positive degrees rotates clockwise.
Given::
| A B C | | c -s dx |
Matrix = | D E F |, R(degrees, px, py) = | s c dy |
| G H I | | 0 0 1 |
where::
c = cos(degrees)
s = sin(degrees)
dx = s * py + (1 - c) * px
dy = -s * px + (1 - c) * py
sets :py:class:`Matrix` to::
| A B C | | c -s dx | | Ac+Bs -As+Bc A*dx+B*dy+C |
Matrix * R(degrees, px, py) = | D E F | | s c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F |
| G H I | | 0 0 1 | | Gc+Hs -Gs+Hc G*dx+H*dy+I |
:degrees: angle of axes relative to upright axes
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("degrees"), py::arg("px"), py::arg("py"))
.def("preRotate",
py::overload_cast<SkScalar>(&SkMatrix::preRotate),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from rotating by degrees about pivot
point (0, 0).
This can be thought of as rotating about the origin before applying
:py:class:`Matrix`.
Positive degrees rotates clockwise.
Given::
| A B C | | c -s 0 |
Matrix = | D E F |, R(degrees, px, py) = | s c 0 |
| G H I | | 0 0 1 |
where::
c = cos(degrees)
s = sin(degrees)
sets :py:class:`Matrix` to::
| A B C | | c -s 0 | | Ac+Bs -As+Bc C |
Matrix * R(degrees, px, py) = | D E F | | s c 0 | = | Dc+Es -Ds+Ec F |
| G H I | | 0 0 1 | | Gc+Hs -Gs+Hc I |
:degrees: angle of axes relative to upright axes
)docstring",
py::arg("degrees"))
.def("preSkew",
py::overload_cast<SkScalar, SkScalar, SkScalar, SkScalar>(
&SkMatrix::preSkew),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from skewing by (kx, ky) about pivot
point (px, py).
This can be thought of as skewing about a pivot point before applying
:py:class:`Matrix`.
Given::
| A B C | | 1 kx dx |
Matrix = | D E F |, K(kx, ky, px, py) = | ky 1 dy |
| G H I | | 0 0 1 |
where::
dx = -kx * py
dy = -ky * px
sets :py:class:`Matrix` to::
| A B C | | 1 kx dx | | A+B*ky A*kx+B A*dx+B*dy+C |
Matrix * K(kx, ky, px, py) = | D E F | | ky 1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F |
| G H I | | 0 0 1 | | G+H*ky G*kx+H G*dx+H*dy+I |
:kx: horizontal skew factor
:ky: vertical skew factor
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("kx"), py::arg("ky"), py::arg("px"), py::arg("py"))
.def("preSkew",
py::overload_cast<SkScalar, SkScalar>(&SkMatrix::preSkew),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` constructed from skewing by (kx, ky) about pivot
point (0, 0).
This can be thought of as skewing about the origin before applying
:py:class:`Matrix`.
Given::
| A B C | | 1 kx 0 |
Matrix = | D E F |, K(kx, ky) = | ky 1 0 |
| G H I | | 0 0 1 |
sets :py:class:`Matrix` to::
| A B C | | 1 kx 0 | | A+B*ky A*kx+B C |
Matrix * K(kx, ky) = | D E F | | ky 1 0 | = | D+E*ky D*kx+E F |
| G H I | | 0 0 1 | | G+H*ky G*kx+H I |
:kx: horizontal skew factor
:ky: vertical skew factor
)docstring",
py::arg("kx"), py::arg("ky"))
.def("preConcat", &SkMatrix::preConcat,
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` multiplied by
:py:class:`Matrix` other.
This can be thought of mapping by other before applying
:py:class:`Matrix`.
Given::
| A B C | | J K L |
Matrix = | D E F |, other = | M N O |
| G H I | | P Q R |
sets :py:class:`Matrix` to::
| A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
| G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
:param skia.Matrix other: :py:class:`Matrix` on right side of multiply
expression
)docstring",
py::arg("other"))
.def("postTranslate", &SkMatrix::postTranslate,
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` constructed from
translation (dx, dy) multiplied by :py:class:`Matrix`.
This can be thought of as moving the point to be mapped after applying
:py:class:`Matrix`.
Given::
| J K L | | 1 0 dx |
Matrix = | M N O |, T(dx, dy) = | 0 1 dy |
| P Q R | | 0 0 1 |
sets :py:class:`Matrix` to::
| 1 0 dx | | J K L | | J+dx*P K+dx*Q L+dx*R |
T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R |
| 0 0 1 | | P Q R | | P Q R |
:param float dx: x-axis translation after applying :py:class:`Matrix`
:param float dy: y-axis translation after applying :py:class:`Matrix`
)docstring",
py::arg("dx"), py::arg("dy"))
.def("postScale",
py::overload_cast<SkScalar, SkScalar, SkScalar, SkScalar>(
&SkMatrix::postScale),
R"docstring(
Sets :py:class:`Matrix` to :py:class:`Matrix` constructed from scaling
by (sx, sy) about pivot point (px, py), multiplied by
:py:class:`Matrix`.
This can be thought of as scaling about a pivot point after applying :py:class:`Matrix`.
Given::
| J K L | | sx 0 dx |
Matrix = | M N O |, S(sx, sy, px, py) = | 0 sy dy |
| P Q R | | 0 0 1 |
where::
dx = px - sx * px
dy = py - sy * py
sets :py:class:`Matrix` to::
| sx 0 dx | | J K L | | sx*J+dx*P sx*K+dx*Q sx*L+dx+R |
S(sx, sy, px, py) * Matrix = | 0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R |
| 0 0 1 | | P Q R | | P Q R |
:sx: horizontal scale factor
:sy: vertical scale factor
:px: pivot on x-axis
:py: pivot on y-axis
)docstring",
py::arg("sx"), py::arg("sy"), py::arg("px"), py::arg("py"))
.def("postScale",
py::overload_cast<SkScalar, SkScalar>(&SkMatrix::postScale),