aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/SkPoint_Reference.bmh
blob: 598f963ca98109cd17b6fbedf24503709b46697e (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
#Topic Point
#Alias Points ##
#Alias Point_Reference ##

#Struct SkPoint

SkPoint holds two 32-bit floating point coordinates.

#Subtopic Overview
#Populate
##

#Subtopic Related_Function
#Populate
##

#Subtopic Member_Function
#Populate
##

#Subtopic Member
#Populate

#Member SkScalar  fX
#Line # x-axis value ##
x-axis value used by both Point and Vector. May contain any value, including
infinities and NaN.
##

#Member SkScalar  fY
#Line # y-axis value ##
y-axis value used by both Point and Vector. May contain any value, including
infinities and NaN.
##

#Subtopic Member ##

# ------------------------------------------------------------------------------

#Subtopic Constructor
#Populate
##

#Method static constexpr SkPoint Make(SkScalar x, SkScalar y)
#In Constructor
#Line # constructs from SkScalar inputs ##
Sets fX to x, fY to y. Used both to set Point and Vector.

#Param x  SkScalar x-axis value of constructed Point or Vector ##
#Param y  SkScalar y-axis value of constructed Point or Vector ##

#Return Point (x, y) ##

#Example
SkPoint pt1 = {45, 66};
SkPoint pt2 = SkPoint::Make(45, 66);
SkVector v1 = {45, 66};
SkVector v2 = SkPoint::Make(45, 66);
SkDebugf("all %s" "equal\n", pt1 == pt2 && pt2 == v1 && v1 == v2 ? "" : "not ");
#StdOut
all equal
##
##

#SeeAlso set() iset() SkIPoint::Make

#Method ##

# ------------------------------------------------------------------------------

#Subtopic Property
#Line # member values ##
#Populate
##

#Method SkScalar x() const
#In Property
#Line # returns fX ##
Returns x-axis value of Point or Vector.

#Return fX ##

#Example
SkPoint pt1 = {45, 66};
SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
#StdOut
pt1.fX == pt1.x()
##
##

#SeeAlso y() SkIPoint::x()

#Method ##

# ------------------------------------------------------------------------------

#Method SkScalar y() const
#In Property
#Line # returns fY ##
Returns y-axis value of Point or Vector.

#Return fY ##

#Example
SkPoint pt1 = {45, 66};
SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
#StdOut
pt1.fY == pt1.y()
##
##

#SeeAlso x() SkIPoint::y()

#Method ##

# ------------------------------------------------------------------------------

#Method bool isZero() const
#In Property
#Line # returns true if both members equal zero ##
Returns true if fX and fY are both zero.

#Return true if fX is zero and fY is zero ##

#Example
SkPoint pt = { 0.f, -0.f};
SkDebugf("pt.fX=%c%g pt.fY=%c%g\n", std::signbit(pt.fX) ? '-' : '+', fabsf(pt.fX),
                                    std::signbit(pt.fY) ? '-' : '+', fabsf(pt.fY));
SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
#StdOut
pt.fX=+0 pt.fY=-0
pt.isZero() == true
##
##

#SeeAlso isFinite SkIPoint::isZero

#Method ##

# ------------------------------------------------------------------------------

#Subtopic Set
#Populate
#Line # replaces all values ##
##

#Method void set(SkScalar x, SkScalar y)
#In Set
#Line # sets to SkScalar input ##
Sets fX to x and fY to y.

#Param x  new value for fX ##
#Param y  new value for fY ##

#Example
SkPoint pt1, pt2 = { SK_ScalarPI, SK_ScalarSqrt2 };
pt1.set(SK_ScalarPI, SK_ScalarSqrt2);
SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
#StdOut
pt1 == pt2
##
##

#SeeAlso iset() Make

#Method ##

# ------------------------------------------------------------------------------

#Method void iset(int32_t x, int32_t y)
#In Set
#Line # sets to integer input ##
Sets fX to x and fY to y, promoting integers to SkScalar values.

Assigning a large integer value directly to fX or fY may cause a compiler
error, triggered by narrowing conversion of int to SkScalar. This safely
casts x and y to avoid the error.

#Param x  new value for fX ##
#Param y  new value for fY ##

#Example
SkPoint pt1, pt2 = { SK_MinS16, SK_MaxS16 };
pt1.iset(SK_MinS16, SK_MaxS16);
SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
##

#SeeAlso set Make SkIPoint::set

#Method ##

# ------------------------------------------------------------------------------

#Method void iset(const SkIPoint& p)

Sets fX to p.fX and fY to p.fY, promoting integers to SkScalar values.

Assigning an IPoint containing a large integer value directly to fX or fY may
cause a compiler error, triggered by narrowing conversion of int to SkScalar.
This safely casts p.fX and p.fY to avoid the error.

#Param p  IPoint members promoted to SkScalar ##

#Example
SkIPoint iPt = { SK_MinS32, SK_MaxS32 };
SkPoint fPt;
fPt.iset(iPt);
SkDebugf("iPt: %d, %d\n", iPt.fX, iPt.fY);
SkDebugf("fPt: %g, %g\n", fPt.fX, fPt.fY);
#StdOut
iPt: -2147483647, 2147483647
fPt: -2.14748e+09, 2.14748e+09
##
##

#SeeAlso set Make SkIPoint::set

#Method ##

# ------------------------------------------------------------------------------

#Method void setAbs(const SkPoint& pt)
#In Set
#Line # sets sign of both members to positive ##
Sets fX to absolute value of pt.fX; and fY to absolute value of pt.fY.

#Param pt  members providing magnitude for fX and fY ##

#Example
SkPoint test[] = { {0.f, -0.f}, {-1, -2},
                   { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
                   { SK_ScalarNaN, -SK_ScalarNaN } };
for (const SkPoint& pt : test) {
    SkPoint absPt;
    absPt.setAbs(pt);
    SkDebugf("pt: %g, %g  abs: %g, %g\n", pt.fX, pt.fY, absPt.fX, absPt.fY);
}
#StdOut
pt: 0, -0  abs: 0, 0
pt: -1, -2  abs: 1, 2
pt: inf, -inf  abs: inf, inf
pt: nan, -nan  abs: nan, nan
##
##

#SeeAlso set Make negate

#Method ##

# ------------------------------------------------------------------------------

#Subtopic Offset
#Line # moves sides ##
#Populate
##

#Method static void Offset(SkPoint points[], int count, const SkVector& offset)
#In Offset
#Line # translates Point array ##
Adds offset to each Point in points array with count entries.

#Param points  Point array ##
#Param count  entries in array ##
#Param offset  Vector added to points ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    SkPoint::Offset(points, SK_ARRAY_COUNT(points), { 1, 9 } );
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso offset operator+=(const SkVector& v)

#Method ##

# ------------------------------------------------------------------------------

#Method static void Offset(SkPoint points[], int count, SkScalar dx, SkScalar dy)

Adds offset (dx, dy) to each Point in points array of length count.

#Param points  Point array ##
#Param count  entries in array ##
#Param dx  added to fX in points ##
#Param dy  added to fY in points ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    SkPoint::Offset(points, SK_ARRAY_COUNT(points), 1, 9);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso offset operator+=(const SkVector& v)

#Method ##

# ------------------------------------------------------------------------------

#Method void offset(SkScalar dx, SkScalar dy)
#In Offset
#Line # translates Point ##
Adds offset (dx, dy) to Point.

#Param dx  added to fX ##
#Param dy  added to fY ##

#Example
#Height 128
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    points[1].offset(1, 1);
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso Offset operator+=(const SkVector& v)

#Method ##

# ------------------------------------------------------------------------------

#Method SkScalar length() const
#In Property
#Line # returns straight-line distance to origin ##
Returns the Euclidean_Distance from origin, computed as:
#Code
#Literal
sqrt(fX * fX + fY * fY)
##
.

#Return straight-line distance to origin ##

#Example
#Height 192
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint points[] = { { 90, 30 }, { 120, 150 }, { 150, 30 }, { 210, 90 } };
    const SkPoint origin = {30, 140};
    for (auto point : points) {
        canvas->drawLine(origin, point, paint);
        SkAutoCanvasRestore acr(canvas, true);
        SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX);
        canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY);
        SkString length("length = ");
        length.appendScalar(point.length());
        canvas->drawString(length, origin.fX + 25, origin.fY - 4, paint);
    }
