blob: 2ed3b7b80c945b8bb8c8b62bdffcd964af9ed800 [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic IPoint
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias IPoints ##
3#Alias IPoint_Reference ##
Cary Clarka560c472017-11-27 10:44:06 -05004
5#Struct SkIPoint
6
Cary Clark682c58d2018-05-16 07:07:07 -04007SkIPoint holds two 32-bit integer coordinates.
8
9#Subtopic Overview
10#Populate
11##
Cary Clarka560c472017-11-27 10:44:06 -050012
Cary Clark4855f782018-02-06 09:41:53 -050013#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050014#Populate
15##
Cary Clarka560c472017-11-27 10:44:06 -050016
Cary Clark4855f782018-02-06 09:41:53 -050017#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -050018#Populate
19##
Cary Clarka560c472017-11-27 10:44:06 -050020
Cary Clark4855f782018-02-06 09:41:53 -050021#Subtopic Member
Cary Clark08895c42018-02-01 09:37:32 -050022#Populate
Cary Clarka560c472017-11-27 10:44:06 -050023
24#Member int32_t fX
Cary Clark08895c42018-02-01 09:37:32 -050025#Line # x-axis value ##
Cary Clarka560c472017-11-27 10:44:06 -050026x-axis value used by IPoint.
27##
28
29#Member int32_t fY
Cary Clark08895c42018-02-01 09:37:32 -050030#Line # y-axis value ##
Cary Clarka560c472017-11-27 10:44:06 -050031y-axis value used by IPoint.
32##
33
Cary Clark4855f782018-02-06 09:41:53 -050034#Subtopic Member ##
Cary Clark08895c42018-02-01 09:37:32 -050035
Cary Clarka560c472017-11-27 10:44:06 -050036# ------------------------------------------------------------------------------
37
Cary Clark4855f782018-02-06 09:41:53 -050038#Subtopic Constructor
39#Populate
40##
41
Cary Clarka560c472017-11-27 10:44:06 -050042#Method static constexpr SkIPoint Make(int32_t x, int32_t y)
43
Cary Clark4855f782018-02-06 09:41:53 -050044#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -050045#Line # constructs from integer inputs ##
Cary Clarka560c472017-11-27 10:44:06 -050046Sets fX to x, fY to y.
47
48#Param x integer x-axis value of constructed IPoint ##
49#Param y integer y-axis value of constructed IPoint ##
50
51#Return IPoint (x, y) ##
52
53#Example
54SkIPoint pt1 = {45, 66};
55SkIPoint pt2 = SkIPoint::Make(45, 66);
56SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
57#StdOut
58pt1 == pt2
59##
60##
61
Mike Reed1fda0242018-04-04 15:39:46 -040062#SeeAlso set() SkPoint::iset() SkPoint::Make
Cary Clarka560c472017-11-27 10:44:06 -050063
64#Method ##
65
66# ------------------------------------------------------------------------------
67
Cary Clark4855f782018-02-06 09:41:53 -050068#Subtopic Property
69#Line # member values ##
70#Populate
71##
Cary Clarka560c472017-11-27 10:44:06 -050072
Cary Clark4855f782018-02-06 09:41:53 -050073#Method int32_t x() const
74#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050075#Line # returns fX ##
Cary Clarka560c472017-11-27 10:44:06 -050076Returns x-axis value of IPoint.
77
78#Return fX ##
79
80#Example
81SkIPoint pt1 = {45, 66};
82SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
83#StdOut
84pt1.fX == pt1.x()
85##
86##
87
Mike Reed1fda0242018-04-04 15:39:46 -040088#SeeAlso y() SkPoint::x()
Cary Clarka560c472017-11-27 10:44:06 -050089
90#Method ##
91
92# ------------------------------------------------------------------------------
93
94#Method int32_t y() const
Cary Clark4855f782018-02-06 09:41:53 -050095#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050096#Line # returns fY ##
Cary Clarka560c472017-11-27 10:44:06 -050097Returns y-axis value of IPoint.
98
99#Return fY ##
100
101#Example
102SkIPoint pt1 = {45, 66};
103SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
104#StdOut
105pt1.fY == pt1.y()
106##
107##
108
Mike Reed1fda0242018-04-04 15:39:46 -0400109#SeeAlso x() SkPoint::y()
Cary Clarka560c472017-11-27 10:44:06 -0500110
111#Method ##
112
113# ------------------------------------------------------------------------------
114
115#Method bool isZero() const
Cary Clark4855f782018-02-06 09:41:53 -0500116#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500117#Line # returns true if both members equal zero ##
Cary Clarka560c472017-11-27 10:44:06 -0500118Returns true if fX and fY are both zero.
119
120#Return true if fX is zero and fY is zero ##
121
122#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500123SkIPoint pt = { 0, -0};
Cary Clarka560c472017-11-27 10:44:06 -0500124SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
125#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500126pt.isZero() == true
Cary Clarka560c472017-11-27 10:44:06 -0500127##
128##
129
130#SeeAlso SkPoint::isZero
131
132#Method ##
133
134# ------------------------------------------------------------------------------
135
Cary Clark4855f782018-02-06 09:41:53 -0500136#Subtopic Set
137#Populate
138#Line # replaces all values ##
139##
Cary Clarka560c472017-11-27 10:44:06 -0500140
Cary Clark4855f782018-02-06 09:41:53 -0500141#Method void set(int32_t x, int32_t y)
142#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500143#Line # sets to integer input ##
Cary Clarka560c472017-11-27 10:44:06 -0500144Sets fX to x and fY to y.
145
146#Param x new value for fX ##
147#Param y new value for fY ##
148
149#Example
150SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 };
151pt1.set(SK_MinS32, SK_MaxS32);
152SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
153#StdOut
154pt1 == pt2
155##
156##
157
Mike Reed1fda0242018-04-04 15:39:46 -0400158#SeeAlso Make
Cary Clarka560c472017-11-27 10:44:06 -0500159
160#Method ##
161
162# ------------------------------------------------------------------------------
Cary Clark4855f782018-02-06 09:41:53 -0500163#Subtopic Operator
164#Populate
165##
Cary Clarka560c472017-11-27 10:44:06 -0500166
167#Method SkIPoint operator-()_const
168
Cary Clarkab2621d2018-01-30 10:08:57 -0500169#Line # reverses sign of IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500170Returns IPoint changing the signs of fX and fY.
171
172#Return IPoint as (-fX, -fY) ##
173
174#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500175SkIPoint test[] = { {0, -0}, {-1, -2},
176 { SK_MaxS32, SK_MinS32 },
Cary Clark681287e2018-03-16 11:34:15 -0400177 { SK_NaN32, SK_NaN32 } };
Cary Clark0c5f5462017-12-15 11:21:51 -0500178for (const SkIPoint& pt : test) {
179 SkIPoint negPt = -pt;
180 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
Cary Clarka560c472017-11-27 10:44:06 -0500181}
182#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500183pt: 0, 0 negate: 0, 0
184pt: -1, -2 negate: 1, 2
185pt: 2147483647, -2147483647 negate: -2147483647, 2147483647
Cary Clarka560c472017-11-27 10:44:06 -0500186pt: -2147483648, -2147483648 negate: -2147483648, -2147483648
187##
188##
189
190#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const
191
192#Method ##
193
194# ------------------------------------------------------------------------------
195
196#Method void operator+=(const SkIVector& v)
197
Cary Clarkab2621d2018-01-30 10:08:57 -0500198#Line # adds IVector to IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500199Offsets IPoint by IVector v. Sets IPoint to
200#Formula
201(fX + v.fX, fY + v.fY)
202##
203.
204
205#Param v IVector to add ##
206
207#Example
208#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500209 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
210 for (size_t i = 0; i < count - 1; ++i) {
211 SkPoint p0, p1;
212 p0.iset(pts[i]);
213 p1.iset(pts[i + 1]);
214 canvas->drawLine(p0, p1, paint);
215 }
216 };
217 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
218 SkPaint paint;
219 paint.setAntiAlias(true);
220 paint.setStyle(SkPaint::kStroke_Style);
221 canvas->scale(30, 15);
222 draw_lines(points, SK_ARRAY_COUNT(points), paint);
223 points[1] += {1, 1};
224 points[2] += {-1, -1};
225 paint.setColor(SK_ColorRED);
226 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500227##
228
229#SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v)
230
231#Method ##
232
233# ------------------------------------------------------------------------------
234
235#Method void operator-=(const SkIVector& v)
236
Cary Clarkab2621d2018-01-30 10:08:57 -0500237#Line # subtracts IVector from IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500238Subtracts IVector v from IPoint. Sets IPoint to:
239#Formula
240(fX - v.fX, fY - v.fY)
241##
242.
243
244#Param v IVector to subtract ##
245
246#Example
247#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500248 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
249 for (size_t i = 0; i < count - 1; ++i) {
250 SkPoint p0, p1;
251 p0.iset(pts[i]);
252 p1.iset(pts[i + 1]);
253 canvas->drawLine(p0, p1, paint);
254 }
255 };
256 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
257 SkPaint paint;
258 paint.setAntiAlias(true);
259 paint.setStyle(SkPaint::kStroke_Style);
260 canvas->scale(30, 15);
261 draw_lines(points, SK_ARRAY_COUNT(points), paint);
262 points[1] -= {1, 1};
263 points[2] -= {-1, -1};
264 paint.setColor(SK_ColorRED);
265 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500266##
267
268#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v)
269
270#Method ##
271
272# ------------------------------------------------------------------------------
273
274#Method bool equals(int32_t x, int32_t y) const
Cary Clark4855f782018-02-06 09:41:53 -0500275#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500276#Line # returns true if members are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500277Returns true if IPoint is equivalent to IPoint constructed from (x, y).
278
279#Param x value compared with fX ##
280#Param y value compared with fY ##
281
282#Return true if IPoint equals (x, y) ##
283
284#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500285SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
286for (const SkIPoint& pt : test) {
287 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500288}
289#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500290pt: 0, 0 == pt
291pt: -1, -2 == pt
292pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500293pt: -2147483648, -1 == pt
294##
295##
296
297#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b)
298
299#Method ##
300
301# ------------------------------------------------------------------------------
302
303#Method bool operator==(const SkIPoint& a, const SkIPoint& b)
304
Cary Clarkab2621d2018-01-30 10:08:57 -0500305#Line # returns true if IPoints are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500306Returns true if a is equivalent to b.
307
308#Param a IPoint to compare ##
309#Param b IPoint to compare ##
310
311#Return true if a.fX == b.fX and a.fY == b.fY ##
312
313#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500314SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
315for (const SkIPoint& pt : test) {
316 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500317}
318#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500319pt: 0, 0 == pt
320pt: -1, -2 == pt
321pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500322pt: -2147483648, -1 == pt
323##
324##
325
326#SeeAlso equals() operator!=(const SkIPoint& a, const SkIPoint& b)
327
328#Method ##
329
330# ------------------------------------------------------------------------------
331
332#Method bool operator!=(const SkIPoint& a, const SkIPoint& b)
333
Cary Clarkab2621d2018-01-30 10:08:57 -0500334#Line # returns true if IPoints are unequal ##
Cary Clarka560c472017-11-27 10:44:06 -0500335Returns true if a is not equivalent to b.
336
337#Param a IPoint to compare ##
338#Param b IPoint to compare ##
339
340#Return true if a.fX != b.fX or a.fY != b.fY ##
341
342#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500343SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
344for (const SkIPoint& pt : test) {
345 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
Cary Clarka560c472017-11-27 10:44:06 -0500346}
347#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500348pt: 0, 0 == pt
349pt: -1, -2 == pt
350pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500351pt: -2147483648, -1 == pt
352##
353##
354
355#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) equals()
356
357#Method ##
358
359# ------------------------------------------------------------------------------
360
361#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)
362
Cary Clarkab2621d2018-01-30 10:08:57 -0500363#Line # returns IVector between IPoints ##
Cary Clarka560c472017-11-27 10:44:06 -0500364Returns IVector from b to a; computed as
365#Formula
366(a.fX - b.fX, a.fY - b.fY)
367##
368.
369
370Can also be used to subtract IVector from IVector, returning IVector.
371
372#Param a IPoint or IVector to subtract from ##
373#Param b IVector to subtract ##
374
375#Return IVector from b to a ##
376
377#Example
378#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500379 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
380 for (size_t i = 0; i < count - 1; ++i) {
381 SkPoint p0, p1;
382 p0.iset(pts[i]);
383 p1.iset(pts[i + 1]);
384 canvas->drawLine(p0, p1, paint);
385 }
386 };
387 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
388 SkPaint paint;
389 paint.setAntiAlias(true);
390 paint.setStyle(SkPaint::kStroke_Style);
391 canvas->scale(30, 15);
392 draw_lines(points, SK_ARRAY_COUNT(points), paint);
393 points[1] += points[0] - points[3];
394 points[2] -= points[1] - points[0];
395 paint.setColor(SK_ColorRED);
396 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500397##
398
399#SeeAlso operator-=(const SkIVector& v)
400
401#Method ##
402
403# ------------------------------------------------------------------------------
404
405#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)
406
Cary Clarkab2621d2018-01-30 10:08:57 -0500407#Line # returns IPoint offset by IVector ##
Cary Clarka560c472017-11-27 10:44:06 -0500408Returns IPoint resulting from IPoint a offset by IVector b, computed as:
409#Formula
410(a.fX + b.fX, a.fY + b.fY)
411##
412.
413
414Can also be used to offset IPoint b by IVector a, returning IPoint.
415Can also be used to add IVector to IVector, returning IVector.
416
417#Param a IPoint or IVector to add to ##
418#Param b IPoint or IVector to add ##
419
420#Return IPoint equal to a offset by b ##
421
422#Example
423#Height 128
Cary Clark0c5f5462017-12-15 11:21:51 -0500424 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
425 for (size_t i = 0; i < count - 1; ++i) {
426 SkPoint p0, p1;
427 p0.iset(pts[i]);
428 p1.iset(pts[i + 1]);
429 canvas->drawLine(p0, p1, paint);
430 }
431 };
432 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
433 SkPaint paint;
434 paint.setAntiAlias(true);
435 paint.setStyle(SkPaint::kStroke_Style);
436 canvas->scale(30, 15);
437 draw_lines(points, SK_ARRAY_COUNT(points), paint);
438 SkIPoint mod = {4, 1};
439 for (auto& point : points) {
440 point = point + mod;
441 mod.fX -= 1;
442 mod.fY += 1;
443 }
444 paint.setColor(SK_ColorRED);
445 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500446##
447
448#SeeAlso operator+=(const SkIVector& v)
449
450#Method ##
451
452#Struct SkIPoint ##
453
Cary Clarka560c472017-11-27 10:44:06 -0500454
Cary Clark682c58d2018-05-16 07:07:07 -0400455#Subtopic IVector
456#Line # alias for IPoint ##
Cary Clark137b8742018-05-30 09:21:49 -0400457 #Alias IVector ##
458 #Alias IVectors ##
Cary Clarka560c472017-11-27 10:44:06 -0500459 #Typedef SkIPoint SkIVector
Cary Clark682c58d2018-05-16 07:07:07 -0400460 #Line # alias for IPoint ##
461 #Code
462 typedef SkIPoint SkIVector;
463 ##
464 SkIVector provides an alternative name for SkIPoint. SkIVector and SkIPoint
Cary Clark137b8742018-05-30 09:21:49 -0400465 can be used interchangeably for all purposes.
Cary Clarka560c472017-11-27 10:44:06 -0500466 #Typedef ##
467##
Cary Clark682c58d2018-05-16 07:07:07 -0400468
469#Topic IPoint ##
470