blob: 178a14f2c3d85f34d57273d6c41f5ab1324bf9c5 [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
7SkIPoint holds two 32 bit integer coordinates
8
9#Topic Overview
10
11#Subtopic Subtopics
12#ToDo manually add subtopics ##
13#Table
14#Legend
15# topics # description ##
16#Legend ##
17#Table ##
18##
19
20#Subtopic Operators
21#Table
22#Legend
23# description # function ##
24#Legend ##
25# SkIPoint operator-()_const # Reverses sign of IPoint. ##
26# SkIPoint operator+(const SkIPoint& a, const SkIVector& b) # Returns IPoint offset by IVector. ##
27# SkIVector operator-(const SkIPoint& a, const SkIPoint& b) # Returns IVector between IPoints. ##
28# bool operator!=(const SkIPoint& a, const SkIPoint& b) # Returns true if IPoints are unequal. ##
29# bool operator==(const SkIPoint& a, const SkIPoint& b) # Returns true if IPoints are equal. ##
30# void operator+=(const SkIVector& v) # Adds IVector to IPoint. ##
31# void operator-=(const SkIVector& v) # Subtracts IVector from IPoint. ##
32#Table ##
33#Subtopic ##
34
35#Subtopic Member_Functions
36#Table
37#Legend
38# description # function ##
39#Legend ##
40# Make # Constructs from integer inputs. ##
41# equals() # Returns true if members are equal. ##
42# isZero # Returns true if both members equal zero. ##
43# set() # Sets to integer input. ##
44# x() # Returns fX. ##
45# y() # Returns fY. ##
46#Table ##
47#Subtopic ##
48
49#Topic ##
50
51#Member int32_t fX
52x-axis value used by IPoint.
53##
54
55#Member int32_t fY
56y-axis value used by IPoint.
57##
58
59# ------------------------------------------------------------------------------
60
61#Method static constexpr SkIPoint Make(int32_t x, int32_t y)
62
63Sets fX to x, fY to y.
64
65#Param x integer x-axis value of constructed IPoint ##
66#Param y integer y-axis value of constructed IPoint ##
67
68#Return IPoint (x, y) ##
69
70#Example
71SkIPoint pt1 = {45, 66};
72SkIPoint pt2 = SkIPoint::Make(45, 66);
73SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
74#StdOut
75pt1 == pt2
76##
77##
78
79#SeeAlso set() SkPoint::iset() SkPoint::Make SkIPoint16::Make
80
81#Method ##
82
83# ------------------------------------------------------------------------------
84
85#Method int32_t x() const
86
87Returns x-axis value of IPoint.
88
89#Return fX ##
90
91#Example
92SkIPoint pt1 = {45, 66};
93SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
94#StdOut
95pt1.fX == pt1.x()
96##
97##
98
99#SeeAlso y() SkPoint::x() SkIPoint16::x()
100
101#Method ##
102
103# ------------------------------------------------------------------------------
104
105#Method int32_t y() const
106
107Returns y-axis value of IPoint.
108
109#Return fY ##
110
111#Example
112SkIPoint pt1 = {45, 66};
113SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
114#StdOut
115pt1.fY == pt1.y()
116##
117##
118
119#SeeAlso x() SkPoint::y() SkIPoint16::y()
120
121#Method ##
122
123# ------------------------------------------------------------------------------
124
125#Method bool isZero() const
126
127Returns true if fX and fY are both zero.
128
129#Return true if fX is zero and fY is zero ##
130
131#Example
132SkIPoint pt = { 0, -0};
133SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
134#StdOut
135pt.isZero() == true
136##
137##
138
139#SeeAlso SkPoint::isZero
140
141#Method ##
142
143# ------------------------------------------------------------------------------
144
145#Method void set(int32_t x, int32_t y)
146
147Sets fX to x and fY to y.
148
149#Param x new value for fX ##
150#Param y new value for fY ##
151
152#Example
153SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 };
154pt1.set(SK_MinS32, SK_MaxS32);
155SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
156#StdOut
157pt1 == pt2
158##
159##
160
161#SeeAlso Make SkIPoint16::set
162
163#Method ##
164
165# ------------------------------------------------------------------------------
166
167#Method SkIPoint operator-()_const
168
169Returns IPoint changing the signs of fX and fY.
170
171#Return IPoint as (-fX, -fY) ##
172
173#Example
174SkIPoint test[] = { {0, -0}, {-1, -2},
175 { SK_MaxS32, SK_MinS32 },
176 { SK_NaN32, -SK_NaN32 } };
177for (const SkIPoint& pt : test) {
178 SkIPoint negPt = -pt;
179 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
180}
181#StdOut
182pt: 0, 0 negate: 0, 0
183pt: -1, -2 negate: 1, 2
184pt: 2147483647, -2147483647 negate: -2147483647, 2147483647
185pt: -2147483648, -2147483648 negate: -2147483648, -2147483648
186##
187##
188
189#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const
190
191#Method ##
192
193# ------------------------------------------------------------------------------
194
195#Method void operator+=(const SkIVector& v)
196
197Offsets IPoint by IVector v. Sets IPoint to
198#Formula
199(fX + v.fX, fY + v.fY)
200##
201.
202
203#Param v IVector to add ##
204
205#Example
206#Height 64
207 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
208 for (size_t i = 0; i < count - 1; ++i) {
209 SkPoint p0, p1;
210 p0.iset(pts[i]);
211 p1.iset(pts[i + 1]);
212 canvas->drawLine(p0, p1, paint);
213 }
214 };
215 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
216 SkPaint paint;
217 paint.setAntiAlias(true);
218 paint.setStyle(SkPaint::kStroke_Style);
219 canvas->scale(30, 15);
220 draw_lines(points, SK_ARRAY_COUNT(points), paint);
221 points[1] += {1, 1};
222 points[2] += {-1, -1};
223 paint.setColor(SK_ColorRED);
224 draw_lines(points, SK_ARRAY_COUNT(points), paint);
225##
226
227#SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v)
228
229#Method ##
230
231# ------------------------------------------------------------------------------
232
233#Method void operator-=(const SkIVector& v)
234
235Subtracts IVector v from IPoint. Sets IPoint to:
236#Formula
237(fX - v.fX, fY - v.fY)
238##
239.
240
241#Param v IVector to subtract ##
242
243#Example
244#Height 64
245 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
246 for (size_t i = 0; i < count - 1; ++i) {
247 SkPoint p0, p1;
248 p0.iset(pts[i]);
249 p1.iset(pts[i + 1]);
250 canvas->drawLine(p0, p1, paint);
251 }
252 };
253 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
254 SkPaint paint;
255 paint.setAntiAlias(true);
256 paint.setStyle(SkPaint::kStroke_Style);
257 canvas->scale(30, 15);
258 draw_lines(points, SK_ARRAY_COUNT(points), paint);
259 points[1] -= {1, 1};
260 points[2] -= {-1, -1};
261 paint.setColor(SK_ColorRED);
262 draw_lines(points, SK_ARRAY_COUNT(points), paint);
263##
264
265#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v)
266
267#Method ##
268
269# ------------------------------------------------------------------------------
270
271#Method bool equals(int32_t x, int32_t y) const
272
273Returns true if IPoint is equivalent to IPoint constructed from (x, y).
274
275#Param x value compared with fX ##
276#Param y value compared with fY ##
277
278#Return true if IPoint equals (x, y) ##
279
280#Example
281SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
282for (const SkIPoint& pt : test) {
283 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
284}
285#StdOut
286pt: 0, 0 == pt
287pt: -1, -2 == pt
288pt: 2147483647, -1 == pt
289pt: -2147483648, -1 == pt
290##
291##
292
293#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b)
294
295#Method ##
296
297# ------------------------------------------------------------------------------
298
299#Method bool operator==(const SkIPoint& a, const SkIPoint& b)
300
301Returns true if a is equivalent to b.
302
303#Param a IPoint to compare ##
304#Param b IPoint to compare ##
305
306#Return true if a.fX == b.fX and a.fY == b.fY ##
307
308#Example
309SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
310for (const SkIPoint& pt : test) {
311 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
312}
313#StdOut
314pt: 0, 0 == pt
315pt: -1, -2 == pt
316pt: 2147483647, -1 == pt
317pt: -2147483648, -1 == pt
318##
319##
320
321#SeeAlso equals() operator!=(const SkIPoint& a, const SkIPoint& b)
322
323#Method ##
324
325# ------------------------------------------------------------------------------
326
327#Method bool operator!=(const SkIPoint& a, const SkIPoint& b)
328
329Returns true if a is not equivalent to b.
330
331#Param a IPoint to compare ##
332#Param b IPoint to compare ##
333
334#Return true if a.fX != b.fX or a.fY != b.fY ##
335
336#Example
337SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
338for (const SkIPoint& pt : test) {
339 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
340}
341#StdOut
342pt: 0, 0 == pt
343pt: -1, -2 == pt
344pt: 2147483647, -1 == pt
345pt: -2147483648, -1 == pt
346##
347##
348
349#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) equals()
350
351#Method ##
352
353# ------------------------------------------------------------------------------
354
355#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)
356
357Returns IVector from b to a; computed as
358#Formula
359(a.fX - b.fX, a.fY - b.fY)
360##
361.
362
363Can also be used to subtract IVector from IVector, returning IVector.
364
365#Param a IPoint or IVector to subtract from ##
366#Param b IVector to subtract ##
367
368#Return IVector from b to a ##
369
370#Example
371#Height 64
372 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
373 for (size_t i = 0; i < count - 1; ++i) {
374 SkPoint p0, p1;
375 p0.iset(pts[i]);
376 p1.iset(pts[i + 1]);
377 canvas->drawLine(p0, p1, paint);
378 }
379 };
380 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
381 SkPaint paint;
382 paint.setAntiAlias(true);
383 paint.setStyle(SkPaint::kStroke_Style);
384 canvas->scale(30, 15);
385 draw_lines(points, SK_ARRAY_COUNT(points), paint);
386 points[1] += points[0] - points[3];
387 points[2] -= points[1] - points[0];
388 paint.setColor(SK_ColorRED);
389 draw_lines(points, SK_ARRAY_COUNT(points), paint);
390##
391
392#SeeAlso operator-=(const SkIVector& v)
393
394#Method ##
395
396# ------------------------------------------------------------------------------
397
398#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)
399
400Returns IPoint resulting from IPoint a offset by IVector b, computed as:
401#Formula
402(a.fX + b.fX, a.fY + b.fY)
403##
404.
405
406Can also be used to offset IPoint b by IVector a, returning IPoint.
407Can also be used to add IVector to IVector, returning IVector.
408
409#Param a IPoint or IVector to add to ##
410#Param b IPoint or IVector to add ##
411
412#Return IPoint equal to a offset by b ##
413
414#Example
415#Height 128
416 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
417 for (size_t i = 0; i < count - 1; ++i) {
418 SkPoint p0, p1;
419 p0.iset(pts[i]);
420 p1.iset(pts[i + 1]);
421 canvas->drawLine(p0, p1, paint);
422 }
423 };
424 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
425 SkPaint paint;
426 paint.setAntiAlias(true);
427 paint.setStyle(SkPaint::kStroke_Style);
428 canvas->scale(30, 15);
429 draw_lines(points, SK_ARRAY_COUNT(points), paint);
430 SkIPoint mod = {4, 1};
431 for (auto& point : points) {
432 point = point + mod;
433 mod.fX -= 1;
434 mod.fY += 1;
435 }
436 paint.setColor(SK_ColorRED);
437 draw_lines(points, SK_ARRAY_COUNT(points), paint);
438##
439
440#SeeAlso operator+=(const SkIVector& v)
441
442#Method ##
443
444#Struct SkIPoint ##
445
446#Topic IPoint ##
447
448#Topic IVector
449 #Alias IVectors
450 #Typedef SkIPoint SkIVector
451 #Typedef ##
452##