##

#SeeAlso distanceToOrigin Length setLength Distance

#Method ##

# ------------------------------------------------------------------------------

#Method SkScalar distanceToOrigin() const
#In Property
#Line # returns straight-line distance to origin ##
Returns the Euclidean_Distance from origin, computed as:
#Code
#Literal
sqrt(fX * fX + fY * fY)
##
.

#Return straight-line distance to origin ##

#Example
#Height 192
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } };
    const SkPoint origin = {0, 0};
    canvas->translate(30, 140);
    for (auto point : points) {
        canvas->drawLine(origin, point, paint);
        SkAutoCanvasRestore acr(canvas, true);
        SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX);
        canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY);
        SkString distance("distance = ");
        distance.appendScalar(point.distanceToOrigin());
        canvas->drawString(distance, origin.fX + 25, origin.fY - 4, paint);
    }
##

#SeeAlso length Length setLength Distance

#Method ##

# ------------------------------------------------------------------------------

#Method bool normalize()
#In Set
#Line # sets length to one, preserving direction ##
Scales (fX, fY) so that length() returns one, while preserving ratio of fX to fY,
if possible. If prior length is nearly zero, sets Vector to (0, 0) and returns
false; otherwise returns true.

#Return true if former length is not zero or nearly zero ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint lines[][2] = { {{  30, 110 }, { 190,  30 }},
                                 {{ 120, 140 }, {  30, 220 }}};
    for (auto line : lines) {
        canvas->drawLine(line[0], line[1], paint);
        SkVector vector = line[1] - line[0];
        if (vector.normalize()) {
            SkVector rotate90 = { -vector.fY, vector.fX };
            rotate90 *= 10.f;
            canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint);
            canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint);
        }
    }
