blob: 857c25df872ed89d8c8bba186e9c49115b1a6187 [file] [log] [blame]
Cary Clarka560c472017-11-27 10:44:06 -05001#Topic IPoint
2#Alias IPoints
3#Alias IPoint_Reference
4
5#Struct SkIPoint
6
Cary Clark5081eed2018-01-22 07:55:48 -05007SkIPoint holds two 32 bit integer coordinates.
Cary Clarka560c472017-11-27 10:44:06 -05008
9#Topic Overview
10
11#Subtopic Subtopics
12#ToDo manually add subtopics ##
13#Table
14#Legend
Cary Clark5081eed2018-01-22 07:55:48 -050015# name # description ##
Cary Clarka560c472017-11-27 10:44:06 -050016#Legend ##
Cary Clark5081eed2018-01-22 07:55:48 -050017# Constructors # functions that construct SkIPoint16 ##
18# Member_Functions # static functions and member methods ##
19# Operators # operator overloading methods ##
Cary Clarka560c472017-11-27 10:44:06 -050020#Table ##
Cary Clark5081eed2018-01-22 07:55:48 -050021#Subtopic ##
22
23#Subtopic Constructors
24#Table
25#Legend
26# name # description ##
27#Legend ##
28# Make # constructs from integer inputs ##
29#Table ##
30#Subtopic ##
Cary Clarka560c472017-11-27 10:44:06 -050031
32#Subtopic Operators
33#Table
34#Legend
Cary Clarkab2621d2018-01-30 10:08:57 -050035# name # description ##
Cary Clarka560c472017-11-27 10:44:06 -050036#Legend ##
Cary Clarkab2621d2018-01-30 10:08:57 -050037# operator+(const SkIPoint& a, const SkIVector& b) # returns IPoint offset by IVector ##
38# operator-()_const # reverses sign of IPoint ##
39# operator-(const SkIPoint& a, const SkIPoint& b) # returns IVector between IPoints ##
40# operator!=(const SkIPoint& a, const SkIPoint& b) # returns true if IPoints are unequal ##
41# operator==(const SkIPoint& a, const SkIPoint& b) # returns true if IPoints are equal ##
42# operator+=(const SkIVector& v) # adds IVector to IPoint ##
43# operator-=(const SkIVector& v) # subtracts IVector from IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -050044#Table ##
45#Subtopic ##
46
47#Subtopic Member_Functions
48#Table
49#Legend
Cary Clark5081eed2018-01-22 07:55:48 -050050# name # description ##
Cary Clarka560c472017-11-27 10:44:06 -050051#Legend ##
Cary Clark5081eed2018-01-22 07:55:48 -050052# Make # constructs from integer inputs ##
53# equals() # returns true if members are equal ##
54# isZero # returns true if both members equal zero ##
55# set() # sets to integer input ##
56# x() # returns fX ##
57# y() # returns fY ##
Cary Clarka560c472017-11-27 10:44:06 -050058#Table ##
59#Subtopic ##
60
Cary Clark5081eed2018-01-22 07:55:48 -050061#Topic Overview ##
Cary Clarka560c472017-11-27 10:44:06 -050062
63#Member int32_t fX
64x-axis value used by IPoint.
65##
66
67#Member int32_t fY
68y-axis value used by IPoint.
69##
70
71# ------------------------------------------------------------------------------
72
73#Method static constexpr SkIPoint Make(int32_t x, int32_t y)
74
Cary Clarkab2621d2018-01-30 10:08:57 -050075#Line # constructs from integer inputs ##
Cary Clarka560c472017-11-27 10:44:06 -050076Sets fX to x, fY to y.
77
78#Param x integer x-axis value of constructed IPoint ##
79#Param y integer y-axis value of constructed IPoint ##
80
81#Return IPoint (x, y) ##
82
83#Example
84SkIPoint pt1 = {45, 66};
85SkIPoint pt2 = SkIPoint::Make(45, 66);
86SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
87#StdOut
88pt1 == pt2
89##
90##
91
92#SeeAlso set() SkPoint::iset() SkPoint::Make SkIPoint16::Make
93
94#Method ##
95
96# ------------------------------------------------------------------------------
97
98#Method int32_t x() const
99
Cary Clarkab2621d2018-01-30 10:08:57 -0500100#Line # returns fX ##
Cary Clarka560c472017-11-27 10:44:06 -0500101Returns x-axis value of IPoint.
102
103#Return fX ##
104
105#Example
106SkIPoint pt1 = {45, 66};
107SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
108#StdOut
109pt1.fX == pt1.x()
110##
111##
112
113#SeeAlso y() SkPoint::x() SkIPoint16::x()
114
115#Method ##
116
117# ------------------------------------------------------------------------------
118
119#Method int32_t y() const
120
Cary Clarkab2621d2018-01-30 10:08:57 -0500121#Line # returns fY ##
Cary Clarka560c472017-11-27 10:44:06 -0500122Returns y-axis value of IPoint.
123
124#Return fY ##
125
126#Example
127SkIPoint pt1 = {45, 66};
128SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
129#StdOut
130pt1.fY == pt1.y()
131##
132##
133
134#SeeAlso x() SkPoint::y() SkIPoint16::y()
135
136#Method ##
137
138# ------------------------------------------------------------------------------
139
140#Method bool isZero() const
141
Cary Clarkab2621d2018-01-30 10:08:57 -0500142#Line # returns true if both members equal zero ##
Cary Clarka560c472017-11-27 10:44:06 -0500143Returns true if fX and fY are both zero.
144
145#Return true if fX is zero and fY is zero ##
146
147#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500148SkIPoint pt = { 0, -0};
Cary Clarka560c472017-11-27 10:44:06 -0500149SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
150#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500151pt.isZero() == true
Cary Clarka560c472017-11-27 10:44:06 -0500152##
153##
154
155#SeeAlso SkPoint::isZero
156
157#Method ##
158
159# ------------------------------------------------------------------------------
160
161#Method void set(int32_t x, int32_t y)
162
Cary Clarkab2621d2018-01-30 10:08:57 -0500163#Line # sets to integer input ##
Cary Clarka560c472017-11-27 10:44:06 -0500164Sets fX to x and fY to y.
165
166#Param x new value for fX ##
167#Param y new value for fY ##
168
169#Example
170SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 };
171pt1.set(SK_MinS32, SK_MaxS32);
172SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
173#StdOut
174pt1 == pt2
175##
176##
177
178#SeeAlso Make SkIPoint16::set
179
180#Method ##
181
182# ------------------------------------------------------------------------------
183
184#Method SkIPoint operator-()_const
185
Cary Clarkab2621d2018-01-30 10:08:57 -0500186#Line # reverses sign of IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500187Returns IPoint changing the signs of fX and fY.
188
189#Return IPoint as (-fX, -fY) ##
190
191#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500192SkIPoint test[] = { {0, -0}, {-1, -2},
193 { SK_MaxS32, SK_MinS32 },
194 { SK_NaN32, -SK_NaN32 } };
195for (const SkIPoint& pt : test) {
196 SkIPoint negPt = -pt;
197 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
Cary Clarka560c472017-11-27 10:44:06 -0500198}
199#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500200pt: 0, 0 negate: 0, 0
201pt: -1, -2 negate: 1, 2
202pt: 2147483647, -2147483647 negate: -2147483647, 2147483647
Cary Clarka560c472017-11-27 10:44:06 -0500203pt: -2147483648, -2147483648 negate: -2147483648, -2147483648
204##
205##
206
207#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const
208
209#Method ##
210
211# ------------------------------------------------------------------------------
212
213#Method void operator+=(const SkIVector& v)
214
Cary Clarkab2621d2018-01-30 10:08:57 -0500215#Line # adds IVector to IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500216Offsets IPoint by IVector v. Sets IPoint to
217#Formula
218(fX + v.fX, fY + v.fY)
219##
220.
221
222#Param v IVector to add ##
223
224#Example
225#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500226 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
227 for (size_t i = 0; i < count - 1; ++i) {
228 SkPoint p0, p1;
229 p0.iset(pts[i]);
230 p1.iset(pts[i + 1]);
231 canvas->drawLine(p0, p1, paint);
232 }
233 };
234 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
235 SkPaint paint;
236 paint.setAntiAlias(true);
237 paint.setStyle(SkPaint::kStroke_Style);
238 canvas->scale(30, 15);
239 draw_lines(points, SK_ARRAY_COUNT(points), paint);
240 points[1] += {1, 1};
241 points[2] += {-1, -1};
242 paint.setColor(SK_ColorRED);
243 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500244##
245
246#SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v)
247
248#Method ##
249
250# ------------------------------------------------------------------------------
251
252#Method void operator-=(const SkIVector& v)
253
Cary Clarkab2621d2018-01-30 10:08:57 -0500254#Line # subtracts IVector from IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500255Subtracts IVector v from IPoint. Sets IPoint to:
256#Formula
257(fX - v.fX, fY - v.fY)
258##
259.
260
261#Param v IVector to subtract ##
262
263#Example
264#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500265 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
266 for (size_t i = 0; i < count - 1; ++i) {
267 SkPoint p0, p1;
268 p0.iset(pts[i]);
269 p1.iset(pts[i + 1]);
270 canvas->drawLine(p0, p1, paint);
271 }
272 };
273 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
274 SkPaint paint;
275 paint.setAntiAlias(true);
276 paint.setStyle(SkPaint::kStroke_Style);
277 canvas->scale(30, 15);
278 draw_lines(points, SK_ARRAY_COUNT(points), paint);
279 points[1] -= {1, 1};
280 points[2] -= {-1, -1};
281 paint.setColor(SK_ColorRED);
282 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500283##
284
285#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v)
286
287#Method ##
288
289# ------------------------------------------------------------------------------
290
291#Method bool equals(int32_t x, int32_t y) const
292
Cary Clarkab2621d2018-01-30 10:08:57 -0500293#Line # returns true if members are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500294Returns true if IPoint is equivalent to IPoint constructed from (x, y).
295
296#Param x value compared with fX ##
297#Param y value compared with fY ##
298
299#Return true if IPoint equals (x, y) ##
300
301#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500302SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
303for (const SkIPoint& pt : test) {
304 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500305}
306#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500307pt: 0, 0 == pt
308pt: -1, -2 == pt
309pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500310pt: -2147483648, -1 == pt
311##
312##
313
314#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b)
315
316#Method ##
317
318# ------------------------------------------------------------------------------
319
320#Method bool operator==(const SkIPoint& a, const SkIPoint& b)
321
Cary Clarkab2621d2018-01-30 10:08:57 -0500322#Line # returns true if IPoints are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500323Returns true if a is equivalent to b.
324
325#Param a IPoint to compare ##
326#Param b IPoint to compare ##
327
328#Return true if a.fX == b.fX and a.fY == b.fY ##
329
330#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500331SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
332for (const SkIPoint& pt : test) {
333 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500334}
335#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500336pt: 0, 0 == pt
337pt: -1, -2 == pt
338pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500339pt: -2147483648, -1 == pt
340##
341##
342
343#SeeAlso equals() operator!=(const SkIPoint& a, const SkIPoint& b)
344
345#Method ##
346
347# ------------------------------------------------------------------------------
348
349#Method bool operator!=(const SkIPoint& a, const SkIPoint& b)
350
Cary Clarkab2621d2018-01-30 10:08:57 -0500351#Line # returns true if IPoints are unequal ##
Cary Clarka560c472017-11-27 10:44:06 -0500352Returns true if a is not equivalent to b.
353
354#Param a IPoint to compare ##
355#Param b IPoint to compare ##
356
357#Return true if a.fX != b.fX or a.fY != b.fY ##
358
359#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500360SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
361for (const SkIPoint& pt : test) {
362 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
Cary Clarka560c472017-11-27 10:44:06 -0500363}
364#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500365pt: 0, 0 == pt
366pt: -1, -2 == pt
367pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500368pt: -2147483648, -1 == pt
369##
370##
371
372#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) equals()
373
374#Method ##
375
376# ------------------------------------------------------------------------------
377
378#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)
379
Cary Clarkab2621d2018-01-30 10:08:57 -0500380#Line # returns IVector between IPoints ##
Cary Clarka560c472017-11-27 10:44:06 -0500381Returns IVector from b to a; computed as
382#Formula
383(a.fX - b.fX, a.fY - b.fY)
384##
385.
386
387Can also be used to subtract IVector from IVector, returning IVector.
388
389#Param a IPoint or IVector to subtract from ##
390#Param b IVector to subtract ##
391
392#Return IVector from b to a ##
393
394#Example
395#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500396 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
397 for (size_t i = 0; i < count - 1; ++i) {
398 SkPoint p0, p1;
399 p0.iset(pts[i]);
400 p1.iset(pts[i + 1]);
401 canvas->drawLine(p0, p1, paint);
402 }
403 };
404 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
405 SkPaint paint;
406 paint.setAntiAlias(true);
407 paint.setStyle(SkPaint::kStroke_Style);
408 canvas->scale(30, 15);
409 draw_lines(points, SK_ARRAY_COUNT(points), paint);
410 points[1] += points[0] - points[3];
411 points[2] -= points[1] - points[0];
412 paint.setColor(SK_ColorRED);
413 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500414##
415
416#SeeAlso operator-=(const SkIVector& v)
417
418#Method ##
419
420# ------------------------------------------------------------------------------
421
422#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)
423
Cary Clarkab2621d2018-01-30 10:08:57 -0500424#Line # returns IPoint offset by IVector ##
Cary Clarka560c472017-11-27 10:44:06 -0500425Returns IPoint resulting from IPoint a offset by IVector b, computed as:
426#Formula
427(a.fX + b.fX, a.fY + b.fY)
428##
429.
430
431Can also be used to offset IPoint b by IVector a, returning IPoint.
432Can also be used to add IVector to IVector, returning IVector.
433
434#Param a IPoint or IVector to add to ##
435#Param b IPoint or IVector to add ##
436
437#Return IPoint equal to a offset by b ##
438
439#Example
440#Height 128
Cary Clark0c5f5462017-12-15 11:21:51 -0500441 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
442 for (size_t i = 0; i < count - 1; ++i) {
443 SkPoint p0, p1;
444 p0.iset(pts[i]);
445 p1.iset(pts[i + 1]);
446 canvas->drawLine(p0, p1, paint);
447 }
448 };
449 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
450 SkPaint paint;
451 paint.setAntiAlias(true);
452 paint.setStyle(SkPaint::kStroke_Style);
453 canvas->scale(30, 15);
454 draw_lines(points, SK_ARRAY_COUNT(points), paint);
455 SkIPoint mod = {4, 1};
456 for (auto& point : points) {
457 point = point + mod;
458 mod.fX -= 1;
459 mod.fY += 1;
460 }
461 paint.setColor(SK_ColorRED);
462 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500463##
464
465#SeeAlso operator+=(const SkIVector& v)
466
467#Method ##
468
469#Struct SkIPoint ##
470
471#Topic IPoint ##
472
473#Topic IVector
474 #Alias IVectors
475 #Typedef SkIPoint SkIVector
476 #Typedef ##
477##