aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/SkIPoint_Reference.bmh
blob: 2ed3b7b80c945b8bb8c8b62bdffcd964af9ed800 (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
#Topic IPoint
#Alias IPoints ##
#Alias IPoint_Reference ##

#Struct SkIPoint

SkIPoint holds two 32-bit integer coordinates.

#Subtopic Overview
#Populate
##

#Subtopic Related_Function
#Populate
##

#Subtopic Member_Function
#Populate
##

#Subtopic Member
#Populate

#Member int32_t  fX
#Line # x-axis value ##
x-axis value used by IPoint.
##

#Member int32_t  fY
#Line # y-axis value ##
y-axis value used by IPoint.
##

#Subtopic Member ##

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

#Subtopic Constructor
#Populate
##

#Method static constexpr SkIPoint Make(int32_t x, int32_t y)

#In Constructor
#Line # constructs from integer inputs ##
Sets fX to x, fY to y.

#Param x  integer x-axis value of constructed IPoint ##
#Param y  integer y-axis value of constructed IPoint ##

#Return IPoint (x, y) ##

#Example
SkIPoint pt1 = {45, 66};
SkIPoint pt2 = SkIPoint::Make(45, 66);
SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
#StdOut
pt1 == pt2
##
##

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

#Method ##

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

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

#Method int32_t x() const
#In Property
#Line # returns fX ##
Returns x-axis value of IPoint.

#Return fX ##

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

#SeeAlso y() SkPoint::x()

#Method ##

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

#Method int32_t y() const
#In Property
#Line # returns fY ##
Returns y-axis value of IPoint.

#Return fY ##

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

#SeeAlso x() SkPoint::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
SkIPoint pt = { 0, -0};
SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
#StdOut
pt.isZero() == true
##
##

#SeeAlso SkPoint::isZero

#Method ##

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

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

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

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

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

#SeeAlso Make

#Method ##

# ------------------------------------------------------------------------------
#Subtopic Operator
#Populate
##

#Method SkIPoint operator-()_const

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

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

#Example
SkIPoint test[] = { {0, -0}, {-1, -2},
                   { SK_MaxS32, SK_MinS32 },
                   { SK_NaN32, SK_NaN32 } };
for (const SkIPoint& pt : test) {
    SkIPoint negPt = -pt;
    SkDebugf("pt: %d, %d  negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
}
#StdOut
pt: 0, 0  negate: 0, 0
pt: -1, -2  negate: 1, 2
pt: 2147483647, -2147483647  negate: -2147483647, 2147483647
pt: -2147483648, -2147483648  negate: -2147483648, -2147483648
##
##

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

#Method ##

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

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

#Line # adds IVector to IPoint ##
Offsets IPoint by IVector v. Sets IPoint to
#Formula
(fX + v.fX, fY + v.fY)
##
.

#Param v  IVector to add ##

#Example
#Height 64
    auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
        for (size_t i = 0; i < count - 1; ++i) {
            SkPoint p0, p1;
            p0.iset(pts[i]);
            p1.iset(pts[i + 1]);
            canvas->drawLine(p0, p1, paint);
        }
    };
    SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->scale(30, 15);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
    points[1] += {1, 1};
    points[2] += {-1, -1};
    paint.setColor(SK_ColorRED);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
##

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

#Method ##

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

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

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

#Param v  IVector to subtract ##

#Example
#Height 64
    auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
        for (size_t i = 0; i < count - 1; ++i) {
            SkPoint p0, p1;
            p0.iset(pts[i]);
            p1.iset(pts[i + 1]);
            canvas->drawLine(p0, p1, paint);
        }
    };
    SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->scale(30, 15);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
    points[1] -= {1, 1};
    points[2] -= {-1, -1};
    paint.setColor(SK_ColorRED);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
##

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

#Method ##

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

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

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

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

#Example
SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
for (const SkIPoint& pt : test) {
    SkDebugf("pt: %d, %d  %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
}
#StdOut
pt: 0, 0  == pt
pt: -1, -2  == pt
pt: 2147483647, -1  == pt
pt: -2147483648, -1  == pt
##
##

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

#Method ##

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

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

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

#Param a  IPoint to compare ##
#Param b  IPoint to compare ##

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

#Example
SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
for (const SkIPoint& pt : test) {
    SkDebugf("pt: %d, %d  %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
}
#StdOut
pt: 0, 0  == pt
pt: -1, -2  == pt
pt: 2147483647, -1  == pt
pt: -2147483648, -1  == pt
##
##

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

#Method ##

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

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

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

#Param a  IPoint to compare ##
#Param b  IPoint to compare ##

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

#Example
SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
for (const SkIPoint& pt : test) {
    SkDebugf("pt: %d, %d  %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
}
#StdOut
pt: 0, 0  == pt
pt: -1, -2  == pt
pt: 2147483647, -1  == pt
pt: -2147483648, -1  == pt
##
##

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

#Method ##

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

#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)

#Line # returns IVector between IPoints ##
Returns IVector from b to a; computed as
#Formula
(a.fX - b.fX, a.fY - b.fY)
##
.

Can also be used to subtract IVector from IVector, returning IVector.

#Param a  IPoint or IVector to subtract from ##
#Param b  IVector to subtract ##

#Return IVector from b to a ##

#Example
#Height 64
    auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
        for (size_t i = 0; i < count - 1; ++i) {
            SkPoint p0, p1;
            p0.iset(pts[i]);
            p1.iset(pts[i + 1]);
            canvas->drawLine(p0, p1, paint);
        }
    };
    SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->scale(30, 15);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
    points[1] += points[0] - points[3];
    points[2] -= points[1] - points[0];
    paint.setColor(SK_ColorRED);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
##

#SeeAlso operator-=(const SkIVector& v)

#Method ##

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

#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)

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

Can also be used to offset IPoint b by IVector a, returning IPoint.
Can also be used to add IVector to IVector, returning IVector.

#Param a  IPoint or IVector to add to ##
#Param b  IPoint or IVector to add ##

#Return IPoint equal to a offset by b ##

#Example
#Height 128
    auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
        for (size_t i = 0; i < count - 1; ++i) {
            SkPoint p0, p1;
            p0.iset(pts[i]);
            p1.iset(pts[i + 1]);
            canvas->drawLine(p0, p1, paint);
        }
    };
    SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
    SkPaint paint;
    paint.setAntiAlias(true);
    paint.setStyle(SkPaint::kStroke_Style);
    canvas->scale(30, 15);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
    SkIPoint mod = {4, 1};
    for (auto& point : points) {
        point = point + mod;
        mod.fX -= 1;
        mod.fY += 1;
    }
    paint.setColor(SK_ColorRED);
    draw_lines(points, SK_ARRAY_COUNT(points), paint);
##

#SeeAlso operator+=(const SkIVector& v)

#Method ##

#Struct SkIPoint ##


#Subtopic IVector
#Line # alias for IPoint ##
    #Alias IVector ##
    #Alias IVectors ##
    #Typedef SkIPoint SkIVector
    #Line # alias for IPoint ##
    #Code
    typedef SkIPoint SkIVector;
    ##
    SkIVector provides an alternative name for SkIPoint. SkIVector and SkIPoint
    can be used interchangeably for all purposes.
    #Typedef ##
##

#Topic IPoint ##