##

#SeeAlso Normalize setLength length Length

#Method ##

# ------------------------------------------------------------------------------

#Method bool setNormalize(SkScalar x, SkScalar y)
#In Set
#Line # sets length to one, in direction of (x, y) ##
Sets Vector to (x, y) scaled so length() returns one, and so that
(fX, fY) is proportional to (x, y).  If (x, y) length is nearly zero,
sets Vector to (0, 0) and returns false; otherwise returns true.

#Param x  proportional value for fX ##
#Param y  proportional value for fY ##

#Return true if (x, y) length is not zero or nearly zero ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } };
    const SkPoint origin = {0, 0};
    canvas->translate(30, 140);
    for (auto point : points) {
        paint.setStrokeWidth(1);
        paint.setColor(SK_ColorBLACK);
        canvas->drawLine(origin, point, paint);
        SkVector normal;
        normal.setNormalize(point.fX, point.fY);
        normal *= 100;
        paint.setStrokeWidth(10);
        paint.setColor(0x3f4512bf);
        canvas->drawLine(origin, normal, paint);
    }
##

#SeeAlso normalize setLength

#Method ##

# ------------------------------------------------------------------------------

#Method bool setLength(SkScalar length)
#In Set
#Line # sets straight-line distance to origin ##
Scales Vector so that distanceToOrigin returns length, if possible. If former
length is nearly zero, sets Vector to (0, 0) and return false; otherwise returns
true.

#Param length  straight-line distance to origin ##

#Return true if former length is not zero or nearly zero  ##

#Example
#Height 160
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } };
    const SkPoint origin = {0, 0};
    canvas->translate(30, 140);
    for (auto point : points) {
        paint.setStrokeWidth(1);
        paint.setColor(SK_ColorBLACK);
        canvas->drawLine(origin, point, paint);
        SkVector normal = point;
        normal.setLength(100);
        paint.setStrokeWidth(10);
        paint.setColor(0x3f45bf12);
        canvas->drawLine(origin, normal, paint);
    }
##

#SeeAlso length Length setNormalize setAbs

#Method ##

# ------------------------------------------------------------------------------

#Method bool setLength(SkScalar x, SkScalar y, SkScalar length)

Sets Vector to (x, y) scaled to length, if possible. If former
length is nearly zero, sets Vector to (0, 0) and return false; otherwise returns
true.

#Param x  proportional value for fX ##
#Param y  proportional value for fY ##
#Param length  straight-line distance to origin ##

#Return true if (x, y) length is not zero or nearly zero ##

#Example
#Height 160
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } };
    const SkPoint origin = {0, 0};
    canvas->translate(30, 140);
    for (auto point : points) {
        paint.setStrokeWidth(1);
        paint.setColor(SK_ColorBLACK);
        canvas->drawLine(origin, point, paint);
        SkVector normal;
        normal.setLength(point.fX, point.fY, 100);
        paint.setStrokeWidth(10);
        paint.setColor(0x3fbf4512);
        canvas->drawLine(origin, normal, paint);
    }
##

#SeeAlso length Length setNormalize setAbs

#Method ##

# ------------------------------------------------------------------------------

#Subtopic Operator
#Populate
##

#Method void scale(SkScalar scale, SkPoint* dst) const
#In Offset
#In Operator
#Line # multiplies Point by scale factor ##
Sets dst to Point times scale. dst may be Point to modify Point in place.

#Param scale  factor to multiply Point by ##
#Param dst  storage for scaled Point ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint point = {40, -15}, scaled;
    SkPoint origin = {30, 110};
    for (auto scale : {1, 2, 3, 5}) {
        paint.setStrokeWidth(scale * 5);
        paint.setARGB(0x7f, 0x9f, 0xbf, 0x33 * scale);
        point.scale(scale, &scaled);
        canvas->drawLine(origin, origin + scaled, paint);
    }
##

#SeeAlso operator*(SkScalar scale)_const operator*=(SkScalar scale) setLength

#Method ##

# ------------------------------------------------------------------------------

#Method void scale(SkScalar value)

Scales Point in place by scale.

#Param value  factor to multiply Point by ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint point = {40, -15};
    SkPoint origin = {30, 110};
    for (auto scale : {1, 2, 3, 5}) {
        paint.setStrokeWidth(scale * 5);
        paint.setARGB(0x7f, 0x9f, 0xbf, 0x33 * scale);
        point.scale(scale);
        canvas->drawLine(origin, origin + point, paint);
    }
##

#SeeAlso operator*(SkScalar scale)_const operator*=(SkScalar scale) setLength

#Method ##

# ------------------------------------------------------------------------------

#Method void negate()
#In Operator
#Line # reverses the sign of both members ##
Changes the sign of fX and fY.

#Example
SkPoint test[] = { {0.f, -0.f}, {-1, -2},
                   { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
                   { SK_ScalarNaN, -SK_ScalarNaN } };
for (const SkPoint& pt : test) {
    SkPoint negPt = pt;
    negPt.negate();
    SkDebugf("pt: %g, %g  negate: %g, %g\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
}
#StdOut
pt: 0, -0  negate: -0, 0
pt: -1, -2  negate: 1, 2
pt: inf, -inf  negate: -inf, inf
pt: nan, -nan  negate: -nan, nan
##
##

#SeeAlso operator-()_const setAbs

#Method ##

# ------------------------------------------------------------------------------

#Method SkPoint operator-()_const

#Line # reverses sign of Point ##
Returns Point changing the signs of fX and fY.

#Return Point as (-fX, -fY) ##

#Example
SkPoint test[] = { {0.f, -0.f}, {-1, -2},
                   { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
                   { SK_ScalarNaN, -SK_ScalarNaN } };
for (const SkPoint& pt : test) {
    SkPoint negPt = -pt;
    SkDebugf("pt: %g, %g  negate: %g, %g\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
}
#StdOut
pt: 0, -0  negate: -0, 0
pt: -1, -2  negate: 1, 2
pt: inf, -inf  negate: -inf, inf
pt: nan, -nan  negate: -nan, nan
##
##

#SeeAlso negate operator-(const SkPoint& a, const SkPoint& b) operator-=(const SkVector& v) SkIPoint::operator-()_const

#Method ##

# ------------------------------------------------------------------------------

#Method void operator+=(const SkVector& v)

#Line # adds Vector to Point ##
Adds Vector v to Point. Sets Point to:
#Formula
(fX + v.fX, fY + v.fY)
##
.

#Param v  Vector to add ##

#Example
#Height 128
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    points[1] += {1, 1};
    points[2] += {-1, -1};
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso offset() operator+(const SkPoint& a, const SkVector& b) SkIPoint::operator+=(const SkIVector& v)

#Method ##

# ------------------------------------------------------------------------------

#Method void operator-=(const SkVector& v)

#Line # subtracts Vector from Point ##
Subtracts Vector v from Point. Sets Point to:
#Formula
(fX - v.fX, fY - v.fY)
##
.

#Param v  Vector to subtract ##

#Example
#Height 128
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    points[1] -= {1, 1};
    points[2] -= {-1, -1};
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso offset() operator-(const SkPoint& a, const SkPoint& b) SkIPoint::operator-=(const SkIVector& v)

#Method ##

# ------------------------------------------------------------------------------

#Method SkPoint operator*(SkScalar scale)_const

#Line # returns Point multiplied by scale ##
Returns Point multiplied by scale.

#Param scale  Scalar to multiply by ##

#Return Point as (fX * scale, fY * scale) ##

#Example
#Height 128
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(15, 10);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    for (auto& point : points) {
        point = point * 1.5f;
    }
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso operator*=(SkScalar scale) scale() setLength setNormalize

#Method ##

# ------------------------------------------------------------------------------

#Method SkPoint& operator*=(SkScalar scale)

#Line # multiplies Point by scale factor ##
Multiplies Point by scale. Sets Point to:
#Formula
(fX * scale, fY * scale)
##
.

#Param scale  Scalar to multiply by ##

#Return reference to Point ##

#Example
#Height 128
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(15, 10);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    for (auto& point : points) {
        point *= 2;
    }
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso operator*(SkScalar scale)_const scale() setLength setNormalize

#Method ##

# ------------------------------------------------------------------------------

#Method bool isFinite() const
#In Property
#Line # returns true if no member is infinite or NaN ##
Returns true if both fX and fY are measurable values.

#Return true for values other than infinities and NaN ##

#Example
SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} };
for (const SkPoint& pt : test) {
    SkDebugf("pt: %g, %g  finite: %s\n", pt.fX, pt.fY, pt.isFinite() ? "true" : "false");
}
#StdOut
pt: 0, -0  finite: true
pt: -1, -2  finite: true
pt: inf, 1  finite: false
pt: nan, -1  finite: false
##
##

#SeeAlso SkRect::isFinite SkPath::isFinite

#Method ##

# ------------------------------------------------------------------------------

#Method bool equals(SkScalar x, SkScalar y) const
#In Operator
#Line # returns true if Points are equal ##
Returns true if Point is equivalent to Point constructed from (x, y).

#Param x  value compared with fX ##
#Param y  value compared with fY ##

#Return true if Point equals (x, y) ##

#Example
SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} };
for (const SkPoint& pt : test) {
    SkDebugf("pt: %g, %g  %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
}
#StdOut
pt: 0, -0  == pt
pt: -1, -2  == pt
pt: inf, 1  == pt
pt: nan, -1  != pt
##
##

#SeeAlso operator==(const SkPoint& a, const SkPoint& b)

#Method ##

# ------------------------------------------------------------------------------

#Method bool operator==(const SkPoint& a, const SkPoint& b)

#Line # returns true if Point are equal ##
Returns true if a is equivalent to b.

#Param a  Point to compare ##
#Param b  Point to compare ##

#Return true if a.fX == b.fX and a.fY == b.fY ##

#Example
SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} };
for (const SkPoint& pt : test) {
    SkDebugf("pt: %g, %g  %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
}
#StdOut
pt: 0, -0  == pt
pt: -1, -2  == pt
pt: inf, 1  == pt
pt: nan, -1  != pt
##
##

#SeeAlso equals() operator!=(const SkPoint& a, const SkPoint& b)

#Method ##

# ------------------------------------------------------------------------------

#Method bool operator!=(const SkPoint& a, const SkPoint& b)

#Line # returns true if Point are unequal ##
Returns true if a is not equivalent to b.

#Param a  Point to compare ##
#Param b  Point to compare ##

#Return true if a.fX != b.fX or a.fY != b.fY ##

#Example
SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} };
for (const SkPoint& pt : test) {
    SkDebugf("pt: %g, %g  %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
}
#StdOut
pt: 0, -0  == pt
pt: -1, -2  == pt
pt: inf, 1  == pt
pt: nan, -1  != pt
##
##

#SeeAlso operator==(const SkPoint& a, const SkPoint& b) equals()

#Method ##

# ------------------------------------------------------------------------------

#Method SkVector operator-(const SkPoint& a, const SkPoint& b)

#Line # returns Vector between Points ##
Returns Vector from b to a, computed as
#Formula
(a.fX - b.fX, a.fY - b.fY)
##
.

Can also be used to subtract Vector from Point, returning Point.
Can also be used to subtract Vector from Vector, returning Vector.

#Param a  Point to subtract from ##
#Param b  Point to subtract ##

#Return Vector from b to a ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    points[1] += points[0] - points[2];
    points[2] -= points[3] - points[5];
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso operator-=(const SkVector& v) offset()

#Method ##

# ------------------------------------------------------------------------------

#Method SkPoint operator+(const SkPoint& a, const SkVector& b)

#Line # returns Point offset by Vector ##
Returns Point resulting from Point a offset by Vector b, computed as:
#Formula
(a.fX + b.fX, a.fY + b.fY)
##
.

Can also be used to offset Point b by Vector a, returning Point.
Can also be used to add Vector to Vector, returning Vector.

#Param a  Point or Vector to add to ##
#Param b  Point or Vector to add ##

#Return Point equal to a offset by b ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
                         { 6, 4 }, { 7, 5 }, { 5, 7 },
                         { 4, 6 }, { 3, 7 }, { 1, 5 },
                         { 2, 4 }, { 1, 3 }, { 3, 1 } };
    canvas->scale(30, 15);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
    SkVector mod = {1, 1};
    for (auto& point : points) {
        point = point + mod;
        mod.fX *= 1.1f;
        mod.fY += .2f;
    }
    paint.setColor(SK_ColorRED);
    canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint);
