blob: c7ba27f08a469e29eb01e22ed6d6f9921103901f [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 Clarka560c472017-11-27 10:44:06 -050029Sets fX to x, fY to y.
30
31#Param x integer x-axis value of constructed IPoint ##
32#Param y integer y-axis value of constructed IPoint ##
33
34#Return IPoint (x, y) ##
35
36#Example
37SkIPoint pt1 = {45, 66};
38SkIPoint pt2 = SkIPoint::Make(45, 66);
39SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
40#StdOut
41pt1 == pt2
42##
43##
44
Mike Reed1fda0242018-04-04 15:39:46 -040045#SeeAlso set() SkPoint::iset() SkPoint::Make
Cary Clarka560c472017-11-27 10:44:06 -050046
47#Method ##
48
Cary Clark61313f32018-10-08 14:57:48 -040049
Cary Clarka560c472017-11-27 10:44:06 -050050# ------------------------------------------------------------------------------
51
Cary Clark4855f782018-02-06 09:41:53 -050052#Subtopic Property
53#Line # member values ##
Cary Clark61313f32018-10-08 14:57:48 -040054#Subtopic Property ##
Cary Clarka560c472017-11-27 10:44:06 -050055
Cary Clark4855f782018-02-06 09:41:53 -050056#Method int32_t x() const
57#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050058#Line # returns fX ##
Cary Clarka560c472017-11-27 10:44:06 -050059Returns x-axis value of IPoint.
60
61#Return fX ##
62
63#Example
64SkIPoint pt1 = {45, 66};
65SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!');
66#StdOut
67pt1.fX == pt1.x()
68##
69##
70
Mike Reed1fda0242018-04-04 15:39:46 -040071#SeeAlso y() SkPoint::x()
Cary Clarka560c472017-11-27 10:44:06 -050072
73#Method ##
74
75# ------------------------------------------------------------------------------
76
77#Method int32_t y() const
Cary Clark4855f782018-02-06 09:41:53 -050078#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -050079#Line # returns fY ##
Cary Clarka560c472017-11-27 10:44:06 -050080Returns y-axis value of IPoint.
81
82#Return fY ##
83
84#Example
85SkIPoint pt1 = {45, 66};
86SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!');
87#StdOut
88pt1.fY == pt1.y()
89##
90##
91
Mike Reed1fda0242018-04-04 15:39:46 -040092#SeeAlso x() SkPoint::y()
Cary Clarka560c472017-11-27 10:44:06 -050093
94#Method ##
95
96# ------------------------------------------------------------------------------
97
98#Method bool isZero() const
Cary Clark4855f782018-02-06 09:41:53 -050099#In Property
Cary Clarkab2621d2018-01-30 10:08:57 -0500100#Line # returns true if both members equal zero ##
Cary Clarka560c472017-11-27 10:44:06 -0500101Returns true if fX and fY are both zero.
102
103#Return true if fX is zero and fY is zero ##
104
105#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500106SkIPoint pt = { 0, -0};
Cary Clarka560c472017-11-27 10:44:06 -0500107SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false");
108#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500109pt.isZero() == true
Cary Clarka560c472017-11-27 10:44:06 -0500110##
111##
112
113#SeeAlso SkPoint::isZero
114
115#Method ##
116
117# ------------------------------------------------------------------------------
118
Cary Clark4855f782018-02-06 09:41:53 -0500119#Subtopic Set
Cary Clark4855f782018-02-06 09:41:53 -0500120#Line # replaces all values ##
121##
Cary Clarka560c472017-11-27 10:44:06 -0500122
Cary Clark4855f782018-02-06 09:41:53 -0500123#Method void set(int32_t x, int32_t y)
124#In Set
Cary Clarkab2621d2018-01-30 10:08:57 -0500125#Line # sets to integer input ##
Cary Clarka560c472017-11-27 10:44:06 -0500126Sets fX to x and fY to y.
127
128#Param x new value for fX ##
129#Param y new value for fY ##
130
131#Example
132SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 };
133pt1.set(SK_MinS32, SK_MaxS32);
134SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!');
135#StdOut
136pt1 == pt2
137##
138##
139
Mike Reed1fda0242018-04-04 15:39:46 -0400140#SeeAlso Make
Cary Clarka560c472017-11-27 10:44:06 -0500141
142#Method ##
143
144# ------------------------------------------------------------------------------
145
146#Method SkIPoint operator-()_const
147
Cary Clarkab2621d2018-01-30 10:08:57 -0500148#Line # reverses sign of IPoint ##
Cary Clarka560c472017-11-27 10:44:06 -0500149Returns IPoint changing the signs of fX and fY.
150
151#Return IPoint as (-fX, -fY) ##
152
153#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500154SkIPoint test[] = { {0, -0}, {-1, -2},
155 { SK_MaxS32, SK_MinS32 },
Cary Clark681287e2018-03-16 11:34:15 -0400156 { SK_NaN32, SK_NaN32 } };
Cary Clark0c5f5462017-12-15 11:21:51 -0500157for (const SkIPoint& pt : test) {
158 SkIPoint negPt = -pt;
159 SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY);
Cary Clarka560c472017-11-27 10:44:06 -0500160}
161#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500162pt: 0, 0 negate: 0, 0
163pt: -1, -2 negate: 1, 2
164pt: 2147483647, -2147483647 negate: -2147483647, 2147483647
Cary Clarka560c472017-11-27 10:44:06 -0500165pt: -2147483648, -2147483648 negate: -2147483648, -2147483648
166##
167##
168
169#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) operator-=(const SkIVector& v) SkPoint::operator-()_const
170
171#Method ##
172
173# ------------------------------------------------------------------------------
174
175#Method void operator+=(const SkIVector& v)
176
Cary Clarkab2621d2018-01-30 10:08:57 -0500177#Line # adds IVector to IPoint ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400178Offsets IPoint by IVector v. Sets IPoint to #Formula # (fX + v.fX, fY + v.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500179
180#Param v IVector to add ##
181
182#Example
183#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500184 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
185 for (size_t i = 0; i < count - 1; ++i) {
186 SkPoint p0, p1;
187 p0.iset(pts[i]);
188 p1.iset(pts[i + 1]);
189 canvas->drawLine(p0, p1, paint);
190 }
191 };
192 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
193 SkPaint paint;
194 paint.setAntiAlias(true);
195 paint.setStyle(SkPaint::kStroke_Style);
196 canvas->scale(30, 15);
197 draw_lines(points, SK_ARRAY_COUNT(points), paint);
198 points[1] += {1, 1};
199 points[2] += {-1, -1};
200 paint.setColor(SK_ColorRED);
201 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500202##
203
204#SeeAlso operator+(const SkIPoint& a, const SkIVector& b) SkPoint::operator+=(const SkVector& v)
205
206#Method ##
207
208# ------------------------------------------------------------------------------
209
210#Method void operator-=(const SkIVector& v)
211
Cary Clarkab2621d2018-01-30 10:08:57 -0500212#Line # subtracts IVector from IPoint ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400213Subtracts IVector v from IPoint. Sets IPoint to: #Formula # (fX - v.fX, fY - v.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500214
215#Param v IVector to subtract ##
216
217#Example
218#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500219 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
220 for (size_t i = 0; i < count - 1; ++i) {
221 SkPoint p0, p1;
222 p0.iset(pts[i]);
223 p1.iset(pts[i + 1]);
224 canvas->drawLine(p0, p1, paint);
225 }
226 };
227 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
228 SkPaint paint;
229 paint.setAntiAlias(true);
230 paint.setStyle(SkPaint::kStroke_Style);
231 canvas->scale(30, 15);
232 draw_lines(points, SK_ARRAY_COUNT(points), paint);
233 points[1] -= {1, 1};
234 points[2] -= {-1, -1};
235 paint.setColor(SK_ColorRED);
236 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500237##
238
239#SeeAlso operator-(const SkIPoint& a, const SkIPoint& b) SkPoint::operator-=(const SkVector& v)
240
241#Method ##
242
243# ------------------------------------------------------------------------------
244
245#Method bool equals(int32_t x, int32_t y) const
Cary Clark61313f32018-10-08 14:57:48 -0400246#In Operators
Cary Clarkab2621d2018-01-30 10:08:57 -0500247#Line # returns true if members are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500248Returns true if IPoint is equivalent to IPoint constructed from (x, y).
249
250#Param x value compared with fX ##
251#Param y value compared with fY ##
252
253#Return true if IPoint equals (x, y) ##
254
255#Example
Cary Clark0c5f5462017-12-15 11:21:51 -0500256SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} };
257for (const SkIPoint& pt : test) {
258 SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!');
Cary Clarka560c472017-11-27 10:44:06 -0500259}
260#StdOut
Cary Clark0c5f5462017-12-15 11:21:51 -0500261pt: 0, 0 == pt
262pt: -1, -2 == pt
263pt: 2147483647, -1 == pt
Cary Clarka560c472017-11-27 10:44:06 -0500264pt: -2147483648, -1 == pt
265##
266##
267
268#SeeAlso operator==(const SkIPoint& a, const SkIPoint& b)
269
270#Method ##
271
272# ------------------------------------------------------------------------------
273
274#Method bool operator==(const SkIPoint& a, const SkIPoint& b)
275
Cary Clarkab2621d2018-01-30 10:08:57 -0500276#Line # returns true if IPoints are equal ##
Cary Clarka560c472017-11-27 10:44:06 -0500277Returns true if a is equivalent to b.
278
279#Param a IPoint to compare ##
280#Param b IPoint to compare ##
281
282#Return true if a.fX == b.fX and a.fY == b.fY ##
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 == pt ? '=' : '!');
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 equals() 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 unequal ##
Cary Clarka560c472017-11-27 10:44:06 -0500306Returns true if a is not 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 or 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 operator==(const SkIPoint& a, const SkIPoint& b) equals()
327
328#Method ##
329
330# ------------------------------------------------------------------------------
331
332#Method SkIVector operator-(const SkIPoint& a, const SkIPoint& b)
333
Cary Clarkab2621d2018-01-30 10:08:57 -0500334#Line # returns IVector between IPoints ##
Cary Clark2be81cf2018-09-13 12:04:30 -0400335Returns IVector from b to a; computed as #Formula # (a.fX - b.fX, a.fY - b.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500336
337Can also be used to subtract IVector from IVector, returning IVector.
338
339#Param a IPoint or IVector to subtract from ##
340#Param b IVector to subtract ##
341
342#Return IVector from b to a ##
343
344#Example
345#Height 64
Cary Clark0c5f5462017-12-15 11:21:51 -0500346 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
347 for (size_t i = 0; i < count - 1; ++i) {
348 SkPoint p0, p1;
349 p0.iset(pts[i]);
350 p1.iset(pts[i + 1]);
351 canvas->drawLine(p0, p1, paint);
352 }
353 };
354 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
355 SkPaint paint;
356 paint.setAntiAlias(true);
357 paint.setStyle(SkPaint::kStroke_Style);
358 canvas->scale(30, 15);
359 draw_lines(points, SK_ARRAY_COUNT(points), paint);
360 points[1] += points[0] - points[3];
361 points[2] -= points[1] - points[0];
362 paint.setColor(SK_ColorRED);
363 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500364##
365
366#SeeAlso operator-=(const SkIVector& v)
367
368#Method ##
369
370# ------------------------------------------------------------------------------
371
372#Method SkIPoint operator+(const SkIPoint& a, const SkIVector& b)
373
Cary Clarkab2621d2018-01-30 10:08:57 -0500374#Line # returns IPoint offset by IVector ##
Cary Clarka560c472017-11-27 10:44:06 -0500375Returns IPoint resulting from IPoint a offset by IVector b, computed as:
Cary Clark2be81cf2018-09-13 12:04:30 -0400376#Formula # (a.fX + b.fX, a.fY + b.fY) ##.
Cary Clarka560c472017-11-27 10:44:06 -0500377
378Can also be used to offset IPoint b by IVector a, returning IPoint.
379Can also be used to add IVector to IVector, returning IVector.
380
381#Param a IPoint or IVector to add to ##
382#Param b IPoint or IVector to add ##
383
384#Return IPoint equal to a offset by b ##
385
386#Example
387#Height 128
Cary Clark0c5f5462017-12-15 11:21:51 -0500388 auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
389 for (size_t i = 0; i < count - 1; ++i) {
390 SkPoint p0, p1;
391 p0.iset(pts[i]);
392 p1.iset(pts[i + 1]);
393 canvas->drawLine(p0, p1, paint);
394 }
395 };
396 SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
397 SkPaint paint;
398 paint.setAntiAlias(true);
399 paint.setStyle(SkPaint::kStroke_Style);
400 canvas->scale(30, 15);
401 draw_lines(points, SK_ARRAY_COUNT(points), paint);
402 SkIPoint mod = {4, 1};
403 for (auto& point : points) {
404 point = point + mod;
405 mod.fX -= 1;
406 mod.fY += 1;
407 }
408 paint.setColor(SK_ColorRED);
409 draw_lines(points, SK_ARRAY_COUNT(points), paint);
Cary Clarka560c472017-11-27 10:44:06 -0500410##
411
412#SeeAlso operator+=(const SkIVector& v)
413
414#Method ##
415
416#Struct SkIPoint ##
417
Cary Clarka560c472017-11-27 10:44:06 -0500418
Cary Clark682c58d2018-05-16 07:07:07 -0400419#Subtopic IVector
420#Line # alias for IPoint ##
Cary Clark137b8742018-05-30 09:21:49 -0400421 #Alias IVector ##
422 #Alias IVectors ##
Cary Clarka560c472017-11-27 10:44:06 -0500423 #Typedef SkIPoint SkIVector
Cary Clark682c58d2018-05-16 07:07:07 -0400424 #Line # alias for IPoint ##
425 #Code
426 typedef SkIPoint SkIVector;
427 ##
428 SkIVector provides an alternative name for SkIPoint. SkIVector and SkIPoint
Cary Clark137b8742018-05-30 09:21:49 -0400429 can be used interchangeably for all purposes.
Cary Clarka560c472017-11-27 10:44:06 -0500430 #Typedef ##
431##
Cary Clark682c58d2018-05-16 07:07:07 -0400432
433#Topic IPoint ##
434