blob: 66f04e5a5d5eb462a7c6a64d2ccad45522b0bc59 [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic IPoint
2#Alias IPoints
3#Alias IPoint_Reference
4
Cary Clark08895c42018-02-01 09:37:32 -05005#Subtopic Overview
Cary Clark4855f782018-02-06 09:41:53 -05006 #Subtopic Subtopic
Cary Clark08895c42018-02-01 09:37:32 -05007 #Populate
8 ##
9##
10
Cary Clarka560c472017-11-27 10:44:06 -050011#Struct SkIPoint
12
Cary Clark5081eed2018-01-22 07:55:48 -050013SkIPoint holds two 32 bit integer coordinates.
Cary Clarka560c472017-11-27 10:44:06 -050014
Cary Clark4855f782018-02-06 09:41:53 -050015#Subtopic Related_Function
Cary Clark08895c42018-02-01 09:37:32 -050016#Populate
17##
Cary Clarka560c472017-11-27 10:44:06 -050018
Cary Clark4855f782018-02-06 09:41:53 -050019#Subtopic Member_Function
Cary Clark08895c42018-02-01 09:37:32 -050020#Populate
21##
Cary Clarka560c472017-11-27 10:44:06 -050022
Cary Clark4855f782018-02-06 09:41:53 -050023#Subtopic Member
Cary Clark08895c42018-02-01 09:37:32 -050024#Populate
Cary Clarka560c472017-11-27 10:44:06 -050025
26#Member int32_t fX
Cary Clark08895c42018-02-01 09:37:32 -050027#Line # x-axis value ##
Cary Clarka560c472017-11-27 10:44:06 -050028x-axis value used by IPoint.
29##
30
31#Member int32_t fY
Cary Clark08895c42018-02-01 09:37:32 -050032#Line # y-axis value ##
Cary Clarka560c472017-11-27 10:44:06 -050033y-axis value used by IPoint.
34##
35
Cary Clark4855f782018-02-06 09:41:53 -050036#Subtopic Member ##
Cary Clark08895c42018-02-01 09:37:32 -050037
Cary Clarka560c472017-11-27 10:44:06 -050038# ------------------------------------------------------------------------------
39
Cary Clark4855f782018-02-06 09:41:53 -050040#Subtopic Constructor
41#Populate
42##
43
Cary Clarka560c472017-11-27 10:44:06 -050044#Method static constexpr SkIPoint Make(int32_t x, int32_t y)
45
Cary Clark4855f782018-02-06 09:41:53 -050046#In Constructor
Cary Clarkab2621d2018-01-30 10:08:57 -050047#Line # constructs from integer inputs ##
Cary Clarka560c472017-11-27 10:44:06 -050048Sets fX to x, fY to y.
49
50#Param x integer x-axis value of constructed IPoint ##
51#Param y integer y-axis value of constructed IPoint ##
52
53#Return IPoint (x, y) ##
54
55#Example
56SkIPoint pt1 = {45, 66};
57SkIPoint pt2 = SkIPoint::Make(45, 66);
58SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
59#StdOut
60pt1 == pt2
61##
62##
63
64#SeeAlso set() SkPoint::iset() SkPoint::Make SkIPoint16::Make
65
66#Method ##
67
68# ------------------------------------------------------------------------------
69
Cary Clark4855f782018-02-06 09:41:53 -050070#Subtopic Property
71#Line # member values ##
72#Populate
73##
Cary Clarka560c472017-11-27 10:44:06 -050074
Cary Clark4855f782018-02-06 09:41:53 -050075#Method int32_t x() const
76#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050077#Line # returns fX ##
Cary Clarka560c472017-11-27 10:44:06 -050078Returns x-axis value of IPoint.
79
80#Return fX ##
81
82#Example
83SkIPoint pt1 = {45, 66};
84SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
85#StdOut
86pt1.fX == pt1.x()
87##
88##
89
90#SeeAlso y() SkPoint::x() SkIPoint16::x()
91
92#Method ##
93
94# ------------------------------------------------------------------------------
95
96#Method int32_t y() const
Cary Clark4855f782018-02-06 09:41:53 -050097#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050098#Line # returns fY ##
Cary Clarka560c472017-11-27 10:44:06 -050099Returns y-axis value of IPoint.
100
101#Return fY ##
102
103#Example
104SkIPoint pt1 = {45, 66};
105SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
106#StdOut
107pt1.fY == pt1.y()
108##
109##
110
111#SeeAlso x() SkPoint::y() SkIPoint16::y()
112
113#Method ##
114
115# ------------------------------------------------------------------------------
116
117#Method bool isZero() const
Cary Clark4855f782018-02-06 09:41:53 -0500118#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500119#Line # returns true if both members equal zero ##
Cary Clarka560c472017-11-27 10:44:06 -0500120Returns true if fX and fY are both zero.
121
122#Return true if fX is zero and fY is zero ##
123
124#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500125SkIPoint pt = { 0, -0};
Cary Clarka560c472017-11-27 10:44:06 -0500126SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
127#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500128pt.isZero() == true
Cary Clarka560c472017-11-27 10:44:06 -0500129##
130##
131
132#SeeAlso SkPoint::isZero
133
134#Method ##
135
136# ------------------------------------------------------------------------------
137
Cary Clark4855f782018-02-06 09:41:53 -0500138#Subtopic Set
139#Populate
140#Line # replaces all values ##
141##
Cary Clarka560c472017-11-27 10:44:06 -0500142
Cary Clark4855f782018-02-06 09:41:53 -0500143#Method void set(int32_t x, int32_t y)
144#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500145#Line # sets to integer input ##
Cary Clarka560c472017-11-27 10:44:06 -0500146Sets fX to x and fY to y.
147
148#Param x new value for fX ##
149#Param y new value for fY ##
150
151#Example
152SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 };
153pt1.set(SK_MinS32, SK_MaxS32);
154SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
155#StdOut
156pt1 == pt2
157##
158##
159
160#SeeAlso Make SkIPoint16::set
161
162#Method ##
163
164# ------------------------------------------------------------------------------
Cary Clark4855f782018-02-06 09:41:53 -0500165#Subtopic Operator
166#Populate
167##
Cary Clarka560c472017-11-27 10:44:06 -0500168
169#Method SkIPoint operator-()_const
170
Cary Clarkab2621d2018-01-30 10:08:57 -0500171#Line # reverses sign of IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500172Returns IPoint changing the signs of fX and fY.
173
174#Return IPoint as (-fX, -fY) ##
175
176#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500177SkIPoint test[] = { {0, -0}, {-1, -2},
178 { SK_MaxS32, SK_MinS32 },
Cary Clark681287e2018-03-16 11:34:15 -0400179 { SK_NaN32, SK_NaN32 } };
Cary Clark0c5f5462017-12-15 11:21:51 -0500180for (const SkIPoint& pt : test) {
181 SkIPoint negPt = -pt;
182 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
Cary Clarka560c472017-11-27 10:44:06 -0500183}
184#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500185pt: 0, 0 negate: 0, 0
186pt: -1, -2 negate: 1, 2
187pt: 2147483647, -2147483647 negate: -2147483647, 2147483647
Cary Clarka560c472017-11-27 10:44:06 -0500188pt: -2147483648, -2147483648 negate: -2147483648, -2147483648
189##
190##
191
192#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const
193
194#Method ##
195
196# ------------------------------------------------------------------------------
197
198#Method void operator+=(const SkIVector& v)
199
Cary Clarkab2621d2018-01-30 10:08:57 -0500200#Line # adds IVector to IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500201Offsets IPoint by IVector v. Sets IPoint to
202#Formula
203(fX + v.fX, fY + v.fY)
204##
205.
206
207#Param v IVector to add ##
208
209#Example
210#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500211 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
212 for (size_t i = 0; i < count - 1; ++i) {
213 SkPoint p0, p1;
214 p0.iset(pts[i]);
215 p1.iset(pts[i + 1]);
216 canvas->drawLine(p0, p1, paint);
217 }
218 };
219 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
220 SkPaint paint;
221 paint.setAntiAlias(true);
222 paint.setStyle(SkPaint::kStroke_Style);
223 canvas->scale(30, 15);
224 draw_lines(points, SK_ARRAY_COUNT(points), paint);
225 points[1] += {1, 1};
226 points[2] += {-1, -1};
227 paint.setColor(SK_ColorRED);
228 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500229##
230
231#SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v)
232
233#Method ##
234
235# ------------------------------------------------------------------------------
236
237#Method void operator-=(const SkIVector& v)
238
Cary Clarkab2621d2018-01-30 10:08:57 -0500239#Line # subtracts IVector from IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500240Subtracts IVector v from IPoint. Sets IPoint to:
241#Formula
242(fX - v.fX, fY - v.fY)
243##
244.
245
246#Param v IVector to subtract ##
247
248#Example
249#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500250 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
251 for (size_t i = 0; i < count - 1; ++i) {
252 SkPoint p0, p1;
253 p0.iset(pts[i]);
254 p1.iset(pts[i + 1]);
255 canvas->drawLine(p0, p1, paint);
256 }
257 };
258 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
259 SkPaint paint;
260 paint.setAntiAlias(true);
261 paint.setStyle(SkPaint::kStroke_Style);
262 canvas->scale(30, 15);
263 draw_lines(points, SK_ARRAY_COUNT(points), paint);
264 points[1] -= {1, 1};
265 points[2] -= {-1, -1};
266 paint.setColor(SK_ColorRED);
267 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500268##
269
270#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v)
271
272#Method ##
273
274# ------------------------------------------------------------------------------
275
276#Method bool equals(int32_t x, int32_t y) const
Cary Clark4855f782018-02-06 09:41:53 -0500277#In Operator
Cary Clarkab2621d2018-01-30 10:08:57 -0500278#Line # returns true if members are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500279Returns true if IPoint is equivalent to IPoint constructed from (x, y).
280
281#Param x value compared with fX ##
282#Param y value compared with fY ##
283
284#Return true if IPoint equals (x, y) ##
285
286#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500287SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
288for (const SkIPoint& pt : test) {
289 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500290}
291#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500292pt: 0, 0 == pt
293pt: -1, -2 == pt
294pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500295pt: -2147483648, -1 == pt
296##
297##
298
299#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b)
300
301#Method ##
302
303# ------------------------------------------------------------------------------
304
305#Method bool operator==(const SkIPoint& a, const SkIPoint& b)
306
Cary Clarkab2621d2018-01-30 10:08:57 -0500307#Line # returns true if IPoints are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500308Returns true if a is equivalent to b.
309
310#Param a IPoint to compare ##
311#Param b IPoint to compare ##
312
313#Return true if a.fX == b.fX and a.fY == b.fY ##
314
315#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500316SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
317for (const SkIPoint& pt : test) {
318 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500319}
320#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500321pt: 0, 0 == pt
322pt: -1, -2 == pt
323pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500324pt: -2147483648, -1 == pt
325##
326##
327
328#SeeAlso equals() operator!=(const SkIPoint& a, const SkIPoint& b)
329
330#Method ##
331
332# ------------------------------------------------------------------------------
333
334#Method bool operator!=(const SkIPoint& a, const SkIPoint& b)
335
Cary Clarkab2621d2018-01-30 10:08:57 -0500336#Line # returns true if IPoints are unequal ##
Cary Clarka560c472017-11-27 10:44:06 -0500337Returns true if a is not equivalent to b.
338
339#Param a IPoint to compare ##
340#Param b IPoint to compare ##
341
342#Return true if a.fX != b.fX or a.fY != b.fY ##
343
344#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500345SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
346for (const SkIPoint& pt : test) {
347 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
Cary Clarka560c472017-11-27 10:44:06 -0500348}
349#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500350pt: 0, 0 == pt
351pt: -1, -2 == pt
352pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500353pt: -2147483648, -1 == pt
354##
355##
356
357#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) equals()
358
359#Method ##
360
361# ------------------------------------------------------------------------------
362
363#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)
364
Cary Clarkab2621d2018-01-30 10:08:57 -0500365#Line # returns IVector between IPoints ##
Cary Clarka560c472017-11-27 10:44:06 -0500366Returns IVector from b to a; computed as
367#Formula
368(a.fX - b.fX, a.fY - b.fY)
369##
370.
371
372Can also be used to subtract IVector from IVector, returning IVector.
373
374#Param a IPoint or IVector to subtract from ##
375#Param b IVector to subtract ##
376
377#Return IVector from b to a ##
378
379#Example
380#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500381 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
382 for (size_t i = 0; i < count - 1; ++i) {
383 SkPoint p0, p1;
384 p0.iset(pts[i]);
385 p1.iset(pts[i + 1]);
386 canvas->drawLine(p0, p1, paint);
387 }
388 };
389 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
390 SkPaint paint;
391 paint.setAntiAlias(true);
392 paint.setStyle(SkPaint::kStroke_Style);
393 canvas->scale(30, 15);
394 draw_lines(points, SK_ARRAY_COUNT(points), paint);
395 points[1] += points[0] - points[3];
396 points[2] -= points[1] - points[0];
397 paint.setColor(SK_ColorRED);
398 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500399##
400
401#SeeAlso operator-=(const SkIVector& v)
402
403#Method ##
404
405# ------------------------------------------------------------------------------
406
407#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)
408
Cary Clarkab2621d2018-01-30 10:08:57 -0500409#Line # returns IPoint offset by IVector ##
Cary Clarka560c472017-11-27 10:44:06 -0500410Returns IPoint resulting from IPoint a offset by IVector b, computed as:
411#Formula
412(a.fX + b.fX, a.fY + b.fY)
413##
414.
415
416Can also be used to offset IPoint b by IVector a, returning IPoint.
417Can also be used to add IVector to IVector, returning IVector.
418
419#Param a IPoint or IVector to add to ##
420#Param b IPoint or IVector to add ##
421
422#Return IPoint equal to a offset by b ##
423
424#Example
425#Height 128
Cary Clark0c5f5462017-12-15 11:21:51 -0500426 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
427 for (size_t i = 0; i < count - 1; ++i) {
428 SkPoint p0, p1;
429 p0.iset(pts[i]);
430 p1.iset(pts[i + 1]);
431 canvas->drawLine(p0, p1, paint);
432 }
433 };
434 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
435 SkPaint paint;
436 paint.setAntiAlias(true);
437 paint.setStyle(SkPaint::kStroke_Style);
438 canvas->scale(30, 15);
439 draw_lines(points, SK_ARRAY_COUNT(points), paint);
440 SkIPoint mod = {4, 1};
441 for (auto& point : points) {
442 point = point + mod;
443 mod.fX -= 1;
444 mod.fY += 1;
445 }
446 paint.setColor(SK_ColorRED);
447 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500448##
449
450#SeeAlso operator+=(const SkIVector& v)
451
452#Method ##
453
454#Struct SkIPoint ##
455
456#Topic IPoint ##
457
458#Topic IVector
459 #Alias IVectors
460 #Typedef SkIPoint SkIVector
461 #Typedef ##
462##