##

#SeeAlso operator+=(const SkVector& v) offset()

#Method ##

# ------------------------------------------------------------------------------

#Method static SkScalar Length(SkScalar x, SkScalar y)
#In Property
#Line # returns straight-line distance to origin ##
Returns the Euclidean_Distance from origin, computed as:
#Code
#Literal
sqrt(x * x + y * y)
##
.

#Param x  component of length ##
#Param y  component of length ##

#Return straight-line distance to origin ##

#Example
#Height 192
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint points[] = { { 90, 30 }, { 120, 150 }, { 150, 30 }, { 210, 90 } };
    const SkPoint origin = {30, 140};
    for (auto point : points) {
        canvas->drawLine(origin, point, paint);
        SkAutoCanvasRestore acr(canvas, true);
        SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX);
        canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY);
        SkString length("length = ");
        length.appendScalar(SkPoint::Length(point.fX, point.fY));
        canvas->drawString(length, origin.fX + 25, origin.fY - 4, paint);
    }
##

#SeeAlso length() Distance setLength

#Method ##

# ------------------------------------------------------------------------------

#Method static SkScalar Normalize(SkVector* vec)
#In Offset
#Line # sets length to one, and returns prior length ##
Scales (vec->fX, vec->fY) so that length() returns one, while preserving ratio of vec->fX to vec->fY,
if possible. If original length is nearly zero, sets vec to (0, 0) and returns zero;
otherwise, returns length of vec before vec is scaled.

