blob: 5f8f5422e82e0ff2e58fe29cdd58eb6a89af23f5 [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 Clark61313f32018-10-08 14:57:48 -04007#Code
8#Populate
9##
10
Cary Clark682c58d2018-05-16 07:07:07 -040011SkIPoint holds two 32-bit integer coordinates.
12
Cary Clarka560c472017-11-27 10:44:06 -050013#Member int32_t fX
Cary Clark08895c42018-02-01 09:37:32 -050014#Line # x-axis value ##
Cary Clarka560c472017-11-27 10:44:06 -050015x-axis value used by IPoint.
16##
17
18#Member int32_t fY
Cary Clark08895c42018-02-01 09:37:32 -050019#Line # y-axis value ##
Cary Clarka560c472017-11-27 10:44:06 -050020y-axis value used by IPoint.
21##
22
23# ------------------------------------------------------------------------------
24
25#Method static constexpr SkIPoint Make(int32_t x, int32_t y)
26
Cary Clark61313f32018-10-08 14:57:48 -040027#In Constructors
Cary Clarkab2621d2018-01-30 10:08:57 -050028#Line # constructs from integer inputs ##
Cary Clark09d80c02018-10-31 12:14:03 -040029#Populate
Cary Clarka560c472017-11-27 10:44:06 -050030
31#Example
32SkIPoint pt1 = {45, 66};
33SkIPoint pt2 = SkIPoint::Make(45, 66);
34SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
35#StdOut
36pt1 == pt2
37##
38##
39
Mike Reed1fda0242018-04-04 15:39:46 -040040#SeeAlso set() SkPoint::iset() SkPoint::Make
Cary Clarka560c472017-11-27 10:44:06 -050041
42#Method ##
43
Cary Clark61313f32018-10-08 14:57:48 -040044
Cary Clarka560c472017-11-27 10:44:06 -050045# ------------------------------------------------------------------------------
46
Cary Clark4855f782018-02-06 09:41:53 -050047#Subtopic Property
48#Line # member values ##
Cary Clark61313f32018-10-08 14:57:48 -040049#Subtopic Property ##
Cary Clarka560c472017-11-27 10:44:06 -050050
Cary Clark4855f782018-02-06 09:41:53 -050051#Method int32_t x() const
52#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050053#Line # returns fX ##
Cary Clark09d80c02018-10-31 12:14:03 -040054#Populate
Cary Clarka560c472017-11-27 10:44:06 -050055
56#Example
57SkIPoint pt1 = {45, 66};
58SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
59#StdOut
60pt1.fX == pt1.x()
61##
62##
63
Mike Reed1fda0242018-04-04 15:39:46 -040064#SeeAlso y() SkPoint::x()
Cary Clarka560c472017-11-27 10:44:06 -050065
66#Method ##
67
68# ------------------------------------------------------------------------------
69
70#Method int32_t y() const
Cary Clark4855f782018-02-06 09:41:53 -050071#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050072#Line # returns fY ##
Cary Clark09d80c02018-10-31 12:14:03 -040073#Populate
Cary Clarka560c472017-11-27 10:44:06 -050074
75#Example
76SkIPoint pt1 = {45, 66};
77SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
78#StdOut
79pt1.fY == pt1.y()
80##
81##
82
Mike Reed1fda0242018-04-04 15:39:46 -040083#SeeAlso x() SkPoint::y()
Cary Clarka560c472017-11-27 10:44:06 -050084
85#Method ##
86
87# ------------------------------------------------------------------------------
88
89#Method bool isZero() const
Cary Clark4855f782018-02-06 09:41:53 -050090#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050091#Line # returns true if both members equal zero ##
Cary Clark09d80c02018-10-31 12:14:03 -040092#Populate
Cary Clarka560c472017-11-27 10:44:06 -050093
94#Example
Cary Clark0c5f5462017-12-15 11:21:51 -050095SkIPoint pt = { 0, -0};
Cary Clarka560c472017-11-27 10:44:06 -050096SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
97#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -050098pt.isZero() == true
Cary Clarka560c472017-11-27 10:44:06 -050099##
100##
101
102#SeeAlso SkPoint::isZero
103
104#Method ##
105
106# ------------------------------------------------------------------------------
107
Cary Clark4855f782018-02-06 09:41:53 -0500108#Subtopic Set
Cary Clark4855f782018-02-06 09:41:53 -0500109#Line # replaces all values ##
110##
Cary Clarka560c472017-11-27 10:44:06 -0500111
Cary Clark4855f782018-02-06 09:41:53 -0500112#Method void set(int32_t x, int32_t y)
113#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500114#Line # sets to integer input ##
Cary Clark09d80c02018-10-31 12:14:03 -0400115#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500116
117#Example
118SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 };
119pt1.set(SK_MinS32, SK_MaxS32);
120SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
121#StdOut
122pt1 == pt2
123##
124##
125
Mike Reed1fda0242018-04-04 15:39:46 -0400126#SeeAlso Make
Cary Clarka560c472017-11-27 10:44:06 -0500127
128#Method ##
129
130# ------------------------------------------------------------------------------
131
132#Method SkIPoint operator-()_const
133
Cary Clarkab2621d2018-01-30 10:08:57 -0500134#Line # reverses sign of IPoint ##
Cary Clark09d80c02018-10-31 12:14:03 -0400135#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500136
137#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500138SkIPoint test[] = { {0, -0}, {-1, -2},
139 { SK_MaxS32, SK_MinS32 },
Cary Clark681287e2018-03-16 11:34:15 -0400140 { SK_NaN32, SK_NaN32 } };
Cary Clark0c5f5462017-12-15 11:21:51 -0500141for (const SkIPoint& pt : test) {
142 SkIPoint negPt = -pt;
143 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
Cary Clarka560c472017-11-27 10:44:06 -0500144}
145#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500146pt: 0, 0 negate: 0, 0
147pt: -1, -2 negate: 1, 2
148pt: 2147483647, -2147483647 negate: -2147483647, 2147483647
Cary Clarka560c472017-11-27 10:44:06 -0500149pt: -2147483648, -2147483648 negate: -2147483648, -2147483648
150##
151##
152
153#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const
154
155#Method ##
156
157# ------------------------------------------------------------------------------
158
159#Method void operator+=(const SkIVector& v)
160
Cary Clarkab2621d2018-01-30 10:08:57 -0500161#Line # adds IVector to IPoint ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400162Offsets IPoint by IVector v. Sets IPoint to #Formula # (fX + v.fX, fY + v.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500163
164#Param v IVector to add ##
165
166#Example
167#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500168 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
169 for (size_t i = 0; i < count - 1; ++i) {
170 SkPoint p0, p1;
171 p0.iset(pts[i]);
172 p1.iset(pts[i + 1]);
173 canvas->drawLine(p0, p1, paint);
174 }
175 };
176 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
177 SkPaint paint;
178 paint.setAntiAlias(true);
179 paint.setStyle(SkPaint::kStroke_Style);
180 canvas->scale(30, 15);
181 draw_lines(points, SK_ARRAY_COUNT(points), paint);
182 points[1] += {1, 1};
183 points[2] += {-1, -1};
184 paint.setColor(SK_ColorRED);
185 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500186##
187
188#SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v)
189
190#Method ##
191
192# ------------------------------------------------------------------------------
193
194#Method void operator-=(const SkIVector& v)
195
Cary Clarkab2621d2018-01-30 10:08:57 -0500196#Line # subtracts IVector from IPoint ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400197Subtracts IVector v from IPoint. Sets IPoint to: #Formula # (fX - v.fX, fY - v.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500198
199#Param v IVector to subtract ##
200
201#Example
202#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500203 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
204 for (size_t i = 0; i < count - 1; ++i) {
205 SkPoint p0, p1;
206 p0.iset(pts[i]);
207 p1.iset(pts[i + 1]);
208 canvas->drawLine(p0, p1, paint);
209 }
210 };
211 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
212 SkPaint paint;
213 paint.setAntiAlias(true);
214 paint.setStyle(SkPaint::kStroke_Style);
215 canvas->scale(30, 15);
216 draw_lines(points, SK_ARRAY_COUNT(points), paint);
217 points[1] -= {1, 1};
218 points[2] -= {-1, -1};
219 paint.setColor(SK_ColorRED);
220 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500221##
222
223#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v)
224
225#Method ##
226
227# ------------------------------------------------------------------------------
228
229#Method bool equals(int32_t x, int32_t y) const
Cary Clark61313f32018-10-08 14:57:48 -0400230#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500231#Line # returns true if members are equal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400232#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500233
234#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500235SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
236for (const SkIPoint& pt : test) {
237 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500238}
239#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500240pt: 0, 0 == pt
241pt: -1, -2 == pt
242pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500243pt: -2147483648, -1 == pt
244##
245##
246
247#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b)
248
249#Method ##
250
251# ------------------------------------------------------------------------------
252
253#Method bool operator==(const SkIPoint& a, const SkIPoint& b)
254
Cary Clarkab2621d2018-01-30 10:08:57 -0500255#Line # returns true if IPoints are equal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400256#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500257
258#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500259SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
260for (const SkIPoint& pt : test) {
261 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500262}
263#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500264pt: 0, 0 == pt
265pt: -1, -2 == pt
266pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500267pt: -2147483648, -1 == pt
268##
269##
270
271#SeeAlso equals() operator!=(const SkIPoint& a, const SkIPoint& b)
272
273#Method ##
274
275# ------------------------------------------------------------------------------
276
277#Method bool operator!=(const SkIPoint& a, const SkIPoint& b)
278
Cary Clarkab2621d2018-01-30 10:08:57 -0500279#Line # returns true if IPoints are unequal ##
Cary Clark09d80c02018-10-31 12:14:03 -0400280#Populate
Cary Clarka560c472017-11-27 10:44:06 -0500281
282#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500283SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
284for (const SkIPoint& pt : test) {
285 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '=');
Cary Clarka560c472017-11-27 10:44:06 -0500286}
287#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500288pt: 0, 0 == pt
289pt: -1, -2 == pt
290pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500291pt: -2147483648, -1 == pt
292##
293##
294
295#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b) equals()
296
297#Method ##
298
299# ------------------------------------------------------------------------------
300
301#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)
302
Cary Clarkab2621d2018-01-30 10:08:57 -0500303#Line # returns IVector between IPoints ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400304Returns IVector from b to a; computed as #Formula # (a.fX - b.fX, a.fY - b.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500305
306Can also be used to subtract IVector from IVector, returning IVector.
307
308#Param a IPoint or IVector to subtract from ##
309#Param b IVector to subtract ##
310
311#Return IVector from b to a ##
312
313#Example
314#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500315 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
316 for (size_t i = 0; i < count - 1; ++i) {
317 SkPoint p0, p1;
318 p0.iset(pts[i]);
319 p1.iset(pts[i + 1]);
320 canvas->drawLine(p0, p1, paint);
321 }
322 };
323 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
324 SkPaint paint;
325 paint.setAntiAlias(true);
326 paint.setStyle(SkPaint::kStroke_Style);
327 canvas->scale(30, 15);
328 draw_lines(points, SK_ARRAY_COUNT(points), paint);
329 points[1] += points[0] - points[3];
330 points[2] -= points[1] - points[0];
331 paint.setColor(SK_ColorRED);
332 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500333##
334
335#SeeAlso operator-=(const SkIVector& v)
336
337#Method ##
338
339# ------------------------------------------------------------------------------
340
341#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)
342
Cary Clarkab2621d2018-01-30 10:08:57 -0500343#Line # returns IPoint offset by IVector ##
Cary Clarka560c472017-11-27 10:44:06 -0500344Returns IPoint resulting from IPoint a offset by IVector b, computed as:
Cary Clark2be81cf2018-09-13 12:04:30 -0400345#Formula # (a.fX + b.fX, a.fY + b.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500346
347Can also be used to offset IPoint b by IVector a, returning IPoint.
348Can also be used to add IVector to IVector, returning IVector.
349
350#Param a IPoint or IVector to add to ##
351#Param b IPoint or IVector to add ##
352
353#Return IPoint equal to a offset by b ##
354
355#Example
356#Height 128
Cary Clark0c5f5462017-12-15 11:21:51 -0500357 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
358 for (size_t i = 0; i < count - 1; ++i) {
359 SkPoint p0, p1;
360 p0.iset(pts[i]);
361 p1.iset(pts[i + 1]);
362 canvas->drawLine(p0, p1, paint);
363 }
364 };
365 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
366 SkPaint paint;
367 paint.setAntiAlias(true);
368 paint.setStyle(SkPaint::kStroke_Style);
369 canvas->scale(30, 15);
370 draw_lines(points, SK_ARRAY_COUNT(points), paint);
371 SkIPoint mod = {4, 1};
372 for (auto& point : points) {
373 point = point + mod;
374 mod.fX -= 1;
375 mod.fY += 1;
376 }
377 paint.setColor(SK_ColorRED);
378 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500379##
380
381#SeeAlso operator+=(const SkIVector& v)
382
383#Method ##
384
385#Struct SkIPoint ##
386
Cary Clarka560c472017-11-27 10:44:06 -0500387
Cary Clark682c58d2018-05-16 07:07:07 -0400388#Subtopic IVector
389#Line # alias for IPoint ##
Cary Clark137b8742018-05-30 09:21:49 -0400390 #Alias IVector ##
391 #Alias IVectors ##
Cary Clarka560c472017-11-27 10:44:06 -0500392 #Typedef SkIPoint SkIVector
Cary Clark682c58d2018-05-16 07:07:07 -0400393 #Line # alias for IPoint ##
394 #Code
395 typedef SkIPoint SkIVector;
396 ##
397 SkIVector provides an alternative name for SkIPoint. SkIVector and SkIPoint
Cary Clark137b8742018-05-30 09:21:49 -0400398 can be used interchangeably for all purposes.
Cary Clarka560c472017-11-27 10:44:06 -0500399 #Typedef ##
400##
Cary Clark682c58d2018-05-16 07:07:07 -0400401
402#Topic IPoint ##