Returned prior length may be SK_ScalarInfinity if it can not be represented by SkScalar.

Note that normalize() is faster if prior length is not required.

#Param vec  normalized to unit length ##

#Return original vec length ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint lines[][2] = { {{  30, 110 }, { 190,  30 }},
                                 {{  30, 220 }, { 120, 140 }}};
    for (auto line : lines) {
        canvas->drawLine(line[0], line[1], paint);
        SkVector vector = line[1] - line[0];
        SkScalar priorLength = SkPoint::Normalize(&vector);
        SkVector rotate90 = { -vector.fY, vector.fX };
        rotate90 *= 10.f;
        canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint);
        canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint);
        SkString length("length = ");
        length.appendScalar(priorLength);
        canvas->drawString(length, line[0].fX + 25, line[0].fY - 4, paint);
    }
##

#SeeAlso normalize() setLength Length

#Method ##

# ------------------------------------------------------------------------------

#Method static SkScalar Distance(const SkPoint& a, const SkPoint& b)
#In Property
#Line # returns straight-line distance between points ##
Returns the Euclidean_Distance between a and b.

#Param a  line end point ##
#Param b  line end point ##

#Return straight-line distance from a to b ##

#Example
#Height 192
    SkPaint paint;
    paint.setAntiAlias(true);
    const SkPoint lines[][2] = {{{-10, -10}, {90, 30}}, {{0, 0}, {150, 30}}, {{10, 25}, {120, 150}}};
    const SkPoint origin = {30, 160};
    for (auto line : lines) {
        SkPoint a = origin + line[0];
        const SkPoint& b = line[1];
        canvas->drawLine(a, b, paint);
        SkAutoCanvasRestore acr(canvas, true);
        SkScalar angle = SkScalarATan2((b.fY - a.fY), b.fX - a.fX);
        canvas->rotate(angle * 180 / SK_ScalarPI, a.fX, a.fY);
        SkString distance("distance = ");
        distance.appendScalar(SkPoint::Distance(a, b));
        canvas->drawString(distance, a.fX + 25, a.fY - 4, paint);
    }
##

#SeeAlso length() setLength

#Method ##

# ------------------------------------------------------------------------------

#Method static SkScalar DotProduct(const SkVector& a, const SkVector& b)
#In Operator
#Line # returns dot product ##
Returns the dot product of Vector a and Vector b.

#Param a  left side of dot product ##
#Param b  right side of dot product ##

#Return product of input magnitudes and cosine of the angle between them ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}},
                             {{-20, -24}, {-24, -20}}};
    SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}};
    paint.setStrokeWidth(2);
    for (size_t i = 0; i < 4; ++i) {
        canvas->drawLine(center[i], center[i] + vectors[i][0], paint);
        canvas->drawLine(center[i], center[i] + vectors[i][1], paint);
        SkString str;
        str.printf("dot = %g", SkPoint::DotProduct(vectors[i][0], vectors[i][1]));
        canvas->drawString(str, center[i].fX, center[i].fY, paint);
    }
##

#SeeAlso dot CrossProduct

#Method ##

# ------------------------------------------------------------------------------

#Method static SkScalar CrossProduct(const SkVector& a, const SkVector& b)
#In Operator
#Line # returns cross product ##
Returns the cross product of Vector a and Vector b.

a and b form three-dimensional vectors with z-axis value equal to zero. The
cross product is a three-dimensional vector with x-axis and y-axis values equal
to zero. The cross product z-axis component is returned.

#Param a  left side of cross product ##
#Param b  right side of cross product ##

#Return area spanned by Vectors signed by angle direction ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}},
                             {{-20, -24}, {-24, -20}}};
    SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}};
    paint.setStrokeWidth(2);
    for (size_t i = 0; i < 4; ++i) {
        paint.setColor(SK_ColorRED);
        canvas->drawLine(center[i], center[i] + vectors[i][0], paint);
        paint.setColor(SK_ColorBLUE);
        canvas->drawLine(center[i], center[i] + vectors[i][1], paint);
        SkString str;
        SkScalar cross = SkPoint::CrossProduct(vectors[i][1], vectors[i][0]);
        str.printf("cross = %g", cross);
        paint.setColor(cross >= 0 ? SK_ColorRED : SK_ColorBLUE);
        canvas->drawString(str, center[i].fX, center[i].fY, paint);
    }
##

#SeeAlso cross DotProduct

#Method ##

# ------------------------------------------------------------------------------

#Method SkScalar cross(const SkVector& vec) const
#In Operator
#Line # returns cross product ##
Returns the cross product of Vector and vec.

Vector and vec form three-dimensional vectors with z-axis value equal to zero.
The cross product is a three-dimensional vector with x-axis and y-axis values
equal to zero. The cross product z-axis component is returned.

#Param vec  right side of cross product ##

#Return area spanned by Vectors signed by angle direction ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}},
                             {{-20, -24}, {-24, -20}}};
    SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}};
    paint.setStrokeWidth(2);
    for (size_t i = 0; i < 4; ++i) {
        paint.setColor(SK_ColorRED);
        canvas->drawLine(center[i], center[i] + vectors[i][0], paint);
        paint.setColor(SK_ColorBLUE);
        canvas->drawLine(center[i], center[i] + vectors[i][1], paint);
        SkString str;
        SkScalar cross = vectors[i][0].cross(vectors[i][1]);
        str.printf("cross = %g", cross);
        paint.setColor(cross >= 0 ? SK_ColorRED : SK_ColorBLUE);
        canvas->drawString(str, center[i].fX, center[i].fY, paint);
    }
##

#SeeAlso CrossProduct dot

#Method ##

# ------------------------------------------------------------------------------

#Method SkScalar dot(const SkVector& vec) const
#In Operator
#Line # returns dot product ##
Returns the dot product of Vector and Vector vec.

#Param vec  right side of dot product ##

#Return product of input magnitudes and cosine of the angle between them ##

#Example
    SkPaint paint;
    paint.setAntiAlias(true);
    SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}},
                             {{-20, -24}, {-24, -20}}};
    SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}};
    paint.setStrokeWidth(2);
    for (size_t i = 0; i < 4; ++i) {
        canvas->drawLine(center[i], center[i] + vectors[i][0], paint);
        canvas->drawLine(center[i], center[i] + vectors[i][1], paint);
        SkString str;
        str.printf("dot = %g", vectors[i][0].dot(vectors[i][1]));
        canvas->drawString(str, center[i].fX, center[i].fY, paint);
    }
##

#SeeAlso DotProduct cross

#Method ##

#Struct SkPoint ##


# ------------------------------------------------------------------------------

#Subtopic Vector
#Line # alias for Point ##
    #Alias Vector ##
    #Alias Vectors ##
    #Typedef SkPoint SkVector
    #Line # alias for Point ##
    #Code
    typedef SkPoint SkVector;
    ##
    SkVector provides an alternative name for SkPoint. SkVector and SkPoint can
    be used interchangeably for all purposes.
    #Typedef ##
##

#Topic